@danielsimonjr/memory-mcp 0.48.0 → 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.
Files changed (209) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +2000 -194
  3. package/dist/__tests__/file-path.test.js +7 -11
  4. package/dist/__tests__/knowledge-graph.test.js +3 -8
  5. package/dist/core/EntityManager.d.ts +266 -0
  6. package/dist/core/EntityManager.d.ts.map +1 -0
  7. package/dist/core/EntityManager.js +85 -133
  8. package/dist/core/GraphEventEmitter.d.ts +202 -0
  9. package/dist/core/GraphEventEmitter.d.ts.map +1 -0
  10. package/dist/core/GraphEventEmitter.js +346 -0
  11. package/dist/core/GraphStorage.d.ts +395 -0
  12. package/dist/core/GraphStorage.d.ts.map +1 -0
  13. package/dist/core/GraphStorage.js +643 -31
  14. package/dist/core/GraphTraversal.d.ts +141 -0
  15. package/dist/core/GraphTraversal.d.ts.map +1 -0
  16. package/dist/core/GraphTraversal.js +573 -0
  17. package/dist/core/HierarchyManager.d.ts +111 -0
  18. package/dist/core/HierarchyManager.d.ts.map +1 -0
  19. package/dist/{features → core}/HierarchyManager.js +14 -9
  20. package/dist/core/ManagerContext.d.ts +72 -0
  21. package/dist/core/ManagerContext.d.ts.map +1 -0
  22. package/dist/core/ManagerContext.js +118 -0
  23. package/dist/core/ObservationManager.d.ts +85 -0
  24. package/dist/core/ObservationManager.d.ts.map +1 -0
  25. package/dist/core/ObservationManager.js +51 -57
  26. package/dist/core/RelationManager.d.ts +131 -0
  27. package/dist/core/RelationManager.d.ts.map +1 -0
  28. package/dist/core/RelationManager.js +31 -7
  29. package/dist/core/SQLiteStorage.d.ts +354 -0
  30. package/dist/core/SQLiteStorage.d.ts.map +1 -0
  31. package/dist/core/SQLiteStorage.js +917 -0
  32. package/dist/core/StorageFactory.d.ts +45 -0
  33. package/dist/core/StorageFactory.d.ts.map +1 -0
  34. package/dist/core/StorageFactory.js +64 -0
  35. package/dist/core/TransactionManager.d.ts +464 -0
  36. package/dist/core/TransactionManager.d.ts.map +1 -0
  37. package/dist/core/TransactionManager.js +490 -13
  38. package/dist/core/index.d.ts +17 -0
  39. package/dist/core/index.d.ts.map +1 -0
  40. package/dist/core/index.js +12 -2
  41. package/dist/features/AnalyticsManager.d.ts +44 -0
  42. package/dist/features/AnalyticsManager.d.ts.map +1 -0
  43. package/dist/features/AnalyticsManager.js +3 -2
  44. package/dist/features/ArchiveManager.d.ts +133 -0
  45. package/dist/features/ArchiveManager.d.ts.map +1 -0
  46. package/dist/features/ArchiveManager.js +221 -14
  47. package/dist/features/CompressionManager.d.ts +117 -0
  48. package/dist/features/CompressionManager.d.ts.map +1 -0
  49. package/dist/features/CompressionManager.js +189 -20
  50. package/dist/features/IOManager.d.ts +225 -0
  51. package/dist/features/IOManager.d.ts.map +1 -0
  52. package/dist/features/IOManager.js +1041 -0
  53. package/dist/features/StreamingExporter.d.ts +123 -0
  54. package/dist/features/StreamingExporter.d.ts.map +1 -0
  55. package/dist/features/StreamingExporter.js +203 -0
  56. package/dist/features/TagManager.d.ts +147 -0
  57. package/dist/features/TagManager.d.ts.map +1 -0
  58. package/dist/features/index.d.ts +12 -0
  59. package/dist/features/index.d.ts.map +1 -0
  60. package/dist/features/index.js +5 -6
  61. package/dist/index.d.ts +9 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +10 -10
  64. package/dist/memory.jsonl +1 -26
  65. package/dist/search/BasicSearch.d.ts +51 -0
  66. package/dist/search/BasicSearch.d.ts.map +1 -0
  67. package/dist/search/BasicSearch.js +9 -3
  68. package/dist/search/BooleanSearch.d.ts +98 -0
  69. package/dist/search/BooleanSearch.d.ts.map +1 -0
  70. package/dist/search/BooleanSearch.js +156 -9
  71. package/dist/search/EmbeddingService.d.ts +178 -0
  72. package/dist/search/EmbeddingService.d.ts.map +1 -0
  73. package/dist/search/EmbeddingService.js +358 -0
  74. package/dist/search/FuzzySearch.d.ts +118 -0
  75. package/dist/search/FuzzySearch.d.ts.map +1 -0
  76. package/dist/search/FuzzySearch.js +241 -25
  77. package/dist/search/QueryCostEstimator.d.ts +111 -0
  78. package/dist/search/QueryCostEstimator.d.ts.map +1 -0
  79. package/dist/search/QueryCostEstimator.js +355 -0
  80. package/dist/search/RankedSearch.d.ts +71 -0
  81. package/dist/search/RankedSearch.d.ts.map +1 -0
  82. package/dist/search/RankedSearch.js +54 -6
  83. package/dist/search/SavedSearchManager.d.ts +79 -0
  84. package/dist/search/SavedSearchManager.d.ts.map +1 -0
  85. package/dist/search/SearchFilterChain.d.ts +120 -0
  86. package/dist/search/SearchFilterChain.d.ts.map +1 -0
  87. package/dist/search/SearchFilterChain.js +2 -4
  88. package/dist/search/SearchManager.d.ts +326 -0
  89. package/dist/search/SearchManager.d.ts.map +1 -0
  90. package/dist/search/SearchManager.js +148 -0
  91. package/dist/search/SearchSuggestions.d.ts +27 -0
  92. package/dist/search/SearchSuggestions.d.ts.map +1 -0
  93. package/dist/search/SearchSuggestions.js +1 -1
  94. package/dist/search/SemanticSearch.d.ts +149 -0
  95. package/dist/search/SemanticSearch.d.ts.map +1 -0
  96. package/dist/search/SemanticSearch.js +323 -0
  97. package/dist/search/TFIDFEventSync.d.ts +85 -0
  98. package/dist/search/TFIDFEventSync.d.ts.map +1 -0
  99. package/dist/search/TFIDFEventSync.js +133 -0
  100. package/dist/search/TFIDFIndexManager.d.ts +151 -0
  101. package/dist/search/TFIDFIndexManager.d.ts.map +1 -0
  102. package/dist/search/TFIDFIndexManager.js +232 -17
  103. package/dist/search/VectorStore.d.ts +235 -0
  104. package/dist/search/VectorStore.d.ts.map +1 -0
  105. package/dist/search/VectorStore.js +311 -0
  106. package/dist/search/index.d.ts +21 -0
  107. package/dist/search/index.d.ts.map +1 -0
  108. package/dist/search/index.js +12 -0
  109. package/dist/server/MCPServer.d.ts +21 -0
  110. package/dist/server/MCPServer.d.ts.map +1 -0
  111. package/dist/server/MCPServer.js +4 -4
  112. package/dist/server/responseCompressor.d.ts +94 -0
  113. package/dist/server/responseCompressor.d.ts.map +1 -0
  114. package/dist/server/responseCompressor.js +127 -0
  115. package/dist/server/toolDefinitions.d.ts +27 -0
  116. package/dist/server/toolDefinitions.d.ts.map +1 -0
  117. package/dist/server/toolDefinitions.js +188 -17
  118. package/dist/server/toolHandlers.d.ts +41 -0
  119. package/dist/server/toolHandlers.d.ts.map +1 -0
  120. package/dist/server/toolHandlers.js +467 -75
  121. package/dist/types/index.d.ts +13 -0
  122. package/dist/types/index.d.ts.map +1 -0
  123. package/dist/types/index.js +1 -1
  124. package/dist/types/types.d.ts +1654 -0
  125. package/dist/types/types.d.ts.map +1 -0
  126. package/dist/types/types.js +9 -0
  127. package/dist/utils/compressedCache.d.ts +192 -0
  128. package/dist/utils/compressedCache.d.ts.map +1 -0
  129. package/dist/utils/compressedCache.js +309 -0
  130. package/dist/utils/compressionUtil.d.ts +214 -0
  131. package/dist/utils/compressionUtil.d.ts.map +1 -0
  132. package/dist/utils/compressionUtil.js +247 -0
  133. package/dist/utils/constants.d.ts +245 -0
  134. package/dist/utils/constants.d.ts.map +1 -0
  135. package/dist/utils/constants.js +124 -0
  136. package/dist/utils/entityUtils.d.ts +321 -0
  137. package/dist/utils/entityUtils.d.ts.map +1 -0
  138. package/dist/utils/entityUtils.js +434 -4
  139. package/dist/utils/errors.d.ts +95 -0
  140. package/dist/utils/errors.d.ts.map +1 -0
  141. package/dist/utils/errors.js +24 -0
  142. package/dist/utils/formatters.d.ts +145 -0
  143. package/dist/utils/formatters.d.ts.map +1 -0
  144. package/dist/utils/{paginationUtils.js → formatters.js} +54 -3
  145. package/dist/utils/index.d.ts +23 -0
  146. package/dist/utils/index.d.ts.map +1 -0
  147. package/dist/utils/index.js +69 -31
  148. package/dist/utils/indexes.d.ts +270 -0
  149. package/dist/utils/indexes.d.ts.map +1 -0
  150. package/dist/utils/indexes.js +526 -0
  151. package/dist/utils/logger.d.ts +24 -0
  152. package/dist/utils/logger.d.ts.map +1 -0
  153. package/dist/utils/operationUtils.d.ts +124 -0
  154. package/dist/utils/operationUtils.d.ts.map +1 -0
  155. package/dist/utils/operationUtils.js +175 -0
  156. package/dist/utils/parallelUtils.d.ts +72 -0
  157. package/dist/utils/parallelUtils.d.ts.map +1 -0
  158. package/dist/utils/parallelUtils.js +169 -0
  159. package/dist/utils/schemas.d.ts +374 -0
  160. package/dist/utils/schemas.d.ts.map +1 -0
  161. package/dist/utils/schemas.js +302 -2
  162. package/dist/utils/searchAlgorithms.d.ts +99 -0
  163. package/dist/utils/searchAlgorithms.d.ts.map +1 -0
  164. package/dist/utils/searchAlgorithms.js +167 -0
  165. package/dist/utils/searchCache.d.ts +108 -0
  166. package/dist/utils/searchCache.d.ts.map +1 -0
  167. package/dist/utils/taskScheduler.d.ts +290 -0
  168. package/dist/utils/taskScheduler.d.ts.map +1 -0
  169. package/dist/utils/taskScheduler.js +466 -0
  170. package/dist/workers/index.d.ts +12 -0
  171. package/dist/workers/index.d.ts.map +1 -0
  172. package/dist/workers/index.js +9 -0
  173. package/dist/workers/levenshteinWorker.d.ts +60 -0
  174. package/dist/workers/levenshteinWorker.d.ts.map +1 -0
  175. package/dist/workers/levenshteinWorker.js +98 -0
  176. package/package.json +17 -4
  177. package/dist/__tests__/edge-cases/edge-cases.test.js +0 -406
  178. package/dist/__tests__/integration/workflows.test.js +0 -449
  179. package/dist/__tests__/performance/benchmarks.test.js +0 -413
  180. package/dist/__tests__/unit/core/EntityManager.test.js +0 -334
  181. package/dist/__tests__/unit/core/GraphStorage.test.js +0 -205
  182. package/dist/__tests__/unit/core/RelationManager.test.js +0 -274
  183. package/dist/__tests__/unit/features/CompressionManager.test.js +0 -350
  184. package/dist/__tests__/unit/search/BasicSearch.test.js +0 -311
  185. package/dist/__tests__/unit/search/BooleanSearch.test.js +0 -432
  186. package/dist/__tests__/unit/search/FuzzySearch.test.js +0 -448
  187. package/dist/__tests__/unit/search/RankedSearch.test.js +0 -379
  188. package/dist/__tests__/unit/utils/levenshtein.test.js +0 -77
  189. package/dist/core/KnowledgeGraphManager.js +0 -423
  190. package/dist/features/BackupManager.js +0 -311
  191. package/dist/features/ExportManager.js +0 -305
  192. package/dist/features/ImportExportManager.js +0 -50
  193. package/dist/features/ImportManager.js +0 -328
  194. package/dist/memory-saved-searches.jsonl +0 -0
  195. package/dist/memory-tag-aliases.jsonl +0 -0
  196. package/dist/types/analytics.types.js +0 -6
  197. package/dist/types/entity.types.js +0 -7
  198. package/dist/types/import-export.types.js +0 -7
  199. package/dist/types/search.types.js +0 -7
  200. package/dist/types/tag.types.js +0 -6
  201. package/dist/utils/dateUtils.js +0 -89
  202. package/dist/utils/filterUtils.js +0 -155
  203. package/dist/utils/levenshtein.js +0 -62
  204. package/dist/utils/pathUtils.js +0 -115
  205. package/dist/utils/responseFormatter.js +0 -55
  206. package/dist/utils/tagUtils.js +0 -107
  207. package/dist/utils/tfidf.js +0 -90
  208. package/dist/utils/validationHelper.js +0 -99
  209. package/dist/utils/validationUtils.js +0 -109
@@ -20,9 +20,9 @@ export class RelationManager {
20
20
  * Create multiple relations in a single batch operation.
21
21
  *
22
22
  * This method performs the following operations:
23
+ * - Validates that all referenced entities exist (prevents dangling relations)
23
24
  * - Filters out duplicate relations (same from, to, and relationType)
24
25
  * - Automatically adds createdAt and lastModified timestamps
25
- * - Validates that entities referenced in relations exist (should be done by caller)
26
26
  *
27
27
  * A relation is considered duplicate if another relation exists with the same:
28
28
  * - from entity name
@@ -31,6 +31,7 @@ export class RelationManager {
31
31
  *
32
32
  * @param relations - Array of relations to create
33
33
  * @returns Promise resolving to array of newly created relations (excludes duplicates)
34
+ * @throws {ValidationError} If any relation references non-existent entities
34
35
  *
35
36
  * @example
36
37
  * ```typescript
@@ -63,13 +64,33 @@ export class RelationManager {
63
64
  const errors = validation.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`);
64
65
  throw new ValidationError('Invalid relation data', errors);
65
66
  }
66
- const graph = await this.storage.loadGraph();
67
+ // Use read-only graph for checking existing relations and entity existence
68
+ const readGraph = await this.storage.loadGraph();
67
69
  const timestamp = new Date().toISOString();
70
+ // Build set of existing entity names for O(1) lookup
71
+ const existingEntityNames = new Set(readGraph.entities.map(e => e.name));
72
+ // Validate that all referenced entities exist (fixes bug 7.2 from analysis)
73
+ const danglingRelations = [];
74
+ for (const relation of relations) {
75
+ const missingEntities = [];
76
+ if (!existingEntityNames.has(relation.from)) {
77
+ missingEntities.push(relation.from);
78
+ }
79
+ if (!existingEntityNames.has(relation.to)) {
80
+ missingEntities.push(relation.to);
81
+ }
82
+ if (missingEntities.length > 0) {
83
+ danglingRelations.push(`Relation from "${relation.from}" to "${relation.to}" references non-existent entities: ${missingEntities.join(', ')}`);
84
+ }
85
+ }
86
+ if (danglingRelations.length > 0) {
87
+ throw new ValidationError('Relations reference non-existent entities', danglingRelations);
88
+ }
68
89
  // Check graph size limits
69
- const relationsToAdd = relations.filter(r => !graph.relations.some(existing => existing.from === r.from &&
90
+ const relationsToAdd = relations.filter(r => !readGraph.relations.some(existing => existing.from === r.from &&
70
91
  existing.to === r.to &&
71
92
  existing.relationType === r.relationType));
72
- if (graph.relations.length + relationsToAdd.length > GRAPH_LIMITS.MAX_RELATIONS) {
93
+ if (readGraph.relations.length + relationsToAdd.length > GRAPH_LIMITS.MAX_RELATIONS) {
73
94
  throw new ValidationError('Graph size limit exceeded', [`Adding ${relationsToAdd.length} relations would exceed maximum of ${GRAPH_LIMITS.MAX_RELATIONS} relations`]);
74
95
  }
75
96
  const newRelations = relationsToAdd
@@ -78,6 +99,8 @@ export class RelationManager {
78
99
  createdAt: r.createdAt || timestamp,
79
100
  lastModified: r.lastModified || timestamp,
80
101
  }));
102
+ // Get mutable copy for write operation
103
+ const graph = await this.storage.getGraphForMutation();
81
104
  graph.relations.push(...newRelations);
82
105
  await this.storage.saveGraph(graph);
83
106
  return newRelations;
@@ -127,7 +150,7 @@ export class RelationManager {
127
150
  const errors = validation.error.issues.map((e) => `${e.path.join('.')}: ${e.message}`);
128
151
  throw new ValidationError('Invalid relation data', errors);
129
152
  }
130
- const graph = await this.storage.loadGraph();
153
+ const graph = await this.storage.getGraphForMutation();
131
154
  const timestamp = new Date().toISOString();
132
155
  // Track affected entities
133
156
  const affectedEntityNames = new Set();
@@ -180,7 +203,8 @@ export class RelationManager {
180
203
  * ```
181
204
  */
182
205
  async getRelations(entityName) {
183
- const graph = await this.storage.loadGraph();
184
- return graph.relations.filter(r => r.from === entityName || r.to === entityName);
206
+ // OPTIMIZED: Uses RelationIndex for O(1) lookup instead of O(n) array scan
207
+ await this.storage.ensureLoaded();
208
+ return this.storage.getRelationsFor(entityName);
185
209
  }
186
210
  }
@@ -0,0 +1,354 @@
1
+ /**
2
+ * SQLite Storage
3
+ *
4
+ * Handles storage operations for the knowledge graph using better-sqlite3 (native SQLite).
5
+ * Implements IGraphStorage interface for storage abstraction.
6
+ *
7
+ * Benefits over sql.js (WASM):
8
+ * - 3-10x faster than WASM-based SQLite
9
+ * - Native FTS5 full-text search support
10
+ * - ACID transactions with proper durability
11
+ * - Concurrent read access support
12
+ * - No memory overhead from WASM runtime
13
+ * - Direct disk I/O (no manual export/import)
14
+ *
15
+ * Features:
16
+ * - Built-in indexes for O(1) lookups
17
+ * - Referential integrity with ON DELETE CASCADE
18
+ * - FTS5 full-text search on entity names and observations
19
+ *
20
+ * @module core/SQLiteStorage
21
+ */
22
+ import type { KnowledgeGraph, Entity, Relation, ReadonlyKnowledgeGraph, IGraphStorage, LowercaseData } from '../types/index.js';
23
+ /**
24
+ * SQLiteStorage manages persistence of the knowledge graph using native SQLite.
25
+ *
26
+ * Uses better-sqlite3 for native SQLite bindings with full FTS5 support,
27
+ * referential integrity, and proper ACID transactions.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const storage = new SQLiteStorage('/path/to/memory.db');
32
+ * await storage.ensureLoaded();
33
+ * const graph = await storage.loadGraph();
34
+ * ```
35
+ */
36
+ export declare class SQLiteStorage implements IGraphStorage {
37
+ private dbFilePath;
38
+ /**
39
+ * Mutex for thread-safe access to storage operations.
40
+ * Prevents concurrent writes from corrupting the cache.
41
+ * Note: SQLite itself handles file-level locking, but we need
42
+ * to protect our in-memory cache and index operations.
43
+ */
44
+ private mutex;
45
+ /**
46
+ * SQLite database instance.
47
+ */
48
+ private db;
49
+ /**
50
+ * Whether the database has been initialized.
51
+ */
52
+ private initialized;
53
+ /**
54
+ * In-memory cache for fast read operations.
55
+ * Synchronized with SQLite on writes.
56
+ */
57
+ private cache;
58
+ /**
59
+ * O(1) entity lookup by name.
60
+ */
61
+ private nameIndex;
62
+ /**
63
+ * O(1) entity lookup by type.
64
+ */
65
+ private typeIndex;
66
+ /**
67
+ * Pre-computed lowercase data for search optimization.
68
+ */
69
+ private lowercaseCache;
70
+ /**
71
+ * Pending changes counter for batching disk writes.
72
+ * Note: better-sqlite3 writes to disk immediately, but we track for API compatibility.
73
+ */
74
+ private pendingChanges;
75
+ /**
76
+ * Phase 4 Sprint 1: Bidirectional relation cache for O(1) repeated lookups.
77
+ * Maps entity name -> all relations involving that entity (both incoming and outgoing).
78
+ */
79
+ private bidirectionalRelationCache;
80
+ /**
81
+ * Create a new SQLiteStorage instance.
82
+ *
83
+ * @param dbFilePath - Absolute path to the SQLite database file
84
+ */
85
+ constructor(dbFilePath: string);
86
+ /**
87
+ * Initialize the database connection and schema.
88
+ */
89
+ private initialize;
90
+ /**
91
+ * Create database tables, indexes, and FTS5 virtual table.
92
+ */
93
+ private createTables;
94
+ /**
95
+ * Load all data from SQLite into memory cache.
96
+ */
97
+ private loadCache;
98
+ /**
99
+ * Convert a database row to an Entity object.
100
+ */
101
+ private rowToEntity;
102
+ /**
103
+ * Convert a database row to a Relation object.
104
+ */
105
+ private rowToRelation;
106
+ /**
107
+ * Update lowercase cache for an entity.
108
+ */
109
+ private updateLowercaseCache;
110
+ /**
111
+ * Load the knowledge graph (read-only access).
112
+ *
113
+ * @returns Promise resolving to read-only knowledge graph reference
114
+ */
115
+ loadGraph(): Promise<ReadonlyKnowledgeGraph>;
116
+ /**
117
+ * Get a mutable copy of the graph for write operations.
118
+ *
119
+ * @returns Promise resolving to mutable knowledge graph copy
120
+ */
121
+ getGraphForMutation(): Promise<KnowledgeGraph>;
122
+ /**
123
+ * Ensure the storage is loaded/initialized.
124
+ *
125
+ * @returns Promise resolving when ready
126
+ */
127
+ ensureLoaded(): Promise<void>;
128
+ /**
129
+ * Phase 4 Sprint 1: Invalidate bidirectional relation cache for an entity.
130
+ *
131
+ * @param entityName - Entity name to invalidate cache for
132
+ */
133
+ private invalidateBidirectionalCache;
134
+ /**
135
+ * Phase 4 Sprint 1: Clear the entire bidirectional relation cache.
136
+ */
137
+ private clearBidirectionalCache;
138
+ /**
139
+ * Save the entire knowledge graph to storage.
140
+ *
141
+ * THREAD-SAFE: Uses mutex to prevent concurrent write operations.
142
+ *
143
+ * @param graph - The knowledge graph to save
144
+ * @returns Promise resolving when save is complete
145
+ */
146
+ saveGraph(graph: KnowledgeGraph): Promise<void>;
147
+ /**
148
+ * Append a single entity to storage.
149
+ *
150
+ * THREAD-SAFE: Uses mutex to prevent concurrent write operations.
151
+ *
152
+ * @param entity - The entity to append
153
+ * @returns Promise resolving when append is complete
154
+ */
155
+ appendEntity(entity: Entity): Promise<void>;
156
+ /**
157
+ * Append a single relation to storage.
158
+ *
159
+ * THREAD-SAFE: Uses mutex to prevent concurrent write operations.
160
+ *
161
+ * @param relation - The relation to append
162
+ * @returns Promise resolving when append is complete
163
+ */
164
+ appendRelation(relation: Relation): Promise<void>;
165
+ /**
166
+ * Update an entity in storage.
167
+ *
168
+ * THREAD-SAFE: Uses mutex to prevent concurrent write operations.
169
+ *
170
+ * @param entityName - Name of the entity to update
171
+ * @param updates - Partial entity updates to apply
172
+ * @returns Promise resolving to true if found and updated
173
+ */
174
+ updateEntity(entityName: string, updates: Partial<Entity>): Promise<boolean>;
175
+ /**
176
+ * Compact the storage (runs VACUUM to reclaim space).
177
+ *
178
+ * THREAD-SAFE: Uses mutex to prevent concurrent operations.
179
+ *
180
+ * @returns Promise resolving when compaction is complete
181
+ */
182
+ compact(): Promise<void>;
183
+ /**
184
+ * Clear any in-memory cache.
185
+ */
186
+ clearCache(): void;
187
+ /**
188
+ * Get an entity by name in O(1) time.
189
+ *
190
+ * OPTIMIZED: Uses NameIndex for constant-time lookup.
191
+ *
192
+ * @param name - Entity name to look up
193
+ * @returns Entity if found, undefined otherwise
194
+ */
195
+ getEntityByName(name: string): Entity | undefined;
196
+ /**
197
+ * Check if an entity exists by name in O(1) time.
198
+ *
199
+ * @param name - Entity name to check
200
+ * @returns True if entity exists
201
+ */
202
+ hasEntity(name: string): boolean;
203
+ /**
204
+ * Get all entities of a given type in O(1) time.
205
+ *
206
+ * OPTIMIZED: Uses TypeIndex for constant-time lookup of entity names,
207
+ * then uses NameIndex for O(1) entity retrieval.
208
+ *
209
+ * @param entityType - Entity type to filter by (case-insensitive)
210
+ * @returns Array of entities with the given type
211
+ */
212
+ getEntitiesByType(entityType: string): Entity[];
213
+ /**
214
+ * Get all unique entity types in the graph.
215
+ *
216
+ * @returns Array of unique entity types (lowercase)
217
+ */
218
+ getEntityTypes(): string[];
219
+ /**
220
+ * Get pre-computed lowercase data for an entity.
221
+ *
222
+ * @param entityName - Entity name to get lowercase data for
223
+ * @returns LowercaseData if entity exists, undefined otherwise
224
+ */
225
+ getLowercased(entityName: string): LowercaseData | undefined;
226
+ /**
227
+ * Perform full-text search using FTS5.
228
+ *
229
+ * @param query - Search query (supports FTS5 query syntax)
230
+ * @returns Array of matching entity names with relevance scores
231
+ */
232
+ fullTextSearch(query: string): Array<{
233
+ name: string;
234
+ score: number;
235
+ }>;
236
+ /**
237
+ * Perform a simple text search (LIKE-based, case-insensitive).
238
+ *
239
+ * @param searchTerm - Term to search for
240
+ * @returns Array of matching entity names
241
+ */
242
+ simpleSearch(searchTerm: string): string[];
243
+ /**
244
+ * Get the storage path/location.
245
+ *
246
+ * @returns The storage path
247
+ */
248
+ getFilePath(): string;
249
+ /**
250
+ * Get the current pending changes count.
251
+ *
252
+ * @returns Number of pending changes since last reset
253
+ */
254
+ getPendingAppends(): number;
255
+ /**
256
+ * Force persistence to disk (no-op for better-sqlite3 as it writes immediately).
257
+ *
258
+ * @returns Promise resolving when persistence is complete
259
+ */
260
+ flush(): Promise<void>;
261
+ /**
262
+ * Close the database connection.
263
+ */
264
+ close(): void;
265
+ /**
266
+ * Get all relations where the entity is the source (outgoing relations).
267
+ *
268
+ * OPTIMIZED: Uses SQLite index on fromEntity for O(log n) lookup.
269
+ *
270
+ * @param entityName - Entity name to look up outgoing relations for
271
+ * @returns Array of relations where entity is the source
272
+ */
273
+ getRelationsFrom(entityName: string): Relation[];
274
+ /**
275
+ * Get all relations where the entity is the target (incoming relations).
276
+ *
277
+ * OPTIMIZED: Uses SQLite index on toEntity for O(log n) lookup.
278
+ *
279
+ * @param entityName - Entity name to look up incoming relations for
280
+ * @returns Array of relations where entity is the target
281
+ */
282
+ getRelationsTo(entityName: string): Relation[];
283
+ /**
284
+ * Get all relations involving the entity (both incoming and outgoing).
285
+ *
286
+ * OPTIMIZED: Phase 4 Sprint 1 - Uses bidirectional cache for O(1) repeated lookups.
287
+ *
288
+ * @param entityName - Entity name to look up all relations for
289
+ * @returns Array of all relations involving the entity
290
+ */
291
+ getRelationsFor(entityName: string): Relation[];
292
+ /**
293
+ * Check if an entity has any relations.
294
+ *
295
+ * @param entityName - Entity name to check
296
+ * @returns True if entity has any relations
297
+ */
298
+ hasRelations(entityName: string): boolean;
299
+ /**
300
+ * Phase 4 Sprint 11: Ensure embeddings table exists.
301
+ *
302
+ * Creates the embeddings table if it doesn't exist.
303
+ * Separate table from entities to avoid schema migration complexity.
304
+ */
305
+ private ensureEmbeddingsTable;
306
+ /**
307
+ * Phase 4 Sprint 11: Store an embedding for an entity.
308
+ *
309
+ * @param entityName - Name of the entity
310
+ * @param vector - Embedding vector
311
+ * @param model - Model name used for the embedding
312
+ */
313
+ storeEmbedding(entityName: string, vector: number[], model: string): void;
314
+ /**
315
+ * Phase 4 Sprint 11: Get an embedding for an entity.
316
+ *
317
+ * @param entityName - Name of the entity
318
+ * @returns Embedding vector if found, null otherwise
319
+ */
320
+ getEmbedding(entityName: string): number[] | null;
321
+ /**
322
+ * Phase 4 Sprint 11: Load all embeddings from storage.
323
+ *
324
+ * @returns Array of [entityName, vector] pairs
325
+ */
326
+ loadAllEmbeddings(): Promise<[string, number[]][]>;
327
+ /**
328
+ * Phase 4 Sprint 11: Remove an embedding for an entity.
329
+ *
330
+ * @param entityName - Name of the entity
331
+ */
332
+ removeEmbedding(entityName: string): void;
333
+ /**
334
+ * Phase 4 Sprint 11: Clear all embeddings from storage.
335
+ */
336
+ clearAllEmbeddings(): void;
337
+ /**
338
+ * Phase 4 Sprint 11: Check if an entity has an embedding.
339
+ *
340
+ * @param entityName - Name of the entity
341
+ * @returns True if embedding exists
342
+ */
343
+ hasEmbedding(entityName: string): boolean;
344
+ /**
345
+ * Phase 4 Sprint 11: Get embedding statistics.
346
+ *
347
+ * @returns Stats about stored embeddings
348
+ */
349
+ getEmbeddingStats(): {
350
+ count: number;
351
+ models: string[];
352
+ };
353
+ }
354
+ //# sourceMappingURL=SQLiteStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SQLiteStorage.d.ts","sourceRoot":"","sources":["../../src/core/SQLiteStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIhI;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAc,YAAW,aAAa;IAyDrC,OAAO,CAAC,UAAU;IAxD9B;;;;;OAKG;IACH,OAAO,CAAC,KAAK,CAAe;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,CAA6B;IAEvC;;OAEG;IACH,OAAO,CAAC,WAAW,CAAkB;IAErC;;;OAGG;IACH,OAAO,C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