@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.
Files changed (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +718 -0
  3. package/dist/KnowledgeGraphManager.d.ts +215 -0
  4. package/dist/KnowledgeGraphManager.js +910 -0
  5. package/dist/KnowledgeGraphManager.js.map +1 -0
  6. package/dist/callToolHandler.d.ts +5 -0
  7. package/dist/callToolHandler.js +26 -0
  8. package/dist/callToolHandler.js.map +1 -0
  9. package/dist/cli/neo4j-setup.d.ts +52 -0
  10. package/dist/cli/neo4j-setup.js +258 -0
  11. package/dist/cli/neo4j-setup.js.map +1 -0
  12. package/dist/config/paths.d.ts +13 -0
  13. package/dist/config/paths.js +41 -0
  14. package/dist/config/paths.js.map +1 -0
  15. package/dist/config/storage.d.ts +35 -0
  16. package/dist/config/storage.js +52 -0
  17. package/dist/config/storage.js.map +1 -0
  18. package/dist/embeddings/DefaultEmbeddingService.d.ts +64 -0
  19. package/dist/embeddings/DefaultEmbeddingService.js +139 -0
  20. package/dist/embeddings/DefaultEmbeddingService.js.map +1 -0
  21. package/dist/embeddings/EmbeddingJobManager.d.ts +212 -0
  22. package/dist/embeddings/EmbeddingJobManager.js +545 -0
  23. package/dist/embeddings/EmbeddingJobManager.js.map +1 -0
  24. package/dist/embeddings/EmbeddingService.d.ts +96 -0
  25. package/dist/embeddings/EmbeddingService.js +44 -0
  26. package/dist/embeddings/EmbeddingService.js.map +1 -0
  27. package/dist/embeddings/EmbeddingServiceFactory.d.ts +72 -0
  28. package/dist/embeddings/EmbeddingServiceFactory.js +147 -0
  29. package/dist/embeddings/EmbeddingServiceFactory.js.map +1 -0
  30. package/dist/embeddings/OpenAIEmbeddingService.d.ts +73 -0
  31. package/dist/embeddings/OpenAIEmbeddingService.js +195 -0
  32. package/dist/embeddings/OpenAIEmbeddingService.js.map +1 -0
  33. package/dist/embeddings/config.d.ts +83 -0
  34. package/dist/embeddings/config.js +65 -0
  35. package/dist/embeddings/config.js.map +1 -0
  36. package/dist/index.d.ts +4 -0
  37. package/dist/index.js +220 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/server/handlers/callToolHandler.d.ts +20 -0
  40. package/dist/server/handlers/callToolHandler.js +505 -0
  41. package/dist/server/handlers/callToolHandler.js.map +1 -0
  42. package/dist/server/handlers/listToolsHandler.d.ts +7 -0
  43. package/dist/server/handlers/listToolsHandler.js +511 -0
  44. package/dist/server/handlers/listToolsHandler.js.map +1 -0
  45. package/dist/server/handlers/toolHandlers/addObservations.d.ts +12 -0
  46. package/dist/server/handlers/toolHandlers/addObservations.js +99 -0
  47. package/dist/server/handlers/toolHandlers/addObservations.js.map +1 -0
  48. package/dist/server/handlers/toolHandlers/createEntities.d.ts +12 -0
  49. package/dist/server/handlers/toolHandlers/createEntities.js +20 -0
  50. package/dist/server/handlers/toolHandlers/createEntities.js.map +1 -0
  51. package/dist/server/handlers/toolHandlers/createRelations.d.ts +12 -0
  52. package/dist/server/handlers/toolHandlers/createRelations.js +20 -0
  53. package/dist/server/handlers/toolHandlers/createRelations.js.map +1 -0
  54. package/dist/server/handlers/toolHandlers/deleteEntities.d.ts +12 -0
  55. package/dist/server/handlers/toolHandlers/deleteEntities.js +20 -0
  56. package/dist/server/handlers/toolHandlers/deleteEntities.js.map +1 -0
  57. package/dist/server/handlers/toolHandlers/index.d.ts +8 -0
  58. package/dist/server/handlers/toolHandlers/index.js +9 -0
  59. package/dist/server/handlers/toolHandlers/index.js.map +1 -0
  60. package/dist/server/handlers/toolHandlers/readGraph.d.ts +12 -0
  61. package/dist/server/handlers/toolHandlers/readGraph.js +20 -0
  62. package/dist/server/handlers/toolHandlers/readGraph.js.map +1 -0
  63. package/dist/server/setup.d.ts +8 -0
  64. package/dist/server/setup.js +48 -0
  65. package/dist/server/setup.js.map +1 -0
  66. package/dist/storage/FileStorageProvider.d.ts +125 -0
  67. package/dist/storage/FileStorageProvider.js +322 -0
  68. package/dist/storage/FileStorageProvider.js.map +1 -0
  69. package/dist/storage/SearchResultCache.d.ts +102 -0
  70. package/dist/storage/SearchResultCache.js +258 -0
  71. package/dist/storage/SearchResultCache.js.map +1 -0
  72. package/dist/storage/StorageProvider.d.ts +171 -0
  73. package/dist/storage/StorageProvider.js +46 -0
  74. package/dist/storage/StorageProvider.js.map +1 -0
  75. package/dist/storage/StorageProviderFactory.d.ts +63 -0
  76. package/dist/storage/StorageProviderFactory.js +113 -0
  77. package/dist/storage/StorageProviderFactory.js.map +1 -0
  78. package/dist/storage/VectorStoreFactory.d.ts +43 -0
  79. package/dist/storage/VectorStoreFactory.js +41 -0
  80. package/dist/storage/VectorStoreFactory.js.map +1 -0
  81. package/dist/storage/neo4j/Neo4jConfig.d.ts +37 -0
  82. package/dist/storage/neo4j/Neo4jConfig.js +13 -0
  83. package/dist/storage/neo4j/Neo4jConfig.js.map +1 -0
  84. package/dist/storage/neo4j/Neo4jConnectionManager.d.ts +40 -0
  85. package/dist/storage/neo4j/Neo4jConnectionManager.js +58 -0
  86. package/dist/storage/neo4j/Neo4jConnectionManager.js.map +1 -0
  87. package/dist/storage/neo4j/Neo4jSchemaManager.d.ts +74 -0
  88. package/dist/storage/neo4j/Neo4jSchemaManager.js +224 -0
  89. package/dist/storage/neo4j/Neo4jSchemaManager.js.map +1 -0
  90. package/dist/storage/neo4j/Neo4jStorageProvider.d.ts +225 -0
  91. package/dist/storage/neo4j/Neo4jStorageProvider.js +1900 -0
  92. package/dist/storage/neo4j/Neo4jStorageProvider.js.map +1 -0
  93. package/dist/storage/neo4j/Neo4jVectorStore.d.ts +80 -0
  94. package/dist/storage/neo4j/Neo4jVectorStore.js +396 -0
  95. package/dist/storage/neo4j/Neo4jVectorStore.js.map +1 -0
  96. package/dist/types/entity-embedding.d.ts +156 -0
  97. package/dist/types/entity-embedding.js +2 -0
  98. package/dist/types/entity-embedding.js.map +1 -0
  99. package/dist/types/relation.d.ts +77 -0
  100. package/dist/types/relation.js +93 -0
  101. package/dist/types/relation.js.map +1 -0
  102. package/dist/types/temporalEntity.d.ts +55 -0
  103. package/dist/types/temporalEntity.js +66 -0
  104. package/dist/types/temporalEntity.js.map +1 -0
  105. package/dist/types/temporalRelation.d.ts +60 -0
  106. package/dist/types/temporalRelation.js +89 -0
  107. package/dist/types/temporalRelation.js.map +1 -0
  108. package/dist/types/vector-index.d.ts +48 -0
  109. package/dist/types/vector-index.js +2 -0
  110. package/dist/types/vector-index.js.map +1 -0
  111. package/dist/types/vector-store.d.ts +16 -0
  112. package/dist/types/vector-store.js +2 -0
  113. package/dist/types/vector-store.js.map +1 -0
  114. package/dist/utils/fs.d.ts +2 -0
  115. package/dist/utils/fs.js +3 -0
  116. package/dist/utils/fs.js.map +1 -0
  117. package/dist/utils/logger.d.ts +10 -0
  118. package/dist/utils/logger.js +35 -0
  119. package/dist/utils/logger.js.map +1 -0
  120. package/package.json +85 -0
@@ -0,0 +1,258 @@
1
+ /**
2
+ * Cache system for search results to improve performance for repeated queries
3
+ */
4
+ /**
5
+ * A memory-efficient cache for search results
6
+ */
7
+ export class SearchResultCache {
8
+ /**
9
+ * Create a new SearchResultCache
10
+ * @param config Configuration options
11
+ */
12
+ constructor(config) {
13
+ this.cache = new Map();
14
+ this.currentSize = 0;
15
+ // Statistics
16
+ this.hits = 0;
17
+ this.misses = 0;
18
+ this.evictions = 0;
19
+ this.totalLookupTime = 0;
20
+ this.totalLookups = 0;
21
+ // Default to 100MB max size
22
+ this.maxSize = config?.maxSize || 100 * 1024 * 1024;
23
+ // Default to 5 minute TTL
24
+ this.defaultTtl = config?.defaultTtl || 5 * 60 * 1000;
25
+ // Enable stats by default
26
+ this.enableStats = config?.enableStats !== false;
27
+ }
28
+ /**
29
+ * Estimate the size of an object in bytes
30
+ * @param obj The object to measure
31
+ * @returns Approximate size in bytes
32
+ */
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ estimateSize(obj) {
35
+ if (obj === null || obj === undefined) {
36
+ return 0;
37
+ }
38
+ // For arrays of numbers (vectors), use more precise calculation
39
+ if (Array.isArray(obj) && obj.length > 0 && typeof obj[0] === 'number') {
40
+ return obj.length * 8; // 8 bytes per number (Float64)
41
+ }
42
+ // For strings, use character count * 2 (for UTF-16)
43
+ if (typeof obj === 'string') {
44
+ return obj.length * 2;
45
+ }
46
+ // For simple objects with a 'data' property containing a string
47
+ if (obj && typeof obj === 'object' && typeof obj.data === 'string') {
48
+ return obj.data.length * 2 + 100; // String length + overhead
49
+ }
50
+ // Use JSON stringification as an approximation for complex objects
51
+ // Add a small overhead to account for object structure
52
+ try {
53
+ const json = JSON.stringify(obj);
54
+ return json ? json.length * 2 + 100 : 100; // UTF-16 characters + overhead
55
+ }
56
+ catch {
57
+ // If stringification fails, use a reasonable default
58
+ return 1024; // 1KB default
59
+ }
60
+ }
61
+ /**
62
+ * Generate a cache key from a query and parameters
63
+ * @param query Original query string
64
+ * @param params Optional parameters that affect the query
65
+ * @returns A cache key string
66
+ */
67
+ generateKey(query, params) {
68
+ if (!params) {
69
+ return query;
70
+ }
71
+ // Sort keys for consistent key generation regardless of parameter order
72
+ const sortedParams = Object.keys(params)
73
+ .sort()
74
+ .map((key) => `${key}:${JSON.stringify(params[key])}`)
75
+ .join(',');
76
+ return `${query}|${sortedParams}`;
77
+ }
78
+ /**
79
+ * Evict the oldest or least valuable entries to free up space
80
+ * @param requiredSpace The amount of space needed
81
+ */
82
+ evictEntries(requiredSpace) {
83
+ // If cache is empty, nothing to evict
84
+ if (this.cache.size === 0) {
85
+ return;
86
+ }
87
+ // Create an array of entries sorted by "value"
88
+ // Value is determined by how recently they were created
89
+ const entries = Array.from(this.cache.entries()).sort((a, b) => a[1].created - b[1].created);
90
+ let freedSpace = 0;
91
+ let evictionCount = 0;
92
+ // Evict entries until we have enough space
93
+ for (const [key, entry] of entries) {
94
+ if (freedSpace >= requiredSpace && evictionCount > 0) {
95
+ break;
96
+ }
97
+ this.cache.delete(key);
98
+ freedSpace += entry.size;
99
+ this.currentSize -= entry.size;
100
+ evictionCount++;
101
+ // Only evict the oldest entry and then check if we have enough space
102
+ if (evictionCount === 1 && freedSpace >= requiredSpace) {
103
+ break;
104
+ }
105
+ }
106
+ // Update statistics
107
+ if (this.enableStats) {
108
+ this.evictions += evictionCount;
109
+ }
110
+ }
111
+ /**
112
+ * Set a cache entry
113
+ * @param query The original query
114
+ * @param params Optional parameters that affect the results
115
+ * @param data The data to cache
116
+ * @param ttl Optional time-to-live in milliseconds
117
+ */
118
+ set(query, data, params, ttl) {
119
+ // Clean expired entries
120
+ this.removeExpired();
121
+ // Generate cache key
122
+ const key = this.generateKey(query, params);
123
+ // Estimate data size
124
+ const size = this.estimateSize(data);
125
+ // If item is too large for the cache, don't cache it
126
+ if (size > this.maxSize) {
127
+ return;
128
+ }
129
+ // Calculate expiration time
130
+ const now = Date.now();
131
+ const expiration = now + (ttl || this.defaultTtl);
132
+ // Create cache entry
133
+ const entry = {
134
+ data,
135
+ expiration,
136
+ created: now,
137
+ size,
138
+ };
139
+ // Check if we need to make space
140
+ if (this.currentSize + size > this.maxSize) {
141
+ this.evictEntries(size);
142
+ }
143
+ // Add to cache
144
+ this.cache.set(key, entry);
145
+ this.currentSize += size;
146
+ }
147
+ /**
148
+ * Get a value from the cache
149
+ * @param query The original query
150
+ * @param params Optional parameters that affect the results
151
+ * @returns The cached data or undefined if not found or expired
152
+ */
153
+ get(query, params) {
154
+ const startTime = this.enableStats ? performance.now() : 0;
155
+ // Generate cache key
156
+ const key = this.generateKey(query, params);
157
+ // Get entry
158
+ const entry = this.cache.get(key);
159
+ // Track lookup time
160
+ if (this.enableStats) {
161
+ const endTime = performance.now();
162
+ this.totalLookupTime += endTime - startTime;
163
+ this.totalLookups++;
164
+ }
165
+ // If entry doesn't exist, return undefined
166
+ if (!entry) {
167
+ if (this.enableStats) {
168
+ this.misses++;
169
+ }
170
+ return undefined;
171
+ }
172
+ // Check if expired
173
+ if (entry.expiration < Date.now()) {
174
+ // Remove expired entry
175
+ this.cache.delete(key);
176
+ this.currentSize -= entry.size;
177
+ if (this.enableStats) {
178
+ this.misses++;
179
+ }
180
+ return undefined;
181
+ }
182
+ // Valid cache hit
183
+ if (this.enableStats) {
184
+ this.hits++;
185
+ }
186
+ return entry.data;
187
+ }
188
+ /**
189
+ * Remove all expired entries from the cache
190
+ */
191
+ removeExpired() {
192
+ const now = Date.now();
193
+ let removedSize = 0;
194
+ for (const [key, entry] of this.cache.entries()) {
195
+ if (entry.expiration < now) {
196
+ this.cache.delete(key);
197
+ removedSize += entry.size;
198
+ }
199
+ }
200
+ this.currentSize -= removedSize;
201
+ }
202
+ /**
203
+ * Clear the entire cache
204
+ */
205
+ clear() {
206
+ this.cache.clear();
207
+ this.currentSize = 0;
208
+ }
209
+ /**
210
+ * Get cache statistics
211
+ * @returns Cache statistics
212
+ */
213
+ getStats() {
214
+ // Calculate hit rate
215
+ const totalRequests = this.hits + this.misses;
216
+ const hitRate = totalRequests > 0 ? this.hits / totalRequests : 0;
217
+ // Calculate average lookup time
218
+ const averageLookupTime = this.totalLookups > 0 ? this.totalLookupTime / this.totalLookups : 0;
219
+ return {
220
+ hits: this.hits,
221
+ misses: this.misses,
222
+ hitRate,
223
+ currentSize: this.currentSize,
224
+ maxSize: this.maxSize,
225
+ entryCount: this.cache.size,
226
+ evictions: this.evictions,
227
+ averageLookupTime,
228
+ };
229
+ }
230
+ /**
231
+ * Get the current number of entries in the cache
232
+ * @returns Number of entries
233
+ */
234
+ size() {
235
+ return this.cache.size;
236
+ }
237
+ /**
238
+ * Check if the cache contains a specific key
239
+ * @param query The original query
240
+ * @param params Optional parameters that affect the results
241
+ * @returns True if the key exists and is not expired
242
+ */
243
+ has(query, params) {
244
+ const key = this.generateKey(query, params);
245
+ const entry = this.cache.get(key);
246
+ if (!entry) {
247
+ return false;
248
+ }
249
+ if (entry.expiration < Date.now()) {
250
+ // Remove expired entry
251
+ this.cache.delete(key);
252
+ this.currentSize -= entry.size;
253
+ return false;
254
+ }
255
+ return true;
256
+ }
257
+ }
258
+ //# sourceMappingURL=SearchResultCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SearchResultCache.js","sourceRoot":"","sources":["../../src/storage/SearchResultCache.ts"],"names":[],"mappings":"AAAA;;GAEG;AA8DH;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAc5B;;;OAGG;IACH,YAAY,MAA0B;QAjB9B,UAAK,GAA+B,IAAI,GAAG,EAAE,CAAC;QAE9C,gBAAW,GAAW,CAAC,CAAC;QAIhC,aAAa;QACL,SAAI,GAAW,CAAC,CAAC;QACjB,WAAM,GAAW,CAAC,CAAC;QACnB,cAAS,GAAW,CAAC,CAAC;QACtB,oBAAe,GAAW,CAAC,CAAC;QAC5B,iBAAY,GAAW,CAAC,CAAC;QAO/B,4BAA4B;QAC5B,IAAI,CAAC,OAAO,GAAG,MAAM,EAAE,OAAO,IAAI,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;QAEpD,0BAA0B;QAC1B,IAAI,CAAC,UAAU,GAAG,MAAM,EAAE,UAAU,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;QAEtD,0BAA0B;QAC1B,IAAI,CAAC,WAAW,GAAG,MAAM,EAAE,WAAW,KAAK,KAAK,CAAC;IACnD,CAAC;IAED;;;;OAIG;IACH,8DAA8D;IACtD,YAAY,CAAC,GAAQ;QAC3B,IAAI,GAAG,KAAK,IAAI,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YACtC,OAAO,CAAC,CAAC;QACX,CAAC;QAED,gEAAgE;QAChE,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YACvE,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,+BAA+B;QACxD,CAAC;QAED,oDAAoD;QACpD,IAAI,OAAO,GAAG,KAAK,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AAC;YAC/B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,171 @@
1
+ import type { KnowledgeGraph } from '../KnowledgeGraphManager.js';
2
+ import type { Relation } from '../types/relation.js';
3
+ import type { EntityEmbedding, SemanticSearchOptions } from '../types/entity-embedding.js';
4
+ /**
5
+ * Options for searching nodes in the knowledge graph
6
+ */
7
+ export interface SearchOptions {
8
+ /**
9
+ * Maximum number of results to return
10
+ */
11
+ limit?: number;
12
+ /**
13
+ * Whether the search should be case-sensitive
14
+ */
15
+ caseSensitive?: boolean;
16
+ /**
17
+ * Filter results by entity types
18
+ */
19
+ entityTypes?: string[];
20
+ }
21
+ /**
22
+ * Interface for storage providers that can load and save knowledge graphs
23
+ */
24
+ export interface StorageProvider {
25
+ /**
26
+ * Load a knowledge graph from storage
27
+ * @returns Promise resolving to the loaded knowledge graph
28
+ */
29
+ loadGraph(): Promise<KnowledgeGraph>;
30
+ /**
31
+ * Save a knowledge graph to storage
32
+ * @param graph The knowledge graph to save
33
+ * @returns Promise that resolves when the save is complete
34
+ */
35
+ saveGraph(graph: KnowledgeGraph): Promise<void>;
36
+ /**
37
+ * Search for nodes in the graph that match the query
38
+ * @param query The search query string
39
+ * @param options Optional search parameters
40
+ * @returns Promise resolving to a KnowledgeGraph containing matching nodes
41
+ */
42
+ searchNodes(query: string, options?: SearchOptions): Promise<KnowledgeGraph>;
43
+ /**
44
+ * Open specific nodes by their exact names
45
+ * @param names Array of node names to open
46
+ * @returns Promise resolving to a KnowledgeGraph containing the specified nodes
47
+ */
48
+ openNodes(names: string[]): Promise<KnowledgeGraph>;
49
+ /**
50
+ * Create new entities in the knowledge graph
51
+ * @param entities Array of entities to create
52
+ * @returns Promise resolving to array of newly created entities with temporal metadata
53
+ */
54
+ createEntities(entities: any[]): Promise<any[]>;
55
+ /**
56
+ * Create new relations between entities
57
+ * @param relations Array of relations to create
58
+ * @returns Promise resolving to array of newly created relations
59
+ */
60
+ createRelations(relations: Relation[]): Promise<Relation[]>;
61
+ /**
62
+ * Add observations to entities
63
+ * @param observations Array of objects with entity name and observation contents
64
+ * @returns Promise resolving to array of objects with entity name and added observations
65
+ */
66
+ addObservations(observations: {
67
+ entityName: string;
68
+ contents: string[];
69
+ }[]): Promise<{
70
+ entityName: string;
71
+ addedObservations: string[];
72
+ }[]>;
73
+ /**
74
+ * Delete entities and their relations
75
+ * @param entityNames Array of entity names to delete
76
+ * @returns Promise that resolves when deletion is complete
77
+ */
78
+ deleteEntities(entityNames: string[]): Promise<void>;
79
+ /**
80
+ * Delete observations from entities
81
+ * @param deletions Array of objects with entity name and observations to delete
82
+ * @returns Promise that resolves when deletion is complete
83
+ */
84
+ deleteObservations(deletions: {
85
+ entityName: string;
86
+ observations: string[];
87
+ }[]): Promise<void>;
88
+ /**
89
+ * Delete relations from the graph
90
+ * @param relations Array of relations to delete
91
+ * @returns Promise that resolves when deletion is complete
92
+ */
93
+ deleteRelations(relations: Relation[]): Promise<void>;
94
+ /**
95
+ * Get a specific relation by its source, target, and type
96
+ * @param from Source entity name
97
+ * @param to Target entity name
98
+ * @param type Relation type
99
+ * @returns Promise resolving to the relation or null if not found
100
+ */
101
+ getRelation?(from: string, to: string, type: string): Promise<Relation | null>;
102
+ /**
103
+ * Update an existing relation with new properties
104
+ * @param relation The relation with updated properties
105
+ * @returns Promise that resolves when the update is complete
106
+ */
107
+ updateRelation?(relation: Relation): Promise<void>;
108
+ /**
109
+ * Get the history of all versions of an entity
110
+ * @param entityName The name of the entity to retrieve history for
111
+ * @returns Promise resolving to an array of entity versions in chronological order
112
+ */
113
+ getEntityHistory?(entityName: string): Promise<any[]>;
114
+ /**
115
+ * Get the history of all versions of a relation
116
+ * @param from Source entity name
117
+ * @param to Target entity name
118
+ * @param relationType Type of the relation
119
+ * @returns Promise resolving to an array of relation versions in chronological order
120
+ */
121
+ getRelationHistory?(from: string, to: string, relationType: string): Promise<any[]>;
122
+ /**
123
+ * Get the state of the knowledge graph at a specific point in time
124
+ * @param timestamp The timestamp to get the graph state at
125
+ * @returns Promise resolving to the knowledge graph as it was at the specified time
126
+ */
127
+ getGraphAtTime?(timestamp: number): Promise<KnowledgeGraph>;
128
+ /**
129
+ * Get the current knowledge graph with confidence decay applied to relations
130
+ * based on their age and the configured decay settings
131
+ * @returns Promise resolving to the knowledge graph with decayed confidence values
132
+ */
133
+ getDecayedGraph?(): Promise<KnowledgeGraph>;
134
+ /**
135
+ * Store or update the embedding vector for an entity
136
+ * @param entityName The name of the entity to update
137
+ * @param embedding The embedding data to store
138
+ * @returns Promise that resolves when the update is complete
139
+ */
140
+ updateEntityEmbedding?(entityName: string, embedding: EntityEmbedding): Promise<void>;
141
+ /**
142
+ * Find entities similar to a query vector
143
+ * @param queryVector The vector to compare against
144
+ * @param limit Maximum number of results to return
145
+ * @returns Promise resolving to array of entities with similarity scores
146
+ */
147
+ findSimilarEntities?(queryVector: number[], limit?: number): Promise<any[]>;
148
+ /**
149
+ * Search for entities using semantic search
150
+ * @param query The search query text
151
+ * @param options Search options including semantic search parameters
152
+ * @returns Promise resolving to a KnowledgeGraph containing matching entities
153
+ */
154
+ semanticSearch?(query: string, options?: SearchOptions & SemanticSearchOptions): Promise<KnowledgeGraph>;
155
+ /**
156
+ * Get an entity by name
157
+ * @param entityName Name of the entity to retrieve
158
+ * @returns Promise resolving to the entity or null if not found
159
+ */
160
+ getEntity(entityName: string): Promise<any | null>;
161
+ }
162
+ export declare namespace StorageProvider {
163
+ function isStorageProvider(obj: any): boolean;
164
+ }
165
+ /**
166
+ * Validator class for StorageProvider interface
167
+ * This exists to ensure there's a concrete export for JavaScript tests
168
+ */
169
+ export declare class StorageProviderValidator {
170
+ static isStorageProvider(obj: any): boolean;
171
+ }
@@ -0,0 +1,46 @@
1
+ // Add static methods to the StorageProvider interface for JavaScript tests
2
+ // This allows tests to access validation methods directly from the interface
3
+ // eslint-disable-next-line @typescript-eslint/no-namespace
4
+ export var StorageProvider;
5
+ (function (StorageProvider) {
6
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
+ function isStorageProvider(obj) {
8
+ return StorageProviderValidator.isStorageProvider(obj);
9
+ }
10
+ StorageProvider.isStorageProvider = isStorageProvider;
11
+ })(StorageProvider || (StorageProvider = {}));
12
+ /**
13
+ * Validator class for StorageProvider interface
14
+ * This exists to ensure there's a concrete export for JavaScript tests
15
+ */
16
+ export class StorageProviderValidator {
17
+ // No implementation - this is just to ensure the symbol exists in the compiled JS
18
+ // JavaScript tests will use this as a type reference
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ static isStorageProvider(obj) {
21
+ const hasRequiredMethods = obj &&
22
+ typeof obj.loadGraph === 'function' &&
23
+ typeof obj.saveGraph === 'function' &&
24
+ typeof obj.searchNodes === 'function' &&
25
+ typeof obj.openNodes === 'function' &&
26
+ typeof obj.createEntities === 'function' &&
27
+ typeof obj.createRelations === 'function' &&
28
+ typeof obj.addObservations === 'function' &&
29
+ typeof obj.deleteEntities === 'function' &&
30
+ typeof obj.deleteObservations === 'function' &&
31
+ typeof obj.deleteRelations === 'function' &&
32
+ typeof obj.getEntity === 'function';
33
+ // Check that any optional methods, if present, are functions
34
+ const optionalMethodsValid = (!obj.getRelation || typeof obj.getRelation === 'function') &&
35
+ (!obj.updateRelation || typeof obj.updateRelation === 'function') &&
36
+ (!obj.getEntityHistory || typeof obj.getEntityHistory === 'function') &&
37
+ (!obj.getRelationHistory || typeof obj.getRelationHistory === 'function') &&
38
+ (!obj.getGraphAtTime || typeof obj.getGraphAtTime === 'function') &&
39
+ (!obj.getDecayedGraph || typeof obj.getDecayedGraph === 'function') &&
40
+ (!obj.updateEntityEmbedding || typeof obj.updateEntityEmbedding === 'function') &&
41
+ (!obj.findSimilarEntities || typeof obj.findSimilarEntities === 'function') &&
42
+ (!obj.semanticSearch || typeof obj.semanticSearch === 'function');
43
+ return hasRequiredMethods && optionalMethodsValid;
44
+ }
45
+ }
46
+ //# sourceMappingURL=StorageProv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E,CAAC,CAAC,GAAG,CAAC,gBAAgB,IAAI,OAAO,GAAG,CAAC,gBAAgB,KAAK,UAAU,CAAC;YACrE,CAAC,CAAC,GAAG,CAAC,kBAAkB,IAAI,OAAO,GAAG,CAAC,kBAAkB,KAAK,UAAU,CAAC;YACzE,CAAC,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,GAAG,CAAC,cAAc,KAAK,UAAU,CAAC;YACjE,CAAC,CAAC,GAAG,CAAC,eAAe,IAAI,OAAO,GAAG,CAAC,eAAe,KAAK,UAAU,CAAC;YACnE,CAAC,CAAC,GAAG,CAAC,qBAAqB,IAAI,OAAO,GAAG,CAAC,qBAAqB,KAAK,UAAU,CAAC;YAC/E,CAAC,CAAC,GAAG,CAAC,mBAAmB,IAAI,OAAO,GAAG,CAAC,mBAAmB,KAAK,UAAU,CAAC;YAC3E,CAAC,CAAC,GAAG,CAAC,cAAc,IAAI,OAAO,GAAG,CAAC,cAAc,KAAK,UAAU,CAAC,CAAC;QAEpE,OAAO,kBAAkB,IAAI,oBAAoB,CAAC;IACpD,CAAC;CACF"}
@@ -0,0 +1,63 @@
1
+ import type { StorageProvider } from './StorageProvider.js';
2
+ import type { VectorStoreFactoryOptions } from './VectorStoreFactory.js';
3
+ export interface StorageProviderConfig {
4
+ type: 'file' | 'neo4j';
5
+ options?: {
6
+ memoryFilePath?: string;
7
+ enableDecay?: boolean;
8
+ decayConfig?: {
9
+ enabled?: boolean;
10
+ halfLifeDays?: number;
11
+ minConfidence?: number;
12
+ };
13
+ neo4jUri?: string;
14
+ neo4jUsername?: string;
15
+ neo4jPassword?: string;
16
+ neo4jDatabase?: string;
17
+ neo4jVectorIndexName?: string;
18
+ neo4jVectorDimensions?: number;
19
+ neo4jSimilarityFunction?: 'cosine' | 'euclidean';
20
+ };
21
+ vectorStoreOptions?: VectorStoreFactoryOptions;
22
+ }
23
+ interface CleanableProvider extends StorageProvider {
24
+ cleanup?: () => Promise<void>;
25
+ }
26
+ /**
27
+ * Factory for creating storage providers
28
+ */
29
+ export declare class StorageProviderFactory {
30
+ private connectedProviders;
31
+ /**
32
+ * Create a storage provider based on configuration
33
+ * @param config Configuration for the provider
34
+ * @returns A storage provider instance
35
+ */
36
+ createProvider(config: StorageProviderConfig): StorageProvider;
37
+ /**
38
+ * Get a default storage provider (Neo4j-based)
39
+ * @returns A default Neo4jStorageProvider instance
40
+ */
41
+ getDefaultProvider(): StorageProvider;
42
+ /**
43
+ * Check if a provider is connected
44
+ * @param provider The provider to check
45
+ * @returns True if the provider is connected, false otherwise
46
+ */
47
+ isProviderConnected(provider: StorageProvider): boolean;
48
+ /**
49
+ * Disconnect a provider
50
+ * @param provider The provider to disconnect
51
+ */
52
+ disconnectProvider(provider: StorageProvider): void;
53
+ /**
54
+ * Cleanup provider resources and disconnect
55
+ * @param provider The provider to cleanup
56
+ */
57
+ cleanupProvider(provider: CleanableProvider): Promise<void>;
58
+ /**
59
+ * Cleanup all connected providers
60
+ */
61
+ cleanupAllProviders(): Promise<void>;
62
+ }
63
+ export {};
@@ -0,0 +1,113 @@
1
+ import { FileStorageProvider } from './FileStorageProvider.js';
2
+ import { Neo4jStorageProvider } from './neo4j/Neo4jStorageProvider.js';
3
+ /**
4
+ * Factory for creating storage providers
5
+ */
6
+ export class StorageProviderFactory {
7
+ constructor() {
8
+ // Track connected providers
9
+ this.connectedProviders = new Set();
10
+ }
11
+ /**
12
+ * Create a storage provider based on configuration
13
+ * @param config Configuration for the provider
14
+ * @returns A storage provider instance
15
+ */
16
+ createProvider(config) {
17
+ if (!config) {
18
+ throw new Error('Storage provider configuration is required');
19
+ }
20
+ if (!config.type) {
21
+ throw new Error('Storage provider type is required');
22
+ }
23
+ if (!config.options) {
24
+ throw new Error('Storage provider options are required');
25
+ }
26
+ let provider;
27
+ switch (config.type.toLowerCase()) {
28
+ case 'file': {
29
+ if (!config.options.memoryFilePath) {
30
+ throw new Error('memoryFilePath is required for file provider');
31
+ }
32
+ provider = new FileStorageProvider({
33
+ filePath: config.options.memoryFilePath,
34
+ vectorStoreOptions: config.vectorStoreOptions,
35
+ });
36
+ break;
37
+ }
38
+ case 'neo4j': {
39
+ // Configure Neo4j provider
40
+ const neo4jConfig = {
41
+ uri: config.options.neo4jUri,
42
+ username: config.options.neo4jUsername,
43
+ password: config.options.neo4jPassword,
44
+ database: config.options.neo4jDatabase,
45
+ vectorIndexName: config.options.neo4jVectorIndexName,
46
+ vectorDimensions: config.options.neo4jVectorDimensions,
47
+ similarityFunction: config.options.neo4jSimilarityFunction,
48
+ };
49
+ provider = new Neo4jStorageProvider({
50
+ config: neo4jConfig,
51
+ decayConfig: config.options.decayConfig
52
+ ? {
53
+ enabled: config.options.decayConfig.enabled ?? true,
54
+ halfLifeDays: config.options.decayConfig.halfLifeDays,
55
+ minConfidence: config.options.decayConfig.minConfidence,
56
+ }
57
+ : undefined,
58
+ });
59
+ break;
60
+ }
61
+ default:
62
+ throw new Error(`Unsupported provider type: ${config.type}`);
63
+ }
64
+ // Track the provider as connected
65
+ this.connectedProviders.add(provider);
66
+ return provider;
67
+ }
68
+ /**
69
+ * Get a default storage provider (Neo4j-based)
70
+ * @returns A default Neo4jStorageProvider instance
71
+ */
72
+ getDefaultProvider() {
73
+ // Create a Neo4j provider with default settings
74
+ const provider = new Neo4jStorageProvider();
75
+ this.connectedProviders.add(provider);
76
+ return provider;
77
+ }
78
+ /**
79
+ * Check if a provider is connected
80
+ * @param provider The provider to check
81
+ * @returns True if the provider is connected, false otherwise
82
+ */
83
+ isProviderConnected(provider) {
84
+ return this.connectedProviders.has(provider);
85
+ }
86
+ /**
87
+ * Disconnect a provider
88
+ * @param provider The provider to disconnect
89
+ */
90
+ disconnectProvider(provider) {
91
+ this.connectedProviders.delete(provider);
92
+ }
93
+ /**
94
+ * Cleanup provider resources and disconnect
95
+ * @param provider The provider to cleanup
96
+ */
97
+ async cleanupProvider(provider) {
98
+ if (this.isProviderConnected(provider)) {
99
+ if (provider.cleanup) {
100
+ await provider.cleanup();
101
+ }
102
+ this.disconnectProvider(provider);
103
+ }
104
+ }
105
+ /**
106
+ * Cleanup all connected providers
107
+ */
108
+ async cleanupAllProviders() {
109
+ const providers = Array.from(this.connectedProviders);
110
+ await Promise.all(providers.map((provider) => this.cleanupProvider(provider)));
111
+ }
112
+ }
113
+ //# sourceMappingURL=StorageProviderFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StorageProviderFactory.js","sourceRoot":"","sources":["../../src/storage/StorageProviderFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AA6BvE;;GAEG;AACH,MAAM,OAAO,sBAAsB;IAAnC;QACE,4BAA4B;QACpB,uBAAkB,GAAG,IAAI,GAAG,EAAmB,CAAC;IAoH1D,CAAC;IAlHC;;;;OAIG;IACH,cAAc,CAAC,MAA6B;QAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAChE,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACvD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAC3D,CAAC;QAED,IAAI,QAAyB,CAAC;QAE9B,QAAQ,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;YAClC,KAAK,MAAM,CAAC,CAAC,CAAC;gBACZ,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC;oBACnC,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;gBAClE,CAAC;gBACD,QAAQ,GAAG,IAAI,mBAAmB,CAAC;oBACjC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,cA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