digdig 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +439 -2
- package/digdig.config.example.json +14 -0
- package/dist/claims/deterministic-checks.d.ts +48 -0
- package/dist/claims/deterministic-checks.d.ts.map +1 -0
- package/dist/claims/deterministic-checks.js +162 -0
- package/dist/claims/deterministic-checks.js.map +1 -0
- package/dist/claims/policy.d.ts +25 -0
- package/dist/claims/policy.d.ts.map +1 -0
- package/dist/claims/policy.js +168 -0
- package/dist/claims/policy.js.map +1 -0
- package/dist/claims/store.d.ts +37 -0
- package/dist/claims/store.d.ts.map +1 -0
- package/dist/claims/store.js +152 -0
- package/dist/claims/store.js.map +1 -0
- package/dist/claims/types.d.ts +98 -0
- package/dist/claims/types.d.ts.map +1 -0
- package/dist/claims/types.js +9 -0
- package/dist/claims/types.js.map +1 -0
- package/dist/commands/build-graph.d.ts +8 -0
- package/dist/commands/build-graph.d.ts.map +1 -0
- package/dist/commands/build-graph.js +70 -0
- package/dist/commands/build-graph.js.map +1 -0
- package/dist/commands/claim.d.ts +13 -0
- package/dist/commands/claim.d.ts.map +1 -0
- package/dist/commands/claim.js +131 -0
- package/dist/commands/claim.js.map +1 -0
- package/dist/commands/doc-index.d.ts +12 -0
- package/dist/commands/doc-index.d.ts.map +1 -0
- package/dist/commands/doc-index.js +49 -0
- package/dist/commands/doc-index.js.map +1 -0
- package/dist/commands/doc-search.d.ts +16 -0
- package/dist/commands/doc-search.d.ts.map +1 -0
- package/dist/commands/doc-search.js +41 -0
- package/dist/commands/doc-search.js.map +1 -0
- package/dist/commands/evidence.d.ts +20 -0
- package/dist/commands/evidence.d.ts.map +1 -0
- package/dist/commands/evidence.js +215 -0
- package/dist/commands/evidence.js.map +1 -0
- package/dist/commands/extract.d.ts +10 -0
- package/dist/commands/extract.d.ts.map +1 -0
- package/dist/commands/extract.js +77 -0
- package/dist/commands/extract.js.map +1 -0
- package/dist/commands/graph-add.d.ts +7 -0
- package/dist/commands/graph-add.d.ts.map +1 -0
- package/dist/commands/graph-add.d.ts.sync-conflict-20260629-232900-2SGIW5T.map +1 -0
- package/dist/commands/graph-add.js +93 -0
- package/dist/commands/graph-add.js.map +1 -0
- package/dist/commands/graph-add.js.sync-conflict-20260629-232916-2SGIW5T.map +1 -0
- package/dist/commands/graph-add.sync-conflict-20260629-232853-2SGIW5T.js +163 -0
- package/dist/commands/graph-drill.d.ts +11 -0
- package/dist/commands/graph-drill.d.ts.map +1 -0
- package/dist/commands/graph-drill.js +26 -0
- package/dist/commands/graph-drill.js.map +1 -0
- package/dist/commands/graph-explore.d.ts +10 -0
- package/dist/commands/graph-explore.d.ts.map +1 -0
- package/dist/commands/graph-explore.js +32 -0
- package/dist/commands/graph-explore.js.map +1 -0
- package/dist/commands/graph-obfuscate.d.ts +17 -0
- package/dist/commands/graph-obfuscate.d.ts.map +1 -0
- package/dist/commands/graph-obfuscate.js +110 -0
- package/dist/commands/graph-obfuscate.js.map +1 -0
- package/dist/commands/graph-search.d.ts +11 -0
- package/dist/commands/graph-search.d.ts.map +1 -0
- package/dist/commands/graph-search.js +19 -0
- package/dist/commands/graph-search.js.map +1 -0
- package/dist/commands/graph-traverse.d.ts +10 -0
- package/dist/commands/graph-traverse.d.ts.map +1 -0
- package/dist/commands/graph-traverse.js +39 -0
- package/dist/commands/graph-traverse.js.map +1 -0
- package/dist/commands/json-input.d.ts +18 -0
- package/dist/commands/json-input.d.ts.map +1 -0
- package/dist/commands/json-input.js +50 -0
- package/dist/commands/json-input.js.map +1 -0
- package/dist/commands/query-graph.d.ts +13 -0
- package/dist/commands/query-graph.d.ts.map +1 -0
- package/dist/commands/query-graph.js +219 -0
- package/dist/commands/query-graph.js.map +1 -0
- package/dist/commands/raw.d.ts +14 -0
- package/dist/commands/raw.d.ts.map +1 -0
- package/dist/commands/raw.js +125 -0
- package/dist/commands/raw.js.map +1 -0
- package/dist/commands/results-add.d.ts +10 -0
- package/dist/commands/results-add.d.ts.map +1 -0
- package/dist/commands/results-add.js +80 -0
- package/dist/commands/results-add.js.map +1 -0
- package/dist/commands/review.d.ts +12 -0
- package/dist/commands/review.d.ts.map +1 -0
- package/dist/commands/review.js +119 -0
- package/dist/commands/review.js.map +1 -0
- package/dist/commands/session.d.ts +28 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +149 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/verdict.d.ts +9 -0
- package/dist/commands/verdict.d.ts.map +1 -0
- package/dist/commands/verdict.js +40 -0
- package/dist/commands/verdict.js.map +1 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +148 -0
- package/dist/config.js.map +1 -0
- package/dist/deep/co-occurrence.d.ts +50 -0
- package/dist/deep/co-occurrence.d.ts.map +1 -0
- package/dist/deep/co-occurrence.js +95 -0
- package/dist/deep/co-occurrence.js.map +1 -0
- package/dist/deep/dedupe.d.ts +19 -0
- package/dist/deep/dedupe.d.ts.map +1 -0
- package/dist/deep/dedupe.js +96 -0
- package/dist/deep/dedupe.js.map +1 -0
- package/dist/deep/degree-utils.d.ts +39 -0
- package/dist/deep/degree-utils.d.ts.map +1 -0
- package/dist/deep/degree-utils.js +42 -0
- package/dist/deep/degree-utils.js.map +1 -0
- package/dist/deep/extractor.d.sync-conflict-20260629-232902-2SGIW5T.ts +37 -0
- package/dist/deep/extractor.d.ts +42 -0
- package/dist/deep/extractor.d.ts.map +1 -0
- package/dist/deep/extractor.d.ts.sync-conflict-20260629-232921-2SGIW5T.map +1 -0
- package/dist/deep/extractor.js +392 -0
- package/dist/deep/extractor.js.map +1 -0
- package/dist/deep/extractor.js.sync-conflict-20260629-232921-2SGIW5T.map +1 -0
- package/dist/deep/extractor.sync-conflict-20260629-232903-2SGIW5T.js +203 -0
- package/dist/deep/graph-explore.d.ts +115 -0
- package/dist/deep/graph-explore.d.ts.map +1 -0
- package/dist/deep/graph-explore.js +588 -0
- package/dist/deep/graph-explore.js.map +1 -0
- package/dist/deep/graph-obfuscate.d.ts +51 -0
- package/dist/deep/graph-obfuscate.d.ts.map +1 -0
- package/dist/deep/graph-obfuscate.js +226 -0
- package/dist/deep/graph-obfuscate.js.map +1 -0
- package/dist/deep/graph-preprocess.d.ts +48 -0
- package/dist/deep/graph-preprocess.d.ts.map +1 -0
- package/dist/deep/graph-preprocess.js +40 -0
- package/dist/deep/graph-preprocess.js.map +1 -0
- package/dist/deep/graph-sampling.d.ts +51 -0
- package/dist/deep/graph-sampling.d.ts.map +1 -0
- package/dist/deep/graph-sampling.js +410 -0
- package/dist/deep/graph-sampling.js.map +1 -0
- package/dist/deep/graph.d.sync-conflict-20260629-232917-2SGIW5T.ts +78 -0
- package/dist/deep/graph.d.ts +87 -0
- package/dist/deep/graph.d.ts.map +1 -0
- package/dist/deep/graph.d.ts.sync-conflict-20260629-232911-2SGIW5T.map +1 -0
- package/dist/deep/graph.js +200 -0
- package/dist/deep/graph.js.map +1 -0
- package/dist/deep/graph.js.sync-conflict-20260629-232855-2SGIW5T.map +1 -0
- package/dist/deep/graph.sync-conflict-20260629-232907-2SGIW5T.js +194 -0
- package/dist/deep/index.d.ts +10 -0
- package/dist/deep/index.d.ts.map +1 -0
- package/dist/deep/index.js +10 -0
- package/dist/deep/index.js.map +1 -0
- package/dist/deep/iteration-data.d.ts +38 -0
- package/dist/deep/iteration-data.d.ts.map +1 -0
- package/dist/deep/iteration-data.js +49 -0
- package/dist/deep/iteration-data.js.map +1 -0
- package/dist/deep/keywords.d.ts +27 -0
- package/dist/deep/keywords.d.ts.map +1 -0
- package/dist/deep/keywords.js +293 -0
- package/dist/deep/keywords.js.map +1 -0
- package/dist/deep/local-doc/indexer.d.ts +30 -0
- package/dist/deep/local-doc/indexer.d.ts.map +1 -0
- package/dist/deep/local-doc/indexer.js +402 -0
- package/dist/deep/local-doc/indexer.js.map +1 -0
- package/dist/deep/local-doc/scanner.d.ts +10 -0
- package/dist/deep/local-doc/scanner.d.ts.map +1 -0
- package/dist/deep/local-doc/scanner.js +165 -0
- package/dist/deep/local-doc/scanner.js.map +1 -0
- package/dist/deep/local-doc/searcher.d.ts +38 -0
- package/dist/deep/local-doc/searcher.d.ts.map +1 -0
- package/dist/deep/local-doc/searcher.js +212 -0
- package/dist/deep/local-doc/searcher.js.map +1 -0
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.d.ts +38 -0
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.d.ts.map +1 -0
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.js +212 -0
- package/dist/deep/local-doc/searcher.sync-conflict-20260805-191858-2SGIW5T.js.map +1 -0
- package/dist/deep/local-doc/types.d.ts +61 -0
- package/dist/deep/local-doc/types.d.ts.map +1 -0
- package/dist/deep/local-doc/types.js +18 -0
- package/dist/deep/local-doc/types.js.map +1 -0
- package/dist/deep/path-extraction.d.ts +53 -0
- package/dist/deep/path-extraction.d.ts.map +1 -0
- package/dist/deep/path-extraction.js +229 -0
- package/dist/deep/path-extraction.js.map +1 -0
- package/dist/deep/quality-assess.d.ts +46 -0
- package/dist/deep/quality-assess.d.ts.map +1 -0
- package/dist/deep/quality-assess.js +122 -0
- package/dist/deep/quality-assess.js.map +1 -0
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.d.ts +46 -0
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.d.ts.map +1 -0
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.js +122 -0
- package/dist/deep/quality-assess.sync-conflict-20260728-195206-JAULAPO.js.map +1 -0
- package/dist/deep/query-redundancy.d.ts +52 -0
- package/dist/deep/query-redundancy.d.ts.map +1 -0
- package/dist/deep/query-redundancy.js +122 -0
- package/dist/deep/query-redundancy.js.map +1 -0
- package/dist/deep/query-suggest.d.ts +35 -0
- package/dist/deep/query-suggest.d.ts.map +1 -0
- package/dist/deep/query-suggest.js +98 -0
- package/dist/deep/query-suggest.js.map +1 -0
- package/dist/deep/recovery-analysis.d.ts +60 -0
- package/dist/deep/recovery-analysis.d.ts.map +1 -0
- package/dist/deep/recovery-analysis.js +185 -0
- package/dist/deep/recovery-analysis.js.map +1 -0
- package/dist/deep/rrf.d.ts +13 -0
- package/dist/deep/rrf.d.ts.map +1 -0
- package/dist/deep/rrf.js +23 -0
- package/dist/deep/rrf.js.map +1 -0
- package/dist/deep/search-strategy.d.ts +37 -0
- package/dist/deep/search-strategy.d.ts.map +1 -0
- package/dist/deep/search-strategy.js +106 -0
- package/dist/deep/search-strategy.js.map +1 -0
- package/dist/deep/session.d.sync-conflict-20260629-232917-2SGIW5T.ts +71 -0
- package/dist/deep/session.d.ts +180 -0
- package/dist/deep/session.d.ts.map +1 -0
- package/dist/deep/session.d.ts.sync-conflict-20260629-232921-2SGIW5T.map +1 -0
- package/dist/deep/session.js +643 -0
- package/dist/deep/session.js.map +1 -0
- package/dist/deep/session.js.sync-conflict-20260629-232854-2SGIW5T.map +1 -0
- package/dist/deep/simhash.d.ts +17 -0
- package/dist/deep/simhash.d.ts.map +1 -0
- package/dist/deep/simhash.js +72 -0
- package/dist/deep/simhash.js.map +1 -0
- package/dist/deep/tfidf.d.ts +38 -0
- package/dist/deep/tfidf.d.ts.map +1 -0
- package/dist/deep/tfidf.js +103 -0
- package/dist/deep/tfidf.js.map +1 -0
- package/dist/deepseek-service.d.ts +22 -0
- package/dist/deepseek-service.d.ts.map +1 -0
- package/dist/deepseek-service.js +80 -0
- package/dist/deepseek-service.js.map +1 -0
- package/dist/entry.d.ts +9 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +24 -0
- package/dist/entry.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +16 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +143 -0
- package/dist/init.js.map +1 -0
- package/dist/legacy.d.ts +60 -0
- package/dist/legacy.d.ts.map +1 -0
- package/dist/legacy.js +119 -0
- package/dist/legacy.js.map +1 -0
- package/dist/ollama-service.d.ts +22 -0
- package/dist/ollama-service.d.ts.map +1 -0
- package/dist/ollama-service.js +50 -0
- package/dist/ollama-service.js.map +1 -0
- package/dist/protocol.d.ts +23 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +26 -0
- package/dist/protocol.js.map +1 -0
- package/dist/runCli.d.ts +8 -0
- package/dist/runCli.d.ts.map +1 -0
- package/dist/runCli.d.ts.sync-conflict-20260629-232854-2SGIW5T.map +1 -0
- package/dist/runCli.js +1564 -0
- package/dist/runCli.js.map +1 -0
- package/dist/runCli.js.sync-conflict-20260629-232857-2SGIW5T.map +1 -0
- package/dist/runCli.sync-conflict-20260629-232915-2SGIW5T.js +1109 -0
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.d.ts +8 -0
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.d.ts.map +1 -0
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.js +1111 -0
- package/dist/runCli.sync-conflict-20260629-233530-JAULAPO.js.map +1 -0
- package/dist/service.d.ts +63 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +139 -0
- package/dist/service.js.map +1 -0
- package/dist/sxng.d.ts +11 -0
- package/dist/sxng.d.ts.map +1 -0
- package/dist/sxng.js +14 -0
- package/dist/sxng.js.map +1 -0
- package/package.json +56 -12
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query redundancy detection via Jaccard similarity.
|
|
3
|
+
*
|
|
4
|
+
* Before executing a new query, compare it against all historical queries
|
|
5
|
+
* in the session. If similarity exceeds a threshold, take action:
|
|
6
|
+
* - warn: output warning, proceed with search
|
|
7
|
+
* - adjust: auto-remove overlapping terms, add differentiation
|
|
8
|
+
* - skip: skip redundant query entirely
|
|
9
|
+
*
|
|
10
|
+
* Short queries (≤2 words) use character-level bigram Jaccard to avoid
|
|
11
|
+
* low similarity from minor word differences. Longer queries use word-level Jaccard.
|
|
12
|
+
*
|
|
13
|
+
* Since bigram and word Jaccard have different sensitivity scales, each algorithm
|
|
14
|
+
* uses its own threshold (jaccardThreshold for word-level, bigramThreshold for bigram).
|
|
15
|
+
* This prevents short queries from being systematically under-detected.
|
|
16
|
+
*/
|
|
17
|
+
export interface RedundancyConfig {
|
|
18
|
+
jaccardThreshold: number;
|
|
19
|
+
bigramThreshold?: number;
|
|
20
|
+
action: 'warn' | 'adjust' | 'skip';
|
|
21
|
+
}
|
|
22
|
+
export interface JaccardResult {
|
|
23
|
+
score: number;
|
|
24
|
+
algorithm: 'bigram' | 'word';
|
|
25
|
+
}
|
|
26
|
+
export interface RedundancyResult {
|
|
27
|
+
isRedundant: boolean;
|
|
28
|
+
maxSimilarity: number;
|
|
29
|
+
similarQueries: Array<{
|
|
30
|
+
query: string;
|
|
31
|
+
similarity: number;
|
|
32
|
+
}>;
|
|
33
|
+
adjustedQuery?: string;
|
|
34
|
+
action: RedundancyConfig['action'];
|
|
35
|
+
}
|
|
36
|
+
/** Compute Jaccard similarity between two queries with algorithm metadata.
|
|
37
|
+
* - ≤2 words: character-level bigram Jaccard (case-insensitive)
|
|
38
|
+
* - >2 words: word-level Jaccard (case-insensitive) */
|
|
39
|
+
export declare function computeJaccardWithMeta(a: string, b: string): JaccardResult;
|
|
40
|
+
/** Compute Jaccard similarity between two queries (score only, backward-compatible). */
|
|
41
|
+
export declare function computeJaccard(a: string, b: string): number;
|
|
42
|
+
/** Adjust a redundant query by removing overlapping terms and adding differentiation.
|
|
43
|
+
* Returns the adjusted query string, or the original if no adjustment is possible. */
|
|
44
|
+
export declare function adjustQuery(newQuery: string, similarQueries: Array<{
|
|
45
|
+
query: string;
|
|
46
|
+
similarity: number;
|
|
47
|
+
}>): string;
|
|
48
|
+
/** Check a new query against session history for redundancy.
|
|
49
|
+
* Uses algorithm-aware thresholding: word-level comparisons use jaccardThreshold,
|
|
50
|
+
* bigram comparisons use bigramThreshold (falls back to jaccardThreshold if unset). */
|
|
51
|
+
export declare function checkQueryRedundancy(newQuery: string, sessionHistory: string[], config: RedundancyConfig): RedundancyResult;
|
|
52
|
+
//# sourceMappingURL=query-redundancy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-redundancy.d.ts","sourceRoot":"","sources":["../../src/deep/query-redundancy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,MAAM,WAAW,gBAAgB;IAC7B,gBAAgB,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;CACtC;AAED,MAAM,WAAW,aAAa;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,QAAQ,GAAG,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAC7B,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;CACtC;AA6BD;;wDAEwD;AACxD,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,aAAa,CAoB1E;AAED,wFAAwF;AACxF,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAE3D;AAID;uFACuF;AACvF,wBAAgB,WAAW,CACvB,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC,GAC7D,MAAM,CAwBR;AAID;;wFAEwF;AACxF,wBAAgB,oBAAoB,CAChC,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,MAAM,EAAE,EACxB,MAAM,EAAE,gBAAgB,GACzB,gBAAgB,CA8BlB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query redundancy detection via Jaccard similarity.
|
|
3
|
+
*
|
|
4
|
+
* Before executing a new query, compare it against all historical queries
|
|
5
|
+
* in the session. If similarity exceeds a threshold, take action:
|
|
6
|
+
* - warn: output warning, proceed with search
|
|
7
|
+
* - adjust: auto-remove overlapping terms, add differentiation
|
|
8
|
+
* - skip: skip redundant query entirely
|
|
9
|
+
*
|
|
10
|
+
* Short queries (≤2 words) use character-level bigram Jaccard to avoid
|
|
11
|
+
* low similarity from minor word differences. Longer queries use word-level Jaccard.
|
|
12
|
+
*
|
|
13
|
+
* Since bigram and word Jaccard have different sensitivity scales, each algorithm
|
|
14
|
+
* uses its own threshold (jaccardThreshold for word-level, bigramThreshold for bigram).
|
|
15
|
+
* This prevents short queries from being systematically under-detected.
|
|
16
|
+
*/
|
|
17
|
+
// ── Jaccard computation ───────────────────────────────────────────
|
|
18
|
+
/** Generate character-level bigrams from a string. */
|
|
19
|
+
function charBigrams(s) {
|
|
20
|
+
const bigrams = new Set();
|
|
21
|
+
for (let i = 0; i < s.length - 1; i++) {
|
|
22
|
+
bigrams.add(s.slice(i, i + 2));
|
|
23
|
+
}
|
|
24
|
+
return bigrams;
|
|
25
|
+
}
|
|
26
|
+
/** Compute Jaccard similarity between two sets. */
|
|
27
|
+
function setJaccard(a, b) {
|
|
28
|
+
if (a.size === 0 && b.size === 0)
|
|
29
|
+
return 0;
|
|
30
|
+
let intersection = 0;
|
|
31
|
+
for (const item of a) {
|
|
32
|
+
if (b.has(item))
|
|
33
|
+
intersection++;
|
|
34
|
+
}
|
|
35
|
+
const union = a.size + b.size - intersection;
|
|
36
|
+
return union === 0 ? 0 : intersection / union;
|
|
37
|
+
}
|
|
38
|
+
/** Count words in a string (split by whitespace). */
|
|
39
|
+
function wordCount(s) {
|
|
40
|
+
return s.trim().split(/\s+/).filter(Boolean).length;
|
|
41
|
+
}
|
|
42
|
+
/** Compute Jaccard similarity between two queries with algorithm metadata.
|
|
43
|
+
* - ≤2 words: character-level bigram Jaccard (case-insensitive)
|
|
44
|
+
* - >2 words: word-level Jaccard (case-insensitive) */
|
|
45
|
+
export function computeJaccardWithMeta(a, b) {
|
|
46
|
+
const aLower = a.toLowerCase().trim();
|
|
47
|
+
const bLower = b.toLowerCase().trim();
|
|
48
|
+
if (aLower === bLower) {
|
|
49
|
+
return { score: aLower.length > 0 ? 1 : 0, algorithm: 'word' };
|
|
50
|
+
}
|
|
51
|
+
if (wordCount(a) <= 2 || wordCount(b) <= 2) {
|
|
52
|
+
// Short query: character-level bigram Jaccard
|
|
53
|
+
const bgA = charBigrams(aLower);
|
|
54
|
+
const bgB = charBigrams(bLower);
|
|
55
|
+
if (bgA.size === 0 || bgB.size === 0)
|
|
56
|
+
return { score: 0, algorithm: 'bigram' };
|
|
57
|
+
return { score: setJaccard(bgA, bgB), algorithm: 'bigram' };
|
|
58
|
+
}
|
|
59
|
+
// Long query: word-level Jaccard
|
|
60
|
+
const setA = new Set(aLower.split(/\s+/).filter(Boolean));
|
|
61
|
+
const setB = new Set(bLower.split(/\s+/).filter(Boolean));
|
|
62
|
+
return { score: setJaccard(setA, setB), algorithm: 'word' };
|
|
63
|
+
}
|
|
64
|
+
/** Compute Jaccard similarity between two queries (score only, backward-compatible). */
|
|
65
|
+
export function computeJaccard(a, b) {
|
|
66
|
+
return computeJaccardWithMeta(a, b).score;
|
|
67
|
+
}
|
|
68
|
+
// ── Query adjustment ──────────────────────────────────────────────
|
|
69
|
+
/** Adjust a redundant query by removing overlapping terms and adding differentiation.
|
|
70
|
+
* Returns the adjusted query string, or the original if no adjustment is possible. */
|
|
71
|
+
export function adjustQuery(newQuery, similarQueries) {
|
|
72
|
+
const newWords = newQuery.toLowerCase().split(/\s+/).filter(Boolean);
|
|
73
|
+
// Collect all overlapping words from similar queries
|
|
74
|
+
const overlappingWords = new Set();
|
|
75
|
+
for (const sq of similarQueries) {
|
|
76
|
+
const sqWords = sq.query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
77
|
+
for (const w of sqWords) {
|
|
78
|
+
if (newWords.includes(w)) {
|
|
79
|
+
overlappingWords.add(w);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Keep non-overlapping words
|
|
84
|
+
const keptWords = newQuery.split(/\s+/).filter(w => !overlappingWords.has(w.toLowerCase()));
|
|
85
|
+
if (keptWords.length === 0) {
|
|
86
|
+
// All words overlap — can't adjust, return original
|
|
87
|
+
return newQuery;
|
|
88
|
+
}
|
|
89
|
+
// Add a differentiation marker to signal this is a refined query
|
|
90
|
+
return keptWords.join(' ');
|
|
91
|
+
}
|
|
92
|
+
// ── Main redundancy check ────────────────────────────────────────
|
|
93
|
+
/** Check a new query against session history for redundancy.
|
|
94
|
+
* Uses algorithm-aware thresholding: word-level comparisons use jaccardThreshold,
|
|
95
|
+
* bigram comparisons use bigramThreshold (falls back to jaccardThreshold if unset). */
|
|
96
|
+
export function checkQueryRedundancy(newQuery, sessionHistory, config) {
|
|
97
|
+
const similarQueries = [];
|
|
98
|
+
const bigramThreshold = config.bigramThreshold ?? config.jaccardThreshold;
|
|
99
|
+
let maxSimilarity = 0;
|
|
100
|
+
for (const pastQuery of sessionHistory) {
|
|
101
|
+
const { score, algorithm } = computeJaccardWithMeta(newQuery, pastQuery);
|
|
102
|
+
const threshold = algorithm === 'bigram' ? bigramThreshold : config.jaccardThreshold;
|
|
103
|
+
if (score >= threshold) {
|
|
104
|
+
similarQueries.push({ query: pastQuery, similarity: score });
|
|
105
|
+
}
|
|
106
|
+
if (score > maxSimilarity) {
|
|
107
|
+
maxSimilarity = score;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const isRedundant = similarQueries.length > 0;
|
|
111
|
+
const result = {
|
|
112
|
+
isRedundant,
|
|
113
|
+
maxSimilarity,
|
|
114
|
+
similarQueries,
|
|
115
|
+
action: config.action,
|
|
116
|
+
};
|
|
117
|
+
if (isRedundant && config.action === 'adjust') {
|
|
118
|
+
result.adjustedQuery = adjustQuery(newQuery, similarQueries);
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=query-redundancy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-redundancy.js","sourceRoot":"","sources":["../../src/deep/query-redundancy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAuBH,qEAAqE;AAErE,sDAAsD;AACtD,SAAS,WAAW,CAAC,CAAS;IAC1B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,mDAAmD;AACnD,SAAS,UAAU,CAAI,CAAS,EAAE,CAAS;IACvC,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,CAAC,CAAC;IAC3C,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,KAAK,MAAM,IAAI,IAAI,CAAC,EAAE,CAAC;QACnB,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,YAAY,EAAE,CAAC;IACpC,CAAC;IACD,MAAM,KAAK,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,YAAY,CAAC;IAC7C,OA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AC,aAAa,GAAG,WAAW,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IACjE,CAAC;IAED,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query suggestion data generation for deep search sessions.
|
|
3
|
+
*
|
|
4
|
+
* CLI outputs analysis data (entities, domains, history, quality)
|
|
5
|
+
* for Agent to use when generating follow-up queries.
|
|
6
|
+
* CLI does NOT auto-generate queries — Agent controls LLM interaction.
|
|
7
|
+
*/
|
|
8
|
+
import { DirectedGraph } from 'graphology';
|
|
9
|
+
import { GraphNodeAttrs, GraphEdgeAttrs } from './graph.js';
|
|
10
|
+
import { SessionResult } from './session.js';
|
|
11
|
+
import { QualityScore } from './quality-assess.js';
|
|
12
|
+
export interface TopEntity {
|
|
13
|
+
label: string;
|
|
14
|
+
obfuscatedLabel?: string;
|
|
15
|
+
degree: number;
|
|
16
|
+
frequency: number;
|
|
17
|
+
entityType?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface RoundHistoryEntry {
|
|
20
|
+
round: number;
|
|
21
|
+
query: string;
|
|
22
|
+
resultCount: number;
|
|
23
|
+
}
|
|
24
|
+
export type SearchStage = 'broad_exploration' | 'targeted_deep_dive';
|
|
25
|
+
export interface QuerySuggestionData {
|
|
26
|
+
topEntities: TopEntity[];
|
|
27
|
+
unexploredDomains: string[];
|
|
28
|
+
currentStage: SearchStage;
|
|
29
|
+
roundHistory: RoundHistoryEntry[];
|
|
30
|
+
qualityLastRound?: QualityScore;
|
|
31
|
+
}
|
|
32
|
+
/** Generate query suggestion data from session context.
|
|
33
|
+
* Returns analysis for Agent — CLI does NOT auto-generate queries. */
|
|
34
|
+
export declare function generateQuerySuggestions(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, sessionResults: SessionResult[], currentStage: SearchStage, qualityLastRound?: QualityScore): QuerySuggestionData;
|
|
35
|
+
//# sourceMappingURL=query-suggest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-suggest.d.ts","sourceRoot":"","sources":["../../src/deep/query-suggest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD,MAAM,WAAW,SAAS;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,WAAW,GAAG,mBAAmB,GAAG,oBAAoB,CAAC;AAErE,MAAM,WAAW,mBAAmB;IAChC,WAAW,EAAE,SAAS,EAAE,CAAC;IACzB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,YAAY,EAAE,WAAW,CAAC;IAC1B,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAClC,gBAAgB,CAAC,EAAE,YAAY,CAAC;CACnC;AA8BD;uEACuE;AACvE,wBAAgB,wBAAwB,CACpC,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,EACpD,cAAc,EAAE,aAAa,EAAE,EAC/B,YAAY,EAAE,WAAW,EACzB,gBAAgB,CAAC,EAAE,YAAY,GAChC,mBAAmB,CAsBrB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query suggestion data generation for deep search sessions.
|
|
3
|
+
*
|
|
4
|
+
* CLI outputs analysis data (entities, domains, history, quality)
|
|
5
|
+
* for Agent to use when generating follow-up queries.
|
|
6
|
+
* CLI does NOT auto-generate queries — Agent controls LLM interaction.
|
|
7
|
+
*/
|
|
8
|
+
import { getEntityDegree } from './degree-utils.js';
|
|
9
|
+
// ── Domain extraction ─────────────────────────────────────────────
|
|
10
|
+
/** Known specialized domains for deep-dive search */
|
|
11
|
+
const SPECIALIZED_DOMAINS = [
|
|
12
|
+
'arxiv.org',
|
|
13
|
+
'semanticscholar.org',
|
|
14
|
+
'github.com',
|
|
15
|
+
'stackoverflow.com',
|
|
16
|
+
'docs.rs',
|
|
17
|
+
'npmjs.com',
|
|
18
|
+
'pypi.org',
|
|
19
|
+
'crates.io',
|
|
20
|
+
'medium.com',
|
|
21
|
+
'dev.to',
|
|
22
|
+
'reddit.com',
|
|
23
|
+
'hackernews.com',
|
|
24
|
+
];
|
|
25
|
+
function extractDomain(url) {
|
|
26
|
+
try {
|
|
27
|
+
return new URL(url).hostname;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// ── Suggestion generation ─────────────────────────────────────────
|
|
34
|
+
/** Generate query suggestion data from session context.
|
|
35
|
+
* Returns analysis for Agent — CLI does NOT auto-generate queries. */
|
|
36
|
+
export function generateQuerySuggestions(graph, sessionResults, currentStage, qualityLastRound) {
|
|
37
|
+
// Collect top entities sorted by degree × frequency descending
|
|
38
|
+
const topEntities = collectTopEntities(graph);
|
|
39
|
+
// Detect unexplored domains
|
|
40
|
+
const exploredDomains = new Set();
|
|
41
|
+
for (const r of sessionResults) {
|
|
42
|
+
const domain = extractDomain(r.url);
|
|
43
|
+
if (domain)
|
|
44
|
+
exploredDomains.add(domain);
|
|
45
|
+
}
|
|
46
|
+
const unexploredDomains = SPECIALIZED_DOMAINS.filter(d => !exploredDomains.has(d));
|
|
47
|
+
// Build round history from query nodes in graph
|
|
48
|
+
const roundHistory = buildRoundHistory(graph, sessionResults);
|
|
49
|
+
return {
|
|
50
|
+
topEntities,
|
|
51
|
+
unexploredDomains,
|
|
52
|
+
currentStage,
|
|
53
|
+
roundHistory,
|
|
54
|
+
qualityLastRound,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** Collect entity nodes sorted by degree × frequency descending */
|
|
58
|
+
function collectTopEntities(graph) {
|
|
59
|
+
const entities = [];
|
|
60
|
+
graph.forEachNode((node, attrs) => {
|
|
61
|
+
if (attrs.type !== 'entity')
|
|
62
|
+
return;
|
|
63
|
+
const degree = getEntityDegree(graph, node);
|
|
64
|
+
const frequency = attrs.frequency ?? 1;
|
|
65
|
+
entities.push({
|
|
66
|
+
label: attrs.label,
|
|
67
|
+
obfuscatedLabel: attrs.obfuscatedLabel,
|
|
68
|
+
degree,
|
|
69
|
+
frequency,
|
|
70
|
+
entityType: attrs.entityType,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
// Sort by degree × frequency descending
|
|
74
|
+
return entities.sort((a, b) => (b.degree * b.frequency) - (a.degree * a.frequency));
|
|
75
|
+
}
|
|
76
|
+
/** Build round history from query nodes in graph */
|
|
77
|
+
function buildRoundHistory(graph, sessionResults) {
|
|
78
|
+
const entries = [];
|
|
79
|
+
graph.forEachNode((node, attrs) => {
|
|
80
|
+
if (attrs.type !== 'query' || !attrs.query)
|
|
81
|
+
return;
|
|
82
|
+
// Count results yielded by this query via edges
|
|
83
|
+
let resultCount = 0;
|
|
84
|
+
graph.forEachOutNeighbor(node, (neighbor) => {
|
|
85
|
+
const nAttrs = graph.getNodeAttributes(neighbor);
|
|
86
|
+
if (nAttrs.type === 'result')
|
|
87
|
+
resultCount++;
|
|
88
|
+
});
|
|
89
|
+
entries.push({
|
|
90
|
+
round: attrs.round ?? entries.length + 1,
|
|
91
|
+
query: attrs.query,
|
|
92
|
+
resultCount,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
// Sort by round number
|
|
96
|
+
return entries.sort((a, b) => a.round - b.round);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=query-suggest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-suggest.js","sourceRoot":"","sources":["../../src/deep/query-suggest.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AA6BpD,qEAAqE;AAErE,qDAAqD;AACrD,MAAM,mBAAmB,GAAG;IACxB,WAAW;IACX,qBAAqB;IACrB,YAAY;IACZ,mBAAmB;IACnB,SAAS;IACT,WAAW;IACX,UAAU;IACV,WAAW;IACX,YAAY;IACZ,QAAQ;IACR,YAAY;IACZ,gBAAgB;CACnB,CAAC;AAEF,SAAS,aAAa,CAAC,GAAW;IAC9B,IAAI,CAAC;QACD,OAAO,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC;AAED,qEAAqE;AAErE;uEACuE;AACvE,MAAM,UAAU,wBAAwB,CACpC,KAAoD,EACpD,cAA+B,EAC/B,YAAyB,EACzB,gBAA+B;IAE/B,+DAA+D;IAC/D,MAAM,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAE9C,4BAA4B;IAC5B,MAAM,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;IAC1C,KAAK,MAAM,CAAC,IAAI,cAAc,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACpC,IAAI,MAAM;YAAE,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,iBAAiB,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAEnF,gDAAgD;IAChD,MAAM,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QACpB,KAAK,CAAC,kBAAkB,CAAC,IAAI,EAAE,CAAC,QAAgB,EAAE,EAAE;YAChD,MAAM,MAAM,GAAG,KAAK,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;YACjD,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ;gBAAE,WAAW,EAAE,CAAC;QAChD,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,IAAI,CAAC;YACT,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;YACxC,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,WAAW;SACd,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,uBAAuB;IACvB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recovery analysis for deep search sessions.
|
|
3
|
+
*
|
|
4
|
+
* When search quality is poor, analyze the session and suggest recovery
|
|
5
|
+
* strategies for the Agent. CLI outputs analysis data only — Agent decides.
|
|
6
|
+
*
|
|
7
|
+
* Recovery strategies:
|
|
8
|
+
* - reformulate: query too specific → remove qualifiers or use broader terms
|
|
9
|
+
* - engine_rotation: current engines not covering sources → try different engines
|
|
10
|
+
* - category_shift: category results poor → switch category
|
|
11
|
+
* - backtrack: ≥2 consecutive poor rounds → return to last successful query direction
|
|
12
|
+
*/
|
|
13
|
+
import { DirectedGraph } from 'graphology';
|
|
14
|
+
import { GraphNodeAttrs, GraphEdgeAttrs } from './graph.js';
|
|
15
|
+
import { SessionResult } from './session.js';
|
|
16
|
+
import { QualityScore, QualityThresholds } from './quality-assess.js';
|
|
17
|
+
import { StrategyConfig } from './search-strategy.js';
|
|
18
|
+
export type RecoveryStrategy = 'reformulate' | 'engine_rotation' | 'category_shift' | 'backtrack';
|
|
19
|
+
export interface RecoveryStrategyInfo {
|
|
20
|
+
strategy: RecoveryStrategy;
|
|
21
|
+
reason: string;
|
|
22
|
+
suggestion: string;
|
|
23
|
+
backtrackTo?: {
|
|
24
|
+
round: number;
|
|
25
|
+
query: string;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export interface RoundQuality {
|
|
29
|
+
round: number;
|
|
30
|
+
query: string;
|
|
31
|
+
verdict: QualityScore['verdict'];
|
|
32
|
+
failedIndicators: string[];
|
|
33
|
+
}
|
|
34
|
+
export interface RecoveryAnalysis {
|
|
35
|
+
qualityScore: QualityScore;
|
|
36
|
+
recentFailures: number;
|
|
37
|
+
availableStrategies: RecoveryStrategyInfo[];
|
|
38
|
+
lastSuccessfulRound: {
|
|
39
|
+
round: number;
|
|
40
|
+
query: string;
|
|
41
|
+
quality: string;
|
|
42
|
+
} | null;
|
|
43
|
+
roundQualityHistory: RoundQuality[];
|
|
44
|
+
}
|
|
45
|
+
/** Build per-round quality history from the session graph and results.
|
|
46
|
+
* Each query node in the graph represents a round. We assess quality
|
|
47
|
+
* of results yielded by that query against the accumulated results up
|
|
48
|
+
* to that round. */
|
|
49
|
+
export declare function buildRoundQualityHistory(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, sessionResults: SessionResult[], qualityThresholds?: Partial<QualityThresholds>): RoundQuality[];
|
|
50
|
+
/** Analyze recovery options for a session with poor quality results.
|
|
51
|
+
* Returns available strategies with reasons and suggestions. */
|
|
52
|
+
export declare function analyzeRecoveryOptions(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>, sessionResults: SessionResult[], qualityScore: QualityScore, config?: Partial<StrategyConfig>): RecoveryAnalysis;
|
|
53
|
+
/** Backtrack via graph traversal: find the query node that yielded
|
|
54
|
+
* the most results connected to high-degree entity nodes.
|
|
55
|
+
* Returns the query and round to backtrack to. */
|
|
56
|
+
export declare function backtrackToBestQuery(graph: DirectedGraph<GraphNodeAttrs, GraphEdgeAttrs>): {
|
|
57
|
+
round: number;
|
|
58
|
+
query: string;
|
|
59
|
+
} | null;
|
|
60
|
+
//# sourceMappingURL=recovery-analysis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery-analysis.d.ts","sourceRoot":"","sources":["../../src/deep/recovery-analysis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAuB,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,MAAM,MAAM,gBAAgB,GAAG,aAAa,GAAG,iBAAiB,GAAG,gBAAgB,GAAG,WAAW,CAAC;AAElG,MAAM,WAAW,oBAAoB;IACjC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CAClD;AAED,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,YAAY,CAAC,SAAS,CAAC,CAAC;IACjC,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC9B;AAED,MAAM,WAAW,gBAAgB;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,mBAAmB,EAAE,oBAAoB,EAAE,CAAC;IAC5C,mBAAmB,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC9E,mBAAmB,EAAE,YAAY,EAAE,CAAC;CACvC;AAID;;;qBAGqB;AACrB,wBAAgB,wBAAwB,CACpC,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,EACpD,cAAc,EAAE,aAAa,EAAE,EAC/B,iBAAiB,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAC/C,YAAY,EAAE,CAgDhB;AAID;iEACiE;AACjE,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,EACpD,cAAc,EAAE,aAAa,EAAE,EAC/B,YAAY,EAAE,YAAY,EAC1B,MAAM,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GACjC,gBAAgB,CA4ElB;AAoBD;;mDAEmD;AACnD,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,aAAa,CAAC,cAAc,EAAE,cAAc,CAAC,GACrD;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAwCzC"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recovery analysis for deep search sessions.
|
|
3
|
+
*
|
|
4
|
+
* When search quality is poor, analyze the session and suggest recovery
|
|
5
|
+
* strategies for the Agent. CLI outputs analysis data only — Agent decides.
|
|
6
|
+
*
|
|
7
|
+
* Recovery strategies:
|
|
8
|
+
* - reformulate: query too specific → remove qualifiers or use broader terms
|
|
9
|
+
* - engine_rotation: current engines not covering sources → try different engines
|
|
10
|
+
* - category_shift: category results poor → switch category
|
|
11
|
+
* - backtrack: ≥2 consecutive poor rounds → return to last successful query direction
|
|
12
|
+
*/
|
|
13
|
+
import { assessResultQuality } from './quality-assess.js';
|
|
14
|
+
// ── Quality history per round ─────────────────────────────────────
|
|
15
|
+
/** Build per-round quality history from the session graph and results.
|
|
16
|
+
* Each query node in the graph represents a round. We assess quality
|
|
17
|
+
* of results yielded by that query against the accumulated results up
|
|
18
|
+
* to that round. */
|
|
19
|
+
export function buildRoundQualityHistory(graph, sessionResults, qualityThresholds) {
|
|
20
|
+
// Collect query nodes sorted by round
|
|
21
|
+
const queryNodes = [];
|
|
22
|
+
graph.forEachNode((node, attrs) => {
|
|
23
|
+
if (attrs.type === 'query' && attrs.query) {
|
|
24
|
+
queryNodes.push({ id: node, round: attrs.round ?? 0, query: attrs.query });
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
queryNodes.sort((a, b) => a.round - b.round);
|
|
28
|
+
if (queryNodes.length === 0)
|
|
29
|
+
return [];
|
|
30
|
+
const history = [];
|
|
31
|
+
const seenUrls = new Set();
|
|
32
|
+
for (const qNode of queryNodes) {
|
|
33
|
+
// Collect result URLs yielded by this query
|
|
34
|
+
const roundResultUrls = new Set();
|
|
35
|
+
graph.forEachOutNeighbor(qNode.id, (neighbor) => {
|
|
36
|
+
const nAttrs = graph.getNodeAttributes(neighbor);
|
|
37
|
+
if (nAttrs.type === 'result' && nAttrs.url) {
|
|
38
|
+
roundResultUrls.add(nAttrs.url);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
// Get SessionResult objects for these URLs
|
|
42
|
+
const roundResults = sessionResults.filter(r => roundResultUrls.has(r.url));
|
|
43
|
+
// Prior results are all results seen before this round
|
|
44
|
+
const priorResults = sessionResults.filter(r => seenUrls.has(r.url));
|
|
45
|
+
// Assess quality of this round's results
|
|
46
|
+
const quality = assessResultQuality(roundResults, priorResults, qualityThresholds);
|
|
47
|
+
history.push({
|
|
48
|
+
round: qNode.round,
|
|
49
|
+
query: qNode.query,
|
|
50
|
+
verdict: quality.verdict,
|
|
51
|
+
failedIndicators: quality.failedIndicators,
|
|
52
|
+
});
|
|
53
|
+
// Mark these URLs as seen for subsequent rounds
|
|
54
|
+
for (const url of roundResultUrls) {
|
|
55
|
+
seenUrls.add(url);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return history;
|
|
59
|
+
}
|
|
60
|
+
// ── Recovery analysis ─────────────────────────────────────────────
|
|
61
|
+
/** Analyze recovery options for a session with poor quality results.
|
|
62
|
+
* Returns available strategies with reasons and suggestions. */
|
|
63
|
+
export function analyzeRecoveryOptions(graph, sessionResults, qualityScore, config) {
|
|
64
|
+
const history = buildRoundQualityHistory(graph, sessionResults);
|
|
65
|
+
// Count consecutive poor/acceptable rounds from the end
|
|
66
|
+
let recentFailures = 0;
|
|
67
|
+
for (let i = history.length - 1; i >= 0; i--) {
|
|
68
|
+
if (history[i].verdict === 'poor') {
|
|
69
|
+
recentFailures++;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// Find last successful round (good verdict)
|
|
76
|
+
const lastSuccessfulRound = findLastSuccessfulRound(history);
|
|
77
|
+
// Build available strategies
|
|
78
|
+
const strategies = [];
|
|
79
|
+
// Reformulate: suggest when contentDepth failed
|
|
80
|
+
if (qualityScore.failedIndicators.includes('contentDepth')) {
|
|
81
|
+
strategies.push({
|
|
82
|
+
strategy: 'reformulate',
|
|
83
|
+
reason: '查询过于具体或范围过窄,可能需要简化',
|
|
84
|
+
suggestion: '移除限定词或尝试更宽泛的表达',
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
// Engine rotation: suggest when sourceDiversity failed
|
|
88
|
+
if (qualityScore.failedIndicators.includes('sourceDiversity')) {
|
|
89
|
+
strategies.push({
|
|
90
|
+
strategy: 'engine_rotation',
|
|
91
|
+
reason: '当前引擎组合可能未覆盖相关来源',
|
|
92
|
+
suggestion: '尝试不同引擎组合(如从 google 切换到 duckduckgo 或添加专业引擎)',
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// Category shift: suggest when novelty failed
|
|
96
|
+
if (qualityScore.failedIndicators.includes('novelty')) {
|
|
97
|
+
strategies.push({
|
|
98
|
+
strategy: 'category_shift',
|
|
99
|
+
reason: '当前分类结果不佳或结果重复',
|
|
100
|
+
suggestion: '切换到更宽泛或不同分类(如从 science 切换到 general 或 it)',
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
// Backtrack: suggest when ≥2 consecutive poor rounds
|
|
104
|
+
if (recentFailures >= 2 && lastSuccessfulRound) {
|
|
105
|
+
strategies.push({
|
|
106
|
+
strategy: 'backtrack',
|
|
107
|
+
reason: `连续 ${recentFailures} 轮质量不佳`,
|
|
108
|
+
suggestion: '回到较早成功的查询方向分支',
|
|
109
|
+
backtrackTo: {
|
|
110
|
+
round: lastSuccessfulRound.round,
|
|
111
|
+
query: lastSuccessfulRound.query,
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// If no strategies were triggered but verdict is still poor/acceptable,
|
|
116
|
+
// add a generic reformulate strategy
|
|
117
|
+
if (strategies.length === 0 && qualityScore.verdict !== 'good') {
|
|
118
|
+
strategies.push({
|
|
119
|
+
strategy: 'reformulate',
|
|
120
|
+
reason: '搜索结果未达标',
|
|
121
|
+
suggestion: '尝试调整查询表达或更换搜索方向',
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
qualityScore,
|
|
126
|
+
recentFailures,
|
|
127
|
+
availableStrategies: strategies,
|
|
128
|
+
lastSuccessfulRound,
|
|
129
|
+
roundQualityHistory: history,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// ── Helpers ───────────────────────────────────────────────────────
|
|
133
|
+
/** Find the last round with 'good' verdict in quality history. */
|
|
134
|
+
function findLastSuccessfulRound(history) {
|
|
135
|
+
for (let i = history.length - 1; i >= 0; i--) {
|
|
136
|
+
if (history[i].verdict === 'good') {
|
|
137
|
+
return {
|
|
138
|
+
round: history[i].round,
|
|
139
|
+
query: history[i].query,
|
|
140
|
+
quality: 'good',
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
/** Backtrack via graph traversal: find the query node that yielded
|
|
147
|
+
* the most results connected to high-degree entity nodes.
|
|
148
|
+
* Returns the query and round to backtrack to. */
|
|
149
|
+
export function backtrackToBestQuery(graph) {
|
|
150
|
+
const queryScores = [];
|
|
151
|
+
graph.forEachNode((node, attrs) => {
|
|
152
|
+
if (attrs.type !== 'query' || !attrs.query)
|
|
153
|
+
return;
|
|
154
|
+
let score = 0;
|
|
155
|
+
let resultCount = 0;
|
|
156
|
+
// Walk query → result → entity and sum entity degrees
|
|
157
|
+
graph.forEachOutNeighbor(node, (resultNode) => {
|
|
158
|
+
const rAttrs = graph.getNodeAttributes(resultNode);
|
|
159
|
+
if (rAttrs.type !== 'result')
|
|
160
|
+
return;
|
|
161
|
+
resultCount++;
|
|
162
|
+
graph.forEachInNeighbor(resultNode, (entityNode) => {
|
|
163
|
+
const eAttrs = graph.getNodeAttributes(entityNode);
|
|
164
|
+
if (eAttrs.type === 'entity') {
|
|
165
|
+
score += graph.inDegree(entityNode) + graph.outDegree(entityNode);
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
queryScores.push({
|
|
170
|
+
id: node,
|
|
171
|
+
query: attrs.query,
|
|
172
|
+
round: attrs.round ?? 0,
|
|
173
|
+
score: resultCount > 0 ? score / resultCount : 0,
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
if (queryScores.length === 0)
|
|
177
|
+
return null;
|
|
178
|
+
// Sort by score descending, then by round ascending (prefer earlier on tie)
|
|
179
|
+
queryScores.sort((a, b) => b.score - a.score || a.round - b.round);
|
|
180
|
+
return {
|
|
181
|
+
round: queryScores[0].round,
|
|
182
|
+
query: queryScores[0].query,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=recovery-analysis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recovery-analysis.js","sourceRoot":"","sources":["../../src/deep/recovery-analysis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;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/**
|
|
2
|
+
* RRF (Reciprocal Rank Fusion) - Merge multiple ranked lists
|
|
3
|
+
*/
|
|
4
|
+
export interface RrfInputItem {
|
|
5
|
+
id: string;
|
|
6
|
+
[key: string]: unknown;
|
|
7
|
+
}
|
|
8
|
+
export interface RrfOutputItem {
|
|
9
|
+
id: string;
|
|
10
|
+
score: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function rrf(rankings: Array<Array<RrfInputItem>>, k?: number): Array<RrfOutputItem>;
|
|
13
|
+
//# sourceMappingURL=rrf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rrf.d.ts","sourceRoot":"","sources":["../../src/deep/rrf.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,GAAG,CACf,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,EACpC,CAAC,GAAE,MAAW,GACf,KAAK,CAAC,aAAa,CAAC,CAkBtB"}
|
package/dist/deep/rrf.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RRF (Reciprocal Rank Fusion) - Merge multiple ranked lists
|
|
3
|
+
*/
|
|
4
|
+
export function rrf(rankings, k = 60) {
|
|
5
|
+
if (k <= 0)
|
|
6
|
+
throw new Error(`RRF parameter k must be positive, got: ${k}`);
|
|
7
|
+
if (rankings.length === 0)
|
|
8
|
+
return [];
|
|
9
|
+
const scores = new Map();
|
|
10
|
+
for (const ranking of rankings) {
|
|
11
|
+
for (let i = 0; i < ranking.length; i++) {
|
|
12
|
+
const doc = ranking[i];
|
|
13
|
+
if (!doc.id)
|
|
14
|
+
continue;
|
|
15
|
+
const score = 1 / (k + i + 1);
|
|
16
|
+
scores.set(doc.id, (scores.get(doc.id) || 0) + score);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return Array.from(scores.entries())
|
|
20
|
+
.map(([id, score]) => ({ id, score }))
|
|
21
|
+
.sort((a, b) => b.score - a.score);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=rrf.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rrf.js","sourceRoot":"","sources":["../../src/deep/rrf.ts"],"names":[],"mappings":"AAAA;;GAEG;AAYH,MAAM,UAAU,GAAG,CACf,QAAoC,EACpC,IAAY,EAAE;IAEd,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,EAAE,CAAC,CAAC;IAC3E,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAErC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEzC,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,MAAM,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YACvB,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,SAAS;YACtB,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9B,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;QAC1D,CAAC;IACL,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;SAC9B,GAAG,CAAC,CA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