@danielsimonjr/memoryjs 1.0.0 → 1.2.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 (300) hide show
  1. package/README.md +385 -113
  2. package/README.md.backup-1768084780988 +266 -0
  3. package/dist/index.cjs +24156 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +16967 -0
  6. package/dist/index.d.ts +16963 -11
  7. package/dist/index.js +23887 -19
  8. package/dist/index.js.map +1 -1
  9. package/dist/workers/levenshteinWorker.cjs +102 -0
  10. package/dist/workers/levenshteinWorker.cjs.map +1 -0
  11. package/dist/workers/levenshteinWorker.js +57 -91
  12. package/dist/workers/levenshteinWorker.js.map +1 -1
  13. package/package.json +75 -69
  14. package/dist/core/EntityManager.d.ts +0 -268
  15. package/dist/core/EntityManager.d.ts.map +0 -1
  16. package/dist/core/EntityManager.js +0 -512
  17. package/dist/core/EntityManager.js.map +0 -1
  18. package/dist/core/GraphEventEmitter.d.ts +0 -202
  19. package/dist/core/GraphEventEmitter.d.ts.map +0 -1
  20. package/dist/core/GraphEventEmitter.js +0 -347
  21. package/dist/core/GraphEventEmitter.js.map +0 -1
  22. package/dist/core/GraphStorage.d.ts +0 -395
  23. package/dist/core/GraphStorage.d.ts.map +0 -1
  24. package/dist/core/GraphStorage.js +0 -786
  25. package/dist/core/GraphStorage.js.map +0 -1
  26. package/dist/core/GraphTraversal.d.ts +0 -141
  27. package/dist/core/GraphTraversal.d.ts.map +0 -1
  28. package/dist/core/GraphTraversal.js +0 -574
  29. package/dist/core/GraphTraversal.js.map +0 -1
  30. package/dist/core/HierarchyManager.d.ts +0 -111
  31. package/dist/core/HierarchyManager.d.ts.map +0 -1
  32. package/dist/core/HierarchyManager.js +0 -225
  33. package/dist/core/HierarchyManager.js.map +0 -1
  34. package/dist/core/ManagerContext.d.ts +0 -76
  35. package/dist/core/ManagerContext.d.ts.map +0 -1
  36. package/dist/core/ManagerContext.js +0 -129
  37. package/dist/core/ManagerContext.js.map +0 -1
  38. package/dist/core/ObservationManager.d.ts +0 -85
  39. package/dist/core/ObservationManager.d.ts.map +0 -1
  40. package/dist/core/ObservationManager.js +0 -124
  41. package/dist/core/ObservationManager.js.map +0 -1
  42. package/dist/core/RelationManager.d.ts +0 -131
  43. package/dist/core/RelationManager.d.ts.map +0 -1
  44. package/dist/core/RelationManager.js +0 -212
  45. package/dist/core/RelationManager.js.map +0 -1
  46. package/dist/core/SQLiteStorage.d.ts +0 -354
  47. package/dist/core/SQLiteStorage.d.ts.map +0 -1
  48. package/dist/core/SQLiteStorage.js +0 -919
  49. package/dist/core/SQLiteStorage.js.map +0 -1
  50. package/dist/core/StorageFactory.d.ts +0 -45
  51. package/dist/core/StorageFactory.d.ts.map +0 -1
  52. package/dist/core/StorageFactory.js +0 -65
  53. package/dist/core/StorageFactory.js.map +0 -1
  54. package/dist/core/TransactionManager.d.ts +0 -464
  55. package/dist/core/TransactionManager.d.ts.map +0 -1
  56. package/dist/core/TransactionManager.js +0 -869
  57. package/dist/core/TransactionManager.js.map +0 -1
  58. package/dist/core/index.d.ts +0 -17
  59. package/dist/core/index.d.ts.map +0 -1
  60. package/dist/core/index.js +0 -20
  61. package/dist/core/index.js.map +0 -1
  62. package/dist/features/AnalyticsManager.d.ts +0 -44
  63. package/dist/features/AnalyticsManager.d.ts.map +0 -1
  64. package/dist/features/AnalyticsManager.js +0 -224
  65. package/dist/features/AnalyticsManager.js.map +0 -1
  66. package/dist/features/ArchiveManager.d.ts +0 -133
  67. package/dist/features/ArchiveManager.d.ts.map +0 -1
  68. package/dist/features/ArchiveManager.js +0 -282
  69. package/dist/features/ArchiveManager.js.map +0 -1
  70. package/dist/features/CompressionManager.d.ts +0 -119
  71. package/dist/features/CompressionManager.d.ts.map +0 -1
  72. package/dist/features/CompressionManager.js +0 -470
  73. package/dist/features/CompressionManager.js.map +0 -1
  74. package/dist/features/IOManager.d.ts +0 -225
  75. package/dist/features/IOManager.d.ts.map +0 -1
  76. package/dist/features/IOManager.js +0 -1093
  77. package/dist/features/IOManager.js.map +0 -1
  78. package/dist/features/KeywordExtractor.d.ts +0 -61
  79. package/dist/features/KeywordExtractor.d.ts.map +0 -1
  80. package/dist/features/KeywordExtractor.js +0 -127
  81. package/dist/features/KeywordExtractor.js.map +0 -1
  82. package/dist/features/ObservationNormalizer.d.ts +0 -90
  83. package/dist/features/ObservationNormalizer.d.ts.map +0 -1
  84. package/dist/features/ObservationNormalizer.js +0 -194
  85. package/dist/features/ObservationNormalizer.js.map +0 -1
  86. package/dist/features/StreamingExporter.d.ts +0 -128
  87. package/dist/features/StreamingExporter.d.ts.map +0 -1
  88. package/dist/features/StreamingExporter.js +0 -212
  89. package/dist/features/StreamingExporter.js.map +0 -1
  90. package/dist/features/TagManager.d.ts +0 -147
  91. package/dist/features/TagManager.d.ts.map +0 -1
  92. package/dist/features/TagManager.js +0 -211
  93. package/dist/features/TagManager.js.map +0 -1
  94. package/dist/features/index.d.ts +0 -14
  95. package/dist/features/index.d.ts.map +0 -1
  96. package/dist/features/index.js +0 -15
  97. package/dist/features/index.js.map +0 -1
  98. package/dist/index.d.ts.map +0 -1
  99. package/dist/search/BM25Search.d.ts +0 -148
  100. package/dist/search/BM25Search.d.ts.map +0 -1
  101. package/dist/search/BM25Search.js +0 -340
  102. package/dist/search/BM25Search.js.map +0 -1
  103. package/dist/search/BasicSearch.d.ts +0 -51
  104. package/dist/search/BasicSearch.d.ts.map +0 -1
  105. package/dist/search/BasicSearch.js +0 -138
  106. package/dist/search/BasicSearch.js.map +0 -1
  107. package/dist/search/BooleanSearch.d.ts +0 -98
  108. package/dist/search/BooleanSearch.d.ts.map +0 -1
  109. package/dist/search/BooleanSearch.js +0 -431
  110. package/dist/search/BooleanSearch.js.map +0 -1
  111. package/dist/search/EarlyTerminationManager.d.ts +0 -140
  112. package/dist/search/EarlyTerminationManager.d.ts.map +0 -1
  113. package/dist/search/EarlyTerminationManager.js +0 -280
  114. package/dist/search/EarlyTerminationManager.js.map +0 -1
  115. package/dist/search/EmbeddingCache.d.ts +0 -175
  116. package/dist/search/EmbeddingCache.d.ts.map +0 -1
  117. package/dist/search/EmbeddingCache.js +0 -247
  118. package/dist/search/EmbeddingCache.js.map +0 -1
  119. package/dist/search/EmbeddingService.d.ts +0 -277
  120. package/dist/search/EmbeddingService.d.ts.map +0 -1
  121. package/dist/search/EmbeddingService.js +0 -531
  122. package/dist/search/EmbeddingService.js.map +0 -1
  123. package/dist/search/FuzzySearch.d.ts +0 -118
  124. package/dist/search/FuzzySearch.d.ts.map +0 -1
  125. package/dist/search/FuzzySearch.js +0 -313
  126. package/dist/search/FuzzySearch.js.map +0 -1
  127. package/dist/search/HybridScorer.d.ts +0 -181
  128. package/dist/search/HybridScorer.d.ts.map +0 -1
  129. package/dist/search/HybridScorer.js +0 -258
  130. package/dist/search/HybridScorer.js.map +0 -1
  131. package/dist/search/HybridSearchManager.d.ts +0 -80
  132. package/dist/search/HybridSearchManager.d.ts.map +0 -1
  133. package/dist/search/HybridSearchManager.js +0 -188
  134. package/dist/search/HybridSearchManager.js.map +0 -1
  135. package/dist/search/IncrementalIndexer.d.ts +0 -201
  136. package/dist/search/IncrementalIndexer.d.ts.map +0 -1
  137. package/dist/search/IncrementalIndexer.js +0 -343
  138. package/dist/search/IncrementalIndexer.js.map +0 -1
  139. package/dist/search/OptimizedInvertedIndex.d.ts +0 -163
  140. package/dist/search/OptimizedInvertedIndex.d.ts.map +0 -1
  141. package/dist/search/OptimizedInvertedIndex.js +0 -359
  142. package/dist/search/OptimizedInvertedIndex.js.map +0 -1
  143. package/dist/search/ParallelSearchExecutor.d.ts +0 -172
  144. package/dist/search/ParallelSearchExecutor.d.ts.map +0 -1
  145. package/dist/search/ParallelSearchExecutor.js +0 -310
  146. package/dist/search/ParallelSearchExecutor.js.map +0 -1
  147. package/dist/search/QuantizedVectorStore.d.ts +0 -171
  148. package/dist/search/QuantizedVectorStore.d.ts.map +0 -1
  149. package/dist/search/QuantizedVectorStore.js +0 -308
  150. package/dist/search/QuantizedVectorStore.js.map +0 -1
  151. package/dist/search/QueryAnalyzer.d.ts +0 -76
  152. package/dist/search/QueryAnalyzer.d.ts.map +0 -1
  153. package/dist/search/QueryAnalyzer.js +0 -228
  154. package/dist/search/QueryAnalyzer.js.map +0 -1
  155. package/dist/search/QueryCostEstimator.d.ts +0 -244
  156. package/dist/search/QueryCostEstimator.d.ts.map +0 -1
  157. package/dist/search/QueryCostEstimator.js +0 -653
  158. package/dist/search/QueryCostEstimator.js.map +0 -1
  159. package/dist/search/QueryPlanCache.d.ts +0 -220
  160. package/dist/search/QueryPlanCache.d.ts.map +0 -1
  161. package/dist/search/QueryPlanCache.js +0 -380
  162. package/dist/search/QueryPlanCache.js.map +0 -1
  163. package/dist/search/QueryPlanner.d.ts +0 -58
  164. package/dist/search/QueryPlanner.d.ts.map +0 -1
  165. package/dist/search/QueryPlanner.js +0 -138
  166. package/dist/search/QueryPlanner.js.map +0 -1
  167. package/dist/search/RankedSearch.d.ts +0 -71
  168. package/dist/search/RankedSearch.d.ts.map +0 -1
  169. package/dist/search/RankedSearch.js +0 -239
  170. package/dist/search/RankedSearch.js.map +0 -1
  171. package/dist/search/ReflectionManager.d.ts +0 -120
  172. package/dist/search/ReflectionManager.d.ts.map +0 -1
  173. package/dist/search/ReflectionManager.js +0 -232
  174. package/dist/search/ReflectionManager.js.map +0 -1
  175. package/dist/search/SavedSearchManager.d.ts +0 -79
  176. package/dist/search/SavedSearchManager.d.ts.map +0 -1
  177. package/dist/search/SavedSearchManager.js +0 -147
  178. package/dist/search/SavedSearchManager.js.map +0 -1
  179. package/dist/search/SearchFilterChain.d.ts +0 -120
  180. package/dist/search/SearchFilterChain.d.ts.map +0 -1
  181. package/dist/search/SearchFilterChain.js +0 -186
  182. package/dist/search/SearchFilterChain.js.map +0 -1
  183. package/dist/search/SearchManager.d.ts +0 -326
  184. package/dist/search/SearchManager.d.ts.map +0 -1
  185. package/dist/search/SearchManager.js +0 -454
  186. package/dist/search/SearchManager.js.map +0 -1
  187. package/dist/search/SearchSuggestions.d.ts +0 -27
  188. package/dist/search/SearchSuggestions.d.ts.map +0 -1
  189. package/dist/search/SearchSuggestions.js +0 -58
  190. package/dist/search/SearchSuggestions.js.map +0 -1
  191. package/dist/search/SemanticSearch.d.ts +0 -149
  192. package/dist/search/SemanticSearch.d.ts.map +0 -1
  193. package/dist/search/SemanticSearch.js +0 -324
  194. package/dist/search/SemanticSearch.js.map +0 -1
  195. package/dist/search/SymbolicSearch.d.ts +0 -61
  196. package/dist/search/SymbolicSearch.d.ts.map +0 -1
  197. package/dist/search/SymbolicSearch.js +0 -164
  198. package/dist/search/SymbolicSearch.js.map +0 -1
  199. package/dist/search/TFIDFEventSync.d.ts +0 -85
  200. package/dist/search/TFIDFEventSync.d.ts.map +0 -1
  201. package/dist/search/TFIDFEventSync.js +0 -134
  202. package/dist/search/TFIDFEventSync.js.map +0 -1
  203. package/dist/search/TFIDFIndexManager.d.ts +0 -151
  204. package/dist/search/TFIDFIndexManager.d.ts.map +0 -1
  205. package/dist/search/TFIDFIndexManager.js +0 -433
  206. package/dist/search/TFIDFIndexManager.js.map +0 -1
  207. package/dist/search/VectorStore.d.ts +0 -235
  208. package/dist/search/VectorStore.d.ts.map +0 -1
  209. package/dist/search/VectorStore.js +0 -312
  210. package/dist/search/VectorStore.js.map +0 -1
  211. package/dist/search/index.d.ts +0 -35
  212. package/dist/search/index.d.ts.map +0 -1
  213. package/dist/search/index.js +0 -53
  214. package/dist/search/index.js.map +0 -1
  215. package/dist/types/index.d.ts +0 -13
  216. package/dist/types/index.d.ts.map +0 -1
  217. package/dist/types/index.js +0 -13
  218. package/dist/types/index.js.map +0 -1
  219. package/dist/types/types.d.ts +0 -1811
  220. package/dist/types/types.d.ts.map +0 -1
  221. package/dist/types/types.js +0 -10
  222. package/dist/types/types.js.map +0 -1
  223. package/dist/utils/BatchProcessor.d.ts +0 -271
  224. package/dist/utils/BatchProcessor.d.ts.map +0 -1
  225. package/dist/utils/BatchProcessor.js +0 -377
  226. package/dist/utils/BatchProcessor.js.map +0 -1
  227. package/dist/utils/MemoryMonitor.d.ts +0 -176
  228. package/dist/utils/MemoryMonitor.d.ts.map +0 -1
  229. package/dist/utils/MemoryMonitor.js +0 -306
  230. package/dist/utils/MemoryMonitor.js.map +0 -1
  231. package/dist/utils/WorkerPoolManager.d.ts +0 -233
  232. package/dist/utils/WorkerPoolManager.d.ts.map +0 -1
  233. package/dist/utils/WorkerPoolManager.js +0 -421
  234. package/dist/utils/WorkerPoolManager.js.map +0 -1
  235. package/dist/utils/compressedCache.d.ts +0 -221
  236. package/dist/utils/compressedCache.d.ts.map +0 -1
  237. package/dist/utils/compressedCache.js +0 -349
  238. package/dist/utils/compressedCache.js.map +0 -1
  239. package/dist/utils/compressionUtil.d.ts +0 -214
  240. package/dist/utils/compressionUtil.d.ts.map +0 -1
  241. package/dist/utils/compressionUtil.js +0 -248
  242. package/dist/utils/compressionUtil.js.map +0 -1
  243. package/dist/utils/constants.d.ts +0 -245
  244. package/dist/utils/constants.d.ts.map +0 -1
  245. package/dist/utils/constants.js +0 -253
  246. package/dist/utils/constants.js.map +0 -1
  247. package/dist/utils/entityUtils.d.ts +0 -379
  248. package/dist/utils/entityUtils.d.ts.map +0 -1
  249. package/dist/utils/entityUtils.js +0 -649
  250. package/dist/utils/entityUtils.js.map +0 -1
  251. package/dist/utils/errors.d.ts +0 -95
  252. package/dist/utils/errors.d.ts.map +0 -1
  253. package/dist/utils/errors.js +0 -146
  254. package/dist/utils/errors.js.map +0 -1
  255. package/dist/utils/formatters.d.ts +0 -145
  256. package/dist/utils/formatters.d.ts.map +0 -1
  257. package/dist/utils/formatters.js +0 -133
  258. package/dist/utils/formatters.js.map +0 -1
  259. package/dist/utils/index.d.ts +0 -26
  260. package/dist/utils/index.d.ts.map +0 -1
  261. package/dist/utils/index.js +0 -88
  262. package/dist/utils/index.js.map +0 -1
  263. package/dist/utils/indexes.d.ts +0 -270
  264. package/dist/utils/indexes.d.ts.map +0 -1
  265. package/dist/utils/indexes.js +0 -527
  266. package/dist/utils/indexes.js.map +0 -1
  267. package/dist/utils/logger.d.ts +0 -31
  268. package/dist/utils/logger.d.ts.map +0 -1
  269. package/dist/utils/logger.js +0 -41
  270. package/dist/utils/logger.js.map +0 -1
  271. package/dist/utils/operationUtils.d.ts +0 -124
  272. package/dist/utils/operationUtils.d.ts.map +0 -1
  273. package/dist/utils/operationUtils.js +0 -176
  274. package/dist/utils/operationUtils.js.map +0 -1
  275. package/dist/utils/parallelUtils.d.ts +0 -76
  276. package/dist/utils/parallelUtils.d.ts.map +0 -1
  277. package/dist/utils/parallelUtils.js +0 -192
  278. package/dist/utils/parallelUtils.js.map +0 -1
  279. package/dist/utils/schemas.d.ts +0 -556
  280. package/dist/utils/schemas.d.ts.map +0 -1
  281. package/dist/utils/schemas.js +0 -485
  282. package/dist/utils/schemas.js.map +0 -1
  283. package/dist/utils/searchAlgorithms.d.ts +0 -99
  284. package/dist/utils/searchAlgorithms.d.ts.map +0 -1
  285. package/dist/utils/searchAlgorithms.js +0 -168
  286. package/dist/utils/searchAlgorithms.js.map +0 -1
  287. package/dist/utils/searchCache.d.ts +0 -108
  288. package/dist/utils/searchCache.d.ts.map +0 -1
  289. package/dist/utils/searchCache.js +0 -210
  290. package/dist/utils/searchCache.js.map +0 -1
  291. package/dist/utils/taskScheduler.d.ts +0 -294
  292. package/dist/utils/taskScheduler.d.ts.map +0 -1
  293. package/dist/utils/taskScheduler.js +0 -487
  294. package/dist/utils/taskScheduler.js.map +0 -1
  295. package/dist/workers/index.d.ts +0 -12
  296. package/dist/workers/index.d.ts.map +0 -1
  297. package/dist/workers/index.js +0 -10
  298. package/dist/workers/index.js.map +0 -1
  299. package/dist/workers/levenshteinWorker.d.ts +0 -60
  300. package/dist/workers/levenshteinWorker.d.ts.map +0 -1
@@ -1,395 +0,0 @@
1
- /**
2
- * Graph Storage
3
- *
4
- * Handles file I/O operations for the knowledge graph using JSONL format.
5
- * Implements IGraphStorage interface for storage abstraction.
6
- *
7
- * @module core/GraphStorage
8
- */
9
- import type { KnowledgeGraph, Entity, Relation, ReadonlyKnowledgeGraph, IGraphStorage, LowercaseData } from '../types/index.js';
10
- import { BatchTransaction } from './TransactionManager.js';
11
- import { GraphEventEmitter } from './GraphEventEmitter.js';
12
- /**
13
- * GraphStorage manages persistence of the knowledge graph to disk.
14
- *
15
- * Uses JSONL (JSON Lines) format where each line is a separate JSON object
16
- * representing either an entity or a relation.
17
- *
18
- * OPTIMIZED: Implements in-memory caching to avoid repeated disk reads.
19
- * Cache is invalidated on every write operation to ensure consistency.
20
- *
21
- * @example
22
- * ```typescript
23
- * const storage = new GraphStorage('/path/to/memory.jsonl');
24
- * const graph = await storage.loadGraph();
25
- * graph.entities.push(newEntity);
26
- * await storage.saveGraph(graph);
27
- * ```
28
- */
29
- export declare class GraphStorage implements IGraphStorage {
30
- private memoryFilePath;
31
- /**
32
- * Mutex for thread-safe access to storage operations.
33
- * Prevents concurrent writes from corrupting the file or cache.
34
- */
35
- private mutex;
36
- /**
37
- * In-memory cache of the knowledge graph.
38
- * Null when cache is empty or invalidated.
39
- */
40
- private cache;
41
- /**
42
- * Number of pending append operations since last compaction.
43
- * Used to trigger automatic compaction when threshold is reached.
44
- */
45
- private pendingAppends;
46
- /**
47
- * Dynamic threshold for automatic compaction.
48
- *
49
- * Returns the larger of 100 or 10% of the current entity count.
50
- * This scales with graph size to avoid too-frequent compaction on large graphs
51
- * while maintaining a reasonable minimum for small graphs.
52
- *
53
- * @returns Compaction threshold value
54
- */
55
- private get compactionThreshold();
56
- /**
57
- * O(1) entity lookup by name.
58
- */
59
- private nameIndex;
60
- /**
61
- * O(1) entity lookup by type.
62
- */
63
- private typeIndex;
64
- /**
65
- * Pre-computed lowercase strings for search optimization.
66
- */
67
- private lowercaseCache;
68
- /**
69
- * O(1) relation lookup by entity name.
70
- */
71
- private relationIndex;
72
- /**
73
- * O(1) observation word lookup by entity.
74
- * Maps words in observations to entity names.
75
- */
76
- private observationIndex;
77
- /**
78
- * Phase 10 Sprint 2: Event emitter for graph change notifications.
79
- * Allows external systems to subscribe to graph changes.
80
- */
81
- private eventEmitter;
82
- /**
83
- * Create a new GraphStorage instance.
84
- *
85
- * @param memoryFilePath - Absolute path to the JSONL file
86
- */
87
- constructor(memoryFilePath: string);
88
- /**
89
- * Get the event emitter for subscribing to graph changes.
90
- *
91
- * @returns GraphEventEmitter instance
92
- *
93
- * @example
94
- * ```typescript
95
- * const storage = new GraphStorage('/data/memory.jsonl');
96
- *
97
- * // Subscribe to entity creation events
98
- * storage.events.on('entity:created', (event) => {
99
- * console.log(`Entity ${event.entity.name} created`);
100
- * });
101
- *
102
- * // Subscribe to all events
103
- * storage.events.onAny((event) => {
104
- * console.log(`Graph event: ${event.type}`);
105
- * });
106
- * ```
107
- */
108
- get events(): GraphEventEmitter;
109
- /**
110
- * Write content to file with fsync for durability.
111
- *
112
- * @param content - Content to write
113
- */
114
- private durableWriteFile;
115
- /**
116
- * Append content to file with fsync for durability.
117
- *
118
- * @param content - Content to append
119
- * @param prependNewline - Whether to prepend a newline
120
- */
121
- private durableAppendFile;
122
- /**
123
- * Load the knowledge graph from disk (read-only access).
124
- *
125
- * OPTIMIZED: Returns cached reference directly without copying.
126
- * This is O(1) regardless of graph size. For mutation operations,
127
- * use getGraphForMutation() instead.
128
- *
129
- * @returns Promise resolving to read-only knowledge graph reference
130
- * @throws Error if file exists but cannot be read or parsed
131
- */
132
- loadGraph(): Promise<ReadonlyKnowledgeGraph>;
133
- /**
134
- * Get a mutable copy of the graph for write operations.
135
- *
136
- * Creates deep copies of entity and relation arrays to allow
137
- * safe mutation without affecting the cached data.
138
- *
139
- * @returns Promise resolving to mutable knowledge graph copy
140
- */
141
- getGraphForMutation(): Promise<KnowledgeGraph>;
142
- /**
143
- * Ensure the cache is loaded from disk.
144
- *
145
- * @returns Promise resolving when cache is populated
146
- */
147
- ensureLoaded(): Promise<void>;
148
- /**
149
- * Internal method to load graph from disk into cache.
150
- */
151
- private loadFromDisk;
152
- /**
153
- * Build all entity indexes from entity array.
154
- */
155
- private buildEntityIndexes;
156
- /**
157
- * Build relation index from relation array.
158
- */
159
- private buildRelationIndex;
160
- /**
161
- * Clear all indexes.
162
- */
163
- private clearIndexes;
164
- /**
165
- * Save the knowledge graph to disk.
166
- *
167
- * OPTIMIZED: Updates cache directly after write to avoid re-reading.
168
- * THREAD-SAFE: Uses mutex to prevent concurrent write operations.
169
- *
170
- * Writes the graph to JSONL format, with one JSON object per line.
171
- *
172
- * @param graph - The knowledge graph to save
173
- * @returns Promise resolving when save is complete
174
- * @throws Error if file cannot be written
175
- */
176
- saveGraph(graph: KnowledgeGraph): Promise<void>;
177
- /**
178
- * Append a single entity to the file (O(1) write operation).
179
- *
180
- * OPTIMIZED: Uses file append instead of full rewrite.
181
- * THREAD-SAFE: Uses mutex to prevent concurrent write operations.
182
- * Updates cache in-place and triggers compaction when threshold is reached.
183
- *
184
- * @param entity - The entity to append
185
- * @returns Promise resolving when append is complete
186
- */
187
- appendEntity(entity: Entity): Promise<void>;
188
- /**
189
- * Append a single relation to the file (O(1) write operation).
190
- *
191
- * OPTIMIZED: Uses file append instead of full rewrite.
192
- * THREAD-SAFE: Uses mutex to prevent concurrent write operations.
193
- * Updates cache in-place and triggers compaction when threshold is reached.
194
- *
195
- * @param relation - The relation to append
196
- * @returns Promise resolving when append is complete
197
- */
198
- appendRelation(relation: Relation): Promise<void>;
199
- /**
200
- * Compact the file by rewriting it with only current cache contents.
201
- *
202
- * THREAD-SAFE: Uses mutex to prevent concurrent operations.
203
- * Removes duplicate entries and cleans up the file.
204
- * Resets pending appends counter.
205
- *
206
- * @returns Promise resolving when compaction is complete
207
- */
208
- compact(): Promise<void>;
209
- /**
210
- * Internal compact implementation (must be called within mutex).
211
- *
212
- * @returns Promise resolving when compaction is complete
213
- */
214
- private compactInternal;
215
- /**
216
- * Internal saveGraph implementation (must be called within mutex).
217
- *
218
- * @param graph - The knowledge graph to save
219
- * @returns Promise resolving when save is complete
220
- */
221
- private saveGraphInternal;
222
- /**
223
- * Get the current pending appends count.
224
- *
225
- * Useful for testing compaction behavior.
226
- *
227
- * @returns Number of pending appends since last compaction
228
- */
229
- getPendingAppends(): number;
230
- /**
231
- * Update an entity in-place in the cache and append to file.
232
- *
233
- * OPTIMIZED: Modifies cache directly and appends updated version to file.
234
- * THREAD-SAFE: Uses mutex to prevent concurrent write operations.
235
- * Does not rewrite the entire file - compaction handles deduplication later.
236
- *
237
- * @param entityName - Name of the entity to update
238
- * @param updates - Partial entity updates to apply
239
- * @returns Promise resolving to true if entity was found and updated, false otherwise
240
- */
241
- updateEntity(entityName: string, updates: Partial<Entity>): Promise<boolean>;
242
- /**
243
- * Manually clear the cache.
244
- *
245
- * Useful for testing or when external processes modify the file.
246
- *
247
- * @returns void
248
- */
249
- clearCache(): void;
250
- /**
251
- * Get the file path being used for storage.
252
- *
253
- * @returns The memory file path
254
- */
255
- getFilePath(): string;
256
- /**
257
- * Get an entity by name in O(1) time.
258
- *
259
- * OPTIMIZED: Uses NameIndex for constant-time lookup.
260
- *
261
- * @param name - Entity name to look up
262
- * @returns Entity if found, undefined otherwise
263
- */
264
- getEntityByName(name: string): Entity | undefined;
265
- /**
266
- * Check if an entity exists by name in O(1) time.
267
- *
268
- * @param name - Entity name to check
269
- * @returns True if entity exists
270
- */
271
- hasEntity(name: string): boolean;
272
- /**
273
- * Get all entities of a given type in O(1) time.
274
- *
275
- * OPTIMIZED: Uses TypeIndex for constant-time lookup of entity names,
276
- * then uses NameIndex for O(1) entity retrieval.
277
- *
278
- * @param entityType - Entity type to filter by (case-insensitive)
279
- * @returns Array of entities with the given type
280
- */
281
- getEntitiesByType(entityType: string): Entity[];
282
- /**
283
- * Get pre-computed lowercase data for an entity.
284
- *
285
- * OPTIMIZED: Avoids repeated toLowerCase() calls during search.
286
- *
287
- * @param entityName - Entity name to get lowercase data for
288
- * @returns LowercaseData if entity exists, undefined otherwise
289
- */
290
- getLowercased(entityName: string): LowercaseData | undefined;
291
- /**
292
- * Get all unique entity types in the graph.
293
- *
294
- * @returns Array of unique entity types (lowercase)
295
- */
296
- getEntityTypes(): string[];
297
- /**
298
- * Get all relations where the entity is the source (outgoing relations) in O(1) time.
299
- *
300
- * OPTIMIZED: Uses RelationIndex for constant-time lookup.
301
- *
302
- * @param entityName - Entity name to look up outgoing relations for
303
- * @returns Array of relations where entity is the source
304
- */
305
- getRelationsFrom(entityName: string): Relation[];
306
- /**
307
- * Get all relations where the entity is the target (incoming relations) in O(1) time.
308
- *
309
- * OPTIMIZED: Uses RelationIndex for constant-time lookup.
310
- *
311
- * @param entityName - Entity name to look up incoming relations for
312
- * @returns Array of relations where entity is the target
313
- */
314
- getRelationsTo(entityName: string): Relation[];
315
- /**
316
- * Get all relations involving the entity (both incoming and outgoing) in O(1) time.
317
- *
318
- * OPTIMIZED: Uses RelationIndex for constant-time lookup.
319
- *
320
- * @param entityName - Entity name to look up all relations for
321
- * @returns Array of all relations involving the entity
322
- */
323
- getRelationsFor(entityName: string): Relation[];
324
- /**
325
- * Check if an entity has any relations.
326
- *
327
- * @param entityName - Entity name to check
328
- * @returns True if entity has any relations
329
- */
330
- hasRelations(entityName: string): boolean;
331
- /**
332
- * Get entities that have observations containing the given word.
333
- * Uses the observation index for O(1) lookup.
334
- *
335
- * OPTIMIZED: Uses ObservationIndex for constant-time lookup instead of
336
- * linear scan through all entities and their observations.
337
- *
338
- * @param word - Word to search for in observations
339
- * @returns Set of entity names
340
- */
341
- getEntitiesByObservationWord(word: string): Set<string>;
342
- /**
343
- * Get entities that have observations containing ANY of the given words (union).
344
- * Uses the observation index for O(1) lookup per word.
345
- *
346
- * OPTIMIZED: Uses ObservationIndex for constant-time lookups.
347
- *
348
- * @param words - Array of words to search for
349
- * @returns Set of entity names containing any of the words
350
- */
351
- getEntitiesByAnyObservationWord(words: string[]): Set<string>;
352
- /**
353
- * Get entities that have observations containing ALL of the given words (intersection).
354
- * Uses the observation index for O(1) lookup per word.
355
- *
356
- * OPTIMIZED: Uses ObservationIndex for constant-time lookups and set intersection.
357
- *
358
- * @param words - Array of words that must all be present
359
- * @returns Set of entity names containing all of the words
360
- */
361
- getEntitiesByAllObservationWords(words: string[]): Set<string>;
362
- /**
363
- * Get statistics about the observation index.
364
- *
365
- * @returns Object with wordCount and entityCount
366
- */
367
- getObservationIndexStats(): {
368
- wordCount: number;
369
- entityCount: number;
370
- };
371
- /**
372
- * Create a new batch transaction for atomic operations.
373
- *
374
- * Returns a BatchTransaction instance that can be used to queue multiple
375
- * operations and execute them atomically with a single save operation.
376
- *
377
- * @returns A new BatchTransaction instance
378
- *
379
- * @example
380
- * ```typescript
381
- * const storage = new GraphStorage('/data/memory.jsonl');
382
- *
383
- * // Create and execute a batch transaction
384
- * const result = await storage.transaction()
385
- * .createEntity({ name: 'Alice', entityType: 'person', observations: ['Developer'] })
386
- * .createEntity({ name: 'Bob', entityType: 'person', observations: ['Designer'] })
387
- * .createRelation({ from: 'Alice', to: 'Bob', relationType: 'knows' })
388
- * .execute();
389
- *
390
- * console.log(`Batch completed: ${result.operationsExecuted} operations`);
391
- * ```
392
- */
393
- transaction(): BatchTransaction;
394
- }
395
- //# sourceMappingURL=GraphStorage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GraphStorage.d.ts","sourceRoot":"","sources":["../../src/core/GraphStorage.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,QAAQ,EAAE,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIhI,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,YAAa,YAAW,aAAa;IAqEpC,OAAO,CAAC,cAAc;IApElC;;;OAGG;IACH,OAAO,CAAC,KA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