@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
package/README.md CHANGED
@@ -1,17 +1,63 @@
1
- # @danielsimonjr/memoryjs
1
+ # MemoryJS
2
2
 
3
- Core knowledge graph library for managing entities, relations, and observations with advanced search capabilities.
3
+ [![Version](https://img.shields.io/badge/version-1.0.0-blue.svg)](https://github.com/danielsimonjr/memoryjs)
4
+ [![NPM](https://img.shields.io/npm/v/@danielsimonjr/memoryjs.svg)](https://www.npmjs.com/package/@danielsimonjr/memoryjs)
5
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
7
+
8
+ A **TypeScript knowledge graph library** for managing entities, relations, and observations with **advanced search capabilities**, **hierarchical organization**, and **multiple storage backends**.
9
+
10
+ > **Core library** powering [@danielsimonjr/memory-mcp](https://www.npmjs.com/package/@danielsimonjr/memory-mcp). Provides 73 TypeScript files, ~29K lines of code, dual storage backends (JSONL/SQLite), and sophisticated search algorithms including BM25, TF-IDF, fuzzy, semantic, and hybrid search.
11
+
12
+ ## Table of Contents
13
+
14
+ - [Features](#features)
15
+ - [Installation](#installation)
16
+ - [Quick Start](#quick-start)
17
+ - [Core Concepts](#core-concepts)
18
+ - [Storage Options](#storage-options)
19
+ - [Search Capabilities](#search-capabilities)
20
+ - [Graph Algorithms](#graph-algorithms)
21
+ - [API Reference](#api-reference)
22
+ - [Configuration](#configuration)
23
+ - [Development](#development)
24
+ - [Documentation](#documentation)
25
+ - [License](#license)
4
26
 
5
27
  ## Features
6
28
 
7
- - **Entity Management**: Create, read, update, delete entities with observations
8
- - **Relation Management**: Connect entities with typed relationships
9
- - **Hierarchical Organization**: Parent-child entity nesting
10
- - **Multiple Storage Backends**: JSONL (default) or SQLite
11
- - **Advanced Search**: Basic, ranked (TF-IDF), boolean, fuzzy, semantic, and hybrid search
12
- - **Tag Management**: Tag aliasing, bulk operations
13
- - **Graph Algorithms**: Shortest path, centrality, connected components
14
- - **Import/Export**: JSON, CSV, GraphML formats with compression
29
+ ### Core Capabilities
30
+
31
+ - **Knowledge Graph Storage**: Entity-Relation-Observation model for structured data
32
+ - **Dual Storage Backends**: JSONL (human-readable) or SQLite (FTS5, 3-10x faster)
33
+ - **Full CRUD Operations**: Create, read, update, delete entities and relations
34
+ - **Hierarchical Nesting**: Parent-child relationships for tree structures
35
+ - **Timestamps**: Automatic createdAt and lastModified tracking
36
+
37
+ ### Advanced Features
38
+
39
+ | Category | Description |
40
+ |----------|-------------|
41
+ | **Search Algorithms** | Basic, TF-IDF ranked, BM25, Boolean (AND/OR/NOT), Fuzzy (Levenshtein), Semantic (embeddings), Hybrid |
42
+ | **Graph Algorithms** | Shortest path (BFS), all paths, centrality metrics (degree, betweenness, PageRank), connected components |
43
+ | **Hierarchical Nesting** | Parent-child relationships, ancestor/descendant traversal, subtree operations |
44
+ | **Duplicate Detection** | Intelligent compression with similarity scoring |
45
+ | **Tag Management** | Tags, aliases, bulk operations, importance scores (0-10) |
46
+ | **Import/Export** | JSON, CSV, GraphML formats with Brotli compression |
47
+ | **Analytics** | Graph statistics, validation, integrity checks |
48
+
49
+ ### Module Statistics
50
+
51
+ | Module | Files | Key Components |
52
+ |--------|-------|----------------|
53
+ | `core/` | 12 | EntityManager, GraphStorage, SQLiteStorage, TransactionManager |
54
+ | `search/` | 29 | SearchManager, BM25Search, HybridScorer, VectorStore, QueryPlanner |
55
+ | `features/` | 9 | IOManager, ArchiveManager, CompressionManager, StreamingExporter |
56
+ | `utils/` | 18 | BatchProcessor, CompressedCache, WorkerPoolManager, MemoryMonitor |
57
+ | `types/` | 2 | Entity, Relation, KnowledgeGraph interfaces |
58
+ | `workers/` | 2 | Levenshtein distance calculations |
59
+
60
+ **Total:** 73 TypeScript files | ~29,000 lines of code | 558 exports
15
61
 
16
62
  ## Installation
17
63
 
@@ -19,198 +65,292 @@ Core knowledge graph library for managing entities, relations, and observations
19
65
  npm install @danielsimonjr/memoryjs
20
66
  ```
21
67
 
68
+ ### Requirements
69
+
70
+ - Node.js >= 18.0.0
71
+ - TypeScript >= 5.0 (for development)
72
+
22
73
  ## Quick Start
23
74
 
75
+ ### 1. Initialize Storage
76
+
24
77
  ```typescript
25
78
  import { ManagerContext } from '@danielsimonjr/memoryjs';
26
79
 
27
- // Initialize with JSONL storage (default)
80
+ // JSONL storage (default, human-readable)
28
81
  const ctx = new ManagerContext({
29
82
  storagePath: './memory.jsonl'
30
83
  });
31
84
 
32
- // Create entities
85
+ // Or SQLite storage (faster, FTS5 search)
86
+ const ctx = new ManagerContext({
87
+ storageType: 'sqlite',
88
+ storagePath: './memory.db'
89
+ });
90
+ ```
91
+
92
+ ### 2. Create Entities
93
+
94
+ ```typescript
33
95
  await ctx.entityManager.createEntities([
34
- { name: 'TypeScript', entityType: 'language', observations: ['A typed superset of JavaScript'] },
35
- { name: 'Node.js', entityType: 'runtime', observations: ['JavaScript runtime built on V8'] }
96
+ {
97
+ name: 'TypeScript',
98
+ entityType: 'language',
99
+ observations: ['A typed superset of JavaScript'],
100
+ tags: ['programming', 'frontend'],
101
+ importance: 8
102
+ },
103
+ {
104
+ name: 'Node.js',
105
+ entityType: 'runtime',
106
+ observations: ['JavaScript runtime built on V8'],
107
+ tags: ['backend', 'server']
108
+ }
36
109
  ]);
110
+ ```
37
111
 
38
- // Create relations
112
+ ### 3. Create Relations
113
+
114
+ ```typescript
39
115
  await ctx.relationManager.createRelations([
40
116
  { from: 'TypeScript', to: 'Node.js', relationType: 'runs_on' }
41
117
  ]);
118
+ ```
119
+
120
+ ### 4. Search
42
121
 
43
- // Search entities
122
+ ```typescript
123
+ // Basic search
44
124
  const results = await ctx.searchManager.search('JavaScript');
125
+
126
+ // Ranked search (TF-IDF scoring)
127
+ const ranked = await ctx.searchManager.searchRanked('runtime environment', { limit: 10 });
128
+
129
+ // Boolean search
130
+ const filtered = await ctx.searchManager.booleanSearch('TypeScript AND runtime');
131
+
132
+ // Fuzzy search (typo-tolerant)
133
+ const fuzzy = await ctx.searchManager.fuzzySearch('Typscript', { threshold: 0.7 });
45
134
  ```
46
135
 
47
- ## Storage Options
136
+ ## Core Concepts
137
+
138
+ ### Entities
48
139
 
49
- ### JSONL (Default)
140
+ Primary nodes in the knowledge graph.
50
141
 
51
142
  ```typescript
52
- const ctx = new ManagerContext({
53
- storagePath: './memory.jsonl'
54
- });
143
+ interface Entity {
144
+ name: string; // Unique identifier
145
+ entityType: string; // Classification (person, project, concept)
146
+ observations: string[]; // Facts about the entity
147
+ parentId?: string; // Parent entity for hierarchical nesting
148
+ tags?: string[]; // Lowercase tags for categorization
149
+ importance?: number; // 0-10 scale for prioritization
150
+ createdAt?: string; // ISO 8601 timestamp
151
+ lastModified?: string; // ISO 8601 timestamp
152
+ }
55
153
  ```
56
154
 
57
- ### SQLite
155
+ ### Relations
156
+
157
+ Directed connections between entities.
58
158
 
59
159
  ```typescript
60
- const ctx = new ManagerContext({
61
- storageType: 'sqlite',
62
- storagePath: './memory.db'
63
- });
160
+ interface Relation {
161
+ from: string; // Source entity name
162
+ to: string; // Target entity name
163
+ relationType: string; // Relationship type (active voice)
164
+ }
64
165
  ```
65
166
 
66
- SQLite provides:
67
- - FTS5 full-text search with BM25 ranking
68
- - Referential integrity (ON DELETE CASCADE)
69
- - WAL mode for better concurrency
70
- - ACID transactions
167
+ ### Observations
71
168
 
72
- ## Core Components
169
+ Discrete facts about entities. Each observation should be atomic and independently manageable. Use `addObservations()` to append new facts without overwriting existing ones.
73
170
 
74
171
  ### ManagerContext
75
172
 
76
- Central access point for all managers:
173
+ Central access point for all managers with lazy initialization:
77
174
 
78
175
  ```typescript
79
176
  ctx.entityManager // Entity CRUD + hierarchy
80
177
  ctx.relationManager // Relation management
81
178
  ctx.searchManager // All search operations
82
- ctx.tagManager // Tag aliases
179
+ ctx.tagManager // Tag aliases and bulk operations
83
180
  ctx.ioManager // Import/export/backup
84
181
  ctx.graphTraversal // Graph algorithms
85
182
  ctx.semanticSearch // Vector similarity search (optional)
86
183
  ```
87
184
 
88
- ### Entity Structure
185
+ ## Storage Options
186
+
187
+ ### Comparison
188
+
189
+ | Feature | JSONL (Default) | SQLite (better-sqlite3) |
190
+ |---------|-----------------|-------------------------|
191
+ | Format | Human-readable text | Native binary database |
192
+ | Transactions | Basic | Full ACID with WAL mode |
193
+ | Full-Text Search | Basic | FTS5 with BM25 ranking |
194
+ | Performance | Good | 3-10x faster |
195
+ | Concurrency | Single-threaded | Thread-safe with async-mutex |
196
+ | Best For | Small graphs, debugging | Large graphs (10k+ entities) |
197
+
198
+ ### JSONL Storage
89
199
 
90
200
  ```typescript
91
- interface Entity {
92
- name: string; // Unique identifier
93
- entityType: string; // Classification
94
- observations: string[]; // Facts about the entity
95
- parentId?: string; // For hierarchy
96
- tags?: string[]; // Categories
97
- importance?: number; // 0-10 scale
98
- createdAt?: string; // ISO 8601
99
- lastModified?: string;
100
- }
201
+ const ctx = new ManagerContext({
202
+ storagePath: './memory.jsonl'
203
+ });
101
204
  ```
102
205
 
103
- ### Relation Structure
206
+ Features:
207
+ - Human-readable line-delimited JSON
208
+ - In-memory caching with write-through invalidation
209
+ - Atomic writes via temp file + rename
210
+ - Backward compatibility for legacy formats
211
+
212
+ ### SQLite Storage
104
213
 
105
214
  ```typescript
106
- interface Relation {
107
- from: string; // Source entity name
108
- to: string; // Target entity name
109
- relationType: string; // Connection type
110
- }
215
+ const ctx = new ManagerContext({
216
+ storageType: 'sqlite',
217
+ storagePath: './memory.db'
218
+ });
219
+ ```
220
+
221
+ Features:
222
+ - FTS5 full-text search with BM25 ranking
223
+ - WAL mode for better concurrency
224
+ - Referential integrity with ON DELETE CASCADE
225
+ - ACID transactions
226
+
227
+ ### Storage Files
228
+
229
+ When using JSONL, related files are automatically created:
230
+
231
+ ```
232
+ /your/data/directory/
233
+ ├── memory.jsonl # Main knowledge graph
234
+ ├── memory-saved-searches.jsonl # Saved search queries
235
+ ├── memory-tag-aliases.jsonl # Tag synonym mappings
236
+ └── .backups/ # Timestamped backups
111
237
  ```
112
238
 
113
239
  ## Search Capabilities
114
240
 
241
+ ### Search Methods
242
+
243
+ | Method | Description | Use Case |
244
+ |--------|-------------|----------|
245
+ | `search()` | Basic substring matching | Simple queries |
246
+ | `searchRanked()` | TF-IDF relevance scoring | Finding most relevant results |
247
+ | `booleanSearch()` | AND/OR/NOT operators | Complex filtering |
248
+ | `fuzzySearch()` | Levenshtein distance | Typo tolerance |
249
+ | `hybridSearch()` | Semantic + lexical + symbolic | Multi-signal ranking |
250
+
115
251
  ### Basic Search
116
252
 
117
253
  ```typescript
118
- // Find entities by name or observation content
119
254
  const results = await ctx.searchManager.search('TypeScript');
120
255
  ```
121
256
 
122
257
  ### Ranked Search (TF-IDF)
123
258
 
124
259
  ```typescript
125
- // Get relevance-scored results
126
- const ranked = await ctx.searchManager.searchRanked('JavaScript runtime', { limit: 10 });
260
+ const ranked = await ctx.searchManager.searchRanked('JavaScript runtime', {
261
+ limit: 10,
262
+ minScore: 0.1
263
+ });
127
264
  ```
128
265
 
129
266
  ### Boolean Search
130
267
 
131
268
  ```typescript
132
- // AND, OR, NOT operators
269
+ // AND - both terms must match
133
270
  const results = await ctx.searchManager.booleanSearch('TypeScript AND runtime');
134
- const excluded = await ctx.searchManager.booleanSearch('JavaScript NOT browser');
271
+
272
+ // OR - either term matches
273
+ const results = await ctx.searchManager.booleanSearch('frontend OR backend');
274
+
275
+ // NOT - exclude term
276
+ const results = await ctx.searchManager.booleanSearch('JavaScript NOT browser');
277
+
278
+ // Parentheses for grouping
279
+ const results = await ctx.searchManager.booleanSearch('(TypeScript OR JavaScript) AND server');
135
280
  ```
136
281
 
137
282
  ### Fuzzy Search
138
283
 
139
284
  ```typescript
140
- // Typo-tolerant search
141
- const results = await ctx.searchManager.fuzzySearch('Typscript', { threshold: 0.7 });
285
+ // Typo-tolerant search with threshold (0-1, higher = stricter)
286
+ const results = await ctx.searchManager.fuzzySearch('Typscript', {
287
+ threshold: 0.7
288
+ });
142
289
  ```
143
290
 
144
291
  ### Hybrid Search
145
292
 
146
- Combines semantic (vector), lexical (TF-IDF), and symbolic (metadata) signals:
293
+ Combines three signal layers for sophisticated ranking:
147
294
 
148
295
  ```typescript
149
296
  const results = await ctx.searchManager.hybridSearch('programming concepts', {
150
- weights: { semantic: 0.5, lexical: 0.3, symbolic: 0.2 },
151
- filters: { entityTypes: ['concept'], minImportance: 5 }
297
+ weights: {
298
+ semantic: 0.5, // Vector similarity (requires embeddings)
299
+ lexical: 0.3, // TF-IDF text matching
300
+ symbolic: 0.2 // Metadata (tags, importance, type)
301
+ },
302
+ filters: {
303
+ entityTypes: ['concept'],
304
+ minImportance: 5,
305
+ tags: ['programming']
306
+ }
152
307
  });
153
308
  ```
154
309
 
155
310
  ## Graph Algorithms
156
311
 
312
+ ### Path Finding
313
+
157
314
  ```typescript
158
- // Shortest path between entities
315
+ // Shortest path between entities (BFS)
159
316
  const path = await ctx.graphTraversal.findShortestPath('A', 'Z');
317
+ // Returns: ['A', 'B', 'C', 'Z']
160
318
 
161
- // All paths up to max depth
319
+ // All paths with max depth
162
320
  const paths = await ctx.graphTraversal.findAllPaths('A', 'Z', { maxDepth: 5 });
163
-
164
- // Centrality analysis
165
- const centrality = await ctx.graphTraversal.getCentrality({ algorithm: 'pagerank' });
166
-
167
- // Connected components
168
- const components = await ctx.graphTraversal.getConnectedComponents();
321
+ // Returns: [['A', 'B', 'Z'], ['A', 'C', 'D', 'Z'], ...]
169
322
  ```
170
323
 
171
- ## Import/Export
324
+ ### Centrality Analysis
172
325
 
173
326
  ```typescript
174
- // Export to JSON
175
- const json = await ctx.ioManager.exportGraph('json');
176
-
177
- // Export to CSV
178
- const csv = await ctx.ioManager.exportGraph('csv');
179
-
180
- // Export to GraphML (with compression)
181
- await ctx.ioManager.exportGraph('graphml', {
182
- outputPath: './graph.graphml.br',
183
- compress: true
327
+ // Calculate importance metrics
328
+ const centrality = await ctx.graphTraversal.getCentrality({
329
+ algorithm: 'pagerank' // or 'degree', 'betweenness'
184
330
  });
185
-
186
- // Import from file
187
- await ctx.ioManager.importGraph('json', jsonData, { mergeStrategy: 'merge' });
331
+ // Returns: Map<string, number> with entity scores
188
332
  ```
189
333
 
190
- ## Hierarchical Organization
334
+ ### Connected Components
191
335
 
192
336
  ```typescript
193
- // Set parent
194
- await ctx.entityManager.setEntityParent('Component', 'Module');
195
-
196
- // Get hierarchy
197
- const children = await ctx.entityManager.getChildren('Module');
198
- const ancestors = await ctx.entityManager.getAncestors('Component');
199
- const subtree = await ctx.entityManager.getSubtree('Module');
337
+ // Find isolated subgraphs
338
+ const components = await ctx.graphTraversal.getConnectedComponents();
339
+ // Returns: [['A', 'B', 'C'], ['X', 'Y'], ...]
200
340
  ```
201
341
 
202
- ## Tag Management
342
+ ### Traversal
203
343
 
204
344
  ```typescript
205
- // Add/remove tags
206
- await ctx.entityManager.addTags('Entity1', ['tag1', 'tag2']);
207
- await ctx.entityManager.removeTags('Entity1', ['tag1']);
208
-
209
- // Tag aliases (synonyms)
210
- await ctx.tagManager.addTagAlias('js', 'javascript');
345
+ // Breadth-first traversal
346
+ await ctx.graphTraversal.bfs('startNode', (node) => {
347
+ console.log('Visited:', node.name);
348
+ });
211
349
 
212
- // Bulk operations
213
- await ctx.entityManager.addTagsToMultipleEntities(['E1', 'E2'], ['shared-tag']);
350
+ // Depth-first traversal
351
+ await ctx.graphTraversal.dfs('startNode', (node) => {
352
+ console.log('Visited:', node.name);
353
+ });
214
354
  ```
215
355
 
216
356
  ## API Reference
@@ -223,23 +363,31 @@ await ctx.entityManager.addTagsToMultipleEntities(['E1', 'E2'], ['shared-tag']);
223
363
  | `deleteEntities(names)` | Delete entities by name |
224
364
  | `getEntityByName(name)` | Get single entity |
225
365
  | `addObservations(name, observations)` | Add observations to entity |
226
- | `deleteObservations(name, observations)` | Remove observations |
366
+ | `deleteObservations(name, observations)` | Remove specific observations |
227
367
  | `addTags(name, tags)` | Add tags to entity |
228
368
  | `removeTags(name, tags)` | Remove tags from entity |
229
369
  | `setImportance(name, score)` | Set importance (0-10) |
230
- | `setEntityParent(name, parentName)` | Set hierarchy parent |
231
- | `getChildren(name)` | Get child entities |
370
+ | `setEntityParent(name, parentName)` | Set/remove parent |
371
+ | `getChildren(name)` | Get immediate children |
232
372
  | `getAncestors(name)` | Get ancestor chain |
233
373
  | `getDescendants(name)` | Get all descendants |
234
374
 
375
+ ### RelationManager
376
+
377
+ | Method | Description |
378
+ |--------|-------------|
379
+ | `createRelations(relations)` | Create multiple relations |
380
+ | `getRelations(entityName)` | Get incoming/outgoing relations |
381
+ | `deleteRelations(relations)` | Delete specific relations |
382
+
235
383
  ### SearchManager
236
384
 
237
385
  | Method | Description |
238
386
  |--------|-------------|
239
- | `search(query, options)` | Basic search |
387
+ | `search(query, options)` | Basic substring search |
240
388
  | `searchRanked(query, options)` | TF-IDF ranked search |
241
- | `booleanSearch(query, options)` | Boolean operators |
242
- | `fuzzySearch(query, options)` | Typo-tolerant |
389
+ | `booleanSearch(query, options)` | Boolean operators (AND/OR/NOT) |
390
+ | `fuzzySearch(query, options)` | Levenshtein-based typo tolerance |
243
391
  | `hybridSearch(query, options)` | Multi-signal search |
244
392
  | `smartSearch(query, options)` | AI-assisted refinement |
245
393
 
@@ -247,20 +395,144 @@ await ctx.entityManager.addTagsToMultipleEntities(['E1', 'E2'], ['shared-tag']);
247
395
 
248
396
  | Method | Description |
249
397
  |--------|-------------|
250
- | `exportGraph(format, options)` | Export to format |
251
- | `importGraph(format, data, options)` | Import from format |
252
- | `createBackup(options)` | Create backup |
398
+ | `exportGraph(format, options)` | Export to JSON/CSV/GraphML |
399
+ | `importGraph(format, data, options)` | Import with merge strategies |
400
+ | `createBackup(options)` | Create timestamped backup |
253
401
  | `restoreBackup(path)` | Restore from backup |
254
402
 
255
- ## Requirements
403
+ ### GraphTraversal
256
404
 
257
- - Node.js >= 18.0.0
258
- - TypeScript >= 5.0 (for development)
405
+ | Method | Description |
406
+ |--------|-------------|
407
+ | `findShortestPath(from, to)` | BFS shortest path |
408
+ | `findAllPaths(from, to, options)` | All paths with max depth |
409
+ | `getCentrality(options)` | Centrality metrics |
410
+ | `getConnectedComponents()` | Find isolated subgraphs |
411
+ | `bfs(start, visitor)` | Breadth-first traversal |
412
+ | `dfs(start, visitor)` | Depth-first traversal |
413
+
414
+ ## Configuration
415
+
416
+ ### Environment Variables
417
+
418
+ | Variable | Description | Default |
419
+ |----------|-------------|---------|
420
+ | `MEMORY_STORAGE_TYPE` | Storage backend: `jsonl` or `sqlite` | `jsonl` |
421
+ | `EMBEDDING_PROVIDER` | Embedding provider: `openai`, `local`, or `none` | `none` |
422
+ | `OPENAI_API_KEY` | OpenAI API key (required if provider is `openai`) | - |
423
+
424
+ ## Development
425
+
426
+ ### Prerequisites
427
+
428
+ - Node.js 18+
429
+ - npm 9+
430
+ - TypeScript 5.0+
431
+
432
+ ### Build Commands
433
+
434
+ ```bash
435
+ npm install # Install dependencies
436
+ npm run build # Build TypeScript to dist/
437
+ npm run build:watch # Watch mode compilation
438
+ npm test # Run all tests
439
+ npm run test:watch # Watch mode testing
440
+ npm run test:coverage # Run with coverage report
441
+ npm run typecheck # Type checking without emit
442
+ ```
443
+
444
+ ### Architecture
445
+
446
+ ```
447
+ ┌─────────────────────────────────────────────────────────────┐
448
+ │ Layer 1: ManagerContext (Central Facade) │
449
+ │ ┌───────────────────────────────────────────────────────┐ │
450
+ │ │ Lazy-initialized access to all managers │ │
451
+ │ └───────────────────────────────────────────────────────┘ │
452
+ └──────────────────────────┬──────────────────────────────────┘
453
+
454
+ ┌──────────────────────────┴──────────────────────────────────┐
455
+ │ Layer 2: Specialized Managers │
456
+ │ • EntityManager (CRUD + hierarchy + archive) │
457
+ │ • RelationManager (relation CRUD) │
458
+ │ • SearchManager (search + compression + analytics) │
459
+ │ • IOManager (import + export + backup) │
460
+ │ • TagManager (tag aliases) │
461
+ │ • GraphTraversal (path finding, centrality) │
462
+ │ • SemanticSearch (embeddings, similarity) │
463
+ └──────────────────────────┬──────────────────────────────────┘
464
+
465
+ ┌──────────────────────────┴──────────────────────────────────┐
466
+ │ Layer 3: Storage Layer │
467
+ │ GraphStorage (JSONL) or SQLiteStorage (better-sqlite3) │
468
+ └─────────────────────────────────────────────────────────────┘
469
+ ```
470
+
471
+ ### Project Structure
472
+
473
+ ```
474
+ memoryjs/
475
+ ├── src/ # Source (73 TypeScript files)
476
+ │ ├── index.ts # Entry point
477
+ │ ├── core/ # Core managers (12 files)
478
+ │ │ ├── ManagerContext.ts # Context holder (lazy init)
479
+ │ │ ├── EntityManager.ts # Entity CRUD + hierarchy
480
+ │ │ ├── RelationManager.ts # Relation CRUD
481
+ │ │ ├── GraphStorage.ts # JSONL I/O + caching
482
+ │ │ ├── SQLiteStorage.ts # SQLite with better-sqlite3
483
+ │ │ ├── TransactionManager.ts # ACID transactions
484
+ │ │ └── ...
485
+ │ ├── search/ # Search implementations (29 files)
486
+ │ │ ├── SearchManager.ts # Search orchestrator
487
+ │ │ ├── BasicSearch.ts # Text matching
488
+ │ │ ├── RankedSearch.ts # TF-IDF scoring
489
+ │ │ ├── BooleanSearch.ts # AND/OR/NOT logic
490
+ │ │ ├── FuzzySearch.ts # Typo tolerance
491
+ │ │ ├── SemanticSearch.ts # Embedding-based
492
+ │ │ ├── HybridSearchManager.ts # Multi-layer search
493
+ │ │ └── ...
494
+ │ ├── features/ # Advanced capabilities (9 files)
495
+ │ │ ├── IOManager.ts # Import/export/backup
496
+ │ │ ├── TagManager.ts # Tag aliases
497
+ │ │ ├── ArchiveManager.ts # Entity archival
498
+ │ │ ├── CompressionManager.ts # Duplicate detection
499
+ │ │ └── ...
500
+ │ ├── types/ # TypeScript definitions (2 files)
501
+ │ ├── utils/ # Shared utilities (18 files)
502
+ │ └── workers/ # Worker pool (2 files)
503
+ ├── tests/ # Test suite
504
+ │ ├── unit/ # Unit tests
505
+ │ ├── integration/ # Integration tests
506
+ │ └── performance/ # Benchmarks
507
+ ├── docs/ # Documentation
508
+ │ └── architecture/ # Architecture docs
509
+ ├── tools/ # Development utilities
510
+ │ ├── chunking-for-files/ # File splitting tool
511
+ │ └── create-dependency-graph/ # Dependency analyzer
512
+ └── README.md # This file
513
+ ```
514
+
515
+ ## Documentation
516
+
517
+ Comprehensive architecture documentation in `docs/architecture/`:
518
+
519
+ - [OVERVIEW.md](docs/architecture/OVERVIEW.md) - High-level project overview
520
+ - [ARCHITECTURE.md](docs/architecture/ARCHITECTURE.md) - Technical architecture and design
521
+ - [COMPONENTS.md](docs/architecture/COMPONENTS.md) - Component breakdown
522
+ - [DATAFLOW.md](docs/architecture/DATAFLOW.md) - Data flow patterns
523
+ - [API.md](docs/architecture/API.md) - Complete API documentation
524
+ - [DEPENDENCY_GRAPH.md](docs/architecture/DEPENDENCY_GRAPH.md) - Module dependencies
259
525
 
260
526
  ## License
261
527
 
262
- MIT
528
+ **MIT License** - see [LICENSE](LICENSE)
263
529
 
264
530
  ## Related
265
531
 
266
532
  - [@danielsimonjr/memory-mcp](https://github.com/danielsimonjr/memory-mcp) - MCP server built on this library
533
+
534
+ ---
535
+
536
+ **Repository:** https://github.com/danielsimonjr/memoryjs
537
+ **NPM:** https://www.npmjs.com/package/@danielsimonjr/memoryjs
538
+ **Issues:** https://github.com/danielsimonjr/memoryjs/issues