@henrychong-ai/mcp-neo4j-knowledge-graph 1.0.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 +21 -0
- package/README.md +718 -0
- package/dist/KnowledgeGraphManager.d.ts +215 -0
- package/dist/KnowledgeGraphManager.js +910 -0
- package/dist/KnowledgeGraphManager.js.map +1 -0
- package/dist/callToolHandler.d.ts +5 -0
- package/dist/callToolHandler.js +26 -0
- package/dist/callToolHandler.js.map +1 -0
- package/dist/cli/neo4j-setup.d.ts +52 -0
- package/dist/cli/neo4j-setup.js +258 -0
- package/dist/cli/neo4j-setup.js.map +1 -0
- package/dist/config/paths.d.ts +13 -0
- package/dist/config/paths.js +41 -0
- package/dist/config/paths.js.map +1 -0
- package/dist/config/storage.d.ts +35 -0
- package/dist/config/storage.js +52 -0
- package/dist/config/storage.js.map +1 -0
- package/dist/embeddings/DefaultEmbeddingService.d.ts +64 -0
- package/dist/embeddings/DefaultEmbeddingService.js +139 -0
- package/dist/embeddings/DefaultEmbeddingService.js.map +1 -0
- package/dist/embeddings/EmbeddingJobManager.d.ts +212 -0
- package/dist/embeddings/EmbeddingJobManager.js +545 -0
- package/dist/embeddings/EmbeddingJobManager.js.map +1 -0
- package/dist/embeddings/EmbeddingService.d.ts +96 -0
- package/dist/embeddings/EmbeddingService.js +44 -0
- package/dist/embeddings/EmbeddingService.js.map +1 -0
- package/dist/embeddings/EmbeddingServiceFactory.d.ts +72 -0
- package/dist/embeddings/EmbeddingServiceFactory.js +147 -0
- package/dist/embeddings/EmbeddingServiceFactory.js.map +1 -0
- package/dist/embeddings/OpenAIEmbeddingService.d.ts +73 -0
- package/dist/embeddings/OpenAIEmbeddingService.js +195 -0
- package/dist/embeddings/OpenAIEmbeddingService.js.map +1 -0
- package/dist/embeddings/config.d.ts +83 -0
- package/dist/embeddings/config.js +65 -0
- package/dist/embeddings/config.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +220 -0
- package/dist/index.js.map +1 -0
- package/dist/server/handlers/callToolHandler.d.ts +20 -0
- package/dist/server/handlers/callToolHandler.js +505 -0
- package/dist/server/handlers/callToolHandler.js.map +1 -0
- package/dist/server/handlers/listToolsHandler.d.ts +7 -0
- package/dist/server/handlers/listToolsHandler.js +511 -0
- package/dist/server/handlers/listToolsHandler.js.map +1 -0
- package/dist/server/handlers/toolHandlers/addObservations.d.ts +12 -0
- package/dist/server/handlers/toolHandlers/addObservations.js +99 -0
- package/dist/server/handlers/toolHandlers/addObservations.js.map +1 -0
- package/dist/server/handlers/toolHandlers/createEntities.d.ts +12 -0
- package/dist/server/handlers/toolHandlers/createEntities.js +20 -0
- package/dist/server/handlers/toolHandlers/createEntities.js.map +1 -0
- package/dist/server/handlers/toolHandlers/createRelations.d.ts +12 -0
- package/dist/server/handlers/toolHandlers/createRelations.js +20 -0
- package/dist/server/handlers/toolHandlers/createRelations.js.map +1 -0
- package/dist/server/handlers/toolHandlers/deleteEntities.d.ts +12 -0
- package/dist/server/handlers/toolHandlers/deleteEntities.js +20 -0
- package/dist/server/handlers/toolHandlers/deleteEntities.js.map +1 -0
- package/dist/server/handlers/toolHandlers/index.d.ts +8 -0
- package/dist/server/handlers/toolHandlers/index.js +9 -0
- package/dist/server/handlers/toolHandlers/index.js.map +1 -0
- package/dist/server/handlers/toolHandlers/readGraph.d.ts +12 -0
- package/dist/server/handlers/toolHandlers/readGraph.js +20 -0
- package/dist/server/handlers/toolHandlers/readGraph.js.map +1 -0
- package/dist/server/setup.d.ts +8 -0
- package/dist/server/setup.js +48 -0
- package/dist/server/setup.js.map +1 -0
- package/dist/storage/FileStorageProvider.d.ts +125 -0
- package/dist/storage/FileStorageProvider.js +322 -0
- package/dist/storage/FileStorageProvider.js.map +1 -0
- package/dist/storage/SearchResultCache.d.ts +102 -0
- package/dist/storage/SearchResultCache.js +258 -0
- package/dist/storage/SearchResultCache.js.map +1 -0
- package/dist/storage/StorageProvider.d.ts +171 -0
- package/dist/storage/StorageProvider.js +46 -0
- package/dist/storage/StorageProvider.js.map +1 -0
- package/dist/storage/StorageProviderFactory.d.ts +63 -0
- package/dist/storage/StorageProviderFactory.js +113 -0
- package/dist/storage/StorageProviderFactory.js.map +1 -0
- package/dist/storage/VectorStoreFactory.d.ts +43 -0
- package/dist/storage/VectorStoreFactory.js +41 -0
- package/dist/storage/VectorStoreFactory.js.map +1 -0
- package/dist/storage/neo4j/Neo4jConfig.d.ts +37 -0
- package/dist/storage/neo4j/Neo4jConfig.js +13 -0
- package/dist/storage/neo4j/Neo4jConfig.js.map +1 -0
- package/dist/storage/neo4j/Neo4jConnectionManager.d.ts +40 -0
- package/dist/storage/neo4j/Neo4jConnectionManager.js +58 -0
- package/dist/storage/neo4j/Neo4jConnectionManager.js.map +1 -0
- package/dist/storage/neo4j/Neo4jSchemaManager.d.ts +74 -0
- package/dist/storage/neo4j/Neo4jSchemaManager.js +224 -0
- package/dist/storage/neo4j/Neo4jSchemaManager.js.map +1 -0
- package/dist/storage/neo4j/Neo4jStorageProvider.d.ts +225 -0
- package/dist/storage/neo4j/Neo4jStorageProvider.js +1900 -0
- package/dist/storage/neo4j/Neo4jStorageProvider.js.map +1 -0
- package/dist/storage/neo4j/Neo4jVectorStore.d.ts +80 -0
- package/dist/storage/neo4j/Neo4jVectorStore.js +396 -0
- package/dist/storage/neo4j/Neo4jVectorStore.js.map +1 -0
- package/dist/types/entity-embedding.d.ts +156 -0
- package/dist/types/entity-embedding.js +2 -0
- package/dist/types/entity-embedding.js.map +1 -0
- package/dist/types/relation.d.ts +77 -0
- package/dist/types/relation.js +93 -0
- package/dist/types/relation.js.map +1 -0
- package/dist/types/temporalEntity.d.ts +55 -0
- package/dist/types/temporalEntity.js +66 -0
- package/dist/types/temporalEntity.js.map +1 -0
- package/dist/types/temporalRelation.d.ts +60 -0
- package/dist/types/temporalRelation.js +89 -0
- package/dist/types/temporalRelation.js.map +1 -0
- package/dist/types/vector-index.d.ts +48 -0
- package/dist/types/vector-index.js +2 -0
- package/dist/types/vector-index.js.map +1 -0
- package/dist/types/vector-store.d.ts +16 -0
- package/dist/types/vector-store.js +2 -0
- package/dist/types/vector-store.js.map +1 -0
- package/dist/utils/fs.d.ts +2 -0
- package/dist/utils/fs.js +3 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/logger.d.ts +10 -0
- package/dist/utils/logger.js +35 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
/**
|
|
4
|
+
* A storage provider that uses the file system to store the knowledge graph
|
|
5
|
+
* @deprecated This storage provider is deprecated and will be removed in a future version.
|
|
6
|
+
* Please migrate to SqliteStorageProvider.
|
|
7
|
+
*/
|
|
8
|
+
export class FileStorageProvider {
|
|
9
|
+
/**
|
|
10
|
+
* Create a new FileStorageProvider
|
|
11
|
+
* @param options Configuration options for the file storage provider
|
|
12
|
+
* @deprecated This storage provider is deprecated and will be removed in a future version.
|
|
13
|
+
* Please migrate to SqliteStorageProvider.
|
|
14
|
+
*/
|
|
15
|
+
constructor(options) {
|
|
16
|
+
this.graph = { entities: [], relations: [] };
|
|
17
|
+
// Only emit warning in test environments to avoid disrupting JSON-RPC protocol
|
|
18
|
+
if (process.env.NODE_ENV === 'test') {
|
|
19
|
+
// console.warn('WARNING: FileStorageProvider is deprecated and will be removed in a future version. Please migrate to SqliteStorageProvider.');
|
|
20
|
+
}
|
|
21
|
+
this._fs = fs;
|
|
22
|
+
// Store vector store options for initialization
|
|
23
|
+
this.vectorStoreOptions = options?.vectorStoreOptions;
|
|
24
|
+
// Default to test-output directory during tests
|
|
25
|
+
if (!options?.memoryFilePath && !options?.filePath) {
|
|
26
|
+
const testOutputDir = path.join(process.cwd(), 'test-output', 'file-storage');
|
|
27
|
+
if (!fs.existsSync(testOutputDir)) {
|
|
28
|
+
fs.mkdirSync(testOutputDir, { recursive: true });
|
|
29
|
+
}
|
|
30
|
+
this.filePath = path.join(testOutputDir, 'memory.json');
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.filePath = options?.memoryFilePath || options?.filePath || '';
|
|
34
|
+
}
|
|
35
|
+
this.loadGraph();
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Set the fs module (for testing purposes)
|
|
39
|
+
*/
|
|
40
|
+
setFs(fsModule) {
|
|
41
|
+
this._fs = fsModule;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Load the entire knowledge graph from the file
|
|
45
|
+
* @returns Promise resolving to the loaded KnowledgeGraph
|
|
46
|
+
*/
|
|
47
|
+
async loadGraph() {
|
|
48
|
+
try {
|
|
49
|
+
const content = await this._fs.promises.readFile(this.filePath, 'utf-8');
|
|
50
|
+
this.graph = JSON.parse(content);
|
|
51
|
+
return this.graph;
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error.code === 'ENOENT') {
|
|
56
|
+
// File doesn't exist, return empty graph
|
|
57
|
+
return { entities: [], relations: [] };
|
|
58
|
+
}
|
|
59
|
+
throw new Error(`Error loading graph from ${this.filePath}: ${error.message}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Save the entire knowledge graph to the file
|
|
64
|
+
* @param graph The KnowledgeGraph to save
|
|
65
|
+
* @returns Promise that resolves when the save is complete
|
|
66
|
+
*/
|
|
67
|
+
async saveGraph(graph) {
|
|
68
|
+
await this._fs.promises.writeFile(this.filePath, JSON.stringify(graph, null, 2), 'utf-8');
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Search for nodes in the graph that match the query
|
|
72
|
+
* @param query The search query string
|
|
73
|
+
* @param options Optional search parameters
|
|
74
|
+
* @returns Promise resolving to a KnowledgeGraph containing matching nodes
|
|
75
|
+
*/
|
|
76
|
+
async searchNodes(query, options) {
|
|
77
|
+
// Load the entire graph
|
|
78
|
+
const graph = await this.loadGraph();
|
|
79
|
+
// Apply default options
|
|
80
|
+
const searchOptions = {
|
|
81
|
+
limit: options?.limit ?? Number.MAX_SAFE_INTEGER,
|
|
82
|
+
caseSensitive: options?.caseSensitive ?? false,
|
|
83
|
+
entityTypes: options?.entityTypes ?? [],
|
|
84
|
+
};
|
|
85
|
+
// Filter entities that match the query
|
|
86
|
+
let matchingEntities = graph.entities.filter((entity) => {
|
|
87
|
+
// Check if entity matches the query
|
|
88
|
+
const nameMatches = searchOptions.caseSensitive
|
|
89
|
+
? entity.name.includes(query)
|
|
90
|
+
: entity.name.toLowerCase().includes(query.toLowerCase());
|
|
91
|
+
const observationsMatch = entity.observations.some((obs) => searchOptions.caseSensitive
|
|
92
|
+
? obs.includes(query)
|
|
93
|
+
: obs.toLowerCase().includes(query.toLowerCase()));
|
|
94
|
+
// Match if name or any observation contains the query
|
|
95
|
+
return nameMatches || observationsMatch;
|
|
96
|
+
});
|
|
97
|
+
// Filter by entity type if specified
|
|
98
|
+
if (searchOptions.entityTypes.length > 0) {
|
|
99
|
+
matchingEntities = matchingEntities.filter((entity) => searchOptions.entityTypes.includes(entity.entityType));
|
|
100
|
+
}
|
|
101
|
+
// Apply limit
|
|
102
|
+
matchingEntities = matchingEntities.slice(0, searchOptions.limit);
|
|
103
|
+
// Get entity names for relation filtering
|
|
104
|
+
const entityNames = new Set(matchingEntities.map((entity) => entity.name));
|
|
105
|
+
// Filter relations that connect matching entities
|
|
106
|
+
const matchingRelations = graph.relations.filter((relation) => entityNames.has(relation.from) && entityNames.has(relation.to));
|
|
107
|
+
return {
|
|
108
|
+
entities: matchingEntities,
|
|
109
|
+
relations: matchingRelations,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Open specific nodes by their exact names
|
|
114
|
+
* @param names Array of node names to open
|
|
115
|
+
* @returns Promise resolving to a KnowledgeGraph containing the specified nodes
|
|
116
|
+
*/
|
|
117
|
+
async openNodes(names) {
|
|
118
|
+
// Handle empty input array case
|
|
119
|
+
if (names.length === 0) {
|
|
120
|
+
return { entities: [], relations: [] };
|
|
121
|
+
}
|
|
122
|
+
// Load the entire graph
|
|
123
|
+
const graph = await this.loadGraph();
|
|
124
|
+
// Create a Set of names for faster lookups
|
|
125
|
+
const nameSet = new Set(names);
|
|
126
|
+
// Filter entities by name
|
|
127
|
+
const filteredEntities = graph.entities.filter((entity) => nameSet.has(entity.name));
|
|
128
|
+
// Create a Set of entity names that were found
|
|
129
|
+
const foundEntityNames = new Set(filteredEntities.map((entity) => entity.name));
|
|
130
|
+
// Filter relations to only include those between found entities
|
|
131
|
+
const filteredRelations = graph.relations.filter((relation) => foundEntityNames.has(relation.from) && foundEntityNames.has(relation.to));
|
|
132
|
+
return {
|
|
133
|
+
entities: filteredEntities,
|
|
134
|
+
relations: filteredRelations,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create new relations between entities
|
|
139
|
+
* @param relations Array of relations to create
|
|
140
|
+
* @returns Promise resolving to array of newly created relations
|
|
141
|
+
*/
|
|
142
|
+
async createRelations(relations) {
|
|
143
|
+
const graph = await this.loadGraph();
|
|
144
|
+
const newRelations = relations.filter((r) => !graph.relations.some((existingRelation) => existingRelation.from === r.from &&
|
|
145
|
+
existingRelation.to === r.to &&
|
|
146
|
+
existingRelation.relationType === r.relationType));
|
|
147
|
+
// Always save the graph, even when no new relations are found
|
|
148
|
+
// This ensures backward compatibility with existing tests
|
|
149
|
+
await this.saveGraph({
|
|
150
|
+
entities: graph.entities,
|
|
151
|
+
relations: [...graph.relations, ...newRelations],
|
|
152
|
+
});
|
|
153
|
+
return newRelations;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Add observations to entities
|
|
157
|
+
* @param observations Array of observations to add
|
|
158
|
+
* @returns Promise resolving to array of added observations
|
|
159
|
+
*/
|
|
160
|
+
async addObservations(observations) {
|
|
161
|
+
if (!observations || observations.length === 0) {
|
|
162
|
+
return [];
|
|
163
|
+
}
|
|
164
|
+
const graph = await this.loadGraph();
|
|
165
|
+
// Process each observation request
|
|
166
|
+
const results = observations.map((obs) => {
|
|
167
|
+
const entity = graph.entities.find((e) => e.name === obs.entityName);
|
|
168
|
+
if (!entity) {
|
|
169
|
+
throw new Error(`Entity with name ${obs.entityName} not found`);
|
|
170
|
+
}
|
|
171
|
+
// Filter out observations that already exist
|
|
172
|
+
const newObservations = obs.contents.filter((content) => !entity.observations.includes(content));
|
|
173
|
+
// Add new observations to entity
|
|
174
|
+
entity.observations.push(...newObservations);
|
|
175
|
+
return {
|
|
176
|
+
entityName: obs.entityName,
|
|
177
|
+
addedObservations: newObservations,
|
|
178
|
+
};
|
|
179
|
+
});
|
|
180
|
+
// Save the updated graph
|
|
181
|
+
await this.saveGraph(graph);
|
|
182
|
+
return results;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Delete entities and their relations from the knowledge graph
|
|
186
|
+
* @param entityNames Array of entity names to delete
|
|
187
|
+
* @returns Promise that resolves when deletion is complete
|
|
188
|
+
*/
|
|
189
|
+
async deleteEntities(entityNames) {
|
|
190
|
+
if (!entityNames || entityNames.length === 0) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
const graph = await this.loadGraph();
|
|
194
|
+
// Create a set for faster lookups
|
|
195
|
+
const nameSet = new Set(entityNames);
|
|
196
|
+
// Filter out entities that are in the delete list
|
|
197
|
+
graph.entities = graph.entities.filter((e) => !nameSet.has(e.name));
|
|
198
|
+
// Filter out relations that reference deleted entities
|
|
199
|
+
graph.relations = graph.relations.filter((r) => !nameSet.has(r.from) && !nameSet.has(r.to));
|
|
200
|
+
// Save the updated graph
|
|
201
|
+
await this.saveGraph(graph);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Delete specific observations from entities
|
|
205
|
+
* @param deletions Array of objects with entity name and observations to delete
|
|
206
|
+
* @returns Promise that resolves when deletion is complete
|
|
207
|
+
*/
|
|
208
|
+
async deleteObservations(deletions) {
|
|
209
|
+
if (!deletions || deletions.length === 0) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
const graph = await this.loadGraph();
|
|
213
|
+
// Process each deletion request
|
|
214
|
+
deletions.forEach((deletion) => {
|
|
215
|
+
const entity = graph.entities.find((e) => e.name === deletion.entityName);
|
|
216
|
+
if (entity) {
|
|
217
|
+
// Filter out the observations that should be deleted
|
|
218
|
+
entity.observations = entity.observations.filter((obs) => !deletion.observations.includes(obs));
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
// Save the updated graph
|
|
222
|
+
await this.saveGraph(graph);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Delete relations from the graph
|
|
226
|
+
* @param relations Array of relations to delete
|
|
227
|
+
* @returns Promise that resolves when deletion is complete
|
|
228
|
+
* @deprecated FileStorageProvider is deprecated. Use SqliteStorageProvider instead.
|
|
229
|
+
*/
|
|
230
|
+
async deleteRelations(relations) {
|
|
231
|
+
await this.loadGraph();
|
|
232
|
+
for (const relation of relations) {
|
|
233
|
+
this.graph.relations = this.graph.relations.filter((r) => !(r.from === relation.from &&
|
|
234
|
+
r.to === relation.to &&
|
|
235
|
+
r.relationType === relation.relationType));
|
|
236
|
+
}
|
|
237
|
+
await this.saveGraph(this.graph);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Get a specific relation by its identifying properties
|
|
241
|
+
* @param from Source entity name
|
|
242
|
+
* @param to Target entity name
|
|
243
|
+
* @param relationType Type of relation
|
|
244
|
+
* @returns Promise resolving to the relation or null if not found
|
|
245
|
+
*/
|
|
246
|
+
async getRelation(from, to, relationType) {
|
|
247
|
+
const graph = await this.loadGraph();
|
|
248
|
+
const relation = graph.relations.find((r) => r.from === from && r.to === to && r.relationType === relationType);
|
|
249
|
+
return relation || null;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Update an existing relation with new properties
|
|
253
|
+
* @param relation The relation with updated properties (from, to, and relationType identify the relation)
|
|
254
|
+
* @returns Promise that resolves when the update is complete
|
|
255
|
+
* @throws Error if the relation doesn't exist
|
|
256
|
+
*/
|
|
257
|
+
async updateRelation(relation) {
|
|
258
|
+
const graph = await this.loadGraph();
|
|
259
|
+
// Find the index of the relation to update
|
|
260
|
+
const index = graph.relations.findIndex((r) => r.from === relation.from && r.to === relation.to && r.relationType === relation.relationType);
|
|
261
|
+
if (index === -1) {
|
|
262
|
+
throw new Error(`Relation from ${relation.from} to ${relation.to} of type ${relation.relationType} not found`);
|
|
263
|
+
}
|
|
264
|
+
// Update the relation with new properties, preserving any existing properties not specified
|
|
265
|
+
graph.relations[index] = {
|
|
266
|
+
...graph.relations[index], // Keep existing properties
|
|
267
|
+
...relation, // Overwrite with new properties
|
|
268
|
+
};
|
|
269
|
+
// Save the updated graph
|
|
270
|
+
await this.saveGraph(graph);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Create new entities in the knowledge graph
|
|
274
|
+
* @param entities Array of entities to create
|
|
275
|
+
* @returns Promise resolving to the array of created entities with timestamps
|
|
276
|
+
* @deprecated FileStorageProvider is deprecated. Use SqliteStorageProvider instead.
|
|
277
|
+
*/
|
|
278
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
279
|
+
async createEntities(entities) {
|
|
280
|
+
await this.loadGraph();
|
|
281
|
+
const timestamp = Date.now();
|
|
282
|
+
const createdEntities = [];
|
|
283
|
+
for (const entity of entities) {
|
|
284
|
+
// Check if entity already exists
|
|
285
|
+
const exists = this.graph.entities.some((e) => e.name === entity.name);
|
|
286
|
+
if (!exists) {
|
|
287
|
+
// Add temporal metadata to match SqliteStorageProvider behavior
|
|
288
|
+
const createdEntity = {
|
|
289
|
+
...entity,
|
|
290
|
+
createdAt: timestamp,
|
|
291
|
+
updatedAt: timestamp,
|
|
292
|
+
validFrom: timestamp,
|
|
293
|
+
validTo: null,
|
|
294
|
+
version: 1,
|
|
295
|
+
changedBy: null,
|
|
296
|
+
};
|
|
297
|
+
this.graph.entities.push(createdEntity);
|
|
298
|
+
createdEntities.push(createdEntity);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
// Entity already exists, just return the original
|
|
302
|
+
createdEntities.push(entity);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// Save the updated graph
|
|
306
|
+
await this.saveGraph(this.graph);
|
|
307
|
+
return createdEntities;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Get an entity by name
|
|
311
|
+
* @param entityName Name of the entity to retrieve
|
|
312
|
+
* @returns Promise resolving to the entity or null if not found
|
|
313
|
+
* @deprecated FileStorageProvider is deprecated. Use SqliteStorageProvider instead.
|
|
314
|
+
*/
|
|
315
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
316
|
+
async getEntity(entityName) {
|
|
317
|
+
await this.loadGraph();
|
|
318
|
+
const entity = this.graph.entities.find((e) => e.name === entityName);
|
|
319
|
+
return entity || null;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
//# sourceMappingURL=FileStorageProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileStorageProvider.js","sourceRoot":"","sources":["../../src/storage/FileStorageProvider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AAEzB,OAAO,IAAI,MAAM,MAAM,CAAC;AASxB;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAM9B;;;;;OAKG;IACH,YAAY,OAAoC;QATxC,UAAK,GAAmB,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC;QAU9D,+EAA+E;QAC/E,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;YACpC,gJAAgJ;QAClJ,CAAC;QAED,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QAEd,gDAAgD;QAChD,IAAI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AAM,CAAC,IAAI,CAAC,CAAC;YAEvE,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,gEAAgE;gBAChE,MAAM,aAAa,GAAG;oBACpB,GAAG,MAAM;oBACT,SAAS,EAAE,SAAS;oBACpB,SAAS,EAAE,SAAS;oBACpB,SAAS,EAAE,SAAS;oBACpB,OAAO,EAAE,IAAI;oBACb,OAAO,EAAE,CAAC;oBACV,SAAS,EAAE,IAAI;iBAChB,CAAC;gBAEF,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;gBACxC,eAAe,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACtC,CAAC;iBAAM,CAAC;gBACN,kDAAkD;gBAClD,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,yBAAyB;QACzB,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAEjC,OAAO,eAAe,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACH,8DAA8D;IAC9D,KAAK,CAAC,SAAS,CAAC,UAAkB;QAChC,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QAEvB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;QACtE,OAAO,MAAM,IAAI,IAAI,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache system for search results to improve performance for repeated queries
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Cache configuration
|
|
6
|
+
*/
|
|
7
|
+
export interface SearchCacheConfig {
|
|
8
|
+
maxSize?: number;
|
|
9
|
+
defaultTtl?: number;
|
|
10
|
+
enableStats?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Cache statistics
|
|
14
|
+
*/
|
|
15
|
+
export interface CacheStats {
|
|
16
|
+
hits: number;
|
|
17
|
+
misses: number;
|
|
18
|
+
hitRate: number;
|
|
19
|
+
currentSize: number;
|
|
20
|
+
maxSize: number;
|
|
21
|
+
entryCount: number;
|
|
22
|
+
evictions: number;
|
|
23
|
+
averageLookupTime: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A memory-efficient cache for search results
|
|
27
|
+
*/
|
|
28
|
+
export declare class SearchResultCache<T> {
|
|
29
|
+
private cache;
|
|
30
|
+
private maxSize;
|
|
31
|
+
private currentSize;
|
|
32
|
+
private defaultTtl;
|
|
33
|
+
private enableStats;
|
|
34
|
+
private hits;
|
|
35
|
+
private misses;
|
|
36
|
+
private evictions;
|
|
37
|
+
private totalLookupTime;
|
|
38
|
+
private totalLookups;
|
|
39
|
+
/**
|
|
40
|
+
* Create a new SearchResultCache
|
|
41
|
+
* @param config Configuration options
|
|
42
|
+
*/
|
|
43
|
+
constructor(config?: SearchCacheConfig);
|
|
44
|
+
/**
|
|
45
|
+
* Estimate the size of an object in bytes
|
|
46
|
+
* @param obj The object to measure
|
|
47
|
+
* @returns Approximate size in bytes
|
|
48
|
+
*/
|
|
49
|
+
private estimateSize;
|
|
50
|
+
/**
|
|
51
|
+
* Generate a cache key from a query and parameters
|
|
52
|
+
* @param query Original query string
|
|
53
|
+
* @param params Optional parameters that affect the query
|
|
54
|
+
* @returns A cache key string
|
|
55
|
+
*/
|
|
56
|
+
private generateKey;
|
|
57
|
+
/**
|
|
58
|
+
* Evict the oldest or least valuable entries to free up space
|
|
59
|
+
* @param requiredSpace The amount of space needed
|
|
60
|
+
*/
|
|
61
|
+
private evictEntries;
|
|
62
|
+
/**
|
|
63
|
+
* Set a cache entry
|
|
64
|
+
* @param query The original query
|
|
65
|
+
* @param params Optional parameters that affect the results
|
|
66
|
+
* @param data The data to cache
|
|
67
|
+
* @param ttl Optional time-to-live in milliseconds
|
|
68
|
+
*/
|
|
69
|
+
set(query: string, data: T, params?: Record<string, unknown>, ttl?: number): void;
|
|
70
|
+
/**
|
|
71
|
+
* Get a value from the cache
|
|
72
|
+
* @param query The original query
|
|
73
|
+
* @param params Optional parameters that affect the results
|
|
74
|
+
* @returns The cached data or undefined if not found or expired
|
|
75
|
+
*/
|
|
76
|
+
get(query: string, params?: Record<string, unknown>): T | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Remove all expired entries from the cache
|
|
79
|
+
*/
|
|
80
|
+
removeExpired(): void;
|
|
81
|
+
/**
|
|
82
|
+
* Clear the entire cache
|
|
83
|
+
*/
|
|
84
|
+
clear(): void;
|
|
85
|
+
/**
|
|
86
|
+
* Get cache statistics
|
|
87
|
+
* @returns Cache statistics
|
|
88
|
+
*/
|
|
89
|
+
getStats(): CacheStats;
|
|
90
|
+
/**
|
|
91
|
+
* Get the current number of entries in the cache
|
|
92
|
+
* @returns Number of entries
|
|
93
|
+
*/
|
|
94
|
+
size(): number;
|
|
95
|
+
/**
|
|
96
|
+
* Check if the cache contains a specific key
|
|
97
|
+
* @param query The original query
|
|
98
|
+
* @param params Optional parameters that affect the results
|
|
99
|
+
* @returns True if the key exists and is not expired
|
|
100
|
+
*/
|
|
101
|
+
has(query: string, params?: Record<string, unknown>): boolean;
|
|
102
|
+
}
|