@danielsimonjr/memory-mcp 11.0.1 → 11.1.1
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/LICENSE +22 -22
- package/dist/core/EntityManager.d.ts +10 -15
- package/dist/core/EntityManager.d.ts.map +1 -1
- package/dist/core/EntityManager.js +21 -54
- package/dist/core/GraphStorage.d.ts +0 -51
- package/dist/core/GraphStorage.d.ts.map +1 -1
- package/dist/core/GraphStorage.js +2 -79
- package/dist/core/GraphTraversal.d.ts +2 -7
- package/dist/core/GraphTraversal.d.ts.map +1 -1
- package/dist/core/GraphTraversal.js +2 -19
- package/dist/core/ManagerContext.d.ts +0 -4
- package/dist/core/ManagerContext.d.ts.map +1 -1
- package/dist/core/ManagerContext.js +2 -12
- package/dist/core/RelationManager.d.ts.map +1 -1
- package/dist/core/RelationManager.js +4 -5
- package/dist/core/SQLiteStorage.d.ts.map +1 -1
- package/dist/core/SQLiteStorage.js +2 -3
- package/dist/core/TransactionManager.d.ts +2 -207
- package/dist/core/TransactionManager.d.ts.map +1 -1
- package/dist/core/TransactionManager.js +6 -482
- package/dist/core/index.d.ts +1 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -3
- package/dist/features/ArchiveManager.d.ts +2 -14
- package/dist/features/ArchiveManager.d.ts.map +1 -1
- package/dist/features/ArchiveManager.js +3 -44
- package/dist/features/CompressionManager.d.ts +4 -14
- package/dist/features/CompressionManager.d.ts.map +1 -1
- package/dist/features/CompressionManager.js +9 -74
- package/dist/features/IOManager.d.ts +2 -6
- package/dist/features/IOManager.d.ts.map +1 -1
- package/dist/features/IOManager.js +10 -105
- package/dist/features/StreamingExporter.d.ts +4 -27
- package/dist/features/StreamingExporter.d.ts.map +1 -1
- package/dist/features/StreamingExporter.js +4 -65
- package/dist/features/index.d.ts +0 -2
- package/dist/features/index.d.ts.map +1 -1
- package/dist/features/index.js +0 -3
- package/dist/search/EmbeddingService.d.ts +9 -108
- package/dist/search/EmbeddingService.d.ts.map +1 -1
- package/dist/search/EmbeddingService.js +15 -187
- package/dist/search/FuzzySearch.js +1 -1
- package/dist/search/SavedSearchManager.d.ts.map +1 -1
- package/dist/search/SavedSearchManager.js +2 -3
- package/dist/search/SearchManager.d.ts +1 -42
- package/dist/search/SearchManager.d.ts.map +1 -1
- package/dist/search/SearchManager.js +0 -115
- package/dist/search/SemanticSearch.d.ts +1 -4
- package/dist/search/SemanticSearch.d.ts.map +1 -1
- package/dist/search/SemanticSearch.js +2 -12
- package/dist/search/TFIDFIndexManager.d.ts +0 -88
- package/dist/search/TFIDFIndexManager.d.ts.map +1 -1
- package/dist/search/TFIDFIndexManager.js +0 -217
- package/dist/search/index.d.ts +1 -18
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +1 -32
- package/dist/server/MCPServer.d.ts.map +1 -1
- package/dist/server/MCPServer.js +4 -1
- package/dist/server/responseCompressor.js +5 -5
- package/dist/server/toolDefinitions.d.ts.map +1 -1
- package/dist/server/toolDefinitions.js +5 -1
- package/dist/server/toolHandlers.d.ts +9 -5
- package/dist/server/toolHandlers.d.ts.map +1 -1
- package/dist/server/toolHandlers.js +23 -8
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +2 -579
- package/dist/types/types.d.ts.map +1 -1
- package/dist/utils/compressedCache.d.ts +0 -29
- package/dist/utils/compressedCache.d.ts.map +1 -1
- package/dist/utils/compressedCache.js +0 -39
- package/dist/utils/entityUtils.d.ts +1 -59
- package/dist/utils/entityUtils.d.ts.map +1 -1
- package/dist/utils/entityUtils.js +3 -113
- package/dist/utils/errors.d.ts +0 -18
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +0 -24
- package/dist/utils/index.d.ts +2 -6
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -14
- package/dist/utils/logger.d.ts +0 -7
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +2 -9
- package/dist/utils/parallelUtils.d.ts +1 -5
- package/dist/utils/parallelUtils.d.ts.map +1 -1
- package/dist/utils/parallelUtils.js +1 -23
- package/dist/utils/schemas.d.ts +16 -16
- package/dist/utils/schemas.d.ts.map +1 -1
- package/dist/utils/schemas.js +12 -12
- package/dist/utils/taskScheduler.d.ts +0 -4
- package/dist/utils/taskScheduler.d.ts.map +1 -1
- package/dist/utils/taskScheduler.js +1 -21
- package/dist/workers/WorkerPool.d.ts +81 -0
- package/dist/workers/WorkerPool.d.ts.map +1 -0
- package/dist/workers/WorkerPool.js +121 -0
- package/dist/workers/index.d.ts +1 -1
- package/dist/workers/index.d.ts.map +1 -1
- package/dist/workers/levenshteinWorker.js +1 -1
- package/package.json +1 -4
- package/dist/__tests__/file-path.test.js +0 -119
- package/dist/__tests__/knowledge-graph.test.js +0 -318
- package/dist/core/GraphEventEmitter.d.ts +0 -202
- package/dist/core/GraphEventEmitter.d.ts.map +0 -1
- package/dist/core/GraphEventEmitter.js +0 -346
- package/dist/features/KeywordExtractor.d.ts +0 -61
- package/dist/features/KeywordExtractor.d.ts.map +0 -1
- package/dist/features/KeywordExtractor.js +0 -126
- package/dist/features/ObservationNormalizer.d.ts +0 -90
- package/dist/features/ObservationNormalizer.d.ts.map +0 -1
- package/dist/features/ObservationNormalizer.js +0 -193
- package/dist/memory.jsonl +0 -1
- package/dist/search/BM25Search.d.ts +0 -148
- package/dist/search/BM25Search.d.ts.map +0 -1
- package/dist/search/BM25Search.js +0 -339
- package/dist/search/EarlyTerminationManager.d.ts +0 -140
- package/dist/search/EarlyTerminationManager.d.ts.map +0 -1
- package/dist/search/EarlyTerminationManager.js +0 -279
- package/dist/search/EmbeddingCache.d.ts +0 -175
- package/dist/search/EmbeddingCache.d.ts.map +0 -1
- package/dist/search/EmbeddingCache.js +0 -246
- package/dist/search/HybridScorer.d.ts +0 -181
- package/dist/search/HybridScorer.d.ts.map +0 -1
- package/dist/search/HybridScorer.js +0 -257
- package/dist/search/HybridSearchManager.d.ts +0 -80
- package/dist/search/HybridSearchManager.d.ts.map +0 -1
- package/dist/search/HybridSearchManager.js +0 -187
- package/dist/search/IncrementalIndexer.d.ts +0 -201
- package/dist/search/IncrementalIndexer.d.ts.map +0 -1
- package/dist/search/IncrementalIndexer.js +0 -342
- package/dist/search/OptimizedInvertedIndex.d.ts +0 -163
- package/dist/search/OptimizedInvertedIndex.d.ts.map +0 -1
- package/dist/search/OptimizedInvertedIndex.js +0 -358
- package/dist/search/ParallelSearchExecutor.d.ts +0 -172
- package/dist/search/ParallelSearchExecutor.d.ts.map +0 -1
- package/dist/search/ParallelSearchExecutor.js +0 -309
- package/dist/search/QuantizedVectorStore.d.ts +0 -171
- package/dist/search/QuantizedVectorStore.d.ts.map +0 -1
- package/dist/search/QuantizedVectorStore.js +0 -307
- package/dist/search/QueryAnalyzer.d.ts +0 -76
- package/dist/search/QueryAnalyzer.d.ts.map +0 -1
- package/dist/search/QueryAnalyzer.js +0 -227
- package/dist/search/QueryCostEstimator.d.ts +0 -244
- package/dist/search/QueryCostEstimator.d.ts.map +0 -1
- package/dist/search/QueryCostEstimator.js +0 -652
- package/dist/search/QueryPlanCache.d.ts +0 -220
- package/dist/search/QueryPlanCache.d.ts.map +0 -1
- package/dist/search/QueryPlanCache.js +0 -379
- package/dist/search/QueryPlanner.d.ts +0 -58
- package/dist/search/QueryPlanner.d.ts.map +0 -1
- package/dist/search/QueryPlanner.js +0 -137
- package/dist/search/ReflectionManager.d.ts +0 -120
- package/dist/search/ReflectionManager.d.ts.map +0 -1
- package/dist/search/ReflectionManager.js +0 -231
- package/dist/search/SymbolicSearch.d.ts +0 -61
- package/dist/search/SymbolicSearch.d.ts.map +0 -1
- package/dist/search/SymbolicSearch.js +0 -163
- package/dist/search/TFIDFEventSync.d.ts +0 -85
- package/dist/search/TFIDFEventSync.d.ts.map +0 -1
- package/dist/search/TFIDFEventSync.js +0 -133
- package/dist/utils/BatchProcessor.d.ts +0 -271
- package/dist/utils/BatchProcessor.d.ts.map +0 -1
- package/dist/utils/BatchProcessor.js +0 -376
- package/dist/utils/MemoryMonitor.d.ts +0 -176
- package/dist/utils/MemoryMonitor.d.ts.map +0 -1
- package/dist/utils/MemoryMonitor.js +0 -305
- package/dist/utils/WorkerPoolManager.d.ts +0 -233
- package/dist/utils/WorkerPoolManager.d.ts.map +0 -1
- package/dist/utils/WorkerPoolManager.js +0 -420
- package/dist/utils/operationUtils.d.ts +0 -124
- package/dist/utils/operationUtils.d.ts.map +0 -1
- package/dist/utils/operationUtils.js +0 -175
- package/dist/vitest.config.js +0 -13
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Query Planner
|
|
3
|
-
*
|
|
4
|
-
* Phase 11: Generates execution plans for queries based on analysis.
|
|
5
|
-
*
|
|
6
|
-
* @module search/QueryPlanner
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Query Planner generates execution plans from query analysis.
|
|
10
|
-
*
|
|
11
|
-
* Creates optimized plans that:
|
|
12
|
-
* - Select appropriate search layers
|
|
13
|
-
* - Determine execution strategy (parallel/sequential)
|
|
14
|
-
* - Set up query dependencies
|
|
15
|
-
* - Configure merge strategies
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* const analyzer = new QueryAnalyzer();
|
|
20
|
-
* const planner = new QueryPlanner();
|
|
21
|
-
*
|
|
22
|
-
* const analysis = analyzer.analyze('Find projects by Alice');
|
|
23
|
-
* const plan = planner.createPlan('Find projects by Alice', analysis);
|
|
24
|
-
* // { originalQuery: '...', subQueries: [...], executionStrategy: 'iterative', ... }
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export class QueryPlanner {
|
|
28
|
-
/**
|
|
29
|
-
* Create an execution plan from query analysis.
|
|
30
|
-
*/
|
|
31
|
-
createPlan(query, analysis) {
|
|
32
|
-
const subQueries = this.createSubQueries(query, analysis);
|
|
33
|
-
const executionStrategy = this.selectExecutionStrategy(subQueries);
|
|
34
|
-
const mergeStrategy = this.selectMergeStrategy(analysis);
|
|
35
|
-
return {
|
|
36
|
-
originalQuery: query,
|
|
37
|
-
subQueries,
|
|
38
|
-
executionStrategy,
|
|
39
|
-
mergeStrategy,
|
|
40
|
-
estimatedComplexity: this.calculateComplexity(subQueries),
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Create sub-queries from analysis.
|
|
45
|
-
*/
|
|
46
|
-
createSubQueries(query, analysis) {
|
|
47
|
-
const subQueries = [];
|
|
48
|
-
let id = 0;
|
|
49
|
-
// If query was decomposed, create sub-query for each part
|
|
50
|
-
if (analysis.subQueries && analysis.subQueries.length > 1) {
|
|
51
|
-
for (const sq of analysis.subQueries) {
|
|
52
|
-
subQueries.push({
|
|
53
|
-
id: `sq_${id++}`,
|
|
54
|
-
query: sq,
|
|
55
|
-
targetLayer: this.selectLayer(analysis),
|
|
56
|
-
priority: id === 1 ? 1 : 2,
|
|
57
|
-
dependsOn: id > 1 ? [`sq_${id - 2}`] : undefined,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
// Single query
|
|
63
|
-
subQueries.push({
|
|
64
|
-
id: `sq_${id}`,
|
|
65
|
-
query,
|
|
66
|
-
targetLayer: this.selectLayer(analysis),
|
|
67
|
-
priority: 1,
|
|
68
|
-
filters: this.buildFilters(analysis),
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return subQueries;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Select the most appropriate search layer.
|
|
75
|
-
*/
|
|
76
|
-
selectLayer(analysis) {
|
|
77
|
-
// Use symbolic for tag/type/date filtered queries
|
|
78
|
-
if (analysis.temporalRange || analysis.requiredInfoTypes.includes('temporal')) {
|
|
79
|
-
return 'symbolic';
|
|
80
|
-
}
|
|
81
|
-
// Use semantic for complex concept queries
|
|
82
|
-
if (analysis.complexity === 'high' || analysis.questionType === 'comparative') {
|
|
83
|
-
return 'semantic';
|
|
84
|
-
}
|
|
85
|
-
// Use hybrid for balanced approach
|
|
86
|
-
return 'hybrid';
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Select execution strategy based on sub-queries.
|
|
90
|
-
*/
|
|
91
|
-
selectExecutionStrategy(subQueries) {
|
|
92
|
-
const hasDependencies = subQueries.some(sq => sq.dependsOn && sq.dependsOn.length > 0);
|
|
93
|
-
if (hasDependencies)
|
|
94
|
-
return 'sequential';
|
|
95
|
-
if (subQueries.length > 1)
|
|
96
|
-
return 'parallel';
|
|
97
|
-
return 'iterative';
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Select merge strategy based on question type.
|
|
101
|
-
*/
|
|
102
|
-
selectMergeStrategy(analysis) {
|
|
103
|
-
switch (analysis.questionType) {
|
|
104
|
-
case 'aggregation': return 'union';
|
|
105
|
-
case 'comparative': return 'intersection';
|
|
106
|
-
default: return 'weighted';
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Build symbolic filters from analysis.
|
|
111
|
-
*/
|
|
112
|
-
buildFilters(analysis) {
|
|
113
|
-
const filters = {};
|
|
114
|
-
let hasFilters = false;
|
|
115
|
-
if (analysis.temporalRange) {
|
|
116
|
-
filters.dateRange = {
|
|
117
|
-
start: analysis.temporalRange.start || '',
|
|
118
|
-
end: analysis.temporalRange.end || '',
|
|
119
|
-
};
|
|
120
|
-
hasFilters = true;
|
|
121
|
-
}
|
|
122
|
-
return hasFilters ? filters : undefined;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Calculate plan complexity score.
|
|
126
|
-
*/
|
|
127
|
-
calculateComplexity(subQueries) {
|
|
128
|
-
let complexity = subQueries.length;
|
|
129
|
-
for (const sq of subQueries) {
|
|
130
|
-
if (sq.dependsOn)
|
|
131
|
-
complexity += sq.dependsOn.length * 0.5;
|
|
132
|
-
if (sq.filters)
|
|
133
|
-
complexity += 0.5;
|
|
134
|
-
}
|
|
135
|
-
return Math.min(complexity, 10);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reflection Manager
|
|
3
|
-
*
|
|
4
|
-
* Phase 11: Implements reflection-based iterative retrieval
|
|
5
|
-
* that refines results until adequate.
|
|
6
|
-
*
|
|
7
|
-
* @module search/ReflectionManager
|
|
8
|
-
*/
|
|
9
|
-
import type { ReadonlyKnowledgeGraph, HybridSearchResult, HybridSearchOptions } from '../types/index.js';
|
|
10
|
-
import type { HybridSearchManager } from './HybridSearchManager.js';
|
|
11
|
-
import type { QueryAnalyzer } from './QueryAnalyzer.js';
|
|
12
|
-
/**
|
|
13
|
-
* Options for reflection-based retrieval.
|
|
14
|
-
*/
|
|
15
|
-
export interface ReflectionOptions {
|
|
16
|
-
/** Maximum number of reflection iterations (default: 3) */
|
|
17
|
-
maxIterations?: number;
|
|
18
|
-
/** Adequacy threshold 0-1 (default: 0.7) */
|
|
19
|
-
adequacyThreshold?: number;
|
|
20
|
-
/** Minimum results required (default: 3) */
|
|
21
|
-
minResults?: number;
|
|
22
|
-
/** Hybrid search options */
|
|
23
|
-
searchOptions?: Partial<HybridSearchOptions>;
|
|
24
|
-
/** Phase 12 Sprint 4: Progressive limit increase factor (default: 1.5) */
|
|
25
|
-
limitIncreaseFactor?: number;
|
|
26
|
-
/** Phase 12 Sprint 4: Initial search limit (default: 10) */
|
|
27
|
-
initialLimit?: number;
|
|
28
|
-
/** Phase 12 Sprint 4: Focus on specific missing info types */
|
|
29
|
-
focusMissingTypes?: boolean;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Phase 12 Sprint 4: Refinement history entry.
|
|
33
|
-
*/
|
|
34
|
-
export interface RefinementHistoryEntry {
|
|
35
|
-
/** Iteration number (1-based) */
|
|
36
|
-
iteration: number;
|
|
37
|
-
/** Query used in this iteration */
|
|
38
|
-
query: string;
|
|
39
|
-
/** Search limit used */
|
|
40
|
-
limit: number;
|
|
41
|
-
/** Results found in this iteration */
|
|
42
|
-
resultsFound: number;
|
|
43
|
-
/** Adequacy score after this iteration */
|
|
44
|
-
adequacyScore: number;
|
|
45
|
-
/** Reason for refinement (if not final) */
|
|
46
|
-
refinementReason?: string;
|
|
47
|
-
/** Missing info types that triggered refinement */
|
|
48
|
-
missingInfoTypes?: string[];
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Result of reflection-based retrieval.
|
|
52
|
-
*/
|
|
53
|
-
export interface ReflectionResult {
|
|
54
|
-
results: HybridSearchResult[];
|
|
55
|
-
iterations: number;
|
|
56
|
-
adequate: boolean;
|
|
57
|
-
refinements: string[];
|
|
58
|
-
adequacyScore: number;
|
|
59
|
-
/** Phase 12 Sprint 4: Detailed refinement history */
|
|
60
|
-
refinementHistory: RefinementHistoryEntry[];
|
|
61
|
-
/** Phase 12 Sprint 4: Final search limit used */
|
|
62
|
-
finalLimit: number;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Reflection Manager for iterative retrieval refinement.
|
|
66
|
-
*
|
|
67
|
-
* Implements the SimpleMem-inspired reflection loop:
|
|
68
|
-
* 1. Execute initial search
|
|
69
|
-
* 2. Check result adequacy
|
|
70
|
-
* 3. If inadequate, refine query and repeat
|
|
71
|
-
* 4. Combine results from all iterations
|
|
72
|
-
*
|
|
73
|
-
* @example
|
|
74
|
-
* ```typescript
|
|
75
|
-
* const reflection = new ReflectionManager(hybridSearch, analyzer);
|
|
76
|
-
* const result = await reflection.retrieveWithReflection(
|
|
77
|
-
* graph,
|
|
78
|
-
* 'What projects did Alice work on?',
|
|
79
|
-
* { maxIterations: 3 }
|
|
80
|
-
* );
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export declare class ReflectionManager {
|
|
84
|
-
private hybridSearch;
|
|
85
|
-
private analyzer;
|
|
86
|
-
constructor(hybridSearch: HybridSearchManager, analyzer: QueryAnalyzer);
|
|
87
|
-
/**
|
|
88
|
-
* Perform retrieval with reflection-based refinement.
|
|
89
|
-
*
|
|
90
|
-
* Phase 12 Sprint 4 enhancements:
|
|
91
|
-
* - Progressive limit increase per round
|
|
92
|
-
* - Focused query refinement based on missing information
|
|
93
|
-
* - Detailed refinement history tracking
|
|
94
|
-
*/
|
|
95
|
-
retrieveWithReflection(graph: ReadonlyKnowledgeGraph, query: string, options?: ReflectionOptions): Promise<ReflectionResult>;
|
|
96
|
-
/**
|
|
97
|
-
* Find missing information types based on analysis requirements.
|
|
98
|
-
* @private
|
|
99
|
-
*/
|
|
100
|
-
private findMissingInfoTypes;
|
|
101
|
-
/**
|
|
102
|
-
* Refine query with focus on missing information types.
|
|
103
|
-
* @private
|
|
104
|
-
*/
|
|
105
|
-
private refineQueryFocused;
|
|
106
|
-
/**
|
|
107
|
-
* Get human-readable reason for refinement.
|
|
108
|
-
* @private
|
|
109
|
-
*/
|
|
110
|
-
private getRefinementReason;
|
|
111
|
-
/**
|
|
112
|
-
* Calculate result adequacy score.
|
|
113
|
-
*/
|
|
114
|
-
private calculateAdequacy;
|
|
115
|
-
/**
|
|
116
|
-
* Refine query based on current results and analysis.
|
|
117
|
-
*/
|
|
118
|
-
private refineQuery;
|
|
119
|
-
}
|
|
120
|
-
//# sourceMappingURL=ReflectionManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ReflectionManager.d.ts","sourceRoot":"","sources":["../../src/search/ReflectionManager.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,sBAAsB,EAEtB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,2DAA2D;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4CAA4C;IAC5C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4BAA4B;IAC5B,aAAa,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAC7C,0EAA0E;IAC1E,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,4DAA4D;IAC5D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8DAA8D;IAC9D,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,mCAAmC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mDAAmD;IACnD,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,iBAAiB,EAAE,sBAAsB,EAAE,CAAC;IAC5C,iDAAiD;IACjD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,QAAQ;gBADR,YAAY,EAAE,mBAAmB,EACjC,QAAQ,EAAE,aAAa;IAGjC;;;;;;;OAOG;IACG,sBAAsB,CAC1B,KAAK,EAAE,sBAAsB,EAC7B,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,gBAAgB,CAAC;IAwG5B;;;OAGG;IACH,OAAO,CAAC,oBAAoB;IA4B5B;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAqC1B;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAoB3B;;OAEG;IACH,OAAO,CAAC,iBAAiB;IA6BzB;;OAEG;IACH,OAAO,CAAC,WAAW;CA6BpB"}
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Reflection Manager
|
|
3
|
-
*
|
|
4
|
-
* Phase 11: Implements reflection-based iterative retrieval
|
|
5
|
-
* that refines results until adequate.
|
|
6
|
-
*
|
|
7
|
-
* @module search/ReflectionManager
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Reflection Manager for iterative retrieval refinement.
|
|
11
|
-
*
|
|
12
|
-
* Implements the SimpleMem-inspired reflection loop:
|
|
13
|
-
* 1. Execute initial search
|
|
14
|
-
* 2. Check result adequacy
|
|
15
|
-
* 3. If inadequate, refine query and repeat
|
|
16
|
-
* 4. Combine results from all iterations
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* const reflection = new ReflectionManager(hybridSearch, analyzer);
|
|
21
|
-
* const result = await reflection.retrieveWithReflection(
|
|
22
|
-
* graph,
|
|
23
|
-
* 'What projects did Alice work on?',
|
|
24
|
-
* { maxIterations: 3 }
|
|
25
|
-
* );
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export class ReflectionManager {
|
|
29
|
-
hybridSearch;
|
|
30
|
-
analyzer;
|
|
31
|
-
constructor(hybridSearch, analyzer) {
|
|
32
|
-
this.hybridSearch = hybridSearch;
|
|
33
|
-
this.analyzer = analyzer;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Perform retrieval with reflection-based refinement.
|
|
37
|
-
*
|
|
38
|
-
* Phase 12 Sprint 4 enhancements:
|
|
39
|
-
* - Progressive limit increase per round
|
|
40
|
-
* - Focused query refinement based on missing information
|
|
41
|
-
* - Detailed refinement history tracking
|
|
42
|
-
*/
|
|
43
|
-
async retrieveWithReflection(graph, query, options = {}) {
|
|
44
|
-
const { maxIterations = 3, adequacyThreshold = 0.7, minResults = 3, searchOptions = {}, limitIncreaseFactor = 1.5, initialLimit = 10, focusMissingTypes = true, } = options;
|
|
45
|
-
const allResults = [];
|
|
46
|
-
const refinements = [];
|
|
47
|
-
const refinementHistory = [];
|
|
48
|
-
let currentQuery = query;
|
|
49
|
-
let iteration = 0;
|
|
50
|
-
let adequacyScore = 0;
|
|
51
|
-
let currentLimit = initialLimit;
|
|
52
|
-
// Get initial analysis for tracking
|
|
53
|
-
const analysis = this.analyzer.analyze(query);
|
|
54
|
-
while (iteration < maxIterations) {
|
|
55
|
-
iteration++;
|
|
56
|
-
// Calculate current limit with progressive increase
|
|
57
|
-
currentLimit = Math.round(initialLimit * Math.pow(limitIncreaseFactor, iteration - 1));
|
|
58
|
-
// Execute search with current limit
|
|
59
|
-
const results = await this.hybridSearch.searchWithEntities(graph, currentQuery, { ...searchOptions, limit: currentLimit });
|
|
60
|
-
// Track results found this iteration (before deduplication)
|
|
61
|
-
const newResultsCount = results.filter(r => !allResults.some(existing => existing.entity.name === r.entity.name)).length;
|
|
62
|
-
// Add new results (deduplicated)
|
|
63
|
-
for (const result of results) {
|
|
64
|
-
if (!allResults.some(r => r.entity.name === result.entity.name)) {
|
|
65
|
-
allResults.push(result);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
// Check adequacy
|
|
69
|
-
const iterAnalysis = this.analyzer.analyze(currentQuery);
|
|
70
|
-
adequacyScore = this.calculateAdequacy(allResults, iterAnalysis, minResults);
|
|
71
|
-
// Determine missing info types
|
|
72
|
-
const missingInfoTypes = this.findMissingInfoTypes(allResults, analysis);
|
|
73
|
-
// Record history entry
|
|
74
|
-
const historyEntry = {
|
|
75
|
-
iteration,
|
|
76
|
-
query: currentQuery,
|
|
77
|
-
limit: currentLimit,
|
|
78
|
-
resultsFound: newResultsCount,
|
|
79
|
-
adequacyScore,
|
|
80
|
-
};
|
|
81
|
-
if (adequacyScore >= adequacyThreshold) {
|
|
82
|
-
refinementHistory.push(historyEntry);
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
// Refine query if not adequate
|
|
86
|
-
const refinedQuery = focusMissingTypes && missingInfoTypes.length > 0
|
|
87
|
-
? this.refineQueryFocused(currentQuery, allResults, analysis, missingInfoTypes)
|
|
88
|
-
: this.refineQuery(currentQuery, allResults, analysis);
|
|
89
|
-
if (refinedQuery === currentQuery) {
|
|
90
|
-
// No refinement possible
|
|
91
|
-
historyEntry.refinementReason = 'No further refinement possible';
|
|
92
|
-
refinementHistory.push(historyEntry);
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
// Record refinement details in history
|
|
96
|
-
historyEntry.refinementReason = this.getRefinementReason(currentQuery, refinedQuery, missingInfoTypes);
|
|
97
|
-
historyEntry.missingInfoTypes = missingInfoTypes;
|
|
98
|
-
refinementHistory.push(historyEntry);
|
|
99
|
-
refinements.push(refinedQuery);
|
|
100
|
-
currentQuery = refinedQuery;
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
results: allResults.sort((a, b) => b.scores.combined - a.scores.combined),
|
|
104
|
-
iterations: iteration,
|
|
105
|
-
adequate: adequacyScore >= adequacyThreshold,
|
|
106
|
-
refinements,
|
|
107
|
-
adequacyScore,
|
|
108
|
-
refinementHistory,
|
|
109
|
-
finalLimit: currentLimit,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Find missing information types based on analysis requirements.
|
|
114
|
-
* @private
|
|
115
|
-
*/
|
|
116
|
-
findMissingInfoTypes(results, analysis) {
|
|
117
|
-
const coveredTypes = new Set();
|
|
118
|
-
for (const result of results) {
|
|
119
|
-
const entityType = result.entity.entityType.toLowerCase();
|
|
120
|
-
coveredTypes.add(entityType);
|
|
121
|
-
// Map entity types to info types
|
|
122
|
-
if (['person', 'people', 'user', 'employee'].includes(entityType)) {
|
|
123
|
-
coveredTypes.add('person');
|
|
124
|
-
}
|
|
125
|
-
if (['location', 'place', 'city', 'country', 'address'].includes(entityType)) {
|
|
126
|
-
coveredTypes.add('location');
|
|
127
|
-
}
|
|
128
|
-
if (result.entity.createdAt || result.entity.lastModified) {
|
|
129
|
-
coveredTypes.add('temporal');
|
|
130
|
-
}
|
|
131
|
-
// Entity type covers 'entity' requirement
|
|
132
|
-
coveredTypes.add('entity');
|
|
133
|
-
}
|
|
134
|
-
// Find which required types are missing
|
|
135
|
-
return analysis.requiredInfoTypes.filter(type => !coveredTypes.has(type));
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Refine query with focus on missing information types.
|
|
139
|
-
* @private
|
|
140
|
-
*/
|
|
141
|
-
refineQueryFocused(query, results, analysis, missingInfoTypes) {
|
|
142
|
-
const additions = [];
|
|
143
|
-
for (const missingType of missingInfoTypes) {
|
|
144
|
-
switch (missingType) {
|
|
145
|
-
case 'person':
|
|
146
|
-
additions.push('person people who');
|
|
147
|
-
break;
|
|
148
|
-
case 'location':
|
|
149
|
-
additions.push('location place where');
|
|
150
|
-
break;
|
|
151
|
-
case 'temporal':
|
|
152
|
-
additions.push('when date time');
|
|
153
|
-
break;
|
|
154
|
-
case 'quantity':
|
|
155
|
-
additions.push('count number how many');
|
|
156
|
-
break;
|
|
157
|
-
case 'reason':
|
|
158
|
-
additions.push('reason why because');
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
if (additions.length > 0) {
|
|
163
|
-
// Add relevant keywords to query
|
|
164
|
-
return `${query} ${additions.slice(0, 2).join(' ')}`;
|
|
165
|
-
}
|
|
166
|
-
// Fallback to standard refinement
|
|
167
|
-
return this.refineQuery(query, results, analysis);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Get human-readable reason for refinement.
|
|
171
|
-
* @private
|
|
172
|
-
*/
|
|
173
|
-
getRefinementReason(_originalQuery, refinedQuery, missingInfoTypes) {
|
|
174
|
-
if (missingInfoTypes.length > 0) {
|
|
175
|
-
return `Added keywords for missing info types: ${missingInfoTypes.join(', ')}`;
|
|
176
|
-
}
|
|
177
|
-
if (refinedQuery.includes('person people')) {
|
|
178
|
-
return 'Expanded query to find person-related entities';
|
|
179
|
-
}
|
|
180
|
-
if (refinedQuery.includes('recent history timeline')) {
|
|
181
|
-
return 'Added temporal context to query';
|
|
182
|
-
}
|
|
183
|
-
return 'Broadened query by removing constraints';
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Calculate result adequacy score.
|
|
187
|
-
*/
|
|
188
|
-
calculateAdequacy(results, analysis, minResults) {
|
|
189
|
-
let score = 0;
|
|
190
|
-
const weights = { quantity: 0.4, diversity: 0.3, relevance: 0.3 };
|
|
191
|
-
// Quantity: Do we have enough results?
|
|
192
|
-
const quantityScore = Math.min(results.length / minResults, 1);
|
|
193
|
-
score += quantityScore * weights.quantity;
|
|
194
|
-
// Diversity: Do results cover different entity types?
|
|
195
|
-
const types = new Set(results.map(r => r.entity.entityType));
|
|
196
|
-
const diversityScore = Math.min(types.size / 3, 1);
|
|
197
|
-
score += diversityScore * weights.diversity;
|
|
198
|
-
// Relevance: Average combined score
|
|
199
|
-
const avgScore = results.length > 0
|
|
200
|
-
? results.reduce((sum, r) => sum + r.scores.combined, 0) / results.length
|
|
201
|
-
: 0;
|
|
202
|
-
score += avgScore * weights.relevance;
|
|
203
|
-
// Suppress unused parameter warning - analysis reserved for future enhancements
|
|
204
|
-
void analysis;
|
|
205
|
-
return score;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Refine query based on current results and analysis.
|
|
209
|
-
*/
|
|
210
|
-
refineQuery(query, results, analysis) {
|
|
211
|
-
// Check what information types are missing
|
|
212
|
-
const coveredTypes = new Set();
|
|
213
|
-
for (const result of results) {
|
|
214
|
-
coveredTypes.add(result.entity.entityType.toLowerCase());
|
|
215
|
-
}
|
|
216
|
-
// If looking for persons but no person results, refine
|
|
217
|
-
if (analysis.requiredInfoTypes.includes('person') && !coveredTypes.has('person')) {
|
|
218
|
-
return `${query} person people`;
|
|
219
|
-
}
|
|
220
|
-
// If temporal query but no temporal context, add time hint
|
|
221
|
-
if (analysis.temporalRange && results.length < 3) {
|
|
222
|
-
return `${query} recent history timeline`;
|
|
223
|
-
}
|
|
224
|
-
// Broaden query by removing constraints
|
|
225
|
-
const broader = query.replace(/\b(only|just|exactly|specific)\b/gi, '');
|
|
226
|
-
if (broader !== query) {
|
|
227
|
-
return broader.trim();
|
|
228
|
-
}
|
|
229
|
-
return query;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Symbolic Search Layer
|
|
3
|
-
*
|
|
4
|
-
* Phase 11: Provides metadata-based filtering using structured predicates.
|
|
5
|
-
* Part of the three-layer hybrid search architecture.
|
|
6
|
-
*
|
|
7
|
-
* @module search/SymbolicSearch
|
|
8
|
-
*/
|
|
9
|
-
import type { Entity, SymbolicFilters } from '../types/index.js';
|
|
10
|
-
/**
|
|
11
|
-
* Result from symbolic search with match score.
|
|
12
|
-
*/
|
|
13
|
-
export interface SymbolicResult {
|
|
14
|
-
entity: Entity;
|
|
15
|
-
score: number;
|
|
16
|
-
matchedFilters: string[];
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Symbolic Search provides metadata-based filtering.
|
|
20
|
-
*
|
|
21
|
-
* Filters entities using structured predicates on tags, types,
|
|
22
|
-
* dates, importance, and hierarchy.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* const symbolic = new SymbolicSearch();
|
|
27
|
-
* const results = symbolic.search(entities, {
|
|
28
|
-
* tags: ['important'],
|
|
29
|
-
* entityTypes: ['person'],
|
|
30
|
-
* importance: { min: 5 }
|
|
31
|
-
* });
|
|
32
|
-
* ```
|
|
33
|
-
*/
|
|
34
|
-
export declare class SymbolicSearch {
|
|
35
|
-
/**
|
|
36
|
-
* Filter entities using structured metadata predicates.
|
|
37
|
-
* All filters are AND-combined.
|
|
38
|
-
*
|
|
39
|
-
* @param entities - Entities to filter
|
|
40
|
-
* @param filters - Symbolic filter criteria
|
|
41
|
-
* @returns Filtered entities with match scores
|
|
42
|
-
*/
|
|
43
|
-
search(entities: readonly Entity[], filters: SymbolicFilters): SymbolicResult[];
|
|
44
|
-
/**
|
|
45
|
-
* Evaluate all filters against an entity.
|
|
46
|
-
*/
|
|
47
|
-
private evaluateFilters;
|
|
48
|
-
/**
|
|
49
|
-
* Get entities matching a specific tag.
|
|
50
|
-
*/
|
|
51
|
-
byTag(entities: readonly Entity[], tag: string): Entity[];
|
|
52
|
-
/**
|
|
53
|
-
* Get entities of a specific type.
|
|
54
|
-
*/
|
|
55
|
-
byType(entities: readonly Entity[], entityType: string): Entity[];
|
|
56
|
-
/**
|
|
57
|
-
* Get entities within importance range.
|
|
58
|
-
*/
|
|
59
|
-
byImportance(entities: readonly Entity[], min: number, max: number): Entity[];
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=SymbolicSearch.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SymbolicSearch.d.ts","sourceRoot":"","sources":["../../src/search/SymbolicSearch.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,cAAc;IACzB;;;;;;;OAOG;IACH,MAAM,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,eAAe,GAAG,cAAc,EAAE;IAc/E;;OAEG;IACH,OAAO,CAAC,eAAe;IAyGvB;;OAEG;IACH,KAAK,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE;IAMzD;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE;IAMjE;;OAEG;IACH,YAAY,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE;CAM9E"}
|