@danielsimonjr/memory-mcp 0.47.1 → 9.8.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/LICENSE +22 -0
- package/README.md +2000 -194
- package/dist/__tests__/file-path.test.js +5 -5
- package/dist/__tests__/knowledge-graph.test.js +3 -8
- package/dist/core/EntityManager.d.ts +266 -0
- package/dist/core/EntityManager.d.ts.map +1 -0
- package/dist/core/EntityManager.js +85 -133
- package/dist/core/GraphEventEmitter.d.ts +202 -0
- package/dist/core/GraphEventEmitter.d.ts.map +1 -0
- package/dist/core/GraphEventEmitter.js +346 -0
- package/dist/core/GraphStorage.d.ts +395 -0
- package/dist/core/GraphStorage.d.ts.map +1 -0
- package/dist/core/GraphStorage.js +643 -31
- package/dist/core/GraphTraversal.d.ts +141 -0
- package/dist/core/GraphTraversal.d.ts.map +1 -0
- package/dist/core/GraphTraversal.js +573 -0
- package/dist/core/HierarchyManager.d.ts +111 -0
- package/dist/core/HierarchyManager.d.ts.map +1 -0
- package/dist/{features → core}/HierarchyManager.js +14 -9
- package/dist/core/ManagerContext.d.ts +72 -0
- package/dist/core/ManagerContext.d.ts.map +1 -0
- package/dist/core/ManagerContext.js +118 -0
- package/dist/core/ObservationManager.d.ts +85 -0
- package/dist/core/ObservationManager.d.ts.map +1 -0
- package/dist/core/ObservationManager.js +51 -57
- package/dist/core/RelationManager.d.ts +131 -0
- package/dist/core/RelationManager.d.ts.map +1 -0
- package/dist/core/RelationManager.js +31 -7
- package/dist/core/SQLiteStorage.d.ts +354 -0
- package/dist/core/SQLiteStorage.d.ts.map +1 -0
- package/dist/core/SQLiteStorage.js +917 -0
- package/dist/core/StorageFactory.d.ts +45 -0
- package/dist/core/StorageFactory.d.ts.map +1 -0
- package/dist/core/StorageFactory.js +64 -0
- package/dist/core/TransactionManager.d.ts +464 -0
- package/dist/core/TransactionManager.d.ts.map +1 -0
- package/dist/core/TransactionManager.js +490 -13
- package/dist/core/index.d.ts +17 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +12 -2
- package/dist/features/AnalyticsManager.d.ts +44 -0
- package/dist/features/AnalyticsManager.d.ts.map +1 -0
- package/dist/features/AnalyticsManager.js +14 -13
- package/dist/features/ArchiveManager.d.ts +133 -0
- package/dist/features/ArchiveManager.d.ts.map +1 -0
- package/dist/features/ArchiveManager.js +221 -14
- package/dist/features/CompressionManager.d.ts +117 -0
- package/dist/features/CompressionManager.d.ts.map +1 -0
- package/dist/features/CompressionManager.js +189 -20
- package/dist/features/IOManager.d.ts +225 -0
- package/dist/features/IOManager.d.ts.map +1 -0
- package/dist/features/IOManager.js +1041 -0
- package/dist/features/StreamingExporter.d.ts +123 -0
- package/dist/features/StreamingExporter.d.ts.map +1 -0
- package/dist/features/StreamingExporter.js +203 -0
- package/dist/features/TagManager.d.ts +147 -0
- package/dist/features/TagManager.d.ts.map +1 -0
- package/dist/features/index.d.ts +12 -0
- package/dist/features/index.d.ts.map +1 -0
- package/dist/features/index.js +5 -6
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -45
- package/dist/memory.jsonl +1 -18
- package/dist/search/BasicSearch.d.ts +51 -0
- package/dist/search/BasicSearch.d.ts.map +1 -0
- package/dist/search/BasicSearch.js +9 -3
- package/dist/search/BooleanSearch.d.ts +98 -0
- package/dist/search/BooleanSearch.d.ts.map +1 -0
- package/dist/search/BooleanSearch.js +156 -9
- package/dist/search/EmbeddingService.d.ts +178 -0
- package/dist/search/EmbeddingService.d.ts.map +1 -0
- package/dist/search/EmbeddingService.js +358 -0
- package/dist/search/FuzzySearch.d.ts +118 -0
- package/dist/search/FuzzySearch.d.ts.map +1 -0
- package/dist/search/FuzzySearch.js +241 -25
- package/dist/search/QueryCostEstimator.d.ts +111 -0
- package/dist/search/QueryCostEstimator.d.ts.map +1 -0
- package/dist/search/QueryCostEstimator.js +355 -0
- package/dist/search/RankedSearch.d.ts +71 -0
- package/dist/search/RankedSearch.d.ts.map +1 -0
- package/dist/search/RankedSearch.js +54 -6
- package/dist/search/SavedSearchManager.d.ts +79 -0
- package/dist/search/SavedSearchManager.d.ts.map +1 -0
- package/dist/search/SearchFilterChain.d.ts +120 -0
- package/dist/search/SearchFilterChain.d.ts.map +1 -0
- package/dist/search/SearchFilterChain.js +2 -4
- package/dist/search/SearchManager.d.ts +326 -0
- package/dist/search/SearchManager.d.ts.map +1 -0
- package/dist/search/SearchManager.js +148 -0
- package/dist/search/SearchSuggestions.d.ts +27 -0
- package/dist/search/SearchSuggestions.d.ts.map +1 -0
- package/dist/search/SearchSuggestions.js +1 -1
- package/dist/search/SemanticSearch.d.ts +149 -0
- package/dist/search/SemanticSearch.d.ts.map +1 -0
- package/dist/search/SemanticSearch.js +323 -0
- package/dist/search/TFIDFEventSync.d.ts +85 -0
- package/dist/search/TFIDFEventSync.d.ts.map +1 -0
- package/dist/search/TFIDFEventSync.js +133 -0
- package/dist/search/TFIDFIndexManager.d.ts +151 -0
- package/dist/search/TFIDFIndexManager.d.ts.map +1 -0
- package/dist/search/TFIDFIndexManager.js +232 -17
- package/dist/search/VectorStore.d.ts +235 -0
- package/dist/search/VectorStore.d.ts.map +1 -0
- package/dist/search/VectorStore.js +311 -0
- package/dist/search/index.d.ts +21 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +12 -0
- package/dist/server/MCPServer.d.ts +21 -0
- package/dist/server/MCPServer.d.ts.map +1 -0
- package/dist/server/MCPServer.js +4 -4
- package/dist/server/responseCompressor.d.ts +94 -0
- package/dist/server/responseCompressor.d.ts.map +1 -0
- package/dist/server/responseCompressor.js +127 -0
- package/dist/server/toolDefinitions.d.ts +27 -0
- package/dist/server/toolDefinitions.d.ts.map +1 -0
- package/dist/server/toolDefinitions.js +189 -18
- package/dist/server/toolHandlers.d.ts +41 -0
- package/dist/server/toolHandlers.d.ts.map +1 -0
- package/dist/server/toolHandlers.js +467 -75
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +1 -1
- package/dist/types/types.d.ts +1654 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +9 -0
- package/dist/utils/compressedCache.d.ts +192 -0
- package/dist/utils/compressedCache.d.ts.map +1 -0
- package/dist/utils/compressedCache.js +309 -0
- package/dist/utils/compressionUtil.d.ts +214 -0
- package/dist/utils/compressionUtil.d.ts.map +1 -0
- package/dist/utils/compressionUtil.js +247 -0
- package/dist/utils/constants.d.ts +245 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +124 -0
- package/dist/utils/entityUtils.d.ts +321 -0
- package/dist/utils/entityUtils.d.ts.map +1 -0
- package/dist/utils/entityUtils.js +434 -4
- package/dist/utils/errors.d.ts +95 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +24 -0
- package/dist/utils/formatters.d.ts +145 -0
- package/dist/utils/formatters.d.ts.map +1 -0
- package/dist/utils/{paginationUtils.js → formatters.js} +54 -3
- package/dist/utils/index.d.ts +23 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +69 -31
- package/dist/utils/indexes.d.ts +270 -0
- package/dist/utils/indexes.d.ts.map +1 -0
- package/dist/utils/indexes.js +526 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/operationUtils.d.ts +124 -0
- package/dist/utils/operationUtils.d.ts.map +1 -0
- package/dist/utils/operationUtils.js +175 -0
- package/dist/utils/parallelUtils.d.ts +72 -0
- package/dist/utils/parallelUtils.d.ts.map +1 -0
- package/dist/utils/parallelUtils.js +169 -0
- package/dist/utils/schemas.d.ts +374 -0
- package/dist/utils/schemas.d.ts.map +1 -0
- package/dist/utils/schemas.js +302 -2
- package/dist/utils/searchAlgorithms.d.ts +99 -0
- package/dist/utils/searchAlgorithms.d.ts.map +1 -0
- package/dist/utils/searchAlgorithms.js +167 -0
- package/dist/utils/searchCache.d.ts +108 -0
- package/dist/utils/searchCache.d.ts.map +1 -0
- package/dist/utils/taskScheduler.d.ts +290 -0
- package/dist/utils/taskScheduler.d.ts.map +1 -0
- package/dist/utils/taskScheduler.js +466 -0
- package/dist/workers/index.d.ts +12 -0
- package/dist/workers/index.d.ts.map +1 -0
- package/dist/workers/index.js +9 -0
- package/dist/workers/levenshteinWorker.d.ts +60 -0
- package/dist/workers/levenshteinWorker.d.ts.map +1 -0
- package/dist/workers/levenshteinWorker.js +98 -0
- package/package.json +17 -4
- package/dist/__tests__/edge-cases/edge-cases.test.js +0 -406
- package/dist/__tests__/integration/workflows.test.js +0 -449
- package/dist/__tests__/performance/benchmarks.test.js +0 -413
- package/dist/__tests__/unit/core/EntityManager.test.js +0 -334
- package/dist/__tests__/unit/core/GraphStorage.test.js +0 -205
- package/dist/__tests__/unit/core/RelationManager.test.js +0 -274
- package/dist/__tests__/unit/features/CompressionManager.test.js +0 -350
- package/dist/__tests__/unit/search/BasicSearch.test.js +0 -311
- package/dist/__tests__/unit/search/BooleanSearch.test.js +0 -432
- package/dist/__tests__/unit/search/FuzzySearch.test.js +0 -448
- package/dist/__tests__/unit/search/RankedSearch.test.js +0 -379
- package/dist/__tests__/unit/utils/levenshtein.test.js +0 -77
- package/dist/core/KnowledgeGraphManager.js +0 -423
- package/dist/features/BackupManager.js +0 -311
- package/dist/features/ExportManager.js +0 -305
- package/dist/features/ImportExportManager.js +0 -50
- package/dist/features/ImportManager.js +0 -328
- package/dist/types/analytics.types.js +0 -6
- package/dist/types/entity.types.js +0 -7
- package/dist/types/import-export.types.js +0 -7
- package/dist/types/search.types.js +0 -7
- package/dist/types/tag.types.js +0 -6
- package/dist/utils/dateUtils.js +0 -89
- package/dist/utils/filterUtils.js +0 -155
- package/dist/utils/levenshtein.js +0 -62
- package/dist/utils/pathUtils.js +0 -115
- package/dist/utils/responseFormatter.js +0 -55
- package/dist/utils/tagUtils.js +0 -107
- package/dist/utils/tfidf.js +0 -90
- package/dist/utils/validationHelper.js +0 -99
- package/dist/utils/validationUtils.js +0 -109
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vector Store
|
|
3
|
+
*
|
|
4
|
+
* Phase 4 Sprint 11: Vector storage and retrieval for semantic search.
|
|
5
|
+
* Provides in-memory and SQLite-backed implementations.
|
|
6
|
+
*
|
|
7
|
+
* @module search/VectorStore
|
|
8
|
+
*/
|
|
9
|
+
import type { IVectorStore, VectorSearchResult } from '../types/index.js';
|
|
10
|
+
/**
|
|
11
|
+
* Calculate cosine similarity between two vectors.
|
|
12
|
+
*
|
|
13
|
+
* Uses an optimized inner loop without array methods for maximum performance.
|
|
14
|
+
*
|
|
15
|
+
* @param a - First vector
|
|
16
|
+
* @param b - Second vector
|
|
17
|
+
* @returns Cosine similarity score (0.0 to 1.0)
|
|
18
|
+
*/
|
|
19
|
+
export declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
20
|
+
/**
|
|
21
|
+
* In-Memory Vector Store
|
|
22
|
+
*
|
|
23
|
+
* Stores vectors in memory using a Map for O(1) add/remove operations.
|
|
24
|
+
* Search uses brute-force cosine similarity which is O(n) but fast for
|
|
25
|
+
* small to medium graphs (<10K entities).
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* const store = new InMemoryVectorStore();
|
|
30
|
+
* store.add("entity1", [0.1, 0.2, 0.3]);
|
|
31
|
+
* store.add("entity2", [0.4, 0.5, 0.6]);
|
|
32
|
+
* const results = store.search([0.1, 0.2, 0.3], 5);
|
|
33
|
+
* console.log(results); // [{ name: "entity1", score: 1.0 }, ...]
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare class InMemoryVectorStore implements IVectorStore {
|
|
37
|
+
/** Map of entity name to embedding vector */
|
|
38
|
+
private vectors;
|
|
39
|
+
/**
|
|
40
|
+
* Add a vector for an entity.
|
|
41
|
+
*
|
|
42
|
+
* @param entityName - Name of the entity
|
|
43
|
+
* @param vector - Embedding vector
|
|
44
|
+
*/
|
|
45
|
+
add(entityName: string, vector: number[]): void;
|
|
46
|
+
/**
|
|
47
|
+
* Search for similar vectors using cosine similarity.
|
|
48
|
+
*
|
|
49
|
+
* @param queryVector - Query embedding vector
|
|
50
|
+
* @param k - Number of results to return
|
|
51
|
+
* @returns Array of results with entity name and similarity score
|
|
52
|
+
*/
|
|
53
|
+
search(queryVector: number[], k: number): VectorSearchResult[];
|
|
54
|
+
/**
|
|
55
|
+
* Remove a vector by entity name.
|
|
56
|
+
*
|
|
57
|
+
* @param entityName - Name of the entity to remove
|
|
58
|
+
* @returns True if found and removed
|
|
59
|
+
*/
|
|
60
|
+
remove(entityName: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Get the number of vectors stored.
|
|
63
|
+
*
|
|
64
|
+
* @returns Number of vectors
|
|
65
|
+
*/
|
|
66
|
+
size(): number;
|
|
67
|
+
/**
|
|
68
|
+
* Clear all vectors from the store.
|
|
69
|
+
*/
|
|
70
|
+
clear(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Check if a vector exists for an entity.
|
|
73
|
+
*
|
|
74
|
+
* @param entityName - Name of the entity
|
|
75
|
+
* @returns True if vector exists
|
|
76
|
+
*/
|
|
77
|
+
has(entityName: string): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Get the vector for an entity.
|
|
80
|
+
*
|
|
81
|
+
* @param entityName - Name of the entity
|
|
82
|
+
* @returns Vector if found, undefined otherwise
|
|
83
|
+
*/
|
|
84
|
+
get(entityName: string): number[] | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Get all entity names with stored vectors.
|
|
87
|
+
*
|
|
88
|
+
* @returns Array of entity names
|
|
89
|
+
*/
|
|
90
|
+
getEntityNames(): string[];
|
|
91
|
+
/**
|
|
92
|
+
* Load vectors from an iterable source.
|
|
93
|
+
*
|
|
94
|
+
* @param entries - Iterable of [entityName, vector] pairs
|
|
95
|
+
*/
|
|
96
|
+
loadFrom(entries: Iterable<[string, number[]]>): void;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* SQLite Vector Store
|
|
100
|
+
*
|
|
101
|
+
* Persists vectors to SQLite storage while maintaining an in-memory cache
|
|
102
|
+
* for fast search operations. Combines persistence with performance.
|
|
103
|
+
*
|
|
104
|
+
* Uses SQLiteStorage's embedding storage methods for persistence.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const store = new SQLiteVectorStore(sqliteStorage);
|
|
109
|
+
* await store.initialize();
|
|
110
|
+
* store.add("entity1", [0.1, 0.2, 0.3]);
|
|
111
|
+
* const results = store.search([0.1, 0.2, 0.3], 5);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare class SQLiteVectorStore implements IVectorStore {
|
|
115
|
+
/** In-memory cache for fast search */
|
|
116
|
+
private memoryStore;
|
|
117
|
+
/** SQLite storage reference for persistence */
|
|
118
|
+
private storage;
|
|
119
|
+
/** Whether the store has been initialized */
|
|
120
|
+
private initialized;
|
|
121
|
+
/** Model name used for embeddings */
|
|
122
|
+
private embeddingModel;
|
|
123
|
+
/**
|
|
124
|
+
* Create a SQLite vector store.
|
|
125
|
+
*
|
|
126
|
+
* @param storage - SQLite storage instance with embedding support
|
|
127
|
+
* @param embeddingModel - Model name used for embeddings
|
|
128
|
+
*/
|
|
129
|
+
constructor(storage?: SQLiteStorageWithEmbeddings, embeddingModel?: string);
|
|
130
|
+
/**
|
|
131
|
+
* Initialize the store by loading vectors from SQLite.
|
|
132
|
+
*/
|
|
133
|
+
initialize(): Promise<void>;
|
|
134
|
+
/**
|
|
135
|
+
* Add a vector for an entity.
|
|
136
|
+
* Stores in both memory and SQLite for persistence.
|
|
137
|
+
*
|
|
138
|
+
* @param entityName - Name of the entity
|
|
139
|
+
* @param vector - Embedding vector
|
|
140
|
+
*/
|
|
141
|
+
add(entityName: string, vector: number[]): void;
|
|
142
|
+
/**
|
|
143
|
+
* Search for similar vectors using cosine similarity.
|
|
144
|
+
*
|
|
145
|
+
* @param queryVector - Query embedding vector
|
|
146
|
+
* @param k - Number of results to return
|
|
147
|
+
* @returns Array of results with entity name and similarity score
|
|
148
|
+
*/
|
|
149
|
+
search(queryVector: number[], k: number): VectorSearchResult[];
|
|
150
|
+
/**
|
|
151
|
+
* Remove a vector by entity name.
|
|
152
|
+
*
|
|
153
|
+
* @param entityName - Name of the entity to remove
|
|
154
|
+
* @returns True if found and removed
|
|
155
|
+
*/
|
|
156
|
+
remove(entityName: string): boolean;
|
|
157
|
+
/**
|
|
158
|
+
* Get the number of vectors stored.
|
|
159
|
+
*
|
|
160
|
+
* @returns Number of vectors
|
|
161
|
+
*/
|
|
162
|
+
size(): number;
|
|
163
|
+
/**
|
|
164
|
+
* Clear all vectors from the store.
|
|
165
|
+
*/
|
|
166
|
+
clear(): void;
|
|
167
|
+
/**
|
|
168
|
+
* Check if a vector exists for an entity.
|
|
169
|
+
*
|
|
170
|
+
* @param entityName - Name of the entity
|
|
171
|
+
* @returns True if vector exists
|
|
172
|
+
*/
|
|
173
|
+
has(entityName: string): boolean;
|
|
174
|
+
/**
|
|
175
|
+
* Get the vector for an entity.
|
|
176
|
+
*
|
|
177
|
+
* @param entityName - Name of the entity
|
|
178
|
+
* @returns Vector if found, undefined otherwise
|
|
179
|
+
*/
|
|
180
|
+
get(entityName: string): number[] | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Set the SQLite storage reference.
|
|
183
|
+
*
|
|
184
|
+
* @param storage - SQLite storage instance
|
|
185
|
+
*/
|
|
186
|
+
setStorage(storage: SQLiteStorageWithEmbeddings): void;
|
|
187
|
+
/**
|
|
188
|
+
* Set the embedding model name.
|
|
189
|
+
*
|
|
190
|
+
* @param model - Model name
|
|
191
|
+
*/
|
|
192
|
+
setEmbeddingModel(model: string): void;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Interface for SQLite storage with embedding support.
|
|
196
|
+
*
|
|
197
|
+
* This is a subset of SQLiteStorage that only includes embedding-related methods.
|
|
198
|
+
* Allows for loose coupling between VectorStore and SQLiteStorage.
|
|
199
|
+
*/
|
|
200
|
+
export interface SQLiteStorageWithEmbeddings {
|
|
201
|
+
/**
|
|
202
|
+
* Store an embedding for an entity.
|
|
203
|
+
*
|
|
204
|
+
* @param entityName - Name of the entity
|
|
205
|
+
* @param vector - Embedding vector
|
|
206
|
+
* @param model - Model name used for the embedding
|
|
207
|
+
*/
|
|
208
|
+
storeEmbedding(entityName: string, vector: number[], model: string): void;
|
|
209
|
+
/**
|
|
210
|
+
* Load all embeddings from storage.
|
|
211
|
+
*
|
|
212
|
+
* @returns Array of [entityName, vector] pairs
|
|
213
|
+
*/
|
|
214
|
+
loadAllEmbeddings(): Promise<[string, number[]][]>;
|
|
215
|
+
/**
|
|
216
|
+
* Remove an embedding for an entity.
|
|
217
|
+
*
|
|
218
|
+
* @param entityName - Name of the entity
|
|
219
|
+
*/
|
|
220
|
+
removeEmbedding(entityName: string): void;
|
|
221
|
+
/**
|
|
222
|
+
* Clear all embeddings from storage.
|
|
223
|
+
*/
|
|
224
|
+
clearAllEmbeddings(): void;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Create a vector store based on storage type.
|
|
228
|
+
*
|
|
229
|
+
* @param storageType - Storage type: 'jsonl' or 'sqlite'
|
|
230
|
+
* @param storage - Optional SQLite storage reference for 'sqlite' type
|
|
231
|
+
* @param embeddingModel - Optional model name for embedding tracking
|
|
232
|
+
* @returns Vector store instance
|
|
233
|
+
*/
|
|
234
|
+
export declare function createVectorStore(storageType?: 'jsonl' | 'sqlite', storage?: SQLiteStorageWithEmbeddings, embeddingModel?: string): IVectorStore;
|
|
235
|
+
//# sourceMappingURL=VectorStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VectorStore.d.ts","sourceRoot":"","sources":["../../src/search/VectorStore.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vector Store
|
|
3
|
+
*
|
|
4
|
+
* Phase 4 Sprint 11: Vector storage and retrieval for semantic search.
|
|
5
|
+
* Provides in-memory and SQLite-backed implementations.
|
|
6
|
+
*
|
|
7
|
+
* @module search/VectorStore
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Calculate cosine similarity between two vectors.
|
|
11
|
+
*
|
|
12
|
+
* Uses an optimized inner loop without array methods for maximum performance.
|
|
13
|
+
*
|
|
14
|
+
* @param a - First vector
|
|
15
|
+
* @param b - Second vector
|
|
16
|
+
* @returns Cosine similarity score (0.0 to 1.0)
|
|
17
|
+
*/
|
|
18
|
+
export function cosineSimilarity(a, b) {
|
|
19
|
+
if (a.length !== b.length) {
|
|
20
|
+
throw new Error(`Vector dimensions mismatch: ${a.length} vs ${b.length}`);
|
|
21
|
+
}
|
|
22
|
+
let dotProduct = 0;
|
|
23
|
+
let magnitudeA = 0;
|
|
24
|
+
let magnitudeB = 0;
|
|
25
|
+
// Optimized single-pass loop
|
|
26
|
+
for (let i = 0; i < a.length; i++) {
|
|
27
|
+
const ai = a[i];
|
|
28
|
+
const bi = b[i];
|
|
29
|
+
dotProduct += ai * bi;
|
|
30
|
+
magnitudeA += ai * ai;
|
|
31
|
+
magnitudeB += bi * bi;
|
|
32
|
+
}
|
|
33
|
+
const magnitude = Math.sqrt(magnitudeA) * Math.sqrt(magnitudeB);
|
|
34
|
+
if (magnitude === 0) {
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
// Clamp to [-1, 1] to handle floating point errors
|
|
38
|
+
const similarity = dotProduct / magnitude;
|
|
39
|
+
return Math.max(-1, Math.min(1, similarity));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* In-Memory Vector Store
|
|
43
|
+
*
|
|
44
|
+
* Stores vectors in memory using a Map for O(1) add/remove operations.
|
|
45
|
+
* Search uses brute-force cosine similarity which is O(n) but fast for
|
|
46
|
+
* small to medium graphs (<10K entities).
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const store = new InMemoryVectorStore();
|
|
51
|
+
* store.add("entity1", [0.1, 0.2, 0.3]);
|
|
52
|
+
* store.add("entity2", [0.4, 0.5, 0.6]);
|
|
53
|
+
* const results = store.search([0.1, 0.2, 0.3], 5);
|
|
54
|
+
* console.log(results); // [{ name: "entity1", score: 1.0 }, ...]
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export class InMemoryVectorStore {
|
|
58
|
+
/** Map of entity name to embedding vector */
|
|
59
|
+
vectors = new Map();
|
|
60
|
+
/**
|
|
61
|
+
* Add a vector for an entity.
|
|
62
|
+
*
|
|
63
|
+
* @param entityName - Name of the entity
|
|
64
|
+
* @param vector - Embedding vector
|
|
65
|
+
*/
|
|
66
|
+
add(entityName, vector) {
|
|
67
|
+
this.vectors.set(entityName, vector);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Search for similar vectors using cosine similarity.
|
|
71
|
+
*
|
|
72
|
+
* @param queryVector - Query embedding vector
|
|
73
|
+
* @param k - Number of results to return
|
|
74
|
+
* @returns Array of results with entity name and similarity score
|
|
75
|
+
*/
|
|
76
|
+
search(queryVector, k) {
|
|
77
|
+
if (this.vectors.size === 0) {
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
// Calculate similarity for all vectors
|
|
81
|
+
const results = [];
|
|
82
|
+
for (const [name, vector] of this.vectors) {
|
|
83
|
+
try {
|
|
84
|
+
const score = cosineSimilarity(queryVector, vector);
|
|
85
|
+
results.push({ name, score });
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
// Skip vectors with dimension mismatch
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Sort by score descending and take top k
|
|
93
|
+
results.sort((a, b) => b.score - a.score);
|
|
94
|
+
return results.slice(0, k);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Remove a vector by entity name.
|
|
98
|
+
*
|
|
99
|
+
* @param entityName - Name of the entity to remove
|
|
100
|
+
* @returns True if found and removed
|
|
101
|
+
*/
|
|
102
|
+
remove(entityName) {
|
|
103
|
+
return this.vectors.delete(entityName);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Get the number of vectors stored.
|
|
107
|
+
*
|
|
108
|
+
* @returns Number of vectors
|
|
109
|
+
*/
|
|
110
|
+
size() {
|
|
111
|
+
return this.vectors.size;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Clear all vectors from the store.
|
|
115
|
+
*/
|
|
116
|
+
clear() {
|
|
117
|
+
this.vectors.clear();
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Check if a vector exists for an entity.
|
|
121
|
+
*
|
|
122
|
+
* @param entityName - Name of the entity
|
|
123
|
+
* @returns True if vector exists
|
|
124
|
+
*/
|
|
125
|
+
has(entityName) {
|
|
126
|
+
return this.vectors.has(entityName);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get the vector for an entity.
|
|
130
|
+
*
|
|
131
|
+
* @param entityName - Name of the entity
|
|
132
|
+
* @returns Vector if found, undefined otherwise
|
|
133
|
+
*/
|
|
134
|
+
get(entityName) {
|
|
135
|
+
return this.vectors.get(entityName);
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Get all entity names with stored vectors.
|
|
139
|
+
*
|
|
140
|
+
* @returns Array of entity names
|
|
141
|
+
*/
|
|
142
|
+
getEntityNames() {
|
|
143
|
+
return Array.from(this.vectors.keys());
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Load vectors from an iterable source.
|
|
147
|
+
*
|
|
148
|
+
* @param entries - Iterable of [entityName, vector] pairs
|
|
149
|
+
*/
|
|
150
|
+
loadFrom(entries) {
|
|
151
|
+
for (const [name, vector] of entries) {
|
|
152
|
+
this.vectors.set(name, vector);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* SQLite Vector Store
|
|
158
|
+
*
|
|
159
|
+
* Persists vectors to SQLite storage while maintaining an in-memory cache
|
|
160
|
+
* for fast search operations. Combines persistence with performance.
|
|
161
|
+
*
|
|
162
|
+
* Uses SQLiteStorage's embedding storage methods for persistence.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const store = new SQLiteVectorStore(sqliteStorage);
|
|
167
|
+
* await store.initialize();
|
|
168
|
+
* store.add("entity1", [0.1, 0.2, 0.3]);
|
|
169
|
+
* const results = store.search([0.1, 0.2, 0.3], 5);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export class SQLiteVectorStore {
|
|
173
|
+
/** In-memory cache for fast search */
|
|
174
|
+
memoryStore = new InMemoryVectorStore();
|
|
175
|
+
/** SQLite storage reference for persistence */
|
|
176
|
+
storage = null;
|
|
177
|
+
/** Whether the store has been initialized */
|
|
178
|
+
initialized = false;
|
|
179
|
+
/** Model name used for embeddings */
|
|
180
|
+
embeddingModel = '';
|
|
181
|
+
/**
|
|
182
|
+
* Create a SQLite vector store.
|
|
183
|
+
*
|
|
184
|
+
* @param storage - SQLite storage instance with embedding support
|
|
185
|
+
* @param embeddingModel - Model name used for embeddings
|
|
186
|
+
*/
|
|
187
|
+
constructor(storage, embeddingModel = 'unknown') {
|
|
188
|
+
this.storage = storage || null;
|
|
189
|
+
this.embeddingModel = embeddingModel;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Initialize the store by loading vectors from SQLite.
|
|
193
|
+
*/
|
|
194
|
+
async initialize() {
|
|
195
|
+
if (this.initialized)
|
|
196
|
+
return;
|
|
197
|
+
if (this.storage) {
|
|
198
|
+
// Load all embeddings from SQLite
|
|
199
|
+
const embeddings = await this.storage.loadAllEmbeddings();
|
|
200
|
+
this.memoryStore.loadFrom(embeddings);
|
|
201
|
+
}
|
|
202
|
+
this.initialized = true;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Add a vector for an entity.
|
|
206
|
+
* Stores in both memory and SQLite for persistence.
|
|
207
|
+
*
|
|
208
|
+
* @param entityName - Name of the entity
|
|
209
|
+
* @param vector - Embedding vector
|
|
210
|
+
*/
|
|
211
|
+
add(entityName, vector) {
|
|
212
|
+
// Add to in-memory cache
|
|
213
|
+
this.memoryStore.add(entityName, vector);
|
|
214
|
+
// Persist to SQLite if available
|
|
215
|
+
if (this.storage) {
|
|
216
|
+
this.storage.storeEmbedding(entityName, vector, this.embeddingModel);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Search for similar vectors using cosine similarity.
|
|
221
|
+
*
|
|
222
|
+
* @param queryVector - Query embedding vector
|
|
223
|
+
* @param k - Number of results to return
|
|
224
|
+
* @returns Array of results with entity name and similarity score
|
|
225
|
+
*/
|
|
226
|
+
search(queryVector, k) {
|
|
227
|
+
return this.memoryStore.search(queryVector, k);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Remove a vector by entity name.
|
|
231
|
+
*
|
|
232
|
+
* @param entityName - Name of the entity to remove
|
|
233
|
+
* @returns True if found and removed
|
|
234
|
+
*/
|
|
235
|
+
remove(entityName) {
|
|
236
|
+
const removed = this.memoryStore.remove(entityName);
|
|
237
|
+
// Remove from SQLite if available
|
|
238
|
+
if (this.storage && removed) {
|
|
239
|
+
this.storage.removeEmbedding(entityName);
|
|
240
|
+
}
|
|
241
|
+
return removed;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Get the number of vectors stored.
|
|
245
|
+
*
|
|
246
|
+
* @returns Number of vectors
|
|
247
|
+
*/
|
|
248
|
+
size() {
|
|
249
|
+
return this.memoryStore.size();
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Clear all vectors from the store.
|
|
253
|
+
*/
|
|
254
|
+
clear() {
|
|
255
|
+
this.memoryStore.clear();
|
|
256
|
+
if (this.storage) {
|
|
257
|
+
this.storage.clearAllEmbeddings();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Check if a vector exists for an entity.
|
|
262
|
+
*
|
|
263
|
+
* @param entityName - Name of the entity
|
|
264
|
+
* @returns True if vector exists
|
|
265
|
+
*/
|
|
266
|
+
has(entityName) {
|
|
267
|
+
return this.memoryStore.has(entityName);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Get the vector for an entity.
|
|
271
|
+
*
|
|
272
|
+
* @param entityName - Name of the entity
|
|
273
|
+
* @returns Vector if found, undefined otherwise
|
|
274
|
+
*/
|
|
275
|
+
get(entityName) {
|
|
276
|
+
return this.memoryStore.get(entityName);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Set the SQLite storage reference.
|
|
280
|
+
*
|
|
281
|
+
* @param storage - SQLite storage instance
|
|
282
|
+
*/
|
|
283
|
+
setStorage(storage) {
|
|
284
|
+
this.storage = storage;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Set the embedding model name.
|
|
288
|
+
*
|
|
289
|
+
* @param model - Model name
|
|
290
|
+
*/
|
|
291
|
+
setEmbeddingModel(model) {
|
|
292
|
+
this.embeddingModel = model;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Create a vector store based on storage type.
|
|
297
|
+
*
|
|
298
|
+
* @param storageType - Storage type: 'jsonl' or 'sqlite'
|
|
299
|
+
* @param storage - Optional SQLite storage reference for 'sqlite' type
|
|
300
|
+
* @param embeddingModel - Optional model name for embedding tracking
|
|
301
|
+
* @returns Vector store instance
|
|
302
|
+
*/
|
|
303
|
+
export function createVectorStore(storageType = 'jsonl', storage, embeddingModel) {
|
|
304
|
+
switch (storageType) {
|
|
305
|
+
case 'sqlite':
|
|
306
|
+
return new SQLiteVectorStore(storage, embeddingModel);
|
|
307
|
+
case 'jsonl':
|
|
308
|
+
default:
|
|
309
|
+
return new InMemoryVectorStore();
|
|
310
|
+
}
|
|
311
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search Module Barrel Export
|
|
3
|
+
*
|
|
4
|
+
* Sprint 2: Added SearchFilterChain for centralized filter logic
|
|
5
|
+
* Phase 4 Sprint 10: Added EmbeddingService for semantic search
|
|
6
|
+
*/
|
|
7
|
+
export { BasicSearch } from './BasicSearch.js';
|
|
8
|
+
export { RankedSearch } from './RankedSearch.js';
|
|
9
|
+
export { BooleanSearch } from './BooleanSearch.js';
|
|
10
|
+
export { FuzzySearch, type FuzzySearchOptions } from './FuzzySearch.js';
|
|
11
|
+
export { SearchSuggestions } from './SearchSuggestions.js';
|
|
12
|
+
export { SavedSearchManager } from './SavedSearchManager.js';
|
|
13
|
+
export { SearchManager } from './SearchManager.js';
|
|
14
|
+
export { SearchFilterChain, type SearchFilters, type ValidatedPagination } from './SearchFilterChain.js';
|
|
15
|
+
export { OpenAIEmbeddingService, LocalEmbeddingService, MockEmbeddingService, createEmbeddingService, } from './EmbeddingService.js';
|
|
16
|
+
export { InMemoryVectorStore, SQLiteVectorStore, createVectorStore, cosineSimilarity, type SQLiteStorageWithEmbeddings, } from './VectorStore.js';
|
|
17
|
+
export { SemanticSearch, entityToText, } from './SemanticSearch.js';
|
|
18
|
+
export { TFIDFIndexManager } from './TFIDFIndexManager.js';
|
|
19
|
+
export { TFIDFEventSync } from './TFIDFEventSync.js';
|
|
20
|
+
export { QueryCostEstimator } from './QueryCostEstimator.js';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD,OAAO,EAAE,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAGzG,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,GACvB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,2BAA2B,GACjC,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,cAAc,EACd,YAAY,GACb,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC"}
|
package/dist/search/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Search Module Barrel Export
|
|
3
3
|
*
|
|
4
4
|
* Sprint 2: Added SearchFilterChain for centralized filter logic
|
|
5
|
+
* Phase 4 Sprint 10: Added EmbeddingService for semantic search
|
|
5
6
|
*/
|
|
6
7
|
export { BasicSearch } from './BasicSearch.js';
|
|
7
8
|
export { RankedSearch } from './RankedSearch.js';
|
|
@@ -12,3 +13,14 @@ export { SavedSearchManager } from './SavedSearchManager.js';
|
|
|
12
13
|
export { SearchManager } from './SearchManager.js';
|
|
13
14
|
// Sprint 2: Search Filter Chain utilities
|
|
14
15
|
export { SearchFilterChain } from './SearchFilterChain.js';
|
|
16
|
+
// Phase 4 Sprint 10: Embedding Service for semantic search
|
|
17
|
+
export { OpenAIEmbeddingService, LocalEmbeddingService, MockEmbeddingService, createEmbeddingService, } from './EmbeddingService.js';
|
|
18
|
+
// Phase 4 Sprint 11: Vector Store for semantic search
|
|
19
|
+
export { InMemoryVectorStore, SQLiteVectorStore, createVectorStore, cosineSimilarity, } from './VectorStore.js';
|
|
20
|
+
// Phase 4 Sprint 12: Semantic Search Manager
|
|
21
|
+
export { SemanticSearch, entityToText, } from './SemanticSearch.js';
|
|
22
|
+
// Phase 10 Sprint 3: TF-IDF Index Manager and Event Sync
|
|
23
|
+
export { TFIDFIndexManager } from './TFIDFIndexManager.js';
|
|
24
|
+
export { TFIDFEventSync } from './TFIDFEventSync.js';
|
|
25
|
+
// Phase 10 Sprint 4: Query Cost Estimation
|
|
26
|
+
export { QueryCostEstimator } from './QueryCostEstimator.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Handles Model Context Protocol server initialization and tool registration.
|
|
5
|
+
* Tool definitions and handlers are extracted to separate modules for maintainability.
|
|
6
|
+
*
|
|
7
|
+
* @module server/MCPServer
|
|
8
|
+
*/
|
|
9
|
+
import type { ManagerContext } from '../core/ManagerContext.js';
|
|
10
|
+
/**
|
|
11
|
+
* MCP Server for Knowledge Graph operations.
|
|
12
|
+
* Exposes tools for entity/relation management, search, and analysis.
|
|
13
|
+
*/
|
|
14
|
+
export declare class MCPServer {
|
|
15
|
+
private server;
|
|
16
|
+
private ctx;
|
|
17
|
+
constructor(ctx: ManagerContext);
|
|
18
|
+
private registerToolHandlers;
|
|
19
|
+
start(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=MCPServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MCPServer.d.ts","sourceRoot":"","sources":["../../src/server/MCPServer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,GAAG,CAAiB;gBAEhB,GAAG,EAAE,cAAc;IAiB/B,OAAO,CAAC,oBAAoB;IAetB,KAAK;CAKZ"}
|
package/dist/server/MCPServer.js
CHANGED
|
@@ -18,9 +18,9 @@ import { handleToolCall } from './toolHandlers.js';
|
|
|
18
18
|
*/
|
|
19
19
|
export class MCPServer {
|
|
20
20
|
server;
|
|
21
|
-
|
|
22
|
-
constructor(
|
|
23
|
-
this.
|
|
21
|
+
ctx;
|
|
22
|
+
constructor(ctx) {
|
|
23
|
+
this.ctx = ctx;
|
|
24
24
|
this.server = new Server({
|
|
25
25
|
name: "memory-server",
|
|
26
26
|
version: "0.8.0",
|
|
@@ -41,7 +41,7 @@ export class MCPServer {
|
|
|
41
41
|
// Register call tool handler
|
|
42
42
|
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
43
43
|
const { name, arguments: args } = request.params;
|
|
44
|
-
return handleToolCall(name, args || {}, this.
|
|
44
|
+
return handleToolCall(name, args || {}, this.ctx);
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
async start() {
|