cursor-recursive-rag 0.2.0-alpha.2 → 0.2.0
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 +179 -203
- package/dist/adapters/llm/anthropic.d.ts +27 -0
- package/dist/adapters/llm/anthropic.d.ts.map +1 -0
- package/dist/adapters/llm/anthropic.js +287 -0
- package/dist/adapters/llm/anthropic.js.map +1 -0
- package/dist/adapters/llm/base.d.ts +62 -0
- package/dist/adapters/llm/base.d.ts.map +1 -0
- package/dist/adapters/llm/base.js +140 -0
- package/dist/adapters/llm/base.js.map +1 -0
- package/dist/adapters/llm/deepseek.d.ts +24 -0
- package/dist/adapters/llm/deepseek.d.ts.map +1 -0
- package/dist/adapters/llm/deepseek.js +228 -0
- package/dist/adapters/llm/deepseek.js.map +1 -0
- package/dist/adapters/llm/groq.d.ts +25 -0
- package/dist/adapters/llm/groq.d.ts.map +1 -0
- package/dist/adapters/llm/groq.js +265 -0
- package/dist/adapters/llm/groq.js.map +1 -0
- package/dist/adapters/llm/index.d.ts +62 -0
- package/dist/adapters/llm/index.d.ts.map +1 -0
- package/dist/adapters/llm/index.js +380 -0
- package/dist/adapters/llm/index.js.map +1 -0
- package/dist/adapters/llm/ollama.d.ts +23 -0
- package/dist/adapters/llm/ollama.d.ts.map +1 -0
- package/dist/adapters/llm/ollama.js +261 -0
- package/dist/adapters/llm/ollama.js.map +1 -0
- package/dist/adapters/llm/openai.d.ts +22 -0
- package/dist/adapters/llm/openai.d.ts.map +1 -0
- package/dist/adapters/llm/openai.js +232 -0
- package/dist/adapters/llm/openai.js.map +1 -0
- package/dist/adapters/llm/openrouter.d.ts +27 -0
- package/dist/adapters/llm/openrouter.d.ts.map +1 -0
- package/dist/adapters/llm/openrouter.js +305 -0
- package/dist/adapters/llm/openrouter.js.map +1 -0
- package/dist/adapters/vector/index.d.ts.map +1 -1
- package/dist/adapters/vector/index.js +8 -0
- package/dist/adapters/vector/index.js.map +1 -1
- package/dist/adapters/vector/redis-native.d.ts +35 -0
- package/dist/adapters/vector/redis-native.d.ts.map +1 -0
- package/dist/adapters/vector/redis-native.js +170 -0
- package/dist/adapters/vector/redis-native.js.map +1 -0
- package/dist/cli/commands/chat.d.ts +4 -0
- package/dist/cli/commands/chat.d.ts.map +1 -0
- package/dist/cli/commands/chat.js +374 -0
- package/dist/cli/commands/chat.js.map +1 -0
- package/dist/cli/commands/maintenance.d.ts +4 -0
- package/dist/cli/commands/maintenance.d.ts.map +1 -0
- package/dist/cli/commands/maintenance.js +237 -0
- package/dist/cli/commands/maintenance.js.map +1 -0
- package/dist/cli/commands/rules.d.ts +9 -0
- package/dist/cli/commands/rules.d.ts.map +1 -0
- package/dist/cli/commands/rules.js +639 -0
- package/dist/cli/commands/rules.js.map +1 -0
- package/dist/cli/commands/setup.js +5 -4
- package/dist/cli/commands/setup.js.map +1 -1
- package/dist/cli/index.js +6 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/config/memoryConfig.d.ts +427 -0
- package/dist/config/memoryConfig.d.ts.map +1 -0
- package/dist/config/memoryConfig.js +258 -0
- package/dist/config/memoryConfig.js.map +1 -0
- package/dist/config/rulesConfig.d.ts +486 -0
- package/dist/config/rulesConfig.d.ts.map +1 -0
- package/dist/config/rulesConfig.js +345 -0
- package/dist/config/rulesConfig.js.map +1 -0
- package/dist/dashboard/coreTools.d.ts +14 -0
- package/dist/dashboard/coreTools.d.ts.map +1 -0
- package/dist/dashboard/coreTools.js +413 -0
- package/dist/dashboard/coreTools.js.map +1 -0
- package/dist/dashboard/public/index.html +1982 -13
- package/dist/dashboard/server.d.ts +1 -8
- package/dist/dashboard/server.d.ts.map +1 -1
- package/dist/dashboard/server.js +846 -13
- package/dist/dashboard/server.js.map +1 -1
- package/dist/dashboard/toolRegistry.d.ts +192 -0
- package/dist/dashboard/toolRegistry.d.ts.map +1 -0
- package/dist/dashboard/toolRegistry.js +322 -0
- package/dist/dashboard/toolRegistry.js.map +1 -0
- package/dist/proxy/index.d.ts +1 -1
- package/dist/proxy/index.d.ts.map +1 -1
- package/dist/proxy/index.js +9 -6
- package/dist/proxy/index.js.map +1 -1
- package/dist/server/index.js +21 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/tools/crawl.d.ts.map +1 -1
- package/dist/server/tools/crawl.js +8 -0
- package/dist/server/tools/crawl.js.map +1 -1
- package/dist/server/tools/index.d.ts.map +1 -1
- package/dist/server/tools/index.js +19 -1
- package/dist/server/tools/index.js.map +1 -1
- package/dist/server/tools/ingest.d.ts.map +1 -1
- package/dist/server/tools/ingest.js +5 -0
- package/dist/server/tools/ingest.js.map +1 -1
- package/dist/server/tools/memory.d.ts +250 -0
- package/dist/server/tools/memory.d.ts.map +1 -0
- package/dist/server/tools/memory.js +472 -0
- package/dist/server/tools/memory.js.map +1 -0
- package/dist/server/tools/recursive-query.d.ts.map +1 -1
- package/dist/server/tools/recursive-query.js +6 -0
- package/dist/server/tools/recursive-query.js.map +1 -1
- package/dist/server/tools/search.d.ts.map +1 -1
- package/dist/server/tools/search.js +6 -0
- package/dist/server/tools/search.js.map +1 -1
- package/dist/services/activity-log.d.ts +10 -0
- package/dist/services/activity-log.d.ts.map +1 -0
- package/dist/services/activity-log.js +53 -0
- package/dist/services/activity-log.js.map +1 -0
- package/dist/services/categoryManager.d.ts +110 -0
- package/dist/services/categoryManager.d.ts.map +1 -0
- package/dist/services/categoryManager.js +549 -0
- package/dist/services/categoryManager.js.map +1 -0
- package/dist/services/contextEnvironment.d.ts +206 -0
- package/dist/services/contextEnvironment.d.ts.map +1 -0
- package/dist/services/contextEnvironment.js +481 -0
- package/dist/services/contextEnvironment.js.map +1 -0
- package/dist/services/conversationProcessor.d.ts +99 -0
- package/dist/services/conversationProcessor.d.ts.map +1 -0
- package/dist/services/conversationProcessor.js +311 -0
- package/dist/services/conversationProcessor.js.map +1 -0
- package/dist/services/cursorChatReader.d.ts +129 -0
- package/dist/services/cursorChatReader.d.ts.map +1 -0
- package/dist/services/cursorChatReader.js +419 -0
- package/dist/services/cursorChatReader.js.map +1 -0
- package/dist/services/decayCalculator.d.ts +85 -0
- package/dist/services/decayCalculator.d.ts.map +1 -0
- package/dist/services/decayCalculator.js +182 -0
- package/dist/services/decayCalculator.js.map +1 -0
- package/dist/services/enhancedVectorStore.d.ts +102 -0
- package/dist/services/enhancedVectorStore.d.ts.map +1 -0
- package/dist/services/enhancedVectorStore.js +245 -0
- package/dist/services/enhancedVectorStore.js.map +1 -0
- package/dist/services/hybridScorer.d.ts +120 -0
- package/dist/services/hybridScorer.d.ts.map +1 -0
- package/dist/services/hybridScorer.js +334 -0
- package/dist/services/hybridScorer.js.map +1 -0
- package/dist/services/knowledgeExtractor.d.ts +45 -0
- package/dist/services/knowledgeExtractor.d.ts.map +1 -0
- package/dist/services/knowledgeExtractor.js +436 -0
- package/dist/services/knowledgeExtractor.js.map +1 -0
- package/dist/services/knowledgeStorage.d.ts +102 -0
- package/dist/services/knowledgeStorage.d.ts.map +1 -0
- package/dist/services/knowledgeStorage.js +383 -0
- package/dist/services/knowledgeStorage.js.map +1 -0
- package/dist/services/maintenanceScheduler.d.ts +89 -0
- package/dist/services/maintenanceScheduler.d.ts.map +1 -0
- package/dist/services/maintenanceScheduler.js +479 -0
- package/dist/services/maintenanceScheduler.js.map +1 -0
- package/dist/services/memoryMetadataStore.d.ts +62 -0
- package/dist/services/memoryMetadataStore.d.ts.map +1 -0
- package/dist/services/memoryMetadataStore.js +570 -0
- package/dist/services/memoryMetadataStore.js.map +1 -0
- package/dist/services/recursiveRetrieval.d.ts +122 -0
- package/dist/services/recursiveRetrieval.d.ts.map +1 -0
- package/dist/services/recursiveRetrieval.js +443 -0
- package/dist/services/recursiveRetrieval.js.map +1 -0
- package/dist/services/relationshipGraph.d.ts +77 -0
- package/dist/services/relationshipGraph.d.ts.map +1 -0
- package/dist/services/relationshipGraph.js +411 -0
- package/dist/services/relationshipGraph.js.map +1 -0
- package/dist/services/rlmSafeguards.d.ts +273 -0
- package/dist/services/rlmSafeguards.d.ts.map +1 -0
- package/dist/services/rlmSafeguards.js +705 -0
- package/dist/services/rlmSafeguards.js.map +1 -0
- package/dist/services/rulesAnalyzer.d.ts +119 -0
- package/dist/services/rulesAnalyzer.d.ts.map +1 -0
- package/dist/services/rulesAnalyzer.js +768 -0
- package/dist/services/rulesAnalyzer.js.map +1 -0
- package/dist/services/rulesMerger.d.ts +75 -0
- package/dist/services/rulesMerger.d.ts.map +1 -0
- package/dist/services/rulesMerger.js +404 -0
- package/dist/services/rulesMerger.js.map +1 -0
- package/dist/services/rulesParser.d.ts +127 -0
- package/dist/services/rulesParser.d.ts.map +1 -0
- package/dist/services/rulesParser.js +594 -0
- package/dist/services/rulesParser.js.map +1 -0
- package/dist/services/smartChunker.d.ts +110 -0
- package/dist/services/smartChunker.d.ts.map +1 -0
- package/dist/services/smartChunker.js +520 -0
- package/dist/services/smartChunker.js.map +1 -0
- package/dist/types/categories.d.ts +105 -0
- package/dist/types/categories.d.ts.map +1 -0
- package/dist/types/categories.js +108 -0
- package/dist/types/categories.js.map +1 -0
- package/dist/types/extractedKnowledge.d.ts +233 -0
- package/dist/types/extractedKnowledge.d.ts.map +1 -0
- package/dist/types/extractedKnowledge.js +56 -0
- package/dist/types/extractedKnowledge.js.map +1 -0
- package/dist/types/index.d.ts +9 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +12 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/llmProvider.d.ts +282 -0
- package/dist/types/llmProvider.d.ts.map +1 -0
- package/dist/types/llmProvider.js +48 -0
- package/dist/types/llmProvider.js.map +1 -0
- package/dist/types/memory.d.ts +227 -0
- package/dist/types/memory.d.ts.map +1 -0
- package/dist/types/memory.js +76 -0
- package/dist/types/memory.js.map +1 -0
- package/dist/types/relationships.d.ts +167 -0
- package/dist/types/relationships.d.ts.map +1 -0
- package/dist/types/relationships.js +106 -0
- package/dist/types/relationships.js.map +1 -0
- package/dist/types/rulesOptimizer.d.ts +345 -0
- package/dist/types/rulesOptimizer.d.ts.map +1 -0
- package/dist/types/rulesOptimizer.js +22 -0
- package/dist/types/rulesOptimizer.js.map +1 -0
- package/docs/cursor-recursive-rag-memory-spec.md +4569 -0
- package/docs/cursor-recursive-rag-tasks.md +1355 -0
- package/package.json +6 -3
- package/restart-rag.sh +16 -0
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursive Retrieval Controller
|
|
3
|
+
*
|
|
4
|
+
* Based on the Recursive Language Models paper (Zhang et al., 2024), this controller
|
|
5
|
+
* implements RLM-style iterative retrieval where the model can examine, filter, and
|
|
6
|
+
* recursively process context.
|
|
7
|
+
*
|
|
8
|
+
* Key features:
|
|
9
|
+
* - Complexity assessment to decide retrieval strategy
|
|
10
|
+
* - Iterative processing with action parsing
|
|
11
|
+
* - Cost tracking across iterations
|
|
12
|
+
* - Early termination on budget/iteration limits
|
|
13
|
+
* - Support for both simple and complex queries
|
|
14
|
+
*/
|
|
15
|
+
import type { EnhancedChunk } from '../types/memory.js';
|
|
16
|
+
import type { EnhancedSearchOptions } from '../types/memory.js';
|
|
17
|
+
import type { SearchResult } from '../types/index.js';
|
|
18
|
+
import { type LLMService, type ExecutionStep } from './contextEnvironment.js';
|
|
19
|
+
export interface RetrievalConfig {
|
|
20
|
+
initialRetrievalK: number;
|
|
21
|
+
maxIterations: number;
|
|
22
|
+
enableRecursiveSubCalls: boolean;
|
|
23
|
+
costBudget: number;
|
|
24
|
+
timeoutMs: number;
|
|
25
|
+
complexityThresholds: {
|
|
26
|
+
simpleMaxContext: number;
|
|
27
|
+
moderateMaxContext: number;
|
|
28
|
+
};
|
|
29
|
+
enableHybridScoring: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare const DEFAULT_RETRIEVAL_CONFIG: RetrievalConfig;
|
|
32
|
+
export interface RetrieveOptions {
|
|
33
|
+
searchOptions?: Partial<EnhancedSearchOptions>;
|
|
34
|
+
forceStrategy?: 'direct' | 'recursive';
|
|
35
|
+
seedChunkIds?: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface RetrievalResult {
|
|
38
|
+
chunks: EnhancedChunk[];
|
|
39
|
+
strategy: 'direct' | 'recursive';
|
|
40
|
+
iterations: number;
|
|
41
|
+
cost: number;
|
|
42
|
+
answer?: string;
|
|
43
|
+
executionLog?: ExecutionStep[];
|
|
44
|
+
complexity?: 'simple' | 'moderate' | 'complex';
|
|
45
|
+
terminationReason?: string;
|
|
46
|
+
}
|
|
47
|
+
export type ComplexityLevel = 'simple' | 'moderate' | 'complex';
|
|
48
|
+
export interface RetrievalAction {
|
|
49
|
+
type: 'peek' | 'filter' | 'chunk' | 'subQuery' | 'store' | 'answer' | 'search';
|
|
50
|
+
params: Record<string, unknown>;
|
|
51
|
+
reasoning?: string;
|
|
52
|
+
}
|
|
53
|
+
interface VectorStoreInterface {
|
|
54
|
+
search(embedding: number[], options: {
|
|
55
|
+
topK: number;
|
|
56
|
+
filter?: Record<string, unknown>;
|
|
57
|
+
}): Promise<SearchResult[]>;
|
|
58
|
+
enhancedSearch?(embedding: number[], options: EnhancedSearchOptions): Promise<EnhancedChunk[]>;
|
|
59
|
+
}
|
|
60
|
+
interface EmbeddingsInterface {
|
|
61
|
+
embed(text: string): Promise<number[]>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Recursive Retrieval Controller
|
|
65
|
+
*
|
|
66
|
+
* Orchestrates iterative retrieval with complexity assessment and action parsing.
|
|
67
|
+
*/
|
|
68
|
+
export declare class RecursiveRetrievalController {
|
|
69
|
+
private vectorStore;
|
|
70
|
+
private embeddings;
|
|
71
|
+
private llm;
|
|
72
|
+
private subLlm;
|
|
73
|
+
private config;
|
|
74
|
+
private hybridScorer;
|
|
75
|
+
constructor(vectorStore: VectorStoreInterface, embeddings: EmbeddingsInterface, llm: LLMService, subLlm?: LLMService, config?: Partial<RetrievalConfig>);
|
|
76
|
+
/**
|
|
77
|
+
* Execute recursive retrieval for a query
|
|
78
|
+
*/
|
|
79
|
+
retrieve(query: string, options?: RetrieveOptions): Promise<RetrievalResult>;
|
|
80
|
+
/**
|
|
81
|
+
* Assess query complexity to decide strategy
|
|
82
|
+
* Based on RLM paper: "more complex problems exhibit degradation at shorter lengths"
|
|
83
|
+
*/
|
|
84
|
+
assessComplexity(query: string, chunks: EnhancedChunk[]): ComplexityLevel;
|
|
85
|
+
/**
|
|
86
|
+
* Iterative RLM-style processing
|
|
87
|
+
*/
|
|
88
|
+
private iterativeProcess;
|
|
89
|
+
/**
|
|
90
|
+
* Ask LLM what to do next
|
|
91
|
+
*/
|
|
92
|
+
private getNextAction;
|
|
93
|
+
/**
|
|
94
|
+
* Execute a retrieval action
|
|
95
|
+
*/
|
|
96
|
+
private executeAction;
|
|
97
|
+
/**
|
|
98
|
+
* Parse action from LLM response
|
|
99
|
+
*/
|
|
100
|
+
private parseAction;
|
|
101
|
+
/**
|
|
102
|
+
* Collect relevant chunks from environment
|
|
103
|
+
*/
|
|
104
|
+
private collectRelevantChunks;
|
|
105
|
+
/**
|
|
106
|
+
* Convert SearchResult[] to EnhancedChunk[]
|
|
107
|
+
*/
|
|
108
|
+
private convertToEnhancedChunks;
|
|
109
|
+
/**
|
|
110
|
+
* Update configuration
|
|
111
|
+
*/
|
|
112
|
+
updateConfig(config: Partial<RetrievalConfig>): void;
|
|
113
|
+
/**
|
|
114
|
+
* Get current configuration
|
|
115
|
+
*/
|
|
116
|
+
getConfig(): RetrievalConfig;
|
|
117
|
+
}
|
|
118
|
+
export declare function createRecursiveRetrievalController(vectorStore: VectorStoreInterface, embeddings: EmbeddingsInterface, llm: LLMService, subLlm?: LLMService, config?: Partial<RetrievalConfig>): RecursiveRetrievalController;
|
|
119
|
+
export declare function getRecursiveRetrievalController(vectorStore: VectorStoreInterface, embeddings: EmbeddingsInterface, llm: LLMService, subLlm?: LLMService, config?: Partial<RetrievalConfig>): RecursiveRetrievalController;
|
|
120
|
+
export declare function resetRecursiveRetrievalController(): void;
|
|
121
|
+
export {};
|
|
122
|
+
//# sourceMappingURL=recursiveRetrieval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recursiveRetrieval.d.ts","sourceRoot":"","sources":["../../src/services/recursiveRetrieval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,aAAa,EAKnB,MAAM,yBAAyB,CAAC;AAGjC,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,EAAE,OAAO,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE;QACpB,gBAAgB,EAAE,MAAM,CAAC;QACzB,kBAAkB,EAAE,MAAM,CAAC;KAC5B,CAAC;IACF,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAED,eAAO,MAAM,wBAAwB,EAAE,eAWtC,CAAC;AAEF,MAAM,WAAW,eAAe;IAC9B,aAAa,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC/C,aAAa,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;IACvC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,aAAa,EAAE,CAAC;IACxB,QAAQ,EAAE,QAAQ,GAAG,WAAW,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,aAAa,EAAE,CAAC;IAC/B,UAAU,CAAC,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AEG;IACG,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAmFlF;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,eAAe;IAgCzE;;OAEG;YACW,gBAAgB;IAkE9B;;OAEG;YACW,aAAa;IAqD3B;;OAEG;YACW,aAAa;IAuE3B;;OAEG;IACH,OAAO,CAAC,WAAW;IAkDnB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAoB7B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAsB/B;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,IAAI;IAOpD;;OAEG;IACH,SAAS,IAAI,eAAe;CAG7B;AAID,wBAAgB,kCAAkC,CAChD,WAAW,EAAE,oBAAoB,EACjC,UAAU,EAAE,mBAAmB,EAC/B,GAAG,EAAE,UAAU,EACf,MAAM,CAAC,EAAE,UAAU,EACnB,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAChC,4BAA4B,CAE9B;AAED,wBAAgB,+BAA+B,CAC7C,WAAW,EAAE,oBAAoB,EACjC,UAAU,EAAE,mBAAmB,EAC/B,GAAG,EAAE,UAAU,EACf,MAAM,CAAC,EAAE,UAAU,EACnB,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,GAChC,4BAA4B,CAK9B;AAED,wBAAgB,iCAAiC,IAAI,IAAI,CAExD"}
|
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursive Retrieval Controller
|
|
3
|
+
*
|
|
4
|
+
* Based on the Recursive Language Models paper (Zhang et al., 2024), this controller
|
|
5
|
+
* implements RLM-style iterative retrieval where the model can examine, filter, and
|
|
6
|
+
* recursively process context.
|
|
7
|
+
*
|
|
8
|
+
* Key features:
|
|
9
|
+
* - Complexity assessment to decide retrieval strategy
|
|
10
|
+
* - Iterative processing with action parsing
|
|
11
|
+
* - Cost tracking across iterations
|
|
12
|
+
* - Early termination on budget/iteration limits
|
|
13
|
+
* - Support for both simple and complex queries
|
|
14
|
+
*/
|
|
15
|
+
import { createContextEnvironment, BudgetExceededError, LimitExceededError, TimeoutError, } from './contextEnvironment.js';
|
|
16
|
+
import { getHybridScorer } from './hybridScorer.js';
|
|
17
|
+
export const DEFAULT_RETRIEVAL_CONFIG = {
|
|
18
|
+
initialRetrievalK: 20,
|
|
19
|
+
maxIterations: 10,
|
|
20
|
+
enableRecursiveSubCalls: true,
|
|
21
|
+
costBudget: 0.50,
|
|
22
|
+
timeoutMs: 120000,
|
|
23
|
+
complexityThresholds: {
|
|
24
|
+
simpleMaxContext: 50000,
|
|
25
|
+
moderateMaxContext: 200000,
|
|
26
|
+
},
|
|
27
|
+
enableHybridScoring: true,
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Recursive Retrieval Controller
|
|
31
|
+
*
|
|
32
|
+
* Orchestrates iterative retrieval with complexity assessment and action parsing.
|
|
33
|
+
*/
|
|
34
|
+
export class RecursiveRetrievalController {
|
|
35
|
+
vectorStore;
|
|
36
|
+
embeddings;
|
|
37
|
+
llm;
|
|
38
|
+
subLlm;
|
|
39
|
+
config;
|
|
40
|
+
hybridScorer;
|
|
41
|
+
constructor(vectorStore, embeddings, llm, subLlm, config) {
|
|
42
|
+
this.vectorStore = vectorStore;
|
|
43
|
+
this.embeddings = embeddings;
|
|
44
|
+
this.llm = llm;
|
|
45
|
+
this.subLlm = subLlm ?? llm;
|
|
46
|
+
this.config = {
|
|
47
|
+
...DEFAULT_RETRIEVAL_CONFIG,
|
|
48
|
+
...config,
|
|
49
|
+
};
|
|
50
|
+
this.hybridScorer = getHybridScorer();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Execute recursive retrieval for a query
|
|
54
|
+
*/
|
|
55
|
+
async retrieve(query, options) {
|
|
56
|
+
// Step 1: Initial retrieval
|
|
57
|
+
const embedding = await this.embeddings.embed(query);
|
|
58
|
+
const searchOptions = {
|
|
59
|
+
topK: this.config.initialRetrievalK,
|
|
60
|
+
...options?.searchOptions,
|
|
61
|
+
};
|
|
62
|
+
const rawResults = await this.vectorStore.search(embedding, searchOptions);
|
|
63
|
+
// Convert SearchResult[] to EnhancedChunk[]
|
|
64
|
+
const initialChunks = this.convertToEnhancedChunks(rawResults);
|
|
65
|
+
// Apply hybrid scoring if enabled
|
|
66
|
+
let scoredChunks = initialChunks;
|
|
67
|
+
if (this.config.enableHybridScoring && initialChunks.length > 0) {
|
|
68
|
+
const searchResultInputs = rawResults.map(r => ({
|
|
69
|
+
id: r.id,
|
|
70
|
+
content: r.content,
|
|
71
|
+
score: r.score,
|
|
72
|
+
metadata: r.metadata,
|
|
73
|
+
}));
|
|
74
|
+
const scoredResults = await this.hybridScorer.scoreResults(searchResultInputs, query, { seedChunkIds: options?.seedChunkIds });
|
|
75
|
+
// Re-order chunks based on hybrid scores
|
|
76
|
+
const idToScore = new Map(scoredResults.map(r => [r.id, r.finalScore]));
|
|
77
|
+
scoredChunks = [...initialChunks].sort((a, b) => {
|
|
78
|
+
const scoreA = idToScore.get(a.id) ?? 0;
|
|
79
|
+
const scoreB = idToScore.get(b.id) ?? 0;
|
|
80
|
+
return scoreB - scoreA;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
// Step 2: Check for forced strategy
|
|
84
|
+
if (options?.forceStrategy === 'direct') {
|
|
85
|
+
return {
|
|
86
|
+
chunks: scoredChunks,
|
|
87
|
+
strategy: 'direct',
|
|
88
|
+
iterations: 1,
|
|
89
|
+
cost: 0,
|
|
90
|
+
complexity: 'simple',
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
// Step 3: Assess complexity
|
|
94
|
+
const complexity = this.assessComplexity(query, scoredChunks);
|
|
95
|
+
if (options?.forceStrategy === 'recursive') {
|
|
96
|
+
// Force recursive even for simple queries
|
|
97
|
+
}
|
|
98
|
+
else if (complexity === 'simple') {
|
|
99
|
+
return {
|
|
100
|
+
chunks: scoredChunks,
|
|
101
|
+
strategy: 'direct',
|
|
102
|
+
iterations: 1,
|
|
103
|
+
cost: 0,
|
|
104
|
+
complexity,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// Step 4: Complex query - use RLM-style processing
|
|
108
|
+
const envConfig = {
|
|
109
|
+
maxIterations: this.config.maxIterations,
|
|
110
|
+
costBudget: this.config.costBudget,
|
|
111
|
+
timeoutMs: this.config.timeoutMs,
|
|
112
|
+
enableAsyncSubCalls: this.config.enableRecursiveSubCalls,
|
|
113
|
+
};
|
|
114
|
+
const env = createContextEnvironment(envConfig);
|
|
115
|
+
env.loadContext(scoredChunks);
|
|
116
|
+
const result = await this.iterativeProcess(query, env);
|
|
117
|
+
return {
|
|
118
|
+
...result,
|
|
119
|
+
complexity,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Assess query complexity to decide strategy
|
|
124
|
+
* Based on RLM paper: "more complex problems exhibit degradation at shorter lengths"
|
|
125
|
+
*/
|
|
126
|
+
assessComplexity(query, chunks) {
|
|
127
|
+
const totalContext = chunks.reduce((sum, c) => sum + c.content.length, 0);
|
|
128
|
+
// Check query patterns that indicate complexity
|
|
129
|
+
const aggregationKeywords = /how many|count|list all|compare|summarize|aggregate|total|average/i;
|
|
130
|
+
const multiHopKeywords = /because|therefore|which.*then|after.*when|relationship|connected|related/i;
|
|
131
|
+
const analysisKeywords = /analyze|evaluate|assess|review|investigate|examine/i;
|
|
132
|
+
const isAggregation = aggregationKeywords.test(query);
|
|
133
|
+
const isMultiHop = multiHopKeywords.test(query);
|
|
134
|
+
const isAnalysis = analysisKeywords.test(query);
|
|
135
|
+
// Small context and simple query
|
|
136
|
+
if (totalContext < this.config.complexityThresholds.simpleMaxContext) {
|
|
137
|
+
if (!isAggregation && !isMultiHop && !isAnalysis) {
|
|
138
|
+
return 'simple';
|
|
139
|
+
}
|
|
140
|
+
return 'moderate';
|
|
141
|
+
}
|
|
142
|
+
// Medium context
|
|
143
|
+
if (totalContext < this.config.complexityThresholds.moderateMaxContext) {
|
|
144
|
+
if (isAggregation || isMultiHop || isAnalysis) {
|
|
145
|
+
return 'complex';
|
|
146
|
+
}
|
|
147
|
+
return 'moderate';
|
|
148
|
+
}
|
|
149
|
+
// Large context is always complex
|
|
150
|
+
return 'complex';
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Iterative RLM-style processing
|
|
154
|
+
*/
|
|
155
|
+
async iterativeProcess(query, env) {
|
|
156
|
+
let iteration = 0;
|
|
157
|
+
let answer;
|
|
158
|
+
let terminationReason;
|
|
159
|
+
while (iteration < this.config.maxIterations) {
|
|
160
|
+
iteration++;
|
|
161
|
+
env.markIteration(iteration);
|
|
162
|
+
// Check termination conditions
|
|
163
|
+
const termCheck = env.shouldTerminate();
|
|
164
|
+
if (termCheck.terminate) {
|
|
165
|
+
terminationReason = termCheck.reason;
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
// Get next action from LLM
|
|
170
|
+
const action = await this.getNextAction(query, env, iteration);
|
|
171
|
+
if (action.type === 'answer') {
|
|
172
|
+
answer = action.params.value;
|
|
173
|
+
terminationReason = 'Answer found';
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
// Execute the action
|
|
177
|
+
await this.executeAction(action, env, query);
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (error instanceof BudgetExceededError) {
|
|
181
|
+
terminationReason = 'Budget exceeded';
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
if (error instanceof LimitExceededError) {
|
|
185
|
+
terminationReason = 'Sub-call limit exceeded';
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
if (error instanceof TimeoutError) {
|
|
189
|
+
terminationReason = 'Timeout';
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (!terminationReason && iteration >= this.config.maxIterations) {
|
|
196
|
+
terminationReason = 'Max iterations reached';
|
|
197
|
+
}
|
|
198
|
+
// Collect relevant chunks from the environment
|
|
199
|
+
const relevantChunks = this.collectRelevantChunks(env);
|
|
200
|
+
return {
|
|
201
|
+
chunks: relevantChunks,
|
|
202
|
+
strategy: 'recursive',
|
|
203
|
+
iterations: iteration,
|
|
204
|
+
cost: env.getTotalCost(),
|
|
205
|
+
answer,
|
|
206
|
+
executionLog: env.getExecutionLog(),
|
|
207
|
+
terminationReason,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Ask LLM what to do next
|
|
212
|
+
*/
|
|
213
|
+
async getNextAction(query, env, iteration) {
|
|
214
|
+
const prompt = `You are processing a query using a context environment. Your goal is to find relevant information efficiently.
|
|
215
|
+
|
|
216
|
+
## Query
|
|
217
|
+
${query}
|
|
218
|
+
|
|
219
|
+
${env.getStateDescription()}
|
|
220
|
+
|
|
221
|
+
## Chunk Summary
|
|
222
|
+
${env.getChunkSummary()}
|
|
223
|
+
|
|
224
|
+
## Iteration ${iteration}
|
|
225
|
+
|
|
226
|
+
Based on the query and current state, decide your next action. Available actions:
|
|
227
|
+
|
|
228
|
+
1. **peek** - Look at specific chunks to understand content
|
|
229
|
+
\`{"type": "peek", "params": {"variable": "context", "start": 0, "end": 3}}\`
|
|
230
|
+
|
|
231
|
+
2. **filter** - Filter chunks by keyword/pattern to narrow down
|
|
232
|
+
\`{"type": "filter", "params": {"variable": "context", "pattern": "error|exception", "output": "errors"}}\`
|
|
233
|
+
|
|
234
|
+
3. **subQuery** - Ask a focused question about a subset of context
|
|
235
|
+
\`{"type": "subQuery", "params": {"query": "What error handling patterns are used?", "variable": "context"}}\`
|
|
236
|
+
|
|
237
|
+
4. **store** - Store intermediate findings
|
|
238
|
+
\`{"type": "store", "params": {"variable": "findings", "value": "..."}}\`
|
|
239
|
+
|
|
240
|
+
5. **answer** - Provide final answer if you have enough information
|
|
241
|
+
\`{"type": "answer", "params": {"value": "The answer based on the context is..."}}\`
|
|
242
|
+
|
|
243
|
+
Respond with ONLY a JSON action:
|
|
244
|
+
\`\`\`json
|
|
245
|
+
{
|
|
246
|
+
"type": "...",
|
|
247
|
+
"params": { ... },
|
|
248
|
+
"reasoning": "brief explanation"
|
|
249
|
+
}
|
|
250
|
+
\`\`\`
|
|
251
|
+
|
|
252
|
+
Be efficient - filter first before examining everything. Use subQuery for semantic understanding.`;
|
|
253
|
+
const response = await this.llm.invoke(prompt, {
|
|
254
|
+
maxTokens: 1000,
|
|
255
|
+
temperature: 0.2,
|
|
256
|
+
});
|
|
257
|
+
return this.parseAction(response);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Execute a retrieval action
|
|
261
|
+
*/
|
|
262
|
+
async executeAction(action, env, query) {
|
|
263
|
+
switch (action.type) {
|
|
264
|
+
case 'peek': {
|
|
265
|
+
const variable = action.params.variable ?? 'context';
|
|
266
|
+
const start = action.params.start;
|
|
267
|
+
const end = action.params.end;
|
|
268
|
+
const peekResult = env.peek(variable, start, end);
|
|
269
|
+
env.store('_lastPeek', peekResult);
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case 'filter': {
|
|
273
|
+
const variable = action.params.variable ?? 'context';
|
|
274
|
+
const pattern = action.params.pattern;
|
|
275
|
+
const output = action.params.output ?? 'filtered';
|
|
276
|
+
const count = env.filterAndStore(variable, pattern, output);
|
|
277
|
+
env.store('_lastFilterCount', count);
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
case 'chunk': {
|
|
281
|
+
const variable = action.params.variable ?? 'context';
|
|
282
|
+
const size = action.params.size ?? 5;
|
|
283
|
+
const batches = env.chunk(variable, size);
|
|
284
|
+
for (let i = 0; i < batches.length; i++) {
|
|
285
|
+
env.loadContext(batches[i], `batch_${i}`);
|
|
286
|
+
}
|
|
287
|
+
env.store('_batchCount', batches.length);
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case 'subQuery': {
|
|
291
|
+
const subQuery = action.params.query;
|
|
292
|
+
const variable = action.params.variable ?? 'context';
|
|
293
|
+
const chunks = env.getChunks(variable);
|
|
294
|
+
if (chunks.length > 0) {
|
|
295
|
+
const response = await env.subQuery(this.subLlm, subQuery, chunks);
|
|
296
|
+
const outputVar = action.params.output ?? '_lastSubQuery';
|
|
297
|
+
env.store(outputVar, response);
|
|
298
|
+
}
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
case 'store': {
|
|
302
|
+
const variable = action.params.variable;
|
|
303
|
+
const value = action.params.value;
|
|
304
|
+
env.store(variable, value);
|
|
305
|
+
break;
|
|
306
|
+
}
|
|
307
|
+
case 'search': {
|
|
308
|
+
// Additional search with different parameters
|
|
309
|
+
const searchQuery = action.params.query ?? query;
|
|
310
|
+
const embedding = await this.embeddings.embed(searchQuery);
|
|
311
|
+
const topK = action.params.topK ?? 10;
|
|
312
|
+
const results = await this.vectorStore.search(embedding, { topK });
|
|
313
|
+
const chunks = this.convertToEnhancedChunks(results);
|
|
314
|
+
const outputVar = action.params.output ?? 'additionalResults';
|
|
315
|
+
env.loadContext(chunks, outputVar);
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Parse action from LLM response
|
|
322
|
+
*/
|
|
323
|
+
parseAction(response) {
|
|
324
|
+
// Try to extract JSON from response
|
|
325
|
+
const jsonMatch = response.match(/```json\s*([\s\S]*?)\s*```/);
|
|
326
|
+
const jsonStr = jsonMatch ? jsonMatch[1] : response;
|
|
327
|
+
try {
|
|
328
|
+
// Try direct JSON parse
|
|
329
|
+
const action = JSON.parse(jsonStr.trim());
|
|
330
|
+
// Validate action type
|
|
331
|
+
const validTypes = ['peek', 'filter', 'chunk', 'subQuery', 'store', 'answer', 'search'];
|
|
332
|
+
if (!validTypes.includes(action.type)) {
|
|
333
|
+
// Default to answer if we can't parse
|
|
334
|
+
return {
|
|
335
|
+
type: 'answer',
|
|
336
|
+
params: { value: response },
|
|
337
|
+
reasoning: 'Could not parse valid action',
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
return {
|
|
341
|
+
type: action.type,
|
|
342
|
+
params: action.params || {},
|
|
343
|
+
reasoning: action.reasoning,
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
// Try to find JSON object in response
|
|
348
|
+
const objectMatch = response.match(/\{[\s\S]*\}/);
|
|
349
|
+
if (objectMatch) {
|
|
350
|
+
try {
|
|
351
|
+
const action = JSON.parse(objectMatch[0]);
|
|
352
|
+
return {
|
|
353
|
+
type: action.type || 'answer',
|
|
354
|
+
params: action.params || { value: response },
|
|
355
|
+
reasoning: action.reasoning,
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
catch {
|
|
359
|
+
// Fall through to default
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
// Default: treat entire response as answer
|
|
363
|
+
return {
|
|
364
|
+
type: 'answer',
|
|
365
|
+
params: { value: response },
|
|
366
|
+
reasoning: 'Could not parse action JSON',
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Collect relevant chunks from environment
|
|
372
|
+
*/
|
|
373
|
+
collectRelevantChunks(env) {
|
|
374
|
+
const allChunks = [];
|
|
375
|
+
const seenIds = new Set();
|
|
376
|
+
// Collect from all chunk variables
|
|
377
|
+
for (const varName of env.listVariables()) {
|
|
378
|
+
if (varName.startsWith('_'))
|
|
379
|
+
continue; // Skip internal variables
|
|
380
|
+
const chunks = env.getChunks(varName);
|
|
381
|
+
for (const chunk of chunks) {
|
|
382
|
+
if (!seenIds.has(chunk.id)) {
|
|
383
|
+
seenIds.add(chunk.id);
|
|
384
|
+
allChunks.push(chunk);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return allChunks;
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Convert SearchResult[] to EnhancedChunk[]
|
|
392
|
+
*/
|
|
393
|
+
convertToEnhancedChunks(results) {
|
|
394
|
+
return results.map(r => ({
|
|
395
|
+
id: r.id,
|
|
396
|
+
content: r.content,
|
|
397
|
+
embedding: [],
|
|
398
|
+
source: r.metadata?.source || 'unknown',
|
|
399
|
+
metadata: r.metadata,
|
|
400
|
+
createdAt: r.metadata?.createdAt ? new Date(r.metadata.createdAt) : new Date(),
|
|
401
|
+
updatedAt: r.metadata?.updatedAt ? new Date(r.metadata.updatedAt) : new Date(),
|
|
402
|
+
lastAccessedAt: r.metadata?.lastAccessedAt ? new Date(r.metadata.lastAccessedAt) : null,
|
|
403
|
+
accessCount: r.metadata?.accessCount || 0,
|
|
404
|
+
importance: r.metadata?.importance || 0.5,
|
|
405
|
+
decayScore: r.metadata?.decayScore || 1.0,
|
|
406
|
+
isArchived: r.metadata?.isArchived || false,
|
|
407
|
+
chunkType: r.metadata?.chunkType || 'documentation',
|
|
408
|
+
relatedChunkIds: r.metadata?.relatedChunkIds || [],
|
|
409
|
+
entities: r.metadata?.entities || [],
|
|
410
|
+
sourceConversationId: r.metadata?.sourceConversationId,
|
|
411
|
+
sourceMessageIndex: r.metadata?.sourceMessageIndex,
|
|
412
|
+
}));
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Update configuration
|
|
416
|
+
*/
|
|
417
|
+
updateConfig(config) {
|
|
418
|
+
this.config = {
|
|
419
|
+
...this.config,
|
|
420
|
+
...config,
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Get current configuration
|
|
425
|
+
*/
|
|
426
|
+
getConfig() {
|
|
427
|
+
return { ...this.config };
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
let instance = null;
|
|
431
|
+
export function createRecursiveRetrievalController(vectorStore, embeddings, llm, subLlm, config) {
|
|
432
|
+
return new RecursiveRetrievalController(vectorStore, embeddings, llm, subLlm, config);
|
|
433
|
+
}
|
|
434
|
+
export function getRecursiveRetrievalController(vectorStore, embeddings, llm, subLlm, config) {
|
|
435
|
+
if (!instance) {
|
|
436
|
+
instance = new RecursiveRetrievalController(vectorStore, embeddings, llm, subLlm, config);
|
|
437
|
+
}
|
|
438
|
+
return instance;
|
|
439
|
+
}
|
|
440
|
+
export function resetRecursiveRetrievalController() {
|
|
441
|
+
instance = null;
|
|
442
|
+
}
|
|
443
|
+
//# sourceMappingURL=recursiveRetrieval.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recursiveRetrieval.js","sourceRoot":"","sources":["../../src/services/recursiveRetrieval.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,EAEL,wBAAwB,EAIxB,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,GACb,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAgB,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAelE,MAAM,CAAC,MAAM,wBAAwB,GAAoB;IACvD,iBAAiB,EAAE,EAAE;IACrB,aAAa,EAAE,EAAE;IACjB,uBAAuB,EAAE,IAAI;IAC7B,UAAU,EAAE,IAAI;IAChB,SAAS,EAAE,MAAM;IACjB,oBAAoB,EAAE;QACpB,gBAAgB,EAAE,KAAK;QACvB,kBAAkB,EAAE,MAAM;KAC3B;IACD,mBAAmB,EAAE,IAAI;CAC1B,CAAC;AAoCF;;;;GAIG;AACH,MAAM,OAAO,4BAA4B;IAC/B,WAAW,CAAuB;IAClC,UAAU,CAAsB;IAChC,GAAG,CAAa;IAChB,MAAM,CAAa;IACnB,MAAM,CAAkB;IACxB,YAAY,CAAe;IAEnC,YACE,WAAiC,EACjC,UAA+B,EAC/B,GAAe,EACf,MAAmB,EACnB,MAAiC;QAEjC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI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raversalOptions, type GraphTraversalResult, type Contradiction, type PotentialContradiction, type GraphStats, type FindRelatedOptions, type RelatedChunk, type RelationshipBatch, type RelationshipBatchResult } from '../types/relationships.js';
|
|
2
|
+
import { ChunkType, RelationshipType } from '../types/memory.js';
|
|
3
|
+
import { MemoryMetadataStore } from './memoryMetadataStore.js';
|
|
4
|
+
/**
|
|
5
|
+
* Graph operations for relationship-based retrieval
|
|
6
|
+
*
|
|
7
|
+
* This service provides graph traversal, contradiction detection, and
|
|
8
|
+
* relationship management capabilities for the knowledge base.
|
|
9
|
+
*/
|
|
10
|
+
export declare class RelationshipGraph {
|
|
11
|
+
private metadataStore;
|
|
12
|
+
constructor(metadataStore?: MemoryMetadataStore);
|
|
13
|
+
/**
|
|
14
|
+
* Add a relationship between two chunks
|
|
15
|
+
*/
|
|
16
|
+
addRelationship(fromId: string, toId: string, type: RelationshipType, options?: {
|
|
17
|
+
strength?: number;
|
|
18
|
+
bidirectional?: boolean;
|
|
19
|
+
metadata?: Record<string, unknown>;
|
|
20
|
+
}): void;
|
|
21
|
+
/**
|
|
22
|
+
* Add multiple relationships in a batch
|
|
23
|
+
*/
|
|
24
|
+
addRelationshipBatch(batch: RelationshipBatch): RelationshipBatchResult;
|
|
25
|
+
/**
|
|
26
|
+
* Remove a relationship between two chunks
|
|
27
|
+
*/
|
|
28
|
+
removeRelationship(fromId: string, toId: string, type: RelationshipType): void;
|
|
29
|
+
/**
|
|
30
|
+
* Traverse the graph from a starting chunk using BFS
|
|
31
|
+
*/
|
|
32
|
+
traverse(startChunkId: string, options?: Partial<GraphTraversalOptions>): GraphTraversalResult;
|
|
33
|
+
/**
|
|
34
|
+
* Find all chunks related to a given chunk
|
|
35
|
+
*/
|
|
36
|
+
findRelated(chunkId: string, options?: FindRelatedOptions): RelatedChunk[];
|
|
37
|
+
/**
|
|
38
|
+
* Find known contradictions for a chunk
|
|
39
|
+
*/
|
|
40
|
+
findContradictions(chunkId: string): Contradiction[];
|
|
41
|
+
/**
|
|
42
|
+
* Detect potential contradictions for a new chunk based on similarity and temporal factors
|
|
43
|
+
*/
|
|
44
|
+
detectPotentialContradictions(newChunkId: string, newChunkType: ChunkType, newChunkCreatedAt: Date, similarChunks: Array<{
|
|
45
|
+
id: string;
|
|
46
|
+
similarity: number;
|
|
47
|
+
chunkType: ChunkType;
|
|
48
|
+
createdAt: string;
|
|
49
|
+
}>): PotentialContradiction[];
|
|
50
|
+
/**
|
|
51
|
+
* Mark a chunk as superseding another
|
|
52
|
+
*/
|
|
53
|
+
markSupersedes(newChunkId: string, oldChunkId: string, strength?: number): void;
|
|
54
|
+
/**
|
|
55
|
+
* Mark two chunks as contradicting each other
|
|
56
|
+
*/
|
|
57
|
+
markContradiction(chunkId1: string, chunkId2: string, strength?: number, metadata?: Record<string, unknown>): void;
|
|
58
|
+
/**
|
|
59
|
+
* Find all chunks that supersede a given chunk (chain of updates)
|
|
60
|
+
*/
|
|
61
|
+
findSupersessionChain(chunkId: string): string[];
|
|
62
|
+
/**
|
|
63
|
+
* Get the latest version in a supersession chain
|
|
64
|
+
*/
|
|
65
|
+
getLatestVersion(chunkId: string): string;
|
|
66
|
+
/**
|
|
67
|
+
* Get graph statistics
|
|
68
|
+
*/
|
|
69
|
+
getStats(): GraphStats;
|
|
70
|
+
/**
|
|
71
|
+
* Find strongly connected components (clusters of related knowledge)
|
|
72
|
+
*/
|
|
73
|
+
findClusters(minClusterSize?: number): string[][];
|
|
74
|
+
}
|
|
75
|
+
export declare function getRelationshipGraph(metadataStore?: MemoryMetadataStore): RelationshipGraph;
|
|
76
|
+
export declare function resetRelationshipGraph(): void;
|
|
77
|
+
//# sourceMappingURL=relationshipGraph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relationshipGraph.d.ts","sourceRoot":"","sources":["../../src/services/relationshipGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,qBAAqB,EAE1B,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAA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