agentdb 3.0.0-alpha.10 → 3.0.0-alpha.12

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 (648) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2821 -225
  3. package/dist/src/backends/VectorBackend.d.ts +31 -6
  4. package/dist/src/backends/VectorBackend.d.ts.map +1 -1
  5. package/dist/src/backends/detector.js.map +1 -1
  6. package/dist/src/backends/factory.d.ts +16 -33
  7. package/dist/src/backends/factory.d.ts.map +1 -1
  8. package/dist/src/backends/factory.js +138 -108
  9. package/dist/src/backends/factory.js.map +1 -1
  10. package/dist/src/backends/hnswlib/HNSWLibBackend.d.ts.map +1 -1
  11. package/dist/src/backends/hnswlib/HNSWLibBackend.js +29 -2
  12. package/dist/src/backends/hnswlib/HNSWLibBackend.js.map +1 -1
  13. package/dist/src/backends/ruvector/RuVectorBackend.d.ts +198 -45
  14. package/dist/src/backends/ruvector/RuVectorBackend.d.ts.map +1 -1
  15. package/dist/src/backends/ruvector/RuVectorBackend.js +612 -277
  16. package/dist/src/backends/ruvector/RuVectorBackend.js.map +1 -1
  17. package/dist/src/backends/ruvector/RuVectorLearning.d.ts +0 -4
  18. package/dist/src/backends/ruvector/RuVectorLearning.d.ts.map +1 -1
  19. package/dist/src/backends/ruvector/RuVectorLearning.js +0 -6
  20. package/dist/src/backends/ruvector/RuVectorLearning.js.map +1 -1
  21. package/dist/src/backends/rvf/AdaptiveIndexTuner.d.ts +175 -0
  22. package/dist/src/backends/rvf/AdaptiveIndexTuner.d.ts.map +1 -0
  23. package/dist/src/backends/rvf/AdaptiveIndexTuner.js +559 -0
  24. package/dist/src/backends/rvf/AdaptiveIndexTuner.js.map +1 -0
  25. package/dist/src/backends/rvf/ContrastiveTrainer.d.ts +148 -0
  26. package/dist/src/backends/rvf/ContrastiveTrainer.d.ts.map +1 -0
  27. package/dist/src/backends/rvf/ContrastiveTrainer.js +438 -0
  28. package/dist/src/backends/rvf/ContrastiveTrainer.js.map +1 -0
  29. package/dist/src/backends/rvf/FederatedSessionManager.d.ts +211 -0
  30. package/dist/src/backends/rvf/FederatedSessionManager.d.ts.map +1 -0
  31. package/dist/src/backends/rvf/FederatedSessionManager.js +389 -0
  32. package/dist/src/backends/rvf/FederatedSessionManager.js.map +1 -0
  33. package/dist/src/backends/rvf/FilterBuilder.d.ts +136 -0
  34. package/dist/src/backends/rvf/FilterBuilder.d.ts.map +1 -0
  35. package/dist/src/backends/rvf/FilterBuilder.js +157 -0
  36. package/dist/src/backends/rvf/FilterBuilder.js.map +1 -0
  37. package/dist/src/backends/rvf/NativeAccelerator.d.ts +140 -0
  38. package/dist/src/backends/rvf/NativeAccelerator.d.ts.map +1 -0
  39. package/dist/src/backends/rvf/NativeAccelerator.js +630 -0
  40. package/dist/src/backends/rvf/NativeAccelerator.js.map +1 -0
  41. package/dist/src/backends/rvf/RvfBackend.d.ts +194 -0
  42. package/dist/src/backends/rvf/RvfBackend.d.ts.map +1 -0
  43. package/dist/src/backends/rvf/RvfBackend.js +607 -0
  44. package/dist/src/backends/rvf/RvfBackend.js.map +1 -0
  45. package/dist/src/backends/rvf/RvfSolver.d.ts +175 -0
  46. package/dist/src/backends/rvf/RvfSolver.d.ts.map +1 -0
  47. package/dist/src/backends/rvf/RvfSolver.js +176 -0
  48. package/dist/src/backends/rvf/RvfSolver.js.map +1 -0
  49. package/dist/src/backends/rvf/SelfLearningRvfBackend.d.ts +143 -0
  50. package/dist/src/backends/rvf/SelfLearningRvfBackend.d.ts.map +1 -0
  51. package/dist/src/backends/rvf/SelfLearningRvfBackend.js +569 -0
  52. package/dist/src/backends/rvf/SelfLearningRvfBackend.js.map +1 -0
  53. package/dist/src/backends/rvf/SemanticQueryRouter.d.ts +128 -0
  54. package/dist/src/backends/rvf/SemanticQueryRouter.d.ts.map +1 -0
  55. package/dist/src/backends/rvf/SemanticQueryRouter.js +415 -0
  56. package/dist/src/backends/rvf/SemanticQueryRouter.js.map +1 -0
  57. package/dist/src/backends/rvf/SimdFallbacks.d.ts +25 -0
  58. package/dist/src/backends/rvf/SimdFallbacks.d.ts.map +1 -0
  59. package/dist/src/backends/rvf/SimdFallbacks.js +287 -0
  60. package/dist/src/backends/rvf/SimdFallbacks.js.map +1 -0
  61. package/dist/src/backends/rvf/SolverBandit.d.ts +100 -0
  62. package/dist/src/backends/rvf/SolverBandit.d.ts.map +1 -0
  63. package/dist/src/backends/rvf/SolverBandit.js +216 -0
  64. package/dist/src/backends/rvf/SolverBandit.js.map +1 -0
  65. package/dist/src/backends/rvf/SonaLearningBackend.d.ts +157 -0
  66. package/dist/src/backends/rvf/SonaLearningBackend.d.ts.map +1 -0
  67. package/dist/src/backends/rvf/SonaLearningBackend.js +283 -0
  68. package/dist/src/backends/rvf/SonaLearningBackend.js.map +1 -0
  69. package/dist/src/backends/rvf/SqlJsRvfBackend.d.ts +77 -0
  70. package/dist/src/backends/rvf/SqlJsRvfBackend.d.ts.map +1 -0
  71. package/dist/src/backends/rvf/SqlJsRvfBackend.js +382 -0
  72. package/dist/src/backends/rvf/SqlJsRvfBackend.js.map +1 -0
  73. package/dist/src/backends/rvf/WasmStoreBridge.d.ts +27 -0
  74. package/dist/src/backends/rvf/WasmStoreBridge.d.ts.map +1 -0
  75. package/dist/src/backends/rvf/WasmStoreBridge.js +87 -0
  76. package/dist/src/backends/rvf/WasmStoreBridge.js.map +1 -0
  77. package/dist/src/backends/rvf/validation.d.ts +20 -0
  78. package/dist/src/backends/rvf/validation.d.ts.map +1 -0
  79. package/dist/src/backends/rvf/validation.js +78 -0
  80. package/dist/src/backends/rvf/validation.js.map +1 -0
  81. package/dist/src/benchmark/BenchmarkSuite.d.ts +318 -0
  82. package/dist/src/benchmark/BenchmarkSuite.d.ts.map +1 -0
  83. package/dist/src/benchmark/BenchmarkSuite.js +984 -0
  84. package/dist/src/benchmark/BenchmarkSuite.js.map +1 -0
  85. package/dist/src/benchmark/index.d.ts +29 -0
  86. package/dist/src/benchmark/index.d.ts.map +1 -0
  87. package/dist/src/benchmark/index.js +39 -0
  88. package/dist/src/benchmark/index.js.map +1 -0
  89. package/dist/src/browser/AttentionBrowser.d.ts.map +1 -1
  90. package/dist/src/browser/AttentionBrowser.js +1 -0
  91. package/dist/src/browser/AttentionBrowser.js.map +1 -1
  92. package/dist/src/cli/agentdb-cli.d.ts +13 -0
  93. package/dist/src/cli/agentdb-cli.d.ts.map +1 -1
  94. package/dist/src/cli/agentdb-cli.js +803 -94
  95. package/dist/src/cli/agentdb-cli.js.map +1 -1
  96. package/dist/src/cli/commands/hyperbolic.d.ts +11 -0
  97. package/dist/src/cli/commands/hyperbolic.d.ts.map +1 -0
  98. package/dist/src/cli/commands/hyperbolic.js +428 -0
  99. package/dist/src/cli/commands/hyperbolic.js.map +1 -0
  100. package/dist/src/cli/commands/learn.d.ts +11 -0
  101. package/dist/src/cli/commands/learn.d.ts.map +1 -0
  102. package/dist/src/cli/commands/learn.js +404 -0
  103. package/dist/src/cli/commands/learn.js.map +1 -0
  104. package/dist/src/cli/commands/migrate.d.ts +15 -0
  105. package/dist/src/cli/commands/migrate.d.ts.map +1 -1
  106. package/dist/src/cli/commands/migrate.js +176 -8
  107. package/dist/src/cli/commands/migrate.js.map +1 -1
  108. package/dist/src/cli/commands/route.d.ts +11 -0
  109. package/dist/src/cli/commands/route.d.ts.map +1 -0
  110. package/dist/src/cli/commands/route.js +414 -0
  111. package/dist/src/cli/commands/route.js.map +1 -0
  112. package/dist/src/cli/commands/rvf.d.ts +21 -0
  113. package/dist/src/cli/commands/rvf.d.ts.map +1 -0
  114. package/dist/src/cli/commands/rvf.js +448 -0
  115. package/dist/src/cli/commands/rvf.js.map +1 -0
  116. package/dist/src/cli/lib/report-store.d.ts +2 -1
  117. package/dist/src/cli/lib/report-store.d.ts.map +1 -1
  118. package/dist/src/cli/lib/report-store.js +85 -65
  119. package/dist/src/cli/lib/report-store.js.map +1 -1
  120. package/dist/src/cli/lib/simulation-runner.d.ts +40 -3
  121. package/dist/src/cli/lib/simulation-runner.d.ts.map +1 -1
  122. package/dist/src/cli/lib/simulation-runner.js +248 -6
  123. package/dist/src/cli/lib/simulation-runner.js.map +1 -1
  124. package/dist/src/compatibility/DeprecationWarnings.d.ts +54 -0
  125. package/dist/src/compatibility/DeprecationWarnings.d.ts.map +1 -0
  126. package/dist/src/compatibility/DeprecationWarnings.js +131 -0
  127. package/dist/src/compatibility/DeprecationWarnings.js.map +1 -0
  128. package/dist/src/compatibility/MigrationUtilities.d.ts +30 -0
  129. package/dist/src/compatibility/MigrationUtilities.d.ts.map +1 -0
  130. package/dist/src/compatibility/MigrationUtilities.js +184 -0
  131. package/dist/src/compatibility/MigrationUtilities.js.map +1 -0
  132. package/dist/src/compatibility/V1toV2Adapter.d.ts +76 -0
  133. package/dist/src/compatibility/V1toV2Adapter.d.ts.map +1 -0
  134. package/dist/src/compatibility/V1toV2Adapter.js +185 -0
  135. package/dist/src/compatibility/V1toV2Adapter.js.map +1 -0
  136. package/dist/src/compatibility/VersionDetector.d.ts +32 -0
  137. package/dist/src/compatibility/VersionDetector.d.ts.map +1 -0
  138. package/dist/src/compatibility/VersionDetector.js +144 -0
  139. package/dist/src/compatibility/VersionDetector.js.map +1 -0
  140. package/dist/src/compatibility/index.d.ts +14 -0
  141. package/dist/src/compatibility/index.d.ts.map +1 -0
  142. package/dist/src/compatibility/index.js +21 -0
  143. package/dist/src/compatibility/index.js.map +1 -0
  144. package/dist/src/compatibility/types.d.ts +103 -0
  145. package/dist/src/compatibility/types.d.ts.map +1 -0
  146. package/dist/src/compatibility/types.js +5 -0
  147. package/dist/src/compatibility/types.js.map +1 -0
  148. package/dist/src/controllers/AttentionService.d.ts +99 -202
  149. package/dist/src/controllers/AttentionService.d.ts.map +1 -1
  150. package/dist/src/controllers/AttentionService.js +450 -558
  151. package/dist/src/controllers/AttentionService.js.map +1 -1
  152. package/dist/src/controllers/CausalMemoryGraph.d.ts +30 -5
  153. package/dist/src/controllers/CausalMemoryGraph.d.ts.map +1 -1
  154. package/dist/src/controllers/CausalMemoryGraph.js +89 -13
  155. package/dist/src/controllers/CausalMemoryGraph.js.map +1 -1
  156. package/dist/src/controllers/CausalRecall.d.ts +4 -0
  157. package/dist/src/controllers/CausalRecall.d.ts.map +1 -1
  158. package/dist/src/controllers/CausalRecall.js +19 -2
  159. package/dist/src/controllers/CausalRecall.js.map +1 -1
  160. package/dist/src/controllers/EmbeddingService.d.ts.map +1 -1
  161. package/dist/src/controllers/EmbeddingService.js +28 -11
  162. package/dist/src/controllers/EmbeddingService.js.map +1 -1
  163. package/dist/src/controllers/EnhancedEmbeddingService.d.ts +4 -0
  164. package/dist/src/controllers/EnhancedEmbeddingService.d.ts.map +1 -1
  165. package/dist/src/controllers/EnhancedEmbeddingService.js +17 -3
  166. package/dist/src/controllers/EnhancedEmbeddingService.js.map +1 -1
  167. package/dist/src/controllers/ExplainableRecall.d.ts +1 -1
  168. package/dist/src/controllers/ExplainableRecall.d.ts.map +1 -1
  169. package/dist/src/controllers/ExplainableRecall.js +1 -1
  170. package/dist/src/controllers/ExplainableRecall.js.map +1 -1
  171. package/dist/src/controllers/HNSWIndex.d.ts +20 -2
  172. package/dist/src/controllers/HNSWIndex.d.ts.map +1 -1
  173. package/dist/src/controllers/HNSWIndex.js +82 -6
  174. package/dist/src/controllers/HNSWIndex.js.map +1 -1
  175. package/dist/src/controllers/LearningSystem.d.ts +1 -17
  176. package/dist/src/controllers/LearningSystem.d.ts.map +1 -1
  177. package/dist/src/controllers/LearningSystem.js +18 -135
  178. package/dist/src/controllers/LearningSystem.js.map +1 -1
  179. package/dist/src/controllers/MemoryController.d.ts +161 -0
  180. package/dist/src/controllers/MemoryController.d.ts.map +1 -0
  181. package/dist/src/controllers/MemoryController.js +303 -0
  182. package/dist/src/controllers/MemoryController.js.map +1 -0
  183. package/dist/src/controllers/MincutService.d.ts +92 -0
  184. package/dist/src/controllers/MincutService.d.ts.map +1 -0
  185. package/dist/src/controllers/MincutService.js +336 -0
  186. package/dist/src/controllers/MincutService.js.map +1 -0
  187. package/dist/src/controllers/NightlyLearner.d.ts +5 -1
  188. package/dist/src/controllers/NightlyLearner.d.ts.map +1 -1
  189. package/dist/src/controllers/NightlyLearner.js +17 -3
  190. package/dist/src/controllers/NightlyLearner.js.map +1 -1
  191. package/dist/src/controllers/QUICClient.d.ts +45 -0
  192. package/dist/src/controllers/QUICClient.d.ts.map +1 -1
  193. package/dist/src/controllers/QUICClient.js +190 -0
  194. package/dist/src/controllers/QUICClient.js.map +1 -1
  195. package/dist/src/controllers/ReasoningBank.d.ts +6 -3
  196. package/dist/src/controllers/ReasoningBank.d.ts.map +1 -1
  197. package/dist/src/controllers/ReasoningBank.js +47 -41
  198. package/dist/src/controllers/ReasoningBank.js.map +1 -1
  199. package/dist/src/controllers/ReflexionMemory.d.ts +115 -6
  200. package/dist/src/controllers/ReflexionMemory.d.ts.map +1 -1
  201. package/dist/src/controllers/ReflexionMemory.js +541 -213
  202. package/dist/src/controllers/ReflexionMemory.js.map +1 -1
  203. package/dist/src/controllers/SkillLibrary.d.ts +27 -3
  204. package/dist/src/controllers/SkillLibrary.d.ts.map +1 -1
  205. package/dist/src/controllers/SkillLibrary.js +187 -91
  206. package/dist/src/controllers/SkillLibrary.js.map +1 -1
  207. package/dist/src/controllers/SparsificationService.d.ts +151 -0
  208. package/dist/src/controllers/SparsificationService.d.ts.map +1 -0
  209. package/dist/src/controllers/SparsificationService.js +375 -0
  210. package/dist/src/controllers/SparsificationService.js.map +1 -0
  211. package/dist/src/controllers/SyncCoordinator.d.ts.map +1 -1
  212. package/dist/src/controllers/SyncCoordinator.js +115 -3
  213. package/dist/src/controllers/SyncCoordinator.js.map +1 -1
  214. package/dist/src/controllers/WASMVectorSearch.d.ts +12 -30
  215. package/dist/src/controllers/WASMVectorSearch.d.ts.map +1 -1
  216. package/dist/src/controllers/WASMVectorSearch.js +146 -93
  217. package/dist/src/controllers/WASMVectorSearch.js.map +1 -1
  218. package/dist/src/controllers/attention/AttentionCache.d.ts +38 -0
  219. package/dist/src/controllers/attention/AttentionCache.d.ts.map +1 -0
  220. package/dist/src/controllers/attention/AttentionCache.js +80 -0
  221. package/dist/src/controllers/attention/AttentionCache.js.map +1 -0
  222. package/dist/src/controllers/attention/AttentionConfig.d.ts +127 -0
  223. package/dist/src/controllers/attention/AttentionConfig.d.ts.map +1 -0
  224. package/dist/src/controllers/attention/AttentionConfig.js +124 -0
  225. package/dist/src/controllers/attention/AttentionConfig.js.map +1 -0
  226. package/dist/src/controllers/attention/AttentionCore.d.ts +89 -0
  227. package/dist/src/controllers/attention/AttentionCore.d.ts.map +1 -0
  228. package/dist/src/controllers/attention/AttentionCore.js +289 -0
  229. package/dist/src/controllers/attention/AttentionCore.js.map +1 -0
  230. package/dist/src/controllers/attention/AttentionHelpers.d.ts +55 -0
  231. package/dist/src/controllers/attention/AttentionHelpers.d.ts.map +1 -0
  232. package/dist/src/controllers/attention/AttentionHelpers.js +148 -0
  233. package/dist/src/controllers/attention/AttentionHelpers.js.map +1 -0
  234. package/dist/src/controllers/attention/AttentionMetrics.d.ts +55 -0
  235. package/dist/src/controllers/attention/AttentionMetrics.d.ts.map +1 -0
  236. package/dist/src/controllers/attention/AttentionMetrics.js +72 -0
  237. package/dist/src/controllers/attention/AttentionMetrics.js.map +1 -0
  238. package/dist/src/controllers/attention/AttentionWASM.d.ts +98 -0
  239. package/dist/src/controllers/attention/AttentionWASM.d.ts.map +1 -0
  240. package/dist/src/controllers/attention/AttentionWASM.js +147 -0
  241. package/dist/src/controllers/attention/AttentionWASM.js.map +1 -0
  242. package/dist/src/controllers/attention/CrossAttentionController.d.ts +141 -0
  243. package/dist/src/controllers/attention/CrossAttentionController.d.ts.map +1 -0
  244. package/dist/src/controllers/attention/CrossAttentionController.js +325 -0
  245. package/dist/src/controllers/attention/CrossAttentionController.js.map +1 -0
  246. package/dist/src/controllers/attention/MultiHeadAttentionController.d.ts +137 -0
  247. package/dist/src/controllers/attention/MultiHeadAttentionController.d.ts.map +1 -0
  248. package/dist/src/controllers/attention/MultiHeadAttentionController.js +336 -0
  249. package/dist/src/controllers/attention/MultiHeadAttentionController.js.map +1 -0
  250. package/dist/src/controllers/attention/SelfAttentionController.d.ts +117 -0
  251. package/dist/src/controllers/attention/SelfAttentionController.d.ts.map +1 -0
  252. package/dist/src/controllers/attention/SelfAttentionController.js +205 -0
  253. package/dist/src/controllers/attention/SelfAttentionController.js.map +1 -0
  254. package/dist/src/controllers/attention/index.d.ts +24 -0
  255. package/dist/src/controllers/attention/index.d.ts.map +1 -0
  256. package/dist/src/controllers/attention/index.js +20 -0
  257. package/dist/src/controllers/attention/index.js.map +1 -0
  258. package/dist/src/controllers/index.d.ts +14 -27
  259. package/dist/src/controllers/index.d.ts.map +1 -1
  260. package/dist/src/controllers/index.js +10 -18
  261. package/dist/src/controllers/index.js.map +1 -1
  262. package/dist/src/controllers/prerequisites.d.ts +76 -0
  263. package/dist/src/controllers/prerequisites.d.ts.map +1 -0
  264. package/dist/src/controllers/prerequisites.js +235 -0
  265. package/dist/src/controllers/prerequisites.js.map +1 -0
  266. package/dist/src/core/AgentDB.d.ts +27 -19
  267. package/dist/src/core/AgentDB.d.ts.map +1 -1
  268. package/dist/src/core/AgentDB.js +76 -124
  269. package/dist/src/core/AgentDB.js.map +1 -1
  270. package/dist/src/core/QueryCache.d.ts +138 -0
  271. package/dist/src/core/QueryCache.d.ts.map +1 -0
  272. package/dist/src/core/QueryCache.js +309 -0
  273. package/dist/src/core/QueryCache.js.map +1 -0
  274. package/dist/src/db-fallback.d.ts +10 -1
  275. package/dist/src/db-fallback.d.ts.map +1 -1
  276. package/dist/src/db-fallback.js +205 -28
  277. package/dist/src/db-fallback.js.map +1 -1
  278. package/dist/src/examples/quic-sync-example.js +2 -2
  279. package/dist/src/examples/quic-sync-example.js.map +1 -1
  280. package/dist/src/index.d.ts +15 -15
  281. package/dist/src/index.d.ts.map +1 -1
  282. package/dist/src/index.js +39 -11
  283. package/dist/src/index.js.map +1 -1
  284. package/dist/src/mcp/agentdb-mcp-server.js +47 -2
  285. package/dist/src/mcp/agentdb-mcp-server.js.map +1 -1
  286. package/dist/src/model/ModelCacheLoader.d.ts +24 -0
  287. package/dist/src/model/ModelCacheLoader.d.ts.map +1 -0
  288. package/dist/src/model/ModelCacheLoader.js +121 -0
  289. package/dist/src/model/ModelCacheLoader.js.map +1 -0
  290. package/dist/src/observability/index.d.ts +8 -0
  291. package/dist/src/observability/index.d.ts.map +1 -0
  292. package/dist/src/observability/index.js +8 -0
  293. package/dist/src/observability/index.js.map +1 -0
  294. package/dist/src/observability/integration.d.ts +32 -0
  295. package/dist/src/observability/integration.d.ts.map +1 -0
  296. package/dist/src/observability/integration.js +159 -0
  297. package/dist/src/observability/integration.js.map +1 -0
  298. package/dist/src/observability/telemetry.d.ts +137 -0
  299. package/dist/src/observability/telemetry.d.ts.map +1 -0
  300. package/dist/src/observability/telemetry.js +416 -0
  301. package/dist/src/observability/telemetry.js.map +1 -0
  302. package/dist/src/optimizations/BatchOperations.d.ts +47 -0
  303. package/dist/src/optimizations/BatchOperations.d.ts.map +1 -1
  304. package/dist/src/optimizations/BatchOperations.js +183 -31
  305. package/dist/src/optimizations/BatchOperations.js.map +1 -1
  306. package/dist/src/optimizations/Quantization.d.ts +330 -0
  307. package/dist/src/optimizations/Quantization.d.ts.map +1 -0
  308. package/dist/src/optimizations/Quantization.js +793 -0
  309. package/dist/src/optimizations/Quantization.js.map +1 -0
  310. package/dist/src/optimizations/index.d.ts +1 -3
  311. package/dist/src/optimizations/index.d.ts.map +1 -1
  312. package/dist/src/optimizations/index.js +0 -1
  313. package/dist/src/optimizations/index.js.map +1 -1
  314. package/dist/src/quantization/index.d.ts +7 -0
  315. package/dist/src/quantization/index.d.ts.map +1 -0
  316. package/dist/src/quantization/index.js +15 -0
  317. package/dist/src/quantization/index.js.map +1 -0
  318. package/dist/src/quantization/vector-quantization.d.ts +388 -0
  319. package/dist/src/quantization/vector-quantization.d.ts.map +1 -0
  320. package/dist/src/quantization/vector-quantization.js +1132 -0
  321. package/dist/src/quantization/vector-quantization.js.map +1 -0
  322. package/dist/src/search/HybridSearch.d.ts +311 -0
  323. package/dist/src/search/HybridSearch.d.ts.map +1 -0
  324. package/dist/src/search/HybridSearch.js +712 -0
  325. package/dist/src/search/HybridSearch.js.map +1 -0
  326. package/dist/src/search/index.d.ts +12 -0
  327. package/dist/src/search/index.d.ts.map +1 -0
  328. package/dist/src/search/index.js +16 -0
  329. package/dist/src/search/index.js.map +1 -0
  330. package/dist/src/services/AttentionService.d.ts +303 -0
  331. package/dist/src/services/AttentionService.d.ts.map +1 -0
  332. package/dist/src/services/AttentionService.js +1165 -0
  333. package/dist/src/services/AttentionService.js.map +1 -0
  334. package/dist/src/services/LLMRouter.d.ts +61 -7
  335. package/dist/src/services/LLMRouter.d.ts.map +1 -1
  336. package/dist/src/services/LLMRouter.js +286 -22
  337. package/dist/src/services/LLMRouter.js.map +1 -1
  338. package/dist/src/services/audit-logger.service.d.ts +168 -0
  339. package/dist/src/services/audit-logger.service.d.ts.map +1 -0
  340. package/dist/src/services/audit-logger.service.js +331 -0
  341. package/dist/src/services/audit-logger.service.js.map +1 -0
  342. package/dist/src/services/enhanced-embeddings.d.ts +271 -0
  343. package/dist/src/services/enhanced-embeddings.d.ts.map +1 -0
  344. package/dist/src/services/enhanced-embeddings.js +1035 -0
  345. package/dist/src/services/enhanced-embeddings.js.map +1 -0
  346. package/dist/src/services/federated-learning.d.ts +172 -0
  347. package/dist/src/services/federated-learning.d.ts.map +1 -0
  348. package/dist/src/services/federated-learning.js +342 -0
  349. package/dist/src/services/federated-learning.js.map +1 -0
  350. package/dist/src/simd/index.d.ts +9 -0
  351. package/dist/src/simd/index.d.ts.map +1 -0
  352. package/dist/src/simd/index.js +27 -0
  353. package/dist/src/simd/index.js.map +1 -0
  354. package/dist/src/simd/simd-vector-ops.d.ts +332 -0
  355. package/dist/src/simd/simd-vector-ops.d.ts.map +1 -0
  356. package/dist/src/simd/simd-vector-ops.js +945 -0
  357. package/dist/src/simd/simd-vector-ops.js.map +1 -0
  358. package/dist/src/types/database.types.d.ts +275 -0
  359. package/dist/src/types/database.types.d.ts.map +1 -0
  360. package/dist/src/types/database.types.js +55 -0
  361. package/dist/src/types/database.types.js.map +1 -0
  362. package/dist/src/types/graph.d.ts +29 -0
  363. package/dist/src/types/graph.d.ts.map +1 -0
  364. package/dist/src/types/graph.js +8 -0
  365. package/dist/src/types/graph.js.map +1 -0
  366. package/dist/src/utils/chalk-fallback.d.ts +3 -0
  367. package/dist/src/utils/chalk-fallback.d.ts.map +1 -0
  368. package/dist/src/utils/chalk-fallback.js +20 -0
  369. package/dist/src/utils/chalk-fallback.js.map +1 -0
  370. package/dist/src/utils/similarity.d.ts +11 -0
  371. package/dist/src/utils/similarity.d.ts.map +1 -0
  372. package/dist/src/utils/similarity.js +25 -0
  373. package/dist/src/utils/similarity.js.map +1 -0
  374. package/dist/src/wasm-loader.d.ts +66 -0
  375. package/dist/src/wasm-loader.d.ts.map +1 -0
  376. package/dist/src/wasm-loader.js +76 -0
  377. package/dist/src/wasm-loader.js.map +1 -0
  378. package/dist/src/wrappers/agentdb-fast.d.ts +139 -0
  379. package/dist/src/wrappers/agentdb-fast.d.ts.map +1 -0
  380. package/dist/src/wrappers/agentdb-fast.js +307 -0
  381. package/dist/src/wrappers/agentdb-fast.js.map +1 -0
  382. package/dist/src/wrappers/attention-fallbacks.d.ts +343 -0
  383. package/dist/src/wrappers/attention-fallbacks.d.ts.map +1 -0
  384. package/dist/src/wrappers/attention-fallbacks.js +1484 -0
  385. package/dist/src/wrappers/attention-fallbacks.js.map +1 -0
  386. package/dist/src/wrappers/attention-native.d.ts +111 -0
  387. package/dist/src/wrappers/attention-native.d.ts.map +1 -0
  388. package/dist/src/wrappers/attention-native.js +273 -0
  389. package/dist/src/wrappers/attention-native.js.map +1 -0
  390. package/dist/src/wrappers/embedding-service.d.ts +117 -0
  391. package/dist/src/wrappers/embedding-service.d.ts.map +1 -0
  392. package/dist/src/wrappers/embedding-service.js +370 -0
  393. package/dist/src/wrappers/embedding-service.js.map +1 -0
  394. package/dist/src/wrappers/gnn-wrapper.d.ts +71 -0
  395. package/dist/src/wrappers/gnn-wrapper.d.ts.map +1 -0
  396. package/dist/src/wrappers/gnn-wrapper.js +236 -0
  397. package/dist/src/wrappers/gnn-wrapper.js.map +1 -0
  398. package/dist/src/wrappers/index.d.ts +48 -0
  399. package/dist/src/wrappers/index.d.ts.map +1 -0
  400. package/dist/src/wrappers/index.js +83 -0
  401. package/dist/src/wrappers/index.js.map +1 -0
  402. package/package.json +77 -76
  403. package/scripts/postinstall.cjs +13 -144
  404. package/dist/agentdb.browser.js +0 -1685
  405. package/dist/agentdb.browser.js.map +0 -7
  406. package/dist/agentdb.browser.min.js +0 -3
  407. package/dist/agentdb.browser.min.js.map +0 -7
  408. package/dist/agentdb.wasm-loader.js +0 -207
  409. package/dist/backends/VectorBackend.d.ts +0 -120
  410. package/dist/backends/VectorBackend.js +0 -14
  411. package/dist/backends/VectorBackend.js.map +0 -1
  412. package/dist/optimizations/RVFOptimizer.d.ts +0 -225
  413. package/dist/optimizations/RVFOptimizer.js +0 -541
  414. package/dist/optimizations/RVFOptimizer.js.map +0 -1
  415. package/dist/schemas/frontier-schema.sql +0 -378
  416. package/dist/schemas/schema.sql +0 -382
  417. package/dist/simulation/cli.d.ts +0 -9
  418. package/dist/simulation/cli.d.ts.map +0 -1
  419. package/dist/simulation/cli.js +0 -68
  420. package/dist/simulation/cli.js.map +0 -1
  421. package/dist/simulation/runner.d.ts +0 -21
  422. package/dist/simulation/runner.d.ts.map +0 -1
  423. package/dist/simulation/runner.js +0 -241
  424. package/dist/simulation/runner.js.map +0 -1
  425. package/dist/simulation/scenarios/aidefence-integration.d.ts +0 -24
  426. package/dist/simulation/scenarios/aidefence-integration.d.ts.map +0 -1
  427. package/dist/simulation/scenarios/aidefence-integration.js +0 -124
  428. package/dist/simulation/scenarios/aidefence-integration.js.map +0 -1
  429. package/dist/simulation/scenarios/bmssp-integration.d.ts +0 -23
  430. package/dist/simulation/scenarios/bmssp-integration.d.ts.map +0 -1
  431. package/dist/simulation/scenarios/bmssp-integration.js +0 -104
  432. package/dist/simulation/scenarios/bmssp-integration.js.map +0 -1
  433. package/dist/simulation/scenarios/causal-reasoning.d.ts +0 -16
  434. package/dist/simulation/scenarios/causal-reasoning.d.ts.map +0 -1
  435. package/dist/simulation/scenarios/causal-reasoning.js +0 -108
  436. package/dist/simulation/scenarios/causal-reasoning.js.map +0 -1
  437. package/dist/simulation/scenarios/consciousness-explorer.d.ts +0 -25
  438. package/dist/simulation/scenarios/consciousness-explorer.d.ts.map +0 -1
  439. package/dist/simulation/scenarios/consciousness-explorer.js +0 -108
  440. package/dist/simulation/scenarios/consciousness-explorer.js.map +0 -1
  441. package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.d.ts +0 -135
  442. package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.d.ts.map +0 -1
  443. package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.js +0 -158
  444. package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.js.map +0 -1
  445. package/dist/simulation/scenarios/domain-examples/index.d.ts +0 -14
  446. package/dist/simulation/scenarios/domain-examples/index.d.ts.map +0 -1
  447. package/dist/simulation/scenarios/domain-examples/index.js +0 -14
  448. package/dist/simulation/scenarios/domain-examples/index.js.map +0 -1
  449. package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.d.ts +0 -178
  450. package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.d.ts.map +0 -1
  451. package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.js +0 -218
  452. package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.js.map +0 -1
  453. package/dist/simulation/scenarios/domain-examples/medical-imaging.d.ts +0 -122
  454. package/dist/simulation/scenarios/domain-examples/medical-imaging.d.ts.map +0 -1
  455. package/dist/simulation/scenarios/domain-examples/medical-imaging.js +0 -129
  456. package/dist/simulation/scenarios/domain-examples/medical-imaging.js.map +0 -1
  457. package/dist/simulation/scenarios/domain-examples/robotics-navigation.d.ts +0 -166
  458. package/dist/simulation/scenarios/domain-examples/robotics-navigation.d.ts.map +0 -1
  459. package/dist/simulation/scenarios/domain-examples/robotics-navigation.js +0 -161
  460. package/dist/simulation/scenarios/domain-examples/robotics-navigation.js.map +0 -1
  461. package/dist/simulation/scenarios/domain-examples/scientific-research.d.ts +0 -151
  462. package/dist/simulation/scenarios/domain-examples/scientific-research.d.ts.map +0 -1
  463. package/dist/simulation/scenarios/domain-examples/scientific-research.js +0 -187
  464. package/dist/simulation/scenarios/domain-examples/scientific-research.js.map +0 -1
  465. package/dist/simulation/scenarios/domain-examples/trading-systems.d.ts +0 -102
  466. package/dist/simulation/scenarios/domain-examples/trading-systems.d.ts.map +0 -1
  467. package/dist/simulation/scenarios/domain-examples/trading-systems.js +0 -100
  468. package/dist/simulation/scenarios/domain-examples/trading-systems.js.map +0 -1
  469. package/dist/simulation/scenarios/goalie-integration.d.ts +0 -24
  470. package/dist/simulation/scenarios/goalie-integration.d.ts.map +0 -1
  471. package/dist/simulation/scenarios/goalie-integration.js +0 -121
  472. package/dist/simulation/scenarios/goalie-integration.js.map +0 -1
  473. package/dist/simulation/scenarios/graph-traversal.d.ts +0 -17
  474. package/dist/simulation/scenarios/graph-traversal.d.ts.map +0 -1
  475. package/dist/simulation/scenarios/graph-traversal.js +0 -101
  476. package/dist/simulation/scenarios/graph-traversal.js.map +0 -1
  477. package/dist/simulation/scenarios/latent-space/attention-analysis.d.ts +0 -45
  478. package/dist/simulation/scenarios/latent-space/attention-analysis.d.ts.map +0 -1
  479. package/dist/simulation/scenarios/latent-space/attention-analysis.js +0 -435
  480. package/dist/simulation/scenarios/latent-space/attention-analysis.js.map +0 -1
  481. package/dist/simulation/scenarios/latent-space/clustering-analysis.d.ts +0 -55
  482. package/dist/simulation/scenarios/latent-space/clustering-analysis.d.ts.map +0 -1
  483. package/dist/simulation/scenarios/latent-space/clustering-analysis.js +0 -606
  484. package/dist/simulation/scenarios/latent-space/clustering-analysis.js.map +0 -1
  485. package/dist/simulation/scenarios/latent-space/hnsw-exploration.d.ts +0 -74
  486. package/dist/simulation/scenarios/latent-space/hnsw-exploration.d.ts.map +0 -1
  487. package/dist/simulation/scenarios/latent-space/hnsw-exploration.js +0 -391
  488. package/dist/simulation/scenarios/latent-space/hnsw-exploration.js.map +0 -1
  489. package/dist/simulation/scenarios/latent-space/hypergraph-exploration.d.ts +0 -51
  490. package/dist/simulation/scenarios/latent-space/hypergraph-exploration.d.ts.map +0 -1
  491. package/dist/simulation/scenarios/latent-space/hypergraph-exploration.js +0 -536
  492. package/dist/simulation/scenarios/latent-space/hypergraph-exploration.js.map +0 -1
  493. package/dist/simulation/scenarios/latent-space/index.d.ts +0 -35
  494. package/dist/simulation/scenarios/latent-space/index.d.ts.map +0 -1
  495. package/dist/simulation/scenarios/latent-space/index.js +0 -35
  496. package/dist/simulation/scenarios/latent-space/index.js.map +0 -1
  497. package/dist/simulation/scenarios/latent-space/neural-augmentation.d.ts +0 -52
  498. package/dist/simulation/scenarios/latent-space/neural-augmentation.d.ts.map +0 -1
  499. package/dist/simulation/scenarios/latent-space/neural-augmentation.js +0 -472
  500. package/dist/simulation/scenarios/latent-space/neural-augmentation.js.map +0 -1
  501. package/dist/simulation/scenarios/latent-space/quantum-hybrid.d.ts +0 -53
  502. package/dist/simulation/scenarios/latent-space/quantum-hybrid.d.ts.map +0 -1
  503. package/dist/simulation/scenarios/latent-space/quantum-hybrid.js +0 -391
  504. package/dist/simulation/scenarios/latent-space/quantum-hybrid.js.map +0 -1
  505. package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.d.ts +0 -52
  506. package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.d.ts.map +0 -1
  507. package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.js +0 -514
  508. package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.js.map +0 -1
  509. package/dist/simulation/scenarios/latent-space/traversal-optimization.d.ts +0 -53
  510. package/dist/simulation/scenarios/latent-space/traversal-optimization.d.ts.map +0 -1
  511. package/dist/simulation/scenarios/latent-space/traversal-optimization.js +0 -595
  512. package/dist/simulation/scenarios/latent-space/traversal-optimization.js.map +0 -1
  513. package/dist/simulation/scenarios/lean-agentic-swarm.d.ts +0 -18
  514. package/dist/simulation/scenarios/lean-agentic-swarm.d.ts.map +0 -1
  515. package/dist/simulation/scenarios/lean-agentic-swarm.js +0 -132
  516. package/dist/simulation/scenarios/lean-agentic-swarm.js.map +0 -1
  517. package/dist/simulation/scenarios/multi-agent-swarm.d.ts +0 -17
  518. package/dist/simulation/scenarios/multi-agent-swarm.d.ts.map +0 -1
  519. package/dist/simulation/scenarios/multi-agent-swarm.js +0 -111
  520. package/dist/simulation/scenarios/multi-agent-swarm.js.map +0 -1
  521. package/dist/simulation/scenarios/psycho-symbolic-reasoner.d.ts +0 -23
  522. package/dist/simulation/scenarios/psycho-symbolic-reasoner.d.ts.map +0 -1
  523. package/dist/simulation/scenarios/psycho-symbolic-reasoner.js +0 -98
  524. package/dist/simulation/scenarios/psycho-symbolic-reasoner.js.map +0 -1
  525. package/dist/simulation/scenarios/reflexion-learning.d.ts +0 -16
  526. package/dist/simulation/scenarios/reflexion-learning.d.ts.map +0 -1
  527. package/dist/simulation/scenarios/reflexion-learning.js +0 -98
  528. package/dist/simulation/scenarios/reflexion-learning.js.map +0 -1
  529. package/dist/simulation/scenarios/research-swarm.d.ts +0 -24
  530. package/dist/simulation/scenarios/research-swarm.d.ts.map +0 -1
  531. package/dist/simulation/scenarios/research-swarm.js +0 -146
  532. package/dist/simulation/scenarios/research-swarm.js.map +0 -1
  533. package/dist/simulation/scenarios/skill-evolution.d.ts +0 -16
  534. package/dist/simulation/scenarios/skill-evolution.d.ts.map +0 -1
  535. package/dist/simulation/scenarios/skill-evolution.js +0 -109
  536. package/dist/simulation/scenarios/skill-evolution.js.map +0 -1
  537. package/dist/simulation/scenarios/stock-market-emergence.d.ts +0 -33
  538. package/dist/simulation/scenarios/stock-market-emergence.d.ts.map +0 -1
  539. package/dist/simulation/scenarios/stock-market-emergence.js +0 -246
  540. package/dist/simulation/scenarios/stock-market-emergence.js.map +0 -1
  541. package/dist/simulation/scenarios/strange-loops.d.ts +0 -18
  542. package/dist/simulation/scenarios/strange-loops.d.ts.map +0 -1
  543. package/dist/simulation/scenarios/strange-loops.js +0 -133
  544. package/dist/simulation/scenarios/strange-loops.js.map +0 -1
  545. package/dist/simulation/scenarios/sublinear-solver.d.ts +0 -22
  546. package/dist/simulation/scenarios/sublinear-solver.d.ts.map +0 -1
  547. package/dist/simulation/scenarios/sublinear-solver.js +0 -82
  548. package/dist/simulation/scenarios/sublinear-solver.js.map +0 -1
  549. package/dist/simulation/scenarios/temporal-lead-solver.d.ts +0 -23
  550. package/dist/simulation/scenarios/temporal-lead-solver.d.ts.map +0 -1
  551. package/dist/simulation/scenarios/temporal-lead-solver.js +0 -90
  552. package/dist/simulation/scenarios/temporal-lead-solver.js.map +0 -1
  553. package/dist/simulation/scenarios/voting-system-consensus.d.ts +0 -27
  554. package/dist/simulation/scenarios/voting-system-consensus.d.ts.map +0 -1
  555. package/dist/simulation/scenarios/voting-system-consensus.js +0 -175
  556. package/dist/simulation/scenarios/voting-system-consensus.js.map +0 -1
  557. package/dist/simulation/types.d.ts +0 -162
  558. package/dist/simulation/types.d.ts.map +0 -1
  559. package/dist/simulation/types.js +0 -5
  560. package/dist/simulation/types.js.map +0 -1
  561. package/dist/simulation/utils/PerformanceOptimizer.d.ts +0 -115
  562. package/dist/simulation/utils/PerformanceOptimizer.d.ts.map +0 -1
  563. package/dist/simulation/utils/PerformanceOptimizer.js +0 -223
  564. package/dist/simulation/utils/PerformanceOptimizer.js.map +0 -1
  565. package/dist/src/backends/index.cjs +0 -6
  566. package/dist/src/backends/ruvector/GuardedVectorBackend.d.ts +0 -93
  567. package/dist/src/backends/ruvector/GuardedVectorBackend.d.ts.map +0 -1
  568. package/dist/src/backends/ruvector/GuardedVectorBackend.js +0 -182
  569. package/dist/src/backends/ruvector/GuardedVectorBackend.js.map +0 -1
  570. package/dist/src/consensus/RaftConsensus.d.ts +0 -220
  571. package/dist/src/consensus/RaftConsensus.d.ts.map +0 -1
  572. package/dist/src/consensus/RaftConsensus.js +0 -762
  573. package/dist/src/consensus/RaftConsensus.js.map +0 -1
  574. package/dist/src/controllers/HierarchicalMemory.d.ts +0 -197
  575. package/dist/src/controllers/HierarchicalMemory.d.ts.map +0 -1
  576. package/dist/src/controllers/HierarchicalMemory.js +0 -519
  577. package/dist/src/controllers/HierarchicalMemory.js.map +0 -1
  578. package/dist/src/controllers/MemoryConsolidation.d.ts +0 -142
  579. package/dist/src/controllers/MemoryConsolidation.d.ts.map +0 -1
  580. package/dist/src/controllers/MemoryConsolidation.js +0 -479
  581. package/dist/src/controllers/MemoryConsolidation.js.map +0 -1
  582. package/dist/src/controllers/QUICConnection.d.ts +0 -122
  583. package/dist/src/controllers/QUICConnection.d.ts.map +0 -1
  584. package/dist/src/controllers/QUICConnection.js +0 -329
  585. package/dist/src/controllers/QUICConnection.js.map +0 -1
  586. package/dist/src/controllers/QUICConnectionPool.d.ts +0 -83
  587. package/dist/src/controllers/QUICConnectionPool.d.ts.map +0 -1
  588. package/dist/src/controllers/QUICConnectionPool.js +0 -256
  589. package/dist/src/controllers/QUICConnectionPool.js.map +0 -1
  590. package/dist/src/controllers/QUICStreamManager.d.ts +0 -114
  591. package/dist/src/controllers/QUICStreamManager.d.ts.map +0 -1
  592. package/dist/src/controllers/QUICStreamManager.js +0 -267
  593. package/dist/src/controllers/QUICStreamManager.js.map +0 -1
  594. package/dist/src/controllers/StreamingEmbeddingService.d.ts +0 -82
  595. package/dist/src/controllers/StreamingEmbeddingService.d.ts.map +0 -1
  596. package/dist/src/controllers/StreamingEmbeddingService.js +0 -243
  597. package/dist/src/controllers/StreamingEmbeddingService.js.map +0 -1
  598. package/dist/src/controllers/index.cjs +0 -6
  599. package/dist/src/coordination/MultiDatabaseCoordinator.d.ts +0 -348
  600. package/dist/src/coordination/MultiDatabaseCoordinator.d.ts.map +0 -1
  601. package/dist/src/coordination/MultiDatabaseCoordinator.js +0 -803
  602. package/dist/src/coordination/MultiDatabaseCoordinator.js.map +0 -1
  603. package/dist/src/coordination/index.d.ts +0 -10
  604. package/dist/src/coordination/index.d.ts.map +0 -1
  605. package/dist/src/coordination/index.js +0 -10
  606. package/dist/src/coordination/index.js.map +0 -1
  607. package/dist/src/index.cjs +0 -6
  608. package/dist/src/optimizations/RVFOptimizer.d.ts +0 -226
  609. package/dist/src/optimizations/RVFOptimizer.d.ts.map +0 -1
  610. package/dist/src/optimizations/RVFOptimizer.js +0 -541
  611. package/dist/src/optimizations/RVFOptimizer.js.map +0 -1
  612. package/dist/src/security/AttestationLog.d.ts +0 -70
  613. package/dist/src/security/AttestationLog.d.ts.map +0 -1
  614. package/dist/src/security/AttestationLog.js +0 -174
  615. package/dist/src/security/AttestationLog.js.map +0 -1
  616. package/dist/src/security/MutationGuard.d.ts +0 -83
  617. package/dist/src/security/MutationGuard.d.ts.map +0 -1
  618. package/dist/src/security/MutationGuard.js +0 -364
  619. package/dist/src/security/MutationGuard.js.map +0 -1
  620. package/dist/src/security/index.cjs +0 -6
  621. package/dist/src/security/index.d.ts +0 -15
  622. package/dist/src/security/index.d.ts.map +0 -1
  623. package/dist/src/security/index.js +0 -18
  624. package/dist/src/security/index.js.map +0 -1
  625. package/dist/src/services/GNNService.d.ts +0 -173
  626. package/dist/src/services/GNNService.d.ts.map +0 -1
  627. package/dist/src/services/GNNService.js +0 -639
  628. package/dist/src/services/GNNService.js.map +0 -1
  629. package/dist/src/services/GraphTransformerService.d.ts +0 -80
  630. package/dist/src/services/GraphTransformerService.d.ts.map +0 -1
  631. package/dist/src/services/GraphTransformerService.js +0 -369
  632. package/dist/src/services/GraphTransformerService.js.map +0 -1
  633. package/dist/src/services/SemanticRouter.d.ts +0 -83
  634. package/dist/src/services/SemanticRouter.d.ts.map +0 -1
  635. package/dist/src/services/SemanticRouter.js +0 -160
  636. package/dist/src/services/SemanticRouter.js.map +0 -1
  637. package/dist/src/services/SonaTrajectoryService.d.ts +0 -224
  638. package/dist/src/services/SonaTrajectoryService.d.ts.map +0 -1
  639. package/dist/src/services/SonaTrajectoryService.js +0 -539
  640. package/dist/src/services/SonaTrajectoryService.js.map +0 -1
  641. package/dist/src/utils/LegacyAttentionAdapter.d.ts +0 -93
  642. package/dist/src/utils/LegacyAttentionAdapter.d.ts.map +0 -1
  643. package/dist/src/utils/LegacyAttentionAdapter.js +0 -241
  644. package/dist/src/utils/LegacyAttentionAdapter.js.map +0 -1
  645. package/dist/src/utils/vector-math.d.ts +0 -29
  646. package/dist/src/utils/vector-math.d.ts.map +0 -1
  647. package/dist/src/utils/vector-math.js +0 -66
  648. package/dist/src/utils/vector-math.js.map +0 -1
package/README.md CHANGED
@@ -1,344 +1,2940 @@
1
1
  # AgentDB v3
2
2
 
3
- > **Proof-gated graph intelligence for AI agents every mutation requires cryptographic proof**
3
+ > Intelligent agentic vector memory learns from experience, optimizes itself, runs anywhere
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/agentdb.svg?style=flat-square)](https://www.npmjs.com/package/agentdb)
6
6
  [![npm downloads](https://img.shields.io/npm/dm/agentdb.svg?style=flat-square)](https://www.npmjs.com/package/agentdb)
7
7
  [![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-green?style=flat-square)](LICENSE)
8
8
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
9
+ [![MCP Compatible](https://img.shields.io/badge/MCP-41%20tools-blueviolet?style=flat-square)](docs/guides/)
9
10
 
10
- AgentDB v3 is the first memory system built specifically for autonomous AI agents with **proof-gated mutations** — every state-changing operation requires a cryptographic proof before execution. Powered by `@ruvector/graph-transformer` with 8 verified graph modules, native Rust performance via NAPI-RS, and 82-byte attestations.
11
+ ---
12
+
13
+ ## What is AgentDB?
14
+
15
+ **AgentDB is a vector memory and database that gets smarter every time you use it.**
16
+
17
+ Most vector databases store and retrieve embeddings. AgentDB does that too — 150x faster — but it also watches which results your AI agent actually used, learns from that feedback, and returns better results next time. Search quality improves by up to **36% automatically**, with zero manual tuning.
18
+
19
+ Everything lives in a **single Cognitive Container** (`.rvf` file) — vectors, indexes, learning state, and a cryptographic audit trail. No external services. No API keys. No monthly bills.
20
+
21
+ > **3 lines to self-learning search:**
22
+ >
23
+ > ```typescript
24
+ > const backend = await SelfLearningRvfBackend.create({
25
+ > learning: true,
26
+ > storagePath: "./my.rvf",
27
+ > });
28
+ > const results = await backend.searchAsync(query, 10); // search
29
+ > backend.recordFeedback("q1", 0.9); // learn — next search is smarter
30
+ > ```
31
+
32
+ ### Who is it for?
33
+
34
+ | If you're building... | AgentDB gives you... |
35
+ | ---------------------------- | ------------------------------------------------------------------------------------------------- |
36
+ | **A RAG chatbot** | Search that learns which documents actually answer user questions |
37
+ | **A code review agent** | Pattern memory that remembers what worked across 1000s of reviews |
38
+ | **A research assistant** | Skill library that builds reusable tools from successful strategies |
39
+ | **An RL-powered agent** | 9 algorithms from Q-Learning to PPO, with bandit-guided algorithm selection and transfer learning |
40
+ | **A Claude Code / MCP tool** | 41 tools that plug in with one command |
41
+ | **An offline or edge app** | Full vector DB in the browser via WASM — no server needed |
42
+ | **An enterprise platform** | JWT auth, API key rotation, Argon2id hashing, SOC2/GDPR audit logs |
43
+
44
+ ---
45
+
46
+ ## Features
47
+
48
+ ### Intelligence
49
+
50
+ | | |
51
+ | ------------------------- | ---------------------------------------------------------------------------------------------------------------- |
52
+ | **Self-Learning Search** | Gets 36% better over time — learns from feedback, no manual tuning |
53
+ | **Cognitive Memory** | 6 human-inspired patterns: learn from mistakes, build reusable skills, discover what causes what |
54
+ | **Decision Intelligence** | Thompson Sampling bandit auto-tunes skill selection, pattern ranking, compression tiers, and RL algorithm choice |
55
+ | **9 RL Algorithms** | Q-Learning, SARSA, DQN, PPO, Actor-Critic, Policy Gradient, Decision Transformer, MCTS, Model-Based RL |
56
+ | **Hybrid Search** | BM25 keyword + vector with Reciprocal Rank Fusion — exact matches + semantic understanding |
57
+ | **Graph Intelligence** | Cypher queries, causal reasoning, GNN 8-head attention (+12.4% recall) |
58
+
59
+ ### Performance
60
+
61
+ | | |
62
+ | ----------------- | ---------------------------------------------------------------------------------- |
63
+ | **150x Faster** | 61us search with Rust+SIMD — 800x faster than Pinecone, 160x faster than Chroma |
64
+ | **4 Backends** | Auto-selects best available: RuVector (Rust) > RVF > HNSWLib (C++) > sql.js (WASM) |
65
+ | **Runs Anywhere** | Node.js, browsers (WASM), edge functions, fully offline |
66
+ | **AgentDBFast** | 50-200x faster programmatic API — skip CLI overhead for production workloads |
67
+
68
+ ### Storage & Data
69
+
70
+ | | |
71
+ | ----------------------------- | ------------------------------------------------------------------------------------------ |
72
+ | **Cognitive Container (RVF)** | Single `.rvf` file — vectors, index, learning state, SHAKE-256 witness chain |
73
+ | **COW Branching** | Instant copy-on-write branches for experiments, with full lineage tracking |
74
+ | **Compression** | 5-tier auto-tiering (hot/warm/cool/cold/archive), scalar 8-bit/4-bit, product quantization |
75
+ | **Metadata Filtering** | 10 MongoDB-style operators ($eq, $gt, $in, $contains, $exists, etc.) |
76
+
77
+ ### Integration & Tools
78
+
79
+ | | |
80
+ | ------------------ | ------------------------------------------------------------------------------------------ |
81
+ | **41 MCP Tools** | One command to connect to Claude Code, Cursor, or any MCP-compatible assistant |
82
+ | **Chat UI** | `@agentdb/chat` — deploy a self-learning RAG chatbot in one line |
83
+ | **LLM Router** | Auto-selects best provider: RuvLLM (local), OpenRouter (200+ models), Gemini, Claude, ONNX |
84
+ | **Real-Time Sync** | QUIC transport, multi-instance replication, 4 conflict resolution strategies |
85
+
86
+ ### Enterprise & Security
87
+
88
+ | | |
89
+ | ----------------- | ------------------------------------------------------------------------------------------- |
90
+ | **Auth & Audit** | JWT tokens, Argon2id hashing, API key rotation, SOC2/GDPR/HIPAA logging |
91
+ | **Security** | Input validation, XSS/injection prevention, Cypher sanitization, witness chain verification |
92
+ | **Observability** | OpenTelemetry traces, Prometheus metrics, structured logging |
93
+ | **Benchmarking** | 5 built-in benchmarks, custom benchmark classes, Markdown/JSON reports |
94
+
95
+ > **Zero config, zero cost.** `npm install agentdb` and go — fully local, no API keys, no cloud fees.
96
+
97
+ ### Install
98
+
99
+ ```bash
100
+ npm install agentdb # Latest stable (v2)
101
+ npm install agentdb@alpha # Latest alpha (v3 — unified .rvf, self-learning, SolverBandit)
102
+ ```
103
+
104
+ **Zero native dependencies.** AgentDB uses sql.js (WASM SQLite) — no Python, no C++ compiler, no `node-gyp`. Works on Windows, macOS, Linux, and CI containers out of the box. `better-sqlite3` is supported as an optional performance upgrade but never required.
105
+
106
+ ---
107
+
108
+ ## 🧠 Agent Memory Intelligence
109
+
110
+ AgentDB v3.0.0-alpha.6 introduces revolutionary **sparse attention** and **graph partitioning** capabilities that enable AI agents to handle massive knowledge graphs with 10-100x performance improvements.
111
+
112
+ ### Memory-Oriented Architecture
113
+
114
+ AgentDB is designed as an **agent memory substrate** - a persistent, intelligent memory layer that agents can query, update, and learn from:
115
+
116
+ **Core Memory Capabilities**:
117
+ - 🎯 **Sparse Attention** - 10-100x speedup for large graphs using PPR, random walk, spectral sparsification
118
+ - 📊 **Graph Partitioning** - 50-80% memory reduction with Stoer-Wagner, Karger, flow-based mincut
119
+ - ⚡ **Fused Attention** - 10-50x faster kernel fusion (exceeded 20-25% target by 40x!)
120
+ - 🔍 **Zero-Copy Indexing** - 90% fewer allocations, 40-50% speedup
121
+ - 🏗️ **Clean Architecture** - 6 focused classes replacing 782-line god object
122
+
123
+ ### Agent Memory Pattern
124
+
125
+ ```typescript
126
+ import { SparsificationService, MincutService, AttentionService } from 'agentdb';
127
+
128
+ // Initialize agent memory layer
129
+ const memory = new AttentionService();
130
+ await memory.initialize();
131
+
132
+ // Sparse attention for agent memory retrieval (10-100x faster)
133
+ const relevantMemories = await memory.sparseAttention(
134
+ agentQuery,
135
+ memoryGraph,
136
+ {
137
+ method: 'ppr', // Personalized PageRank
138
+ topK: 50, // Top 50 most relevant
139
+ sparsificationRatio: 0.1 // Keep 10% of edges
140
+ }
141
+ );
142
+
143
+ // Partitioned attention for distributed agent teams
144
+ const teamMemories = await memory.partitionedAttention(
145
+ teamQuery,
146
+ sharedKnowledge,
147
+ {
148
+ method: 'stoer-wagner', // Optimal partitioning
149
+ maxPartitionSize: 1000 // Max 1000 nodes per partition
150
+ }
151
+ );
152
+
153
+ // Fused attention for rapid memory access (10-50x faster)
154
+ const fastAccess = await memory.fusedAttention(
155
+ query,
156
+ keys,
157
+ values
158
+ );
159
+ ```
160
+
161
+ ### Performance Metrics
162
+
163
+ | Operation | Before | After | Improvement |
164
+ |-----------|--------|-------|-------------|
165
+ | Sparse Attention (N=10K) | 1000ms | 10-100ms | **10-100x** |
166
+ | Memory Reduction | 100% | 20-50% | **50-80% less** |
167
+ | Fused Attention | 1010ms | 21ms | **49x faster** |
168
+ | Allocations | 100% | 10% | **90% fewer** |
169
+
170
+ ### Use Cases
171
+
172
+ **Agent Episodic Memory**:
173
+ ```typescript
174
+ // Store agent experiences as sparse graphs
175
+ await sparsification.sparseByPPR(experienceGraph, {
176
+ alpha: 0.15,
177
+ topK: 100
178
+ });
179
+ ```
180
+
181
+ **Multi-Agent Knowledge Sharing**:
182
+ ```typescript
183
+ // Partition knowledge for team collaboration
184
+ const partitions = await mincut.computeStoerWagner(teamKnowledge);
185
+ ```
186
+
187
+ **Rapid Context Retrieval**:
188
+ ```typescript
189
+ // Fused attention for instant memory access
190
+ const context = await attention.fusedAttention(Q, K, V);
191
+ ```
192
+
193
+ ---
194
+ ## Comparison
195
+
196
+ > **61 microseconds.** That's 800x faster than Pinecone, 160x faster than Chroma, and the only vector database that learns from your usage and gets better over time.
197
+
198
+ ### vs. Other Vector Databases
199
+
200
+ #### Intelligence
201
+
202
+ | Feature | AgentDB v3 | Pinecone | Chroma | Weaviate | pgvector |
203
+ | ---------------------- | --------------------------------------- | -------- | ------ | --------- | -------- |
204
+ | Self-learning pipeline | SONA + contrastive + federated + bandit | No | No | No | No |
205
+ | Reinforcement learning | 9 algorithms (Q-Learning to MCTS) | No | No | No | No |
206
+ | Cognitive memory | 6 patterns | No | No | No | No |
207
+ | Hybrid search | BM25 + vector (RRF fusion) | No | No | BM25 only | No |
208
+ | Graph queries | Cypher | No | No | GraphQL | No |
209
+
210
+ #### Performance & Deployment
211
+
212
+ | Feature | AgentDB v3 | Pinecone | Chroma | Weaviate | pgvector |
213
+ | -------------- | ---------- | -------- | ------ | -------- | -------- |
214
+ | Search latency | **61us** | ~50ms | ~10ms | ~5ms | ~2ms |
215
+ | Runs offline | Full | No | Yes | Yes | Yes |
216
+ | Browser (WASM) | Yes | No | No | No | No |
217
+
218
+ #### Storage
219
+
220
+ | Feature | AgentDB v3 | Pinecone | Chroma | Weaviate | pgvector |
221
+ | ------------------- | ---------------------------------- | -------- | ------ | -------- | -------- |
222
+ | Cognitive Container | Single `.rvf` file + COW branching | No | No | No | No |
223
+ | Monthly cost | **$0** | $70+ | $0 | $0+ | $0+ |
224
+
225
+ #### Integration & Security
226
+
227
+ | Feature | AgentDB v3 | Pinecone | Chroma | Weaviate | pgvector |
228
+ | --------------- | -------------------------------- | ---------- | ------ | --------- | -------- |
229
+ | MCP integration | 41 tools | No | No | No | No |
230
+ | Auth & audit | JWT + Argon2id + compliance logs | No | No | No | No |
231
+ | Local-first | Yes | Cloud only | Yes | Self-host | Postgres |
232
+
233
+ ### Backend Performance
234
+
235
+ | Backend | Latency | Recall@10 | Native | Best For |
236
+ | ----------------------------- | ------- | --------- | ------ | ---------------------------- |
237
+ | **RuVector** (Rust + SIMD) | 61us | 96.8% | Yes | Production, high throughput |
238
+ | **Cognitive Container** (RVF) | ~100us | 96.8% | Yes | Portable, branching, lineage |
239
+ | **HNSWLib** (C++) | ~500us | 95%+ | Yes | Compatibility |
240
+ | **sql.js** (WASM) | ~5ms | 90%+ | No | Zero-dependency fallback |
241
+
242
+ AgentDB auto-selects the best available: RuVector > Cognitive Container (RVF) > HNSWLib > sql.js
243
+
244
+ ---
245
+
246
+ ## Quick Start
247
+
248
+ ```bash
249
+ npm install agentdb
250
+ ```
251
+
252
+ ### Unified AgentDB (recommended)
253
+
254
+ The `AgentDB` class is the simplest way to use AgentDB. Everything — vectors, relational data, learning state — lives in a single `.rvf` file:
255
+
256
+ ```typescript
257
+ import { AgentDB } from "agentdb";
258
+
259
+ const db = new AgentDB({ dbPath: "./knowledge.rvf" });
260
+ await db.initialize();
261
+
262
+ // All controllers are ready — reflexion memory, skill library, causal graph
263
+ const reflexion = db.getController("reflexion");
264
+ const skills = db.getController("skills");
265
+ const causal = db.getController("causal");
266
+
267
+ // Store an episode
268
+ await reflexion.storeEpisode({
269
+ sessionId: "session-1",
270
+ task: "Fix auth bug",
271
+ reward: 0.95,
272
+ success: true,
273
+ critique: "OAuth2 PKCE was the right approach",
274
+ });
275
+
276
+ // Create a reusable skill
277
+ await skills.createSkill({
278
+ name: "jwt_auth",
279
+ description: "JWT authentication with refresh tokens",
280
+ code: "implementation...",
281
+ successRate: 0.92,
282
+ });
283
+
284
+ // Save everything to one file and close
285
+ await db.save();
286
+ await db.close();
287
+ ```
288
+
289
+ **Configuration options:**
290
+
291
+ | Option | Default | Description |
292
+ | ----------------- | ------------ | ------------------------------------------------------------------------------------------ |
293
+ | `dbPath` | `':memory:'` | Path to `.rvf` file (or `.db` for legacy mode) |
294
+ | `vectorBackend` | `'rvf'` | Backend: `'rvf'` (unified), `'auto'`, `'ruvector'`, `'hnswlib'` |
295
+ | `vectorDimension` | `384` | Embedding dimension (384 for MiniLM, 768 for bge-base) |
296
+ | `forceWasm` | `false` | Force sql.js WASM backend (sql.js is the default; `better-sqlite3` used only if installed) |
297
+ | `enableAttention` | `false` | Enable GNN attention mechanisms |
298
+
299
+ **Controllers:** `db.getController('reflexion')` (ReflexionMemory), `db.getController('skills')` (SkillLibrary), `db.getController('causal')` (CausalMemoryGraph)
300
+
301
+ ### CLI — try it in 10 seconds
302
+
303
+ ```bash
304
+ npx agentdb init # Initialize a new database
305
+ npx agentdb doctor # Check system health
306
+ npx agentdb rvf status ./store.rvf # Inspect a Cognitive Container
307
+ npx agentdb rvf derive ./prod.rvf ./experiment.rvf # Branch for experiments (instant, COW)
308
+ npx agentdb mcp start # Start MCP server (41 tools)
309
+ npx @agentdb/chat serve --rvf ./kb.rvf --port 3000 # Launch chat UI
310
+ ```
311
+
312
+ <details>
313
+ <summary><strong>Complete CLI Reference</strong> — 60+ commands across 8 categories</summary>
314
+
315
+ #### Core
316
+
317
+ ```bash
318
+ npx agentdb init # Initialize database
319
+ npx agentdb status # System status and diagnostics
320
+ npx agentdb doctor [--fix] [--verbose] # Health check with auto-fix
321
+ ```
322
+
323
+ #### Cognitive Container (RVF) Management
324
+
325
+ ```bash
326
+ npx agentdb rvf status ./store.rvf # Container statistics
327
+ npx agentdb rvf compact ./store.rvf # Reclaim space
328
+ npx agentdb rvf derive ./src.rvf ./dst.rvf # COW branch
329
+ npx agentdb rvf segments ./store.rvf # Segment introspection
330
+ npx agentdb rvf detect # SDK availability
331
+ ```
332
+
333
+ #### Learning & Training
334
+
335
+ ```bash
336
+ npx agentdb learn --session <id> --train # Train a learning session
337
+ npx agentdb learn --status # Learning system status
338
+ ```
339
+
340
+ #### Routing
341
+
342
+ ```bash
343
+ npx agentdb route --query "search term" # Test semantic routing
344
+ npx agentdb route --list # Show learned intents
345
+ ```
346
+
347
+ #### Attention & Hyperbolic
348
+
349
+ ```bash
350
+ npx agentdb attention --benchmark # Attention performance test
351
+ npx agentdb hyperbolic --test # Hyperbolic embedding test
352
+ ```
353
+
354
+ #### Simulation
355
+
356
+ ```bash
357
+ npx agentdb simulate hnsw --iterations 3 # HNSW optimization
358
+ npx agentdb simulate attention --iterations 3 # GNN attention
359
+ npx agentdb simulate self-organizing --days 30 # Self-healing
360
+ npx agentdb simulate --wizard # Interactive wizard
361
+ npx agentdb simulate --custom ./my-scenario.json # Custom simulation
362
+ npx agentdb simulate --report ./output.md # Generate report
363
+ ```
364
+
365
+ #### Migration & Import
366
+
367
+ ```bash
368
+ npx agentdb migrate --source ./old.db --target ./new.db # Full v1→v2 migration
369
+ npx agentdb migrate --source ./v2.db --to v3 --rvf-path ./unified.rvf # v2→v3 unified .rvf
370
+ npx agentdb migrate --to rvf --rvf-path ./out.rvf # Export to Cognitive Container
371
+ npx agentdb migrate --dry-run --verbose # Preview changes
372
+ ```
373
+
374
+ #### MCP Server
375
+
376
+ ```bash
377
+ npx agentdb mcp start # Start MCP server (41 tools)
378
+ npx agentdb mcp start --port 8080 # Custom port
379
+ ```
380
+
381
+ </details>
382
+
383
+ ### Self-Learning Vector Search (the differentiator)
384
+
385
+ Most vector databases return the same results no matter how many times you query them. AgentDB closes the loop: after every search, you tell it which results were actually useful. A contrastive trainer (InfoNCE + hard-negative mining) adjusts a lightweight LoRA adapter in under 1 ms, and EWC++ consolidation keeps old knowledge intact. Over 500 feedback cycles, recall jumps from 54% to 90% — automatically.
386
+
387
+ ```typescript
388
+ import { SelfLearningRvfBackend } from "agentdb/backends/rvf/SelfLearningRvfBackend";
389
+
390
+ // Create a self-learning Cognitive Container
391
+ const backend = await SelfLearningRvfBackend.create({
392
+ dimension: 384,
393
+ metric: "cosine",
394
+ storagePath: "./knowledge.rvf",
395
+ learning: true, // enable the learning pipeline
396
+ });
397
+
398
+ // Insert documents
399
+ await backend.insertAsync("doc-1", embedding, { title: "Auth Guide" });
400
+ await backend.insertAsync("doc-2", embedding2, { title: "API Reference" });
401
+
402
+ // Search — automatically routed through the learning pipeline
403
+ const results = await backend.searchAsync(queryEmbedding, 10);
404
+
405
+ // Tell AgentDB which results were useful — this drives learning
406
+ backend.recordFeedback("query-1", 0.95); // great result
407
+ backend.recordFeedback("query-2", 0.2); // poor result
408
+
409
+ // Run a learning tick — trains the model, updates adapters
410
+ await backend.tick();
411
+ // Next search will be smarter based on your feedback
412
+ ```
413
+
414
+ ### Cognitive Memory (pattern learning)
415
+
416
+ Store and retrieve reasoning patterns — your agent remembers what worked:
417
+
418
+ ```typescript
419
+ import { createDatabase, ReasoningBank, EmbeddingService } from "agentdb";
420
+
421
+ const db = await createDatabase("./agent-memory.db");
422
+ const embedder = new EmbeddingService({ model: "Xenova/all-MiniLM-L6-v2" });
423
+ await embedder.initialize();
424
+
425
+ const reasoningBank = new ReasoningBank(db, embedder);
426
+
427
+ // Store what your agent learned
428
+ await reasoningBank.storePattern({
429
+ taskType: "code_review",
430
+ approach: "Security-first analysis",
431
+ successRate: 0.95,
432
+ });
433
+
434
+ // Find similar successful patterns
435
+ const patterns = await reasoningBank.searchPatterns({
436
+ task: "security code review",
437
+ k: 10,
438
+ });
439
+ ```
440
+
441
+ ### Unified Mode — Everything in One File
442
+
443
+ In v3, `AgentDB` stores vectors, relational data, learning state, and metadata in a single `.rvf` file:
444
+
445
+ ```typescript
446
+ import { AgentDB } from "agentdb";
447
+
448
+ // Single-file mode is the default — no configuration needed
449
+ const db = new AgentDB({ dbPath: "./agent.rvf" });
450
+ await db.initialize();
451
+
452
+ // Access the underlying database for advanced queries
453
+ const raw = db.database;
454
+ const stats = raw.prepare("SELECT COUNT(*) as c FROM episodes").get();
455
+
456
+ // Check mode
457
+ console.log(db.isUnifiedMode); // true — everything in one .rvf file
458
+ console.log(db.vectorBackendName); // 'rvf'
459
+
460
+ // Save and reopen — all data persists in agent.rvf
461
+ await db.save();
462
+ await db.close();
463
+
464
+ const db2 = new AgentDB({ dbPath: "./agent.rvf" });
465
+ await db2.initialize(); // All episodes, skills, vectors restored
466
+ ```
467
+
468
+ ### Chat UI (one-line deployment)
469
+
470
+ Deploy a self-learning RAG chatbot over any Cognitive Container:
471
+
472
+ ```bash
473
+ npx @agentdb/chat serve --rvf ./kb.rvf --port 3000
474
+ ```
475
+
476
+ ---
477
+
478
+ ## How the Learning Loop Works
479
+
480
+ Every search automatically triggers a learning cycle. No configuration needed — just call `recordFeedback()` after using results:
481
+
482
+ ```mermaid
483
+ graph LR
484
+ A["Your Query"] --> B["Semantic Router<br/>classifies intent"]
485
+ B --> C["Embedding Adapter<br/>adjusts in <1ms"]
486
+ C --> D["HNSW Search<br/>61us, 96.8% recall"]
487
+ D --> E["Results"]
488
+ E --> F["Your Feedback<br/>0.0 - 1.0"]
489
+ F --> G["Contrastive Trainer<br/>learns what's good"]
490
+ G --> C
491
+ style G fill:#2d6,stroke:#1a4,color:#fff
492
+ style A fill:#36f,stroke:#24d,color:#fff
493
+ ```
494
+
495
+ > **Result:** Over 10 sessions with 50 episodes each, search quality improved from 54% to 90% — a 36% gain with zero manual tuning.
496
+
497
+ ## Architecture
498
+
499
+ ```mermaid
500
+ graph TD
501
+ A[Your Application] --> B[AgentDB Core]
502
+ B --> C[Cognitive Memory<br/>6 patterns]
503
+ B --> D[Self-Learning Pipeline<br/>SONA + Contrastive + Federated]
504
+ B --> E[Backend Auto-Selection]
505
+ E --> F[RuVector<br/>Rust+SIMD 61us]
506
+ E --> G[Cognitive Container<br/>RVF single-file COW]
507
+ E --> H[HNSWLib<br/>C++ HNSW]
508
+ E --> I[sql.js<br/>WASM fallback]
509
+ B --> J[NativeAccelerator<br/>15 capability groups]
510
+ B --> K[MCP Server<br/>41 tools]
511
+ B --> L[Graph Intelligence<br/>Cypher + GNN]
512
+ ```
513
+
514
+ ---
515
+
516
+ ## MCP Integration
517
+
518
+ > **One command** to give any AI assistant access to self-learning vector search, cognitive memory, and 37 specialized tools.
519
+
520
+ Connect AgentDB to Claude Code, Cursor, or any MCP-compatible AI assistant:
521
+
522
+ ```bash
523
+ claude mcp add agentdb npx agentdb mcp start
524
+ ```
525
+
526
+ Or add to `~/.config/claude/claude_desktop_config.json`:
527
+
528
+ ```json
529
+ {
530
+ "mcpServers": {
531
+ "agentdb": {
532
+ "command": "npx",
533
+ "args": ["agentdb", "mcp", "start"],
534
+ "env": { "AGENTDB_PATH": "./agentdb.rvf" }
535
+ }
536
+ }
537
+ }
538
+ ```
539
+
540
+ ### MCP Tools Overview
541
+
542
+ | Category | Tools | Examples |
543
+ | ------------ | ----- | ------------------------------------------------------------------------------------------------ |
544
+ | **Core DB** | 6 | init, insert, batch insert, search, delete, stats |
545
+ | **Patterns** | 4 | store, search, batch store, statistics |
546
+ | **Memory** | 9 | reflexion store/retrieve/batch, skill create/search/batch, causal edges/queries, nightly learner |
547
+ | **Learning** | 10 | RL sessions, predictions, feedback, training, transfer learning, explainability |
548
+ | **Recall** | 2 | explainable recall with provenance certificates, cache management |
549
+ | **Solver** | 4 | solver train, acceptance testing, policy inspection, witness chain audit |
550
+ | **Admin** | 6 | diagnostics, migration, pruning, experience recording, reward signals, legacy stats |
551
+
552
+ All 41 tools support parallel execution markers, batch operations, intelligent caching, and format parameters for token reduction.
553
+
554
+ ---
555
+
556
+ ## Chat Ecosystem
557
+
558
+ The `@agentdb/chat` package provides a one-line chat UI with self-learning RAG built on top of AgentDB:
559
+
560
+ ```bash
561
+ # Serve a chat interface over your knowledge base
562
+ npx @agentdb/chat serve --rvf ./kb.rvf --port 3000
563
+ ```
564
+
565
+ Programmatic usage:
566
+
567
+ ```typescript
568
+ import { createChatServer } from "@agentdb/chat";
569
+
570
+ const server = await createChatServer("./kb.rvf", {
571
+ port: 3000,
572
+ learning: true,
573
+ });
574
+ ```
575
+
576
+ The chat ecosystem includes:
577
+
578
+ - **Chat Server** — streaming inference with any LLM provider
579
+ - **Chat Persistence** — conversation history stored in Cognitive Containers
580
+ - **MCP Bridge** — expose all 37 AgentDB tools through chat
581
+ - **Chat UI** (`@agentdb/chat-ui`) — SvelteKit frontend with real-time tool invocation
582
+
583
+ See the [@agentdb/chat README](../agentdb-chat/README.md) for full documentation.
584
+
585
+ ---
586
+
587
+ ## Deep Dives
588
+
589
+ > Expand any section below for code examples, configuration, and architecture details.
590
+
591
+ **Getting Started** | [Guides](#guides) | [Tutorials](#tutorials) | [Advanced Usage](#advanced-usage)
592
+
593
+ **Intelligence & Learning** | [Self-Learning Pipeline](#self-learning-pipeline) | [Cognitive Memory](#cognitive-memory-patterns) | [Reinforcement Learning](#reinforcement-learning) | [Hybrid Search](#hybrid-search) | [Graph Intelligence](#graph-intelligence) | [Query Lifecycle](#query-lifecycle)
594
+
595
+ **Performance & Architecture** | [SIMD Acceleration](#simd--native-acceleration) | [Browser & WASM](#browser--wasm-deployment) | [Benchmarks](#performance--benchmarks) | [AgentDBFast](#agentdbfast) | [Benchmark Suite](#benchmark-suite)
596
+
597
+ **Storage & Data** | [Cognitive Container (RVF)](#cognitive-container-rvf-format) | [Quantization](#quantization--compression) | [Metadata Filtering](#metadata-filtering)
598
+
599
+ **Integration & Tools** | [LLM Router](#llm-router) | [Model Import/Export](#model-importexport--embedding-models) | [Multi-Database Sync](#multi-database-coordination) | [Real-Time Sync](#real-time-sync-quic)
600
+
601
+ **Enterprise & Security** | [Security](#security) | [Auth & Audit](#auth--audit) | [Observability](#observability)
602
+
603
+ ---
604
+
605
+ ### Getting Started
606
+
607
+ Step-by-step guides, tutorials, and advanced configuration for every skill level.
608
+
609
+ <details>
610
+ <summary><strong>Guides</strong> — backend selection, migration, health checks, federated learning</summary>
611
+
612
+ #### Backend Selection
613
+
614
+ ```bash
615
+ # Auto-detect best backend (recommended)
616
+ npx agentdb init --backend auto
617
+
618
+ # Force RuVector (fastest, requires native bindings)
619
+ npx agentdb init --backend ruvector
620
+
621
+ # Force Cognitive Container (single-file, portable)
622
+ npx agentdb init --backend rvf --rvf-path ./vectors.rvf
623
+
624
+ # Force HNSWLib (C++ HNSW)
625
+ npx agentdb init --backend hnswlib
626
+ ```
627
+
628
+ #### Migration
629
+
630
+ ```bash
631
+ # Migrate v1 → v2
632
+ npx agentdb migrate --source ./old.db --target ./new.db
633
+
634
+ # Migrate v2 → v3 unified .rvf (same schemas, data copy)
635
+ npx agentdb migrate --source ./v2.db --to v3 --rvf-path ./unified.rvf
636
+
637
+ # Export to Cognitive Container
638
+ npx agentdb migrate --to rvf --rvf-path ./vectors.rvf
639
+
640
+ # Dry-run migration
641
+ npx agentdb migrate --dry-run --verbose
642
+ ```
643
+
644
+ #### Health Checks
645
+
646
+ ```bash
647
+ # Full diagnostic
648
+ npx agentdb doctor --verbose
649
+
650
+ # Check specific Cognitive Container
651
+ npx agentdb doctor --rvf-path ./vectors.rvf
652
+
653
+ # Auto-fix issues
654
+ npx agentdb doctor --fix
655
+ ```
656
+
657
+ #### Federated Learning Setup
658
+
659
+ Configure cross-session federated learning for continuous improvement:
660
+
661
+ ```typescript
662
+ import {
663
+ FederatedLearningCoordinator,
664
+ EphemeralLearningAgent,
665
+ } from "agentdb/services/federated-learning";
666
+
667
+ const coordinator = new FederatedLearningCoordinator({
668
+ agentId: "coordinator-1",
669
+ minQuality: 0.7,
670
+ maxAgents: 100,
671
+ });
672
+
673
+ const agent = new EphemeralLearningAgent({
674
+ agentId: "session-agent-1",
675
+ qualityFiltering: true,
676
+ });
677
+
678
+ const state = agent.exportState();
679
+ await coordinator.aggregate(state);
680
+ const merged = await coordinator.consolidate();
681
+ ```
682
+
683
+ </details>
684
+
685
+ ---
686
+
687
+ <details>
688
+ <summary><strong>Tutorials</strong> — 6 step-by-step walkthroughs from beginner to advanced</summary>
689
+
690
+ #### Tutorial 1: Build a Learning Code Review Agent
691
+
692
+ ```typescript
693
+ import {
694
+ createDatabase,
695
+ ReasoningBank,
696
+ ReflexionMemory,
697
+ EmbeddingService,
698
+ } from "agentdb";
699
+
700
+ const db = await createDatabase("./code-reviewer.db");
701
+ const embedder = new EmbeddingService({ model: "Xenova/all-MiniLM-L6-v2" });
702
+ await embedder.initialize();
703
+
704
+ const reasoningBank = new ReasoningBank(db, embedder);
705
+ const reflexion = new ReflexionMemory(db, embedder);
706
+
707
+ await reasoningBank.storePattern({
708
+ taskType: "code_review",
709
+ approach: "Security scan > Type safety > Code quality > Performance",
710
+ successRate: 0.94,
711
+ });
712
+
713
+ const result = await performCodeReview(code);
714
+ await reflexion.storeEpisode({
715
+ sessionId: "review-1",
716
+ task: "Review authentication PR",
717
+ reward: result.issuesFound > 0 ? 0.9 : 0.6,
718
+ success: true,
719
+ critique: "Found SQL injection — security checks work!",
720
+ input: code,
721
+ output: result.findings,
722
+ });
723
+
724
+ const pastReviews = await reflexion.retrieveRelevant({
725
+ task: "authentication code review",
726
+ k: 5,
727
+ onlySuccesses: true,
728
+ });
729
+ ```
730
+
731
+ #### Tutorial 2: RAG with Self-Learning Skills
732
+
733
+ ```typescript
734
+ import { createDatabase, SkillLibrary, EmbeddingService } from "agentdb";
735
+
736
+ const db = await createDatabase("./rag-system.db");
737
+ const embedder = new EmbeddingService({ model: "Xenova/all-MiniLM-L6-v2" });
738
+ await embedder.initialize();
739
+
740
+ const skills = new SkillLibrary(db, embedder);
741
+
742
+ await skills.createSkill({
743
+ name: "expand_query",
744
+ description: "Expand user query with domain-specific synonyms",
745
+ signature: { inputs: { query: "string" }, outputs: { expanded: "string[]" } },
746
+ code: `const map = { 'bug': ['issue', 'defect', 'error'] }; ...`,
747
+ successRate: 0.92,
748
+ });
749
+
750
+ const applicable = await skills.searchSkills({
751
+ task: "find technical documentation",
752
+ k: 10,
753
+ });
754
+ ```
755
+
756
+ #### Tutorial 3: Run Latent Space Simulations
757
+
758
+ ```bash
759
+ npx agentdb simulate hnsw --iterations 3
760
+ npx agentdb simulate attention --iterations 3
761
+ npx agentdb simulate self-organizing --days 30
762
+ npx agentdb simulate --wizard
763
+ ```
764
+
765
+ #### Tutorial 4: Cognitive Container Branching
766
+
767
+ ```typescript
768
+ import { RvfBackend } from "agentdb/backends/rvf/RvfBackend";
769
+
770
+ const main = new RvfBackend({
771
+ dimension: 384,
772
+ metric: "cosine",
773
+ storagePath: "./main.rvf",
774
+ });
775
+ await main.initialize();
776
+ await main.insertAsync("doc-1", embedding1, { source: "production" });
777
+ await main.flush();
778
+
779
+ // Branch for experiment (copy-on-write, near-instant)
780
+ const experiment = await main.derive("./experiment.rvf");
781
+ await experiment.insertAsync("doc-exp-1", experimentEmbedding);
782
+ console.log(`Lineage depth: ${await experiment.lineageDepth()}`);
783
+ ```
784
+
785
+ #### Tutorial 5: Self-Learning RAG Pipeline
786
+
787
+ ```typescript
788
+ import { SelfLearningRvfBackend } from "agentdb/backends/rvf/SelfLearningRvfBackend";
789
+
790
+ const backend = await SelfLearningRvfBackend.create({
791
+ dimension: 384,
792
+ metric: "cosine",
793
+ storagePath: "./rag-vectors.rvf",
794
+ learning: true,
795
+ federated: true,
796
+ });
797
+
798
+ for (const doc of documents) {
799
+ await backend.insertAsync(doc.id, doc.embedding, { title: doc.title });
800
+ }
801
+
802
+ const results = await backend.searchAsync(queryEmbedding, 10);
803
+ backend.recordFeedback("query-1", 0.95);
804
+ await backend.tick();
805
+ ```
806
+
807
+ #### Tutorial 6: Chat UI with Custom Knowledge Base
808
+
809
+ ```bash
810
+ npx agentdb init --backend rvf --rvf-path ./docs.rvf
811
+ npx agentdb import ./docs/ --rvf-path ./docs.rvf
812
+ npx @agentdb/chat serve --rvf ./docs.rvf --port 3000
813
+ ```
814
+
815
+ </details>
816
+
817
+ ---
818
+
819
+ <details>
820
+ <summary><strong>Advanced Usage</strong> — batch ops, caching, solver tuning, GNN training, context synthesis</summary>
821
+
822
+ #### Batch Operations
823
+
824
+ ```typescript
825
+ import { BatchOperations } from "agentdb/optimizations/BatchOperations";
826
+
827
+ const batchOps = new BatchOperations(db, embedder, {
828
+ batchSize: 100,
829
+ parallelism: 4,
830
+ progressCallback: (done, total) => console.log(`${done}/${total}`),
831
+ });
832
+
833
+ await batchOps.insertSkills([...skills]);
834
+ await batchOps.insertEpisodes([...episodes]);
835
+ await batchOps.insertPatterns([...patterns]);
836
+ ```
837
+
838
+ #### Custom Backend Selection
839
+
840
+ ```typescript
841
+ import { createBackend, detectBackends } from "agentdb/backends/factory";
842
+
843
+ const detection = await detectBackends();
844
+ // { ruvector: { available, native, gnn }, rvf: { sdk, node, wasm }, hnswlib: { available } }
845
+
846
+ const backend = await createBackend({
847
+ type: "rvf",
848
+ dimension: 384,
849
+ metric: "cosine",
850
+ storagePath: "./vectors.rvf",
851
+ });
852
+ ```
853
+
854
+ #### Adaptive Index Tuning
855
+
856
+ ```typescript
857
+ import { AgentDBSolver } from "agentdb/backends/rvf/RvfSolver";
858
+
859
+ const solver = await AgentDBSolver.create();
860
+ const trainResult = solver.train({
861
+ count: 50,
862
+ minDifficulty: 1,
863
+ maxDifficulty: 10,
864
+ });
865
+ const policy = solver.policy();
866
+ // 18 context buckets (3 range x 3 distractor x 2 noise)
867
+ ```
868
+
869
+ #### Federated Session Manager
870
+
871
+ ```typescript
872
+ import {
873
+ FederatedLearningCoordinator,
874
+ EphemeralLearningAgent,
875
+ } from "agentdb/services/federated-learning";
876
+
877
+ const coordinator = new FederatedLearningCoordinator({
878
+ agentId: "coord-main",
879
+ minQuality: 0.7,
880
+ maxAgents: 100,
881
+ });
882
+ const sessionAgent = new EphemeralLearningAgent({
883
+ agentId: `session-${Date.now()}`,
884
+ qualityFiltering: true,
885
+ });
886
+
887
+ await sessionAgent.processTask(embedding, 0.9);
888
+ const state = sessionAgent.exportState();
889
+ await coordinator.aggregate(state);
890
+ const merged = await coordinator.consolidate();
891
+ ```
892
+
893
+ #### Context Synthesizer
894
+
895
+ ```typescript
896
+ import { ContextSynthesizer } from "agentdb/controllers/ContextSynthesizer";
897
+
898
+ const synthesizer = new ContextSynthesizer();
899
+ const context = await synthesizer.synthesize(memories);
900
+ // { summary, patterns, successRate, averageReward, recommendations, keyInsights }
901
+ ```
902
+
903
+ #### GNN Learning Backend
904
+
905
+ ```typescript
906
+ import { LearningBackend } from "agentdb/backends/LearningBackend";
907
+
908
+ const learner = new LearningBackend({ dimension: 384 });
909
+ const enhanced = learner.enhance(queryEmbedding, neighborEmbeddings, weights);
910
+ learner.addSample(embedding, "positive", 1.0, { source: "feedback" });
911
+ const result = await learner.train(10);
912
+ // { epochs: 10, finalLoss: 0.023, improvement: 15.2, durationMs: 340 }
913
+ ```
914
+
915
+ </details>
916
+
917
+ ---
918
+
919
+ ### Intelligence & Learning
920
+
921
+ How AgentDB learns, reasons, and improves over time — from self-learning search to reinforcement learning and causal graphs.
922
+
923
+ <details>
924
+ <summary><strong>Self-Learning Pipeline</strong> — how search improves 36% automatically</summary>
925
+
926
+ AgentDB's self-learning pipeline continuously improves search quality through a six-phase cycle:
927
+
928
+ ```mermaid
929
+ flowchart LR
930
+ Q[Query] --> R[Semantic Router]
931
+ R --> S[SONA Enhancement]
932
+ S --> T[HNSW Search]
933
+ T --> U[Results]
934
+ U --> V[Feedback]
935
+ V --> W[Contrastive Trainer<br/>InfoNCE + Hard Negatives]
936
+ W --> X[Micro-LoRA Update]
937
+ X --> Y[EWC++ Consolidation]
938
+ Y --> Z[Federated Aggregation]
939
+ ```
940
+
941
+ ### 1. Semantic Query Routing
942
+
943
+ The `SemanticQueryRouter` classifies query intent by comparing against learned intent centroids using efficient min-heap top-k selection (O(n log k)). It lazily loads `@ruvector/router` for sub-millisecond HNSW routing and falls back to brute-force cosine with pre-computed norms when native bindings aren't available.
944
+
945
+ The router also selects the adaptive ef-search arm for the query. Four ef-search levels (50, 100, 200, 400) are chosen based on the solver's Thompson Sampling policy for the matching context bucket.
946
+
947
+ ```typescript
948
+ // Router learns intents from usage patterns
949
+ router.addIntent("technical_search", embedding); // up to 100 exemplars per intent
950
+ router.addIntent("conversational", embedding);
951
+ const { intent, confidence } = await router.route(queryEmbedding, k);
952
+
953
+ // Router state persists across restarts (debounced 5s save)
954
+ // Max 1,000 intents, JSON fallback or native persistence
955
+ ```
956
+
957
+ ### 2. SONA Enhancement
958
+
959
+ Context enrichment from trajectory history. The SONA engine (`@ruvector/sona`) tracks query trajectories and enriches embeddings with session context before search. SONA also applies the base LoRA adapter to the query embedding, adjusting it in sub-millisecond time based on learned patterns.
960
+
961
+ ### 3. Contrastive Training
962
+
963
+ InfoNCE contrastive loss with hard negative mining inspired by NV-Retriever's positive-aware filtering:
964
+
965
+ - **Loss function:** `L = -log(exp(sim(anchor, positive) / τ) / Σ exp(sim(anchor, negative_i) / τ))`
966
+ - **Hard negative filtering:** Rejects candidates where `sim(candidate, positive) > 0.85`, eliminating ~70% of false negatives
967
+ - **3-stage curriculum:** Progressively increases difficulty — negatives per sample (4 → 8 → 16), hardness threshold (0.5 → 0.3 → 0.1), 100 batches per stage
968
+ - **AdamW optimizer:** β1=0.9, β2=0.999, decoupled weight decay, full bias correction
969
+ - **Temperature:** Bounded 0.01-1.0 (default: 0.07)
970
+
971
+ ```typescript
972
+ // ContrastiveTrainer handles hard negative mining automatically
973
+ const result = trainer.trainBatch([
974
+ {
975
+ anchor: queryEmb,
976
+ positive: goodResultEmb,
977
+ negatives: [badResult1, badResult2],
978
+ },
979
+ ]);
980
+ // result: { loss, gradients, batchSize }
981
+ ```
982
+
983
+ When native SIMD is available, cosine similarity and AdamW steps delegate to the NativeAccelerator for hardware-accelerated computation.
984
+
985
+ ### 4. Micro-LoRA Adaptation
986
+
987
+ Sub-millisecond embedding adjustment per query. A lightweight projection matrix (W: d×d + bias: d) is applied to the query embedding before search, specializing for each user's query patterns without modifying the base model. LoRA adapters are updated after each contrastive training batch.
988
+
989
+ ### 5. EWC++ Consolidation
990
+
991
+ Elastic Weight Consolidation prevents catastrophic forgetting by penalizing changes to important parameters. The Fisher information matrix is updated incrementally via the NativeAccelerator's `ewcUpdateFisher()` and penalty is computed via `ewcPenalty()`, ensuring previously learned patterns survive new training.
992
+
993
+ ### 6. Federated Session Aggregation
994
+
995
+ Cross-session LoRA merging for continuous improvement. Lightweight `EphemeralLearningAgent` instances (~5MB each) export their state to a `FederatedLearningCoordinator` for quality-filtered aggregation (minimum quality threshold: 0.7, up to 100 agents).
996
+
997
+ ### How `tick()` Works
998
+
999
+ Each learning tick performs these steps in sequence:
1000
+
1001
+ 1. **Flush SONA** — persist trajectory context
1002
+ 2. **Train contrastive batch** — 32 samples from recorded feedback
1003
+ 3. **Train solver** — 50 puzzles to update Thompson Sampling policy
1004
+ 4. **Decay access frequencies** — multiply by 0.99, prune entries below 0.001 (every 50 ticks)
1005
+ 5. **Update temporal compressor** — adjust compression tiers
1006
+ 6. **Assess health** — latency tracking via health monitor
1007
+ 7. **Consolidate federated state** — merge distributed agent states
1008
+ 8. **Acceptance check** — every 100 ticks, run A/B/C ablation (mode A: fixed heuristic, mode B: compiler-suggested, mode C: learned Thompson Sampling) to validate adaptive ef-search
1009
+
1010
+ ### Full Example
1011
+
1012
+ ```typescript
1013
+ import { SelfLearningRvfBackend } from "agentdb/backends/rvf/SelfLearningRvfBackend";
1014
+
1015
+ const backend = await SelfLearningRvfBackend.create({
1016
+ dimension: 384,
1017
+ metric: "cosine",
1018
+ storagePath: "./vectors.rvf",
1019
+ learning: true,
1020
+ federated: true,
1021
+ positiveThreshold: 0.7,
1022
+ negativeThreshold: 0.3,
1023
+ trainingBatchSize: 32,
1024
+ tickIntervalMs: 5000,
1025
+ });
1026
+
1027
+ // Insert vectors
1028
+ await backend.insertAsync("doc-1", embedding, { source: "docs" });
1029
+
1030
+ // Search (automatically enhanced by SONA + router)
1031
+ const results = await backend.searchAsync(queryEmbedding, 10);
1032
+
1033
+ // Record feedback to drive learning
1034
+ backend.recordFeedback("query-123", 0.9); // high quality result
1035
+
1036
+ // Run a learning tick (contrastive training + LoRA update + EWC consolidation)
1037
+ await backend.tick();
1038
+
1039
+ // Check learning progress
1040
+ const stats = backend.getLearningStats();
1041
+ console.log(
1042
+ `Trajectories: ${stats.trajectoryCount}, LoRA rank: ${stats.loraRank}`,
1043
+ );
1044
+ ```
1045
+
1046
+ </details>
1047
+
1048
+ ---
1049
+
1050
+ <details>
1051
+ <summary><strong>Cognitive Memory Patterns</strong> — 6 ways your agent learns like a human</summary>
1052
+
1053
+ AgentDB implements six cognitive memory patterns inspired by how humans learn:
1054
+
1055
+ ### 1. ReasoningBank — Pattern Learning
1056
+
1057
+ Store successful reasoning patterns and retrieve them by semantic similarity. The system learns which approaches work best for different task types.
1058
+
1059
+ ```typescript
1060
+ await reasoningBank.storePattern({
1061
+ taskType: "bug_investigation",
1062
+ approach: "Check logs > Reproduce > Binary search for root cause",
1063
+ successRate: 0.92,
1064
+ tags: ["debugging", "systematic"],
1065
+ });
1066
+
1067
+ const patterns = await reasoningBank.searchPatterns({
1068
+ task: "debug memory leak",
1069
+ k: 10,
1070
+ threshold: 0.7,
1071
+ });
1072
+ ```
1073
+
1074
+ ### 2. Reflexion Memory — Learn from Experience
1075
+
1076
+ Store complete task episodes with self-generated critiques, then replay them to improve future performance. Based on Shinn et al., 2023.
1077
+
1078
+ ```typescript
1079
+ await reflexion.storeEpisode({
1080
+ sessionId: "session-1",
1081
+ task: "Fix authentication bug",
1082
+ reward: 0.95,
1083
+ success: true,
1084
+ critique: "OAuth2 PKCE flow was more secure than basic flow",
1085
+ input: "Users cannot log in",
1086
+ output: "Working OAuth2 implementation",
1087
+ latencyMs: 1200,
1088
+ tokensUsed: 500,
1089
+ });
1090
+
1091
+ const similar = await reflexion.retrieveRelevant({
1092
+ task: "authentication issues",
1093
+ k: 10,
1094
+ onlySuccesses: true,
1095
+ });
1096
+ ```
1097
+
1098
+ ### 3. Skill Library — Lifelong Learning
1099
+
1100
+ Transform successful patterns into reusable, composable skills that improve over time.
1101
+
1102
+ ```typescript
1103
+ await skills.createSkill({
1104
+ name: "jwt_authentication",
1105
+ description: "Generate and validate JWT tokens",
1106
+ signature: { inputs: { userId: "string" }, outputs: { token: "string" } },
1107
+ code: "implementation...",
1108
+ successRate: 0.92,
1109
+ });
1110
+
1111
+ const applicable = await skills.searchSkills({
1112
+ task: "user authentication",
1113
+ k: 5,
1114
+ minSuccessRate: 0.7,
1115
+ });
1116
+ ```
1117
+
1118
+ ### 4. Causal Memory Graph — Intervention Causality
1119
+
1120
+ Track `p(y|do(x))` using doubly robust estimation. Learn what interventions cause what outcomes.
1121
+
1122
+ ```typescript
1123
+ import { CausalMemoryGraph } from "agentdb";
1124
+
1125
+ const causalGraph = new CausalMemoryGraph(db);
1126
+
1127
+ const experimentId = causalGraph.createExperiment({
1128
+ name: "test_error_handling",
1129
+ hypothesis: "Try-catch reduces crash rate",
1130
+ treatmentId: 123,
1131
+ treatmentType: "episode",
1132
+ controlId: 124,
1133
+ startTime: Date.now(),
1134
+ sampleSize: 0,
1135
+ status: "running",
1136
+ });
1137
+
1138
+ const { uplift, pValue } = causalGraph.calculateUplift(experimentId);
1139
+ ```
1140
+
1141
+ ### 5. Explainable Recall — Provenance Certificates
1142
+
1143
+ Every retrieval comes with a cryptographic Merkle proof explaining why specific memories were selected.
1144
+
1145
+ ```typescript
1146
+ const result = await causalRecall.recall(
1147
+ "query-123",
1148
+ "How to optimize API response time",
1149
+ 12,
1150
+ ["performance"],
1151
+ "internal",
1152
+ );
1153
+
1154
+ console.log(`Certificate: ${result.certificate.id}`);
1155
+ console.log(`Completeness: ${result.certificate.completenessScore}`);
1156
+ ```
1157
+
1158
+ ### 6. Nightly Learner — Automated Discovery
1159
+
1160
+ Background process that discovers causal patterns, consolidates skills, and prunes low-quality data automatically.
1161
+
1162
+ ```typescript
1163
+ const learner = new NightlyLearner(db, embedder);
1164
+ const discovered = await learner.discover({
1165
+ minAttempts: 3,
1166
+ minSuccessRate: 0.6,
1167
+ minConfidence: 0.7,
1168
+ dryRun: false,
1169
+ });
1170
+ ```
1171
+
1172
+ </details>
1173
+
1174
+ ---
1175
+
1176
+ ### Storage & Data
1177
+
1178
+ How AgentDB stores vectors, manages compression tiers, and provides MongoDB-style filtering — all in a single Cognitive Container.
1179
+
1180
+ <details>
1181
+ <summary><strong>Cognitive Container (RVF Format)</strong> — single-file storage with crash safety and branching</summary>
1182
+
1183
+ The **Cognitive Container** is AgentDB's native storage format (`.rvf` — RuVector Format). It packs vectors, indexes, learning state, and a cryptographic witness chain into a single file with crash safety, progressive indexing, and full lineage tracking.
1184
+
1185
+ ### Structure
1186
+
1187
+ ```mermaid
1188
+ graph TB
1189
+ subgraph "store.rvf"
1190
+ H[Header + Magic Bytes]
1191
+ S1[Segment 1<br/>Vectors + Metadata]
1192
+ S2[Segment 2]
1193
+ IX[HNSW Index<br/>Progressive]
1194
+ WC[Witness Chain<br/>SHAKE-256]
1195
+ LN[Lineage Record<br/>Parent ID + Depth]
1196
+ end
1197
+ H --> S1
1198
+ S1 --> S2
1199
+ S2 --> IX
1200
+ IX --> WC
1201
+ WC --> LN
1202
+ ```
1203
+
1204
+ ### Key Capabilities
1205
+
1206
+ | Feature | Description |
1207
+ | ------------------------- | ------------------------------------------------------------------------- |
1208
+ | **Single-file** | Everything in one Cognitive Container (`.rvf`) — vectors, index, metadata |
1209
+ | **Crash-safe** | Append-only log with checksums, safe concurrent access |
1210
+ | **COW Branching** | Create copy-on-write branches for experiments (near-instant) |
1211
+ | **Lineage Tracking** | `fileId()`, `parentId()`, `lineageDepth()` for file-level provenance |
1212
+ | **Progressive Indexing** | 3-layer HNSW quality tiers, index builds incrementally as data arrives |
1213
+ | **Witness Chains** | SHAKE-256 cryptographic verification (73 bytes per entry) |
1214
+ | **Filter Expressions** | 11 operators for metadata filtering, max 64 depth |
1215
+ | **Auto-Compaction** | `compact()` reclaims space, reports segments compacted & bytes reclaimed |
1216
+ | **Readonly Mode** | `openReadonly()` for concurrent readers without locks |
1217
+ | **Segment Introspection** | `segments()` returns id, type, and payload length per segment |
1218
+ | **Kernel Embedding** | Embed unikernel images directly into Cognitive Containers |
1219
+ | **eBPF Embedding** | Embed and extract eBPF bytecode for programmable queries |
1220
+
1221
+ ### Configuration
1222
+
1223
+ ```typescript
1224
+ const backend = new RvfBackend({
1225
+ dimension: 384,
1226
+ metric: "cosine", // 'cosine' | 'l2' | 'dotproduct'
1227
+ storagePath: "./vectors.rvf",
1228
+ rvfBackend: "auto", // 'auto' | 'node' (N-API) | 'wasm' (browser)
1229
+ batchThreshold: 100, // Auto-flush after N sync inserts (1-10,000)
1230
+ compression: "none", // 'none' (fp32) | 'scalar' (int8) | 'product' (PQ)
1231
+ hardwareProfile: 0, // 0=Generic | 1=Core | 2=Hot | 3=Full
1232
+ enableStats: true, // Track insert/search/flush/compaction timing
1233
+ });
1234
+ ```
1235
+
1236
+ **Hardware profiles** tune internal parameters for your deployment:
1237
+
1238
+ | Profile | Level | Best For |
1239
+ | ----------- | --------------------------- | ----------------------- |
1240
+ | Generic (0) | Conservative defaults | Unknown hardware |
1241
+ | Core (1) | Balanced throughput/latency | Developer machines |
1242
+ | Hot (2) | Aggressive caching | High-throughput servers |
1243
+ | Full (3) | Maximum parallelism | Dedicated vector search |
1244
+
1245
+ ### Witness Chains
1246
+
1247
+ Every mutation is recorded in a tamper-evident SHAKE-256 witness chain (73 bytes per entry). This provides cryptographic proof that data has not been modified after the fact:
1248
+
1249
+ ```typescript
1250
+ const result = backend.verifyWitnessChain();
1251
+ // { valid: true, entries: 1042, algorithm: 'SHAKE-256' }
1252
+
1253
+ // Verification uses @ruvector/rvf-wasm: rvf_witness_verify(), rvf_witness_count()
1254
+ ```
1255
+
1256
+ ### Filter Expressions
1257
+
1258
+ RVF supports 11 filter operators for metadata-filtered search. Filters are serialized to a compact field-ID format with a maximum depth of 64 expressions for security:
1259
+
1260
+ ```typescript
1261
+ import { FilterBuilder } from "agentdb/backends/rvf/FilterBuilder";
1262
+
1263
+ const filter = new FilterBuilder()
1264
+ .eq("status", "active")
1265
+ .gt("score", 0.5)
1266
+ .range("timestamp", startDate, endDate)
1267
+ .in("category", ["research", "engineering"])
1268
+ .build();
1269
+
1270
+ const results = await backend.searchAsync(queryVector, 10, { filter });
1271
+
1272
+ // Also supports filter-based deletion
1273
+ await backend.deleteByFilter(filter);
1274
+ ```
1275
+
1276
+ **Available operators:** `eq`, `ne`, `lt`, `le`, `gt`, `ge`, `in`, `range`, `and`, `or`, `not`
1277
+
1278
+ ### Performance Stats
1279
+
1280
+ The RVF backend tracks detailed performance counters:
1281
+
1282
+ ```typescript
1283
+ const stats = backend.getPerformanceStats();
1284
+ // {
1285
+ // insertCount: 10432, insertTotalMs: 521.6, avgInsertMs: 0.05,
1286
+ // searchCount: 8891, searchTotalMs: 178.2, avgSearchMs: 0.02,
1287
+ // flushCount: 104, compactionCount: 3
1288
+ // }
1289
+ ```
1290
+
1291
+ ### Kernel & eBPF Embedding
1292
+
1293
+ Cognitive Containers can embed unikernel images and eBPF bytecode directly, enabling self-contained deployable artifacts:
1294
+
1295
+ ```typescript
1296
+ // Embed a kernel image into the Cognitive Container
1297
+ await backend.embedKernel({
1298
+ arch: "x86_64", // 'x86_64' | 'aarch64' | 'riscv64'
1299
+ type: "firecracker", // 'firecracker' | 'qemu' | 'cloud-hypervisor'
1300
+ flags: 0,
1301
+ image: kernelBuffer,
1302
+ apiPort: 8080,
1303
+ cmdline: "console=ttyS0",
1304
+ });
1305
+
1306
+ // Extract it later
1307
+ const kernel = await backend.extractKernel();
1308
+ // { header: { arch, type, ... }, image: Uint8Array }
1309
+
1310
+ // eBPF bytecode for programmable query filters
1311
+ await backend.embedEbpf(ebpfBytecode);
1312
+ const ebpf = await backend.extractEbpf();
1313
+ ```
1314
+
1315
+ ### CLI Commands
1316
+
1317
+ ```bash
1318
+ # Show store status
1319
+ npx agentdb rvf status ./store.rvf
1320
+
1321
+ # Compact to reclaim space
1322
+ npx agentdb rvf compact ./store.rvf
1323
+
1324
+ # Create a branch (copy-on-write)
1325
+ npx agentdb rvf derive ./parent.rvf ./experiment.rvf
1326
+
1327
+ # List segments
1328
+ npx agentdb rvf segments ./store.rvf
1329
+
1330
+ # Detect SDK availability
1331
+ npx agentdb rvf detect
1332
+ ```
1333
+
1334
+ ### Programmatic Usage
1335
+
1336
+ ```typescript
1337
+ import { RvfBackend } from "agentdb/backends/rvf/RvfBackend";
1338
+
1339
+ const backend = new RvfBackend({
1340
+ dimension: 384,
1341
+ metric: "cosine",
1342
+ storagePath: "./vectors.rvf",
1343
+ rvfBackend: "auto", // 'node' for N-API, 'wasm' for browser
1344
+ });
1345
+ await backend.initialize();
1346
+
1347
+ // Async operations (native)
1348
+ await backend.insertAsync("vec-1", embedding, { tag: "example" });
1349
+ const results = await backend.searchAsync(queryVector, 10);
1350
+ await backend.flush();
1351
+
1352
+ // COW branching
1353
+ const branch = await backend.derive("./experiment.rvf");
1354
+ const lineage = await backend.lineageDepth();
1355
+ ```
1356
+
1357
+ ### Backend Selection
1358
+
1359
+ ```bash
1360
+ # Initialize with RVF backend
1361
+ npx agentdb init --backend rvf --rvf-path ./vectors.rvf
1362
+
1363
+ # Migrate v2 database to v3 unified .rvf
1364
+ npx agentdb migrate --source ./v2.db --to v3 --rvf-path ./unified.rvf
1365
+
1366
+ # Migrate existing data to RVF
1367
+ npx agentdb migrate --to rvf --rvf-path ./vectors.rvf
1368
+
1369
+ # Check RVF in diagnostics
1370
+ npx agentdb doctor --rvf-path ./vectors.rvf
1371
+ ```
1372
+
1373
+ </details>
1374
+
1375
+ ---
1376
+
1377
+ ### Performance & Architecture
1378
+
1379
+ The engine behind AgentDB's speed — SIMD acceleration, graph intelligence, browser WASM, and benchmarking.
1380
+
1381
+ <details>
1382
+ <summary><strong>SIMD & Native Acceleration</strong> — 15 capability groups with automatic fallbacks</summary>
1383
+
1384
+ The `NativeAccelerator` provides 15 capability groups bridging 11 `@ruvector` packages, with pure-JS fallbacks for every operation via `SimdFallbacks`.
1385
+
1386
+ ### Capability Groups
1387
+
1388
+ | Group | Operations | Package |
1389
+ | -------------------------- | ---------------------------------------------------- | ---------------------- |
1390
+ | **Vector Distance & Math** | cosine, dot, L2, hamming, add, mul, scale, normalize | `ruvector` |
1391
+ | **Activations** | softmax, relu, gelu, sigmoid, layerNorm | `@ruvector/ruvllm` |
1392
+ | **Loss Functions** | InfoNCE (contrastive) | `@ruvector/sona` |
1393
+ | **Optimizers** | AdamW step | `@ruvector/sona` |
1394
+ | **Quantization** | scalar 8-bit/4-bit, product quantization | `@ruvector/rvf` |
1395
+ | **WASM Store** | create, ingest, query, export, close | `@ruvector/rvf-wasm` |
1396
+ | **Verification** | witness chain, segment header | `@ruvector/rvf-node` |
1397
+ | **Graph Transactions** | begin, commit, rollback | `@ruvector/graph-node` |
1398
+ | **Graph Batch Insert** | high-throughput node/edge ingestion | `@ruvector/graph-node` |
1399
+ | **Graph Cypher** | pattern matching, path queries | `@ruvector/graph-node` |
1400
+ | **Core Batch Insert** | native vector batch ingestion | `ruvector` |
1401
+ | **EWC Memory** | penalty calculation, Fisher update | `@ruvector/sona` |
1402
+ | **Router** | save/load state persistence | `@ruvector/router` |
1403
+ | **SONA** | context addition, flush, base LoRA | `@ruvector/sona` |
1404
+ | **Compression** | tensor compress/decompress | `@ruvector/rvf` |
1405
+
1406
+ ### Auto-Detection
1407
+
1408
+ Each capability group is lazily loaded — only the packages actually installed on the system are loaded, and each load is tried independently so a missing package never blocks others:
1409
+
1410
+ ```typescript
1411
+ import { NativeAccelerator } from "agentdb/backends/rvf/NativeAccelerator";
1412
+
1413
+ const accel = new NativeAccelerator();
1414
+ const stats = await accel.initialize();
1415
+
1416
+ console.log(stats);
1417
+ // AcceleratorStats:
1418
+ // {
1419
+ // simdAvailable: true, // Vector distance + element-wise math
1420
+ // simdActivationsAvailable: true, // softmax, relu, gelu, sigmoid, layerNorm
1421
+ // wasmVerifyAvailable: true, // Witness chain & header verification
1422
+ // wasmStoreAvailable: true, // In-browser HNSW store
1423
+ // wasmQuantizationAvailable: true, // Scalar/product quantization ops
1424
+ // nativeInfoNceAvailable: true, // Hardware-accelerated InfoNCE loss
1425
+ // nativeAdamWAvailable: true, // Hardware-accelerated AdamW optimizer
1426
+ // nativeTensorCompressAvailable: true, // SVD tensor compression
1427
+ // routerPersistAvailable: true, // Semantic router state persistence
1428
+ // sonaExtendedAvailable: true, // SONA trajectory context & base LoRA
1429
+ // }
1430
+ // Additional capabilities (probed separately):
1431
+ // accel.graphTxAvailable // Graph transactions
1432
+ // accel.graphBatchInsertAvailable // Graph batch insert
1433
+ // accel.graphCypherAvailable // Cypher query engine
1434
+ // accel.coreBatchInsertAvailable // Native vector batch insert
1435
+ // accel.ewcManagerAvailable // EWC++ memory consolidation
1436
+ ```
1437
+
1438
+ ### Pure-JS Fallbacks
1439
+
1440
+ Every SIMD operation has a pure-JS fallback with 4-wide loop unrolling for reasonable performance even without native bindings:
1441
+
1442
+ ```typescript
1443
+ import { SimdFallbacks } from "agentdb/backends/rvf/SimdFallbacks";
1444
+
1445
+ // Same API as native, ~10-50x slower but always available
1446
+ const similarity = SimdFallbacks.jsCosineSimilarity(vecA, vecB);
1447
+ const loss = SimdFallbacks.jsInfoNceLoss(
1448
+ anchor,
1449
+ positive,
1450
+ negatives,
1451
+ temperature,
1452
+ );
1453
+ const result = SimdFallbacks.jsAdamWStep(
1454
+ params,
1455
+ grads,
1456
+ m,
1457
+ v,
1458
+ lr,
1459
+ beta1,
1460
+ beta2,
1461
+ weightDecay,
1462
+ t,
1463
+ );
1464
+ ```
1465
+
1466
+ ### Additional SIMD Operations
1467
+
1468
+ The `SIMDVectorOps` class provides batch operations and platform-specific detection:
1469
+
1470
+ ```typescript
1471
+ import { SIMDVectorOps, detectSIMDSupport } from "agentdb/simd";
1472
+
1473
+ const simd = new SIMDVectorOps();
1474
+ const support = detectSIMDSupport();
1475
+ // { wasm: true, x64: false, avx2: false, neon: false }
1476
+
1477
+ const similarities = simd.batchCosineSimilarity(query, [vec1, vec2, vec3]);
1478
+ ```
1479
+
1480
+ </details>
1481
+
1482
+ ---
1483
+
1484
+ <details>
1485
+ <summary><strong>Graph Intelligence</strong> — Cypher queries, causal reasoning, GNN attention</summary>
1486
+
1487
+ AgentDB integrates `@ruvector/graph-node` for a full graph database with Cypher query support, transactional batch inserts, and GNN-powered attention.
1488
+
1489
+ ### Cypher Queries
1490
+
1491
+ Full Neo4j-compatible Cypher syntax including MATCH, RETURN, WHERE, ORDER BY, LIMIT, relationship patterns, and graph traversal:
1492
+
1493
+ ```typescript
1494
+ import { GraphDatabaseAdapter } from "agentdb/backends/graph/GraphDatabaseAdapter";
1495
+
1496
+ const graph = new GraphDatabaseAdapter({
1497
+ storagePath: "./graph.db",
1498
+ dimensions: 384,
1499
+ distanceMetric: "Cosine", // 'Cosine' | 'Euclidean' | 'DotProduct' | 'Manhattan'
1500
+ });
1501
+ await graph.initialize();
1502
+
1503
+ // Create nodes and edges
1504
+ await graph.storeEpisode(episode, embedding);
1505
+ await graph.storeSkill(skill, embedding);
1506
+ await graph.createCausalEdge(edge, embedding);
1507
+
1508
+ // Cypher queries
1509
+ const results = await graph.query(`
1510
+ MATCH (e:Episode)-[:CAUSED]->(s:Skill)
1511
+ WHERE e.reward > 0.8
1512
+ RETURN e, s
1513
+ ORDER BY e.reward DESC
1514
+ LIMIT 10
1515
+ `);
1516
+ ```
1517
+
1518
+ ### Graph Traversal
1519
+
1520
+ Traverse relationships with direction control, depth limits, and label filtering:
1521
+
1522
+ ```typescript
1523
+ const paths = await graph.traverse({
1524
+ startNodeId: "episode-42",
1525
+ pattern: "()-[:RELATES_TO]->(:Skill)",
1526
+ direction: "outgoing", // 'outgoing' | 'incoming' | 'both'
1527
+ maxDepth: 3,
1528
+ relationshipTypes: ["CAUSED", "RELATES_TO"],
1529
+ nodeLabels: ["Episode", "Skill"],
1530
+ });
1531
+ ```
1532
+
1533
+ ### Hybrid Vector + Graph Search
1534
+
1535
+ Combine vector similarity with graph context filtering — find semantically similar nodes that are also connected in the knowledge graph:
1536
+
1537
+ ```typescript
1538
+ // Vector similarity within graph structure
1539
+ const results = await graph.vectorSearch(queryEmbedding, 10);
1540
+ // Returns nodes ranked by embedding similarity with graph context
1541
+
1542
+ // Nodes support multi-label classification
1543
+ await graph.createNode({
1544
+ id: "analysis-1",
1545
+ label: ["Episode", "Analyzed", "Security"],
1546
+ properties: { reward: 0.95, task: "auth review" },
1547
+ embedding: embeddingVector,
1548
+ });
1549
+ ```
1550
+
1551
+ ### Transactional Batch Inserts
1552
+
1553
+ ACID-guaranteed batch operations with rollback support:
1554
+
1555
+ ```typescript
1556
+ const txId = await graph.beginTransaction();
1557
+ try {
1558
+ await graph.batchInsert(
1559
+ nodes.map((n) => ({ id: n.id, label: n.type, properties: n.data })),
1560
+ edges.map((e) => ({
1561
+ from: e.source,
1562
+ to: e.target,
1563
+ label: e.type,
1564
+ properties: e.data,
1565
+ })),
1566
+ );
1567
+ await graph.commitTransaction(txId);
1568
+ } catch (err) {
1569
+ await graph.rollbackTransaction(txId);
1570
+ }
1571
+ ```
1572
+
1573
+ ### GNN 8-Head Attention
1574
+
1575
+ The GNN attention mechanism improves recall by +12.4% with a 3.8ms forward pass and 91% transfer learning retention. Three attention types are available:
1576
+
1577
+ | Type | Algorithm | Best For |
1578
+ | ------ | --------------------------- | ---------------------------------- |
1579
+ | `gat` | Graph Attention Network | Weighted neighbor aggregation |
1580
+ | `gcn` | Graph Convolutional Network | Uniform message passing |
1581
+ | `sage` | GraphSAGE | Inductive learning on unseen nodes |
1582
+
1583
+ ```typescript
1584
+ import { AttentionService } from "agentdb/controllers/AttentionService";
1585
+
1586
+ const attention = new AttentionService({
1587
+ numHeads: 8,
1588
+ dimension: 384,
1589
+ attentionType: "gat", // 'gat' | 'gcn' | 'sage'
1590
+ });
1591
+ const enhanced = await attention.forward(queryEmbedding, neighborEmbeddings);
1592
+ ```
1593
+
1594
+ ### Causal Memory Graph
1595
+
1596
+ Track interventions with `p(y|do(x))` doubly robust estimation and optional Poincare embeddings for hierarchical relationships:
1597
+
1598
+ ```typescript
1599
+ import { CausalMemoryGraph } from "agentdb";
1600
+
1601
+ const causal = new CausalMemoryGraph(db, graph, embedder, {
1602
+ ENABLE_HYPERBOLIC_ATTENTION: true, // Poincaré ball distance for hierarchies
1603
+ });
1604
+
1605
+ await causal.addCausalEdge({
1606
+ fromMemoryId: "episode-1",
1607
+ toMemoryType: "skill", // 'episode' | 'skill' | 'note' | 'fact'
1608
+ uplift: 0.15, // E[y|do(x)] - E[y]
1609
+ confidence: 0.92,
1610
+ mechanism: "error-handling improvement",
1611
+ sampleSize: 50,
1612
+ confounderScore: 0.03,
1613
+ });
1614
+ ```
1615
+
1616
+ </details>
1617
+
1618
+ ---
1619
+
1620
+ <details>
1621
+ <summary><strong>Browser & WASM Deployment</strong> — full vector DB in the browser, no server needed</summary>
1622
+
1623
+ AgentDB runs fully in the browser with WASM-backed vector storage, GNN attention, product quantization, and pure-JS fallbacks.
1624
+
1625
+ ### WasmStoreBridge
1626
+
1627
+ The `WasmStoreBridge` provides a full HNSW vector database in the browser by wrapping `@ruvector/rvf-wasm`:
1628
+
1629
+ ```typescript
1630
+ import { WasmStoreBridge } from "agentdb/backends/rvf/WasmStoreBridge";
1631
+
1632
+ const bridge = new WasmStoreBridge();
1633
+ await bridge.initialize();
1634
+
1635
+ // Create an in-browser vector store
1636
+ const handle = bridge.wasmStoreCreate(384, 0); // 384 dims, cosine metric
1637
+
1638
+ // Ingest vectors
1639
+ bridge.wasmStoreIngest(handle, vectors, ids, count);
1640
+
1641
+ // Query
1642
+ const results = bridge.wasmStoreQuery(handle, queryVector, 10, 0);
1643
+ // [{ id: 42, distance: 0.12 }, ...]
1644
+
1645
+ // Export to transferable binary (share between tabs/workers)
1646
+ const bytes = bridge.wasmStoreExport(handle);
1647
+
1648
+ bridge.wasmStoreClose(handle);
1649
+ ```
1650
+
1651
+ ### Browser Attention Mechanisms
1652
+
1653
+ The `AttentionBrowser` provides three advanced attention types compiled to WASM:
1654
+
1655
+ ```typescript
1656
+ import { AttentionBrowser } from "agentdb/browser/AttentionBrowser";
1657
+
1658
+ const attention = new AttentionBrowser({ numHeads: 8 });
1659
+ // Loading states: 'idle' → 'loading' → 'loaded' | 'error'
1660
+
1661
+ // Standard multi-head attention
1662
+ const enhanced = await attention.forward(query, neighbors);
1663
+
1664
+ // Flash Attention — O(N) memory instead of O(N²)
1665
+ const flash = await attention.flashAttention(query, keys, values);
1666
+
1667
+ // Hyperbolic Attention — Poincaré ball distance for hierarchical data
1668
+ const hyper = await attention.hyperbolicAttention(query, neighbors);
1669
+
1670
+ // Memory Consolidation — agglomerative clustering to merge similar memories
1671
+ const consolidated = await attention.consolidateMemories(memories, {
1672
+ threshold: 0.85,
1673
+ minClusterSize: 3,
1674
+ });
1675
+ ```
1676
+
1677
+ ### Product Quantization (Browser)
1678
+
1679
+ Memory-efficient vector storage with three PQ compression levels:
1680
+
1681
+ | Variant | Compression | Subvectors | Centroids | Best For |
1682
+ | -------- | ----------- | ---------- | --------- | ----------------------- |
1683
+ | **PQ8** | 4x | 8 | 256 | Balanced quality/memory |
1684
+ | **PQ16** | 8x | 16 | 256 | Medium datasets |
1685
+ | **PQ32** | 16x | 32 | 256 | Maximum compression |
1686
+
1687
+ ```typescript
1688
+ import {
1689
+ createProductQuantizedStore,
1690
+ createScalar8BitStore,
1691
+ } from "agentdb/browser/ProductQuantization";
1692
+
1693
+ // Product quantization with asymmetric distance computation (ADC)
1694
+ const pq = createProductQuantizedStore(384, {
1695
+ numSubvectors: 16,
1696
+ bitsPerCode: 8,
1697
+ // Uses K-means++ initialization for codebook training
1698
+ });
1699
+ pq.add("doc-1", embedding);
1700
+ const results = pq.search(query, 10);
1701
+ ```
1702
+
1703
+ ### Browser Configuration Presets
1704
+
1705
+ Pre-tuned configurations for common scenarios:
1706
+
1707
+ | Preset | Features | Target |
1708
+ | ------------------- | ----------------------------------- | ------------------ |
1709
+ | `SMALL_DATASET` | GNN only | <1K vectors |
1710
+ | `MEDIUM_DATASET` | HNSW + PQ8 | 1K-10K vectors |
1711
+ | `LARGE_DATASET` | Aggressive compression + HNSW | 10K-100K vectors |
1712
+ | `MEMORY_OPTIMIZED` | PQ32 + SVD (dim 64) | Memory-constrained |
1713
+ | `SPEED_OPTIMIZED` | HNSW max quality | Latency-critical |
1714
+ | `QUALITY_OPTIMIZED` | No compression, max attention heads | Accuracy-critical |
1715
+
1716
+ ### Maximal Marginal Relevance (MMR)
1717
+
1718
+ Diversify search results to avoid returning near-duplicate items:
1719
+
1720
+ ```typescript
1721
+ import { MMRDiversityRanker } from "agentdb/controllers/MMRDiversityRanker";
1722
+
1723
+ const ranker = new MMRDiversityRanker({
1724
+ lambda: 0.7, // 0=max diversity, 1=max relevance
1725
+ metric: "cosine", // 'cosine' | 'euclidean' | 'dot'
1726
+ });
1727
+
1728
+ // Rerank results: MMR = λ × Sim(Di,Q) - (1-λ) × max Sim(Di,Dj)
1729
+ const diverse = ranker.rerank(queryEmbedding, candidates, 10);
1730
+ const score = ranker.diversityScore(diverse); // average pairwise distance
1731
+ ```
1732
+
1733
+ ### Browser Bundle
1734
+
1735
+ ```typescript
1736
+ import { AgentDB } from "agentdb/browser";
1737
+
1738
+ const db = new AgentDB({ dimension: 384 });
1739
+ await db.initialize();
1740
+
1741
+ await db.insert("doc-1", embedding, { title: "Getting Started" });
1742
+ const results = await db.search(queryEmbedding, 5);
1743
+ ```
1744
+
1745
+ ### sql.js & SIMD Fallbacks
1746
+
1747
+ For zero-dependency environments, AgentDB falls back to `sql.js` (SQLite compiled to WASM) automatically. Non-WASM browsers get pure-JS implementations with 4-wide loop unrolling (~10-50x slower than native SIMD but fully functional):
1748
+
1749
+ ```typescript
1750
+ import { createDatabase } from "agentdb";
1751
+ import { detectSIMDSupport } from "agentdb/simd";
1752
+
1753
+ // In browsers, automatically uses sql.js WASM backend
1754
+ const db = await createDatabase(":memory:");
1755
+
1756
+ const support = detectSIMDSupport();
1757
+ // { wasm: true, x64: false, avx2: false, neon: false }
1758
+ ```
1759
+
1760
+ </details>
1761
+
1762
+ ---
1763
+
1764
+ <details>
1765
+ <summary><strong>Performance & Benchmarks</strong> — 61us latency, 96.8% recall, 32.6M ops/sec</summary>
1766
+
1767
+ ### Core Operations
1768
+
1769
+ | Operation | Throughput | Latency |
1770
+ | ----------------- | ------------------- | --------------------------- |
1771
+ | Pattern search | 32.6M ops/sec | <1ms |
1772
+ | Pattern storage | 388K ops/sec | ~2.5us |
1773
+ | Episode retrieval | 957 ops/sec | ~1ms |
1774
+ | Skill search | 694 ops/sec | ~1.4ms |
1775
+ | Batch insert | 5,556-7,692 ops/sec | 3-4x faster than sequential |
1776
+
1777
+ ### Scaling Behavior
1778
+
1779
+ ```
1780
+ 500 patterns: 1,475/sec, 2MB memory
1781
+ 2,000 patterns: 3,818/sec, 0MB delta
1782
+ 5,000 patterns: 4,536/sec, 4MB memory (super-linear)
1783
+ ```
1784
+
1785
+ ### Self-Learning Improvement
1786
+
1787
+ ```
1788
+ Adaptive Learning (10 sessions, 50 episodes each)
1789
+ Initial success rate: 54%
1790
+ Final success rate: 90%
1791
+ Improvement: +36%
1792
+ ```
1793
+
1794
+ ### Latent Space Validation (31 scenarios, 98.2% reproducibility)
1795
+
1796
+ | Scenario | Result |
1797
+ | ------------------- | ----------------------------------------------- |
1798
+ | HNSW Optimization | 61us p50, 96.8% recall@10, 8.2x vs hnswlib |
1799
+ | GNN Attention | +12.4% recall, 3.8ms forward pass, 91% transfer |
1800
+ | Self-Healing | 97.9% degradation prevention, <100ms repair |
1801
+ | Neural Augmentation | +29.4% improvement, -32% memory, -52% hops |
1802
+
1803
+ ### Adaptive Solver (Thompson Sampling)
1804
+
1805
+ The solver uses 18 context-bucketed bandits (3 range x 3 distractor x 2 noise levels) to dynamically tune search parameters:
1806
+
1807
+ ```typescript
1808
+ const solver = await AgentDBSolver.create();
1809
+
1810
+ // Train the solver with puzzles of varying difficulty
1811
+ const result = solver.train({ count: 50, minDifficulty: 1, maxDifficulty: 10 });
1812
+
1813
+ // Inspect the policy — shows Thompson Sampling alpha/beta per context bucket
1814
+ const policy = solver.policy();
1815
+ console.log(policy.contextStats);
1816
+ // { '0_0_0': { alphaSafety: 12.5, betaSafety: 2.1, costEma: 0.03 }, ... }
1817
+
1818
+ // A/B/C acceptance testing
1819
+ const manifest = solver.acceptance({ holdoutSize: 100, cycles: 3 });
1820
+ console.log(`Passed: ${manifest.passed}, Score: ${manifest.score}`);
1821
+
1822
+ // SHAKE-256 witness chain for audit
1823
+ const chain = solver.witnessChain();
1824
+ ```
1825
+
1826
+ Three-loop architecture:
1827
+
1828
+ 1. **Fast loop** — constraint propagation (~0.1ms)
1829
+ 2. **Medium loop** — PolicyKernel with Thompson Sampling (~1ms)
1830
+ 3. **Slow loop** — KnowledgeCompiler for long-term patterns (~10ms)
1831
+
1832
+ ### SolverBandit — Decision Intelligence Across Controllers (ADR-010)
1833
+
1834
+ The `SolverBandit` is a general-purpose Thompson Sampling bandit that provides explore/exploit decisions for any context-dependent selection problem. It powers adaptive decision-making in 5 AgentDB controllers:
1835
+
1836
+ | Controller | What the Bandit Decides | Context Key |
1837
+ | ---------------------- | -------------------------------------------------- | ------------------- |
1838
+ | **SkillLibrary** | Rerank retrieved skills by task type | `taskType` string |
1839
+ | **ReasoningBank** | Rerank matching patterns by task type | query text |
1840
+ | **NightlyLearner** | Prioritize experiment candidates | `'experiment'` |
1841
+ | **LearningSystem** | Select best RL algorithm (9 options) | task description |
1842
+ | **TemporalCompressor** | Choose compression tier (none/half/pq8/pq4/binary) | `hot`/`warm`/`cold` |
1843
+
1844
+ Each controller uses the bandit optionally — when no bandit is provided, behavior is unchanged from v2. When present, the bandit reranks results using Thompson-sampled Beta distributions, and controllers feed outcomes back via `recordReward()`.
1845
+
1846
+ ```typescript
1847
+ import { SolverBandit } from "agentdb/backends/rvf/SolverBandit";
1848
+
1849
+ const bandit = new SolverBandit();
1850
+
1851
+ // Select best arm for a context
1852
+ const skill = bandit.selectArm("code_review", [
1853
+ "lint_first",
1854
+ "test_first",
1855
+ "security_scan",
1856
+ ]);
1857
+
1858
+ // Record outcome
1859
+ bandit.recordReward("code_review", skill, 0.85, /* latencyMs */ 120);
1860
+
1861
+ // Rerank candidates by learned performance
1862
+ const ranked = bandit.rerank("code_review", [
1863
+ "lint_first",
1864
+ "test_first",
1865
+ "security_scan",
1866
+ ]);
1867
+
1868
+ // Serialize for cross-session persistence
1869
+ const state = bandit.serialize(); // JSON-safe
1870
+ const restored = SolverBandit.deserialize(state);
1871
+ ```
1872
+
1873
+ **Performance:** 100K `selectArm` calls in <200ms, 100K `recordReward` calls in <100ms.
1874
+
1875
+ **Wire into AgentDB controllers:**
1876
+
1877
+ ```typescript
1878
+ import {
1879
+ SolverBandit,
1880
+ SkillLibrary,
1881
+ ReasoningBank,
1882
+ LearningSystem,
1883
+ } from "agentdb";
1884
+
1885
+ const bandit = new SolverBandit({ costWeight: 0.01, explorationBonus: 0.1 });
1886
+
1887
+ // Pass as optional last parameter to any controller
1888
+ const skills = new SkillLibrary(db, embedder, undefined, bandit);
1889
+ const patterns = new ReasoningBank(db, embedder, undefined, bandit);
1890
+ const learning = new LearningSystem(db, undefined, bandit);
1891
+
1892
+ // Controllers automatically rerank results and accept feedback
1893
+ const algorithm = learning.recommendAlgorithm("navigation task");
1894
+ learning.recordAlgorithmOutcome("navigation task", algorithm, 0.92, 340);
1895
+ ```
1896
+
1897
+ </details>
1898
+
1899
+ ---
1900
+
1901
+ ### Enterprise & Security
1902
+
1903
+ Production-ready authentication, audit logging, and defense-in-depth security with cryptographic verification.
1904
+
1905
+ <details>
1906
+ <summary><strong>Security</strong> — defense-in-depth with cryptographic audit trails</summary>
1907
+
1908
+ AgentDB provides defense-in-depth security with validation at every system boundary.
1909
+
1910
+ ### Input Validation
1911
+
1912
+ ```typescript
1913
+ import {
1914
+ validateVector,
1915
+ validateVectorId,
1916
+ validateSearchOptions,
1917
+ validateHNSWParams,
1918
+ sanitizeMetadata,
1919
+ validateCypherParams,
1920
+ validateLabel,
1921
+ validateBatchSize,
1922
+ } from "agentdb/security/validation";
1923
+
1924
+ // Vector validation — prevents NaN/Infinity injection
1925
+ validateVector(embedding, 384, "embedding");
1926
+
1927
+ // ID validation — prevents path traversal (../, etc.)
1928
+ validateVectorId("doc-123", "id");
1929
+
1930
+ // Search bounds — k, threshold, efSearch range checking
1931
+ validateSearchOptions({ k: 10, threshold: 0.7 });
1932
+
1933
+ // HNSW parameter validation — M, efConstruction, efSearch
1934
+ validateHNSWParams({ M: 16, efConstruction: 200, efSearch: 100 });
1935
+
1936
+ // Metadata sanitization — strips password, token, key, apiKey, auth fields
1937
+ const safe = sanitizeMetadata(userInput);
1938
+
1939
+ // Cypher injection prevention
1940
+ validateCypherParams(params);
1941
+ ```
1942
+
1943
+ ### XSS & Injection Prevention
1944
+
1945
+ ```typescript
1946
+ import {
1947
+ validateTaskString,
1948
+ validateNumericRange,
1949
+ validateEnum,
1950
+ } from "agentdb/security/input-validation";
1951
+
1952
+ const task = validateTaskString(input, "task"); // XSS pattern detection
1953
+ const k = validateNumericRange(kVal, "k", 1, 100);
1954
+ const format = validateEnum(fmt, "format", ["json", "concise", "detailed"]);
1955
+ ```
1956
+
1957
+ ### Security Limits
1958
+
1959
+ | Parameter | Limit |
1960
+ | ----------------------- | ---------- |
1961
+ | Max vectors | 10,000,000 |
1962
+ | Max dimension | 4,096 |
1963
+ | Max batch size | 10,000 |
1964
+ | Max k | 10,000 |
1965
+ | Max metadata size | 64 KB |
1966
+ | Max ID length | 256 chars |
1967
+ | Filter expression depth | 64 |
1968
+ | ef-search range | 1 - 1,000 |
1969
+ | ef-construction range | 4 - 500 |
1970
+ | M range | 2 - 64 |
1971
+
1972
+ ### Witness Chain Verification
11
1973
 
12
- ## What's New in v3
1974
+ SHAKE-256 cryptographic witness chains provide tamper-evident audit trails:
13
1975
 
14
- - **Proof-Gated Mutations** — MutationGuard validates every insert, search, remove, save, and load with structural hashes and attestation tokens
15
- - **8 Graph-Transformer Modules** — Sublinear attention, verified training, causal attention, Granger extraction, Hamiltonian dynamics, spiking attention, game-theoretic equilibrium, product manifold distance
16
- - **AttestationLog** — Append-only audit trail with cryptographic proofs for compliance and debugging
17
- - **GuardedVectorBackend** — Drop-in wrapper that enforces proof gates on any vector backend
18
- - **21 Active Controllers** — All cognitive memory patterns are production-ready with proof validation
19
- - **Zero-Native Regression** — Package size reduced from 50.1MB to 1.4MB by removing unused binaries
20
- - **Browser Support** — Runs in Node.js, browsers, edge functions, and MCP tools via WASM fallback
1976
+ ```typescript
1977
+ const result = backend.verifyWitnessChain();
1978
+ if (!result.valid) {
1979
+ console.error("Data integrity compromised!");
1980
+ }
1981
+ ```
21
1982
 
22
- ## Quick Start
1983
+ ### Provenance Certificates (Explainable Recall)
1984
+
1985
+ Every search result can include a Merkle proof explaining why it was selected:
1986
+
1987
+ ```typescript
1988
+ const { results, certificate } = await causalRecall.recall(
1989
+ "query-id",
1990
+ "optimization strategies",
1991
+ 10,
1992
+ ["performance"],
1993
+ "internal",
1994
+ );
1995
+ console.log(`Certificate ID: ${certificate.id}`);
1996
+ console.log(`Completeness: ${certificate.completenessScore}`);
1997
+ ```
1998
+
1999
+ </details>
2000
+
2001
+ ---
2002
+
2003
+ <details>
2004
+ <summary><strong>Quantization & Compression</strong> — up to 32x memory reduction with 5-tier auto-tiering</summary>
2005
+
2006
+ AgentDB supports multiple quantization strategies to reduce memory footprint while maintaining search quality.
2007
+
2008
+ ### Scalar Quantization
2009
+
2010
+ 8-bit and 4-bit scalar quantization for memory-efficient storage:
2011
+
2012
+ ```typescript
2013
+ import {
2014
+ createScalar8BitStore,
2015
+ createProductQuantizedStore,
2016
+ } from "agentdb/browser/ProductQuantization";
2017
+
2018
+ // 8-bit quantization — 4x memory reduction
2019
+ const store8 = createScalar8BitStore(384);
2020
+ store8.add("doc-1", embedding);
2021
+ const results = store8.search(query, 10);
2022
+
2023
+ // Product quantization — up to 32x memory reduction
2024
+ const storePQ = createProductQuantizedStore(384, {
2025
+ numSubvectors: 48,
2026
+ bitsPerCode: 8,
2027
+ });
2028
+ storePQ.add("doc-1", embedding);
2029
+ const results = storePQ.search(query, 10);
2030
+ ```
2031
+
2032
+ ### 5-Tier Temporal Compression
2033
+
2034
+ Vectors are automatically compressed based on age and access frequency:
2035
+
2036
+ | Tier | Compression | Memory | Quality | Trigger |
2037
+ | ----------- | -------------- | ------ | ------- | ---------------------------- |
2038
+ | **Hot** | None | 100% | 100% | Recent / frequently accessed |
2039
+ | **Warm** | Half-precision | 50% | ~99% | Moderate age |
2040
+ | **Cool** | PQ-8 | ~12% | ~95% | Older data |
2041
+ | **Cold** | PQ-4 | ~6% | ~90% | Rarely accessed |
2042
+ | **Archive** | Binary | ~3% | ~80% | Archival storage |
2043
+
2044
+ ### Matryoshka Dimension Truncation
2045
+
2046
+ Reduce embedding dimensions while preserving the most important features:
2047
+
2048
+ ```typescript
2049
+ // Models trained with Matryoshka loss support dimension truncation
2050
+ // 384d -> 128d with minimal quality loss
2051
+ const truncated = embedding.slice(0, 128);
2052
+ ```
2053
+
2054
+ ### NativeAccelerator Quantization
2055
+
2056
+ The NativeAccelerator provides hardware-accelerated quantization/dequantization:
2057
+
2058
+ ```typescript
2059
+ const accel = new NativeAccelerator();
2060
+ await accel.initialize();
2061
+
2062
+ // Load scalar quantization parameters
2063
+ accel.loadSqParams(mins, scales);
2064
+ const restored = accel.dequantI8(quantizedBytes);
2065
+
2066
+ // Product quantization with codebook
2067
+ accel.loadPqCodebook(codebook, numSubvectors, bitsPerCode);
2068
+ const distances = accel.pqDistances(query, codes);
2069
+ ```
2070
+
2071
+ </details>
2072
+
2073
+ ---
2074
+
2075
+ ### Integration & Tools
2076
+
2077
+ Connect AgentDB to LLM providers, embedding models, and distributed systems with real-time sync.
2078
+
2079
+ <details>
2080
+ <summary><strong>Model Import/Export & Embedding Models</strong> — 5 local models, no API keys</summary>
2081
+
2082
+ ### Embedding Models
2083
+
2084
+ AgentDB supports multiple embedding models. No API key required — all Xenova models run locally.
2085
+
2086
+ | Model | Dimension | Quality | Speed | Best For |
2087
+ | ------------------------------ | --------- | --------- | -------- | ----------------- |
2088
+ | **all-MiniLM-L6-v2** (default) | 384 | Good | Fastest | Prototyping |
2089
+ | **bge-small-en-v1.5** | 384 | Excellent | Fast | Best 384d quality |
2090
+ | **bge-base-en-v1.5** | 768 | Excellent | Moderate | Production |
2091
+ | **all-mpnet-base-v2** | 768 | Excellent | Moderate | All-around |
2092
+ | **e5-base-v2** | 768 | Excellent | Moderate | Multilingual |
2093
+
2094
+ ```bash
2095
+ # Default (384d, fast)
2096
+ npx agentdb init
2097
+
2098
+ # Production (768d, high quality)
2099
+ npx agentdb init --dimension 768 --model "Xenova/bge-base-en-v1.5"
2100
+ ```
2101
+
2102
+ ### Offline Embeddings (Bundled Model)
2103
+
2104
+ The default `all-MiniLM-L6-v2` model can be bundled into a `.rvf` file and shipped with the package. This eliminates the ~23MB first-run download and enables fully offline embedding generation.
2105
+
2106
+ **Resolution order** (automatic, no config needed):
2107
+
2108
+ 1. `AGENTDB_MODEL_PATH` env var (user override)
2109
+ 2. Bundled `.rvf` at `dist/models/all-MiniLM-L6-v2.rvf`
2110
+ 3. Existing `@xenova/transformers` cache
2111
+ 4. Network download (fallback)
23
2112
 
24
2113
  ```bash
25
- # Install v3 Alpha
26
- npm install agentdb@v3
2114
+ # Build the bundled model .rvf (requires model to be downloaded first)
2115
+ npm run build:model
2116
+
2117
+ # Or specify a custom source directory
2118
+ node scripts/build-model-rvf.mjs --source /path/to/model/files
2119
+ ```
2120
+
2121
+ ```typescript
2122
+ // Programmatic access
2123
+ import { ModelCacheLoader } from "agentdb/model";
27
2124
 
28
- # Or use stable v2
29
- npm install agentdb@latest
2125
+ const cached = await ModelCacheLoader.resolve("all-MiniLM-L6-v2");
2126
+ if (cached) {
2127
+ console.log(cached.localPath); // path to extracted model
2128
+ console.log(cached.fromBundle); // true if loaded from .rvf
2129
+ }
2130
+ ```
2131
+
2132
+ Set `AGENTDB_MODEL_PATH` to point to a custom model directory:
2133
+
2134
+ ```bash
2135
+ export AGENTDB_MODEL_PATH=/opt/models
2136
+ # expects: /opt/models/Xenova/all-MiniLM-L6-v2/onnx/model_quantized.onnx
30
2137
  ```
31
2138
 
32
- ## Basic Usage
2139
+ ### LLM Router for Multi-Provider Integration
2140
+
2141
+ AgentDB can route queries through multiple LLM providers via `@ruvector/ruvllm`:
33
2142
 
34
2143
  ```typescript
35
- import { AgentDB } from 'agentdb';
2144
+ import { isRuvLLMInstalled } from "agentdb/wrappers";
36
2145
 
37
- // Initialize with proof-gated vectorBackend
38
- const db = new AgentDB({
39
- dbPath: './agent-memory.db',
40
- dimension: 384,
41
- vectorBackend: 'ruvector',
42
- enableProofGate: true // Default: true in v3
2146
+ if (await isRuvLLMInstalled()) {
2147
+ // LLM router available for enrichment and reranking
2148
+ }
2149
+ ```
2150
+
2151
+ ### RVF Export/Import
2152
+
2153
+ Export vector stores to the portable Cognitive Container format:
2154
+
2155
+ ```bash
2156
+ # Migrate v2 database to v3 unified .rvf (vectors + relational in one file)
2157
+ npx agentdb migrate --source ./v2.db --to v3 --rvf-path ./unified.rvf
2158
+
2159
+ # Export existing database to Cognitive Container
2160
+ npx agentdb migrate --to rvf --rvf-path ./vectors.rvf
2161
+
2162
+ # Import from Cognitive Container into a new backend
2163
+ npx agentdb migrate --from rvf --rvf-path ./vectors.rvf --target ./new.db
2164
+ ```
2165
+
2166
+ ### WASM Export
2167
+
2168
+ Export a WASM store to a transferable binary for sharing between browser tabs or workers:
2169
+
2170
+ ```typescript
2171
+ const bytes = bridge.wasmStoreExport(handle); // Uint8Array
2172
+ // Transfer to another worker or save to IndexedDB
2173
+ ```
2174
+
2175
+ </details>
2176
+
2177
+ ---
2178
+
2179
+ <details>
2180
+ <summary><strong>Query Lifecycle</strong> — what happens when you call searchAsync()</summary>
2181
+
2182
+ The full lifecycle of a query through AgentDB's self-learning pipeline:
2183
+
2184
+ ```mermaid
2185
+ sequenceDiagram
2186
+ participant App
2187
+ participant Router as Semantic Router
2188
+ participant SONA
2189
+ participant HNSW as HNSW Index
2190
+ participant Trainer as Contrastive Trainer
2191
+
2192
+ App->>Router: query(embedding)
2193
+ Router->>Router: classify intent
2194
+ Router->>SONA: enhance(embedding, trajectories)
2195
+ SONA->>SONA: apply micro-LoRA
2196
+ SONA->>HNSW: searchAsync(enhanced, k, ef)
2197
+ HNSW-->>App: results[]
2198
+ App->>Trainer: recordFeedback(quality)
2199
+ Trainer->>Trainer: InfoNCE + hard negatives
2200
+ Trainer->>SONA: updateLoRA(gradients)
2201
+ Note over SONA: EWC++ consolidation<br/>prevents forgetting
2202
+ ```
2203
+
2204
+ ### Phase Breakdown
2205
+
2206
+ 1. **Routing** — `SemanticQueryRouter` classifies query intent via HNSW-indexed embeddings and selects the optimal search strategy
2207
+ 2. **Enhancement** — SONA engine enriches the query embedding using trajectory history and context
2208
+ 3. **LoRA Application** — Micro-LoRA adapter adjusts the embedding in sub-millisecond time
2209
+ 4. **Search** — HNSW index returns top-k results with adaptive ef-search
2210
+ 5. **Feedback** — Application records result quality (0.0-1.0)
2211
+ 6. **Training** — Contrastive trainer runs InfoNCE loss with hard negative mining
2212
+ 7. **Update** — LoRA gradients update the adapter weights
2213
+ 8. **Consolidation** — EWC++ prevents catastrophic forgetting of previously learned patterns
2214
+
2215
+ </details>
2216
+
2217
+ ---
2218
+
2219
+ ### Distributed Systems
2220
+
2221
+ Multi-database coordination, real-time replication, and production observability.
2222
+
2223
+ <details>
2224
+ <summary><strong>Multi-Database Coordination</strong> — distributed sync with conflict resolution</summary>
2225
+
2226
+ The `MultiDatabaseCoordinator` enables distributed sync between multiple AgentDB instances with configurable conflict resolution.
2227
+
2228
+ ```typescript
2229
+ import { MultiDatabaseCoordinator } from "agentdb/coordination/MultiDatabaseCoordinator";
2230
+
2231
+ const coordinator = new MultiDatabaseCoordinator({
2232
+ replicationFactor: 3,
2233
+ syncIntervalMs: 5000,
2234
+ conflictResolution: "merge", // 'last-write-wins' | 'merge' | 'manual'
2235
+ autoFailover: true,
2236
+ maxRetries: 3,
43
2237
  });
44
2238
 
45
- await db.initialize();
2239
+ // Register database instances
2240
+ await coordinator.registerInstance({
2241
+ id: "primary",
2242
+ url: "file:///data/primary.rvf",
2243
+ role: "primary",
2244
+ });
2245
+ await coordinator.registerInstance({
2246
+ id: "replica-1",
2247
+ url: "file:///data/replica-1.rvf",
2248
+ role: "replica",
2249
+ });
46
2250
 
47
- // Access controllers
48
- const reflexion = db.getController('reflexion');
49
- const reasoning = db.getController('reasoning');
50
- const causalGraph = db.getController('causalGraph');
2251
+ // Sync a specific instance
2252
+ const result = await coordinator.syncInstance("replica-1");
2253
+ console.log(`Synced: ${result.recordsSynced}, Conflicts: ${result.conflicts}`);
51
2254
 
52
- // Check proof engine status
53
- const guard = db.getMutationGuard();
54
- console.log(guard?.getStats());
55
- // Output: { engineType: 'native', proofsGenerated: 42, denials: 0 }
2255
+ // Broadcast operations to all instances
2256
+ await coordinator.broadcast("insertAsync", [
2257
+ "doc-1",
2258
+ embedding,
2259
+ { source: "api" },
2260
+ ]);
56
2261
 
57
- // Store episode with automatic proof generation
58
- await reflexion.storeEpisode({
59
- sessionId: 'session-1',
60
- task: 'Debug authentication bug',
61
- reward: 0.95,
62
- success: true,
63
- critique: 'OAuth2 PKCE flow was more secure than basic flow',
64
- input: 'Users cannot log in',
65
- output: 'Working OAuth2 implementation'
2262
+ // Monitor instance status
2263
+ coordinator.onStatusChange((instanceId, status) => {
2264
+ console.log(`${instanceId}: ${status.state}`); // 'healthy' | 'degraded' | 'offline'
66
2265
  });
2266
+ ```
67
2267
 
68
- // Search patterns (proof-validated)
69
- const patterns = await reasoning.searchPatterns({
70
- task: 'authentication security',
71
- k: 10,
72
- threshold: 0.7
2268
+ ### Conflict Resolution Strategies
2269
+
2270
+ | Strategy | Description | Best For |
2271
+ | ------------------- | ------------------------------------- | --------------------------------------- |
2272
+ | **last-write-wins** | Most recent write wins (LWW) | Simple setups, eventual consistency |
2273
+ | **merge** | Quality-based weighted average | Learning systems, federated aggregation |
2274
+ | **manual** | Returns conflicts for user resolution | Critical data, compliance requirements |
2275
+
2276
+ </details>
2277
+
2278
+ ---
2279
+
2280
+ <details>
2281
+ <summary><strong>Real-Time Sync (QUIC)</strong> — bidirectional replication with 0-RTT resumption</summary>
2282
+
2283
+ AgentDB supports real-time bidirectional sync between instances using QUIC transport and a high-level `SyncCoordinator`.
2284
+
2285
+ ### QUIC Transport
2286
+
2287
+ QUIC provides multiplexed streams over a single connection with zero head-of-line blocking, connection migration between networks, and 0-RTT session resumption:
2288
+
2289
+ ```typescript
2290
+ import { QUICServer } from "agentdb/controllers/QUICServer";
2291
+
2292
+ const server = new QUICServer({
2293
+ port: 4433,
2294
+ maxConnections: 100,
2295
+ rateLimit: {
2296
+ requestsPerMin: 1000,
2297
+ bytesPerMin: 10_000_000,
2298
+ },
2299
+ authToken: "secret", // optional token validation
2300
+ });
2301
+
2302
+ // Stale connections auto-cleaned after 5 minutes idle
2303
+ // Sync types: 'episodes' | 'skills' | 'edges' | 'full'
2304
+ // Incremental sync via `since` parameter and cursor-based pagination
2305
+ ```
2306
+
2307
+ ### Sync Coordinator
2308
+
2309
+ High-level bidirectional sync with conflict resolution, progress tracking, and auto-sync:
2310
+
2311
+ ```typescript
2312
+ import { SyncCoordinator } from "agentdb/controllers/SyncCoordinator";
2313
+
2314
+ const sync = new SyncCoordinator({
2315
+ conflictStrategy: "latest-wins", // 'local-wins' | 'remote-wins' | 'latest-wins' | 'merge'
2316
+ batchSize: 100,
2317
+ autoSyncInterval: 60000, // Auto-sync every 60 seconds
73
2318
  });
2319
+
2320
+ // Push local changes, pull remote changes, resolve conflicts
2321
+ const report = await sync.sync();
2322
+ console.log(report);
2323
+ // {
2324
+ // success: true,
2325
+ // durationMs: 342,
2326
+ // itemsPushed: 15,
2327
+ // itemsPulled: 8,
2328
+ // conflictsResolved: 2,
2329
+ // bytesTransferred: 48200,
2330
+ // errors: [],
2331
+ // }
2332
+
2333
+ // Progress tracking through 5 phases:
2334
+ // detecting → pushing → pulling → resolving → applying
2335
+
2336
+ // Sync state persists across restarts
2337
+ await sync.saveSyncState();
2338
+ // Tracks: lastSyncAt, lastEpisodeSync, lastSkillSync, lastEdgeSync,
2339
+ // totalItemsSynced, totalBytesSynced, syncCount
74
2340
  ```
75
2341
 
76
- ## Architecture
2342
+ ### Conflict Resolution
2343
+
2344
+ | Strategy | Behavior |
2345
+ | ------------- | --------------------------------------- |
2346
+ | `local-wins` | Local version always kept |
2347
+ | `remote-wins` | Remote version always accepted |
2348
+ | `latest-wins` | Most recent timestamp wins |
2349
+ | `merge` | Quality-weighted merge of both versions |
2350
+
2351
+ </details>
2352
+
2353
+ ---
2354
+
2355
+ <details>
2356
+ <summary><strong>Observability</strong> — OpenTelemetry traces and Prometheus metrics built in</summary>
2357
+
2358
+ AgentDB integrates with OpenTelemetry for production monitoring.
2359
+
2360
+ ### Traces
77
2361
 
78
- AgentDB v3 introduces a 3-layer architecture:
2362
+ Automatic span creation for search, insert, and sync operations:
79
2363
 
2364
+ ```typescript
2365
+ import { initTelemetry } from "agentdb/observability";
2366
+
2367
+ initTelemetry({
2368
+ serviceName: "my-agent",
2369
+ exporterUrl: "http://localhost:4318", // OTLP HTTP endpoint
2370
+ });
2371
+
2372
+ // All AgentDB operations automatically generate spans:
2373
+ // - agentdb.search (with k, backend, latency attributes)
2374
+ // - agentdb.insert (with batchSize, backend)
2375
+ // - agentdb.sync (with itemsSynced, conflicts)
80
2376
  ```
81
- ┌─────────────────────────────────────────────────────┐
82
- │ Application Layer │
83
- │ (ReasoningBank, ReflexionMemory, SkillLibrary) │
84
- └─────────────────────────────────────────────────────┘
85
-
86
- ┌─────────────────────────────────────────────────────┐
87
- │ Proof Validation Layer │
88
- │ MutationGuard AttestationLog GuardedBackend │
89
- └─────────────────────────────────────────────────────┘
90
-
91
- ┌─────────────────────────────────────────────────────┐
92
- │ Backend Layer │
93
- │ RuVector (native) → WASM → JavaScript │
94
- └─────────────────────────────────────────────────────┘
2377
+
2378
+ ### Metrics
2379
+
2380
+ Prometheus-compatible metrics for latency, throughput, and error rates:
2381
+
2382
+ - `agentdb_search_duration_ms` — search latency histogram
2383
+ - `agentdb_insert_duration_ms` — insert latency histogram
2384
+ - `agentdb_cache_hit_ratio` MCP tool cache effectiveness
2385
+ - `agentdb_learning_loss` — contrastive training loss
2386
+ - `agentdb_vector_count` — total vectors stored
2387
+
2388
+ </details>
2389
+
2390
+ ---
2391
+
2392
+ ### Additional Capabilities
2393
+
2394
+ Reinforcement learning, hybrid search, LLM routing, authentication, and high-performance wrappers.
2395
+
2396
+ <details>
2397
+ <summary><strong>Reinforcement Learning</strong> — 9 algorithms from Q-Learning to Monte Carlo Tree Search</summary>
2398
+
2399
+ AgentDB includes a complete reinforcement learning system with 9 algorithms for building agents that learn optimal strategies through interaction:
2400
+
2401
+ ### Available Algorithms
2402
+
2403
+ | Algorithm | Type | Best For |
2404
+ | --------------------------- | -------------- | ------------------------------------------------------- |
2405
+ | **Q-Learning** | Value-based | Simple discrete action spaces |
2406
+ | **SARSA** | Value-based | On-policy learning, safer exploration |
2407
+ | **Deep Q-Network (DQN)** | Value-based | Complex state spaces with neural function approximation |
2408
+ | **Policy Gradient** | Policy-based | Continuous action spaces |
2409
+ | **Actor-Critic** | Hybrid | Balances value and policy learning |
2410
+ | **PPO** | Policy-based | Stable training with clipped objectives |
2411
+ | **Decision Transformer** | Sequence-based | Offline RL from logged trajectories |
2412
+ | **Monte Carlo Tree Search** | Planning | Game-like decision trees, look-ahead planning |
2413
+ | **Model-Based RL** | Model-based | Sample-efficient learning with world models |
2414
+
2415
+ ### Usage
2416
+
2417
+ ```typescript
2418
+ import { LearningSystem } from "agentdb";
2419
+
2420
+ const learner = new LearningSystem(db, {
2421
+ algorithm: "ppo", // any of the 9 algorithms
2422
+ learningRate: 0.001,
2423
+ discountFactor: 0.99,
2424
+ explorationRate: 0.1,
2425
+ });
2426
+
2427
+ // Start a learning session
2428
+ const session = await learner.createSession({
2429
+ task: "optimize_api_responses",
2430
+ maxEpisodes: 100,
2431
+ });
2432
+
2433
+ // Predict next action
2434
+ const prediction = await learner.predict(session.id, currentState);
2435
+ // { action, confidence, explorationUsed }
2436
+
2437
+ // Record outcome
2438
+ await learner.recordReward(session.id, prediction.action, reward);
2439
+
2440
+ // Train on accumulated experience
2441
+ await learner.train(session.id);
2442
+
2443
+ // Transfer learning to new tasks
2444
+ await learner.transfer(sourceSessionId, targetSessionId);
95
2445
  ```
96
2446
 
97
- Every mutation flows through the proof validation layer:
2447
+ ### MCP Tools for RL
2448
+
2449
+ All 9 algorithms are accessible through MCP tools:
98
2450
 
99
- 1. **Application** calls `storeEpisode()` or `searchPatterns()`
100
- 2. **MutationGuard** generates a proof (structural hash + attestation token)
101
- 3. **AttestationLog** records the proof attempt
102
- 4. **GuardedBackend** validates proof before executing native operation
103
- 5. **Result** returns to application with proof certificate
2451
+ - `agentdb_rl_create_session` start a new learning session
2452
+ - `agentdb_rl_predict` get next action recommendation
2453
+ - `agentdb_rl_record_reward` record outcome feedback
2454
+ - `agentdb_rl_train` trigger training round
2455
+ - `agentdb_rl_transfer` transfer learned policy to new task
2456
+ - `agentdb_rl_explain` — explain why a prediction was made
104
2457
 
105
- ## Key Features
2458
+ </details>
106
2459
 
107
- ### 1. Proof-Gated Mutations (ADR-060)
2460
+ ---
2461
+
2462
+ <details>
2463
+ <summary><strong>Hybrid Search</strong> — BM25 keyword + vector fusion for best-of-both-worlds retrieval</summary>
108
2464
 
109
- Every state mutation requires a cryptographic proof:
2465
+ Combine traditional keyword search (BM25) with vector similarity for retrieval that handles both exact matches and semantic meaning:
110
2466
 
111
2467
  ```typescript
112
- import { MutationGuard } from 'agentdb/security';
2468
+ import { createHybridSearch, createKeywordIndex } from "agentdb";
2469
+
2470
+ // Create keyword index (BM25)
2471
+ const keywordIndex = createKeywordIndex({
2472
+ k1: 1.2, // term frequency saturation
2473
+ b: 0.75, // document length normalization
2474
+ avgDocLength: 100,
2475
+ });
113
2476
 
114
- const guard = new MutationGuard({
115
- strictMode: true,
116
- enableNative: true // Prefer native proofs
2477
+ // Index documents
2478
+ keywordIndex.add("doc-1", "JWT authentication with refresh token rotation");
2479
+ keywordIndex.add("doc-2", "OAuth2 PKCE flow for mobile applications");
2480
+
2481
+ // Create hybrid search (keyword + vector)
2482
+ const hybrid = createHybridSearch(keywordIndex, vectorBackend, {
2483
+ fusion: "rrf", // 'rrf' (Reciprocal Rank Fusion) | 'linear' | 'max'
2484
+ keywordWeight: 0.3, // 30% keyword, 70% vector
2485
+ vectorWeight: 0.7,
2486
+ });
2487
+
2488
+ // Search with both keyword and semantic matching
2489
+ const results = await hybrid.search({
2490
+ text: "JWT refresh token", // keyword query
2491
+ embedding: queryEmbedding, // vector query
2492
+ k: 10,
2493
+ });
2494
+ // Results fused from both sources — exact term matches + semantic similarity
2495
+ ```
2496
+
2497
+ ### Fusion Strategies
2498
+
2499
+ | Strategy | How it works | Best For |
2500
+ | ----------------- | ------------------------------------------------------------------- | -------------------------------- |
2501
+ | **RRF** (default) | `1/(k + rank)` — rank-based fusion, no score calibration needed | General use |
2502
+ | **Linear** | `α × keyword_score + β × vector_score` — weighted score combination | When you know the right balance |
2503
+ | **Max** | `max(keyword_score, vector_score)` — takes highest signal | When either source is sufficient |
2504
+
2505
+ > **When to use hybrid search:** When your data contains domain-specific terms (function names, error codes, product IDs) that vector embeddings might miss, but you also want semantic understanding for natural language queries.
2506
+
2507
+ </details>
2508
+
2509
+ ---
2510
+
2511
+ <details>
2512
+ <summary><strong>LLM Router</strong> — auto-select from 5 providers based on cost, quality, and privacy</summary>
2513
+
2514
+ AgentDB can route LLM queries to the optimal provider based on your constraints:
2515
+
2516
+ ```typescript
2517
+ import { LLMRouter } from "agentdb";
2518
+
2519
+ const router = new LLMRouter({
2520
+ providers: {
2521
+ ruvllm: { enabled: true }, // Local, SIMD-optimized, free
2522
+ openrouter: { apiKey: process.env.OPENROUTER_KEY }, // 200+ models, 99% cost savings
2523
+ gemini: { apiKey: process.env.GEMINI_KEY }, // Free tier available
2524
+ anthropic: { apiKey: process.env.ANTHROPIC_KEY }, // Claude models
2525
+ onnx: { enabled: true }, // Local models via transformers.js
2526
+ },
2527
+ strategy: "auto", // auto-selects based on constraints below
2528
+ constraints: {
2529
+ maxCostPerQuery: 0.001, // max $0.001 per query
2530
+ minQuality: 0.8, // minimum quality score
2531
+ preferLocal: true, // prefer local models when possible
2532
+ requirePrivacy: false, // if true, only uses local providers
2533
+ },
117
2534
  });
118
2535
 
119
- // Insert requires proof
120
- const proof = guard.generateProof({
121
- operation: 'insert',
122
- vectorId: 'vec-123',
123
- embedding: [0.1, 0.2, ...],
124
- metadata: { source: 'reflexion' }
2536
+ const response = await router.generate("Summarize this document...", {
2537
+ maxTokens: 500,
2538
+ temperature: 0.7,
125
2539
  });
2540
+ ```
2541
+
2542
+ ### Provider Comparison
126
2543
 
127
- // Proof includes:
128
- // - structuralHash: SHA-256 of operation + data
129
- // - attestationToken: 82-byte cryptographic token
130
- // - timestamp: ISO8601 timestamp
131
- // - nonce: Random 16-byte nonce
2544
+ | Provider | Latency | Cost | Privacy | Models |
2545
+ | -------------- | ------- | --------- | ------------ | ---------------------------------------- |
2546
+ | **RuvLLM** | Fastest | Free | Full (local) | SIMD-optimized local models |
2547
+ | **ONNX** | Fast | Free | Full (local) | transformers.js models |
2548
+ | **OpenRouter** | ~500ms | $0.0001+ | Cloud | 200+ models (GPT-4, Claude, Llama, etc.) |
2549
+ | **Gemini** | ~300ms | Free tier | Cloud | Gemini Pro, Flash |
2550
+ | **Anthropic** | ~1s | $0.003+ | Cloud | Claude Opus, Sonnet, Haiku |
132
2551
 
133
- // Backend validates before execution
134
- if (guard.validateProof(proof)) {
135
- backend.insert(proof.vectorId, proof.embedding, proof.metadata);
2552
+ ```typescript
2553
+ // Check what's available locally
2554
+ import { isRuvLLMInstalled } from "agentdb";
2555
+ if (await isRuvLLMInstalled()) {
2556
+ // Local inference available — no API keys needed
136
2557
  }
137
2558
  ```
138
2559
 
139
- ### 2. Eight Graph-Transformer Modules
2560
+ </details>
2561
+
2562
+ ---
2563
+
2564
+ <details>
2565
+ <summary><strong>Auth & Audit</strong> — JWT, API keys, Argon2id, and compliance-ready logging</summary>
140
2566
 
141
- Native Rust implementations via `@ruvector/graph-transformer`:
2567
+ Enterprise-ready authentication and audit logging for production deployments.
142
2568
 
143
- - **Sublinear Attention** — O(n log n) replacing O(n²) JavaScript fallback
144
- - **Verified Training** — SGD with cryptographic proof of each gradient step
145
- - **Causal Attention** — Temporal-decay weighted attention for CausalRecall
146
- - **Granger Extract** — Time-series causal discovery for memory graphs
147
- - **Hamiltonian Step** — Physics-informed trajectory modeling
148
- - **Spiking Attention** — Biological integrate-and-fire for episodic memory
149
- - **Game-Theoretic Attention** — Nash equilibrium for multi-agent routing
150
- - **Product Manifold Distance** — Curved-space similarity for reasoning patterns
2569
+ ### Authentication
151
2570
 
152
2571
  ```typescript
153
- import { GraphTransformerService } from 'agentdb';
2572
+ import { AuthService } from "agentdb/services/auth";
2573
+
2574
+ const auth = new AuthService(db, {
2575
+ jwtSecret: process.env.JWT_SECRET,
2576
+ accessTokenTTL: "15m",
2577
+ refreshTokenTTL: "7d",
2578
+ maxLoginAttempts: 5, // account lockout after 5 failures
2579
+ lockoutDuration: "30m",
2580
+ });
2581
+
2582
+ // User registration (Argon2id password hashing)
2583
+ const user = await auth.register({ email, password, role: "user" });
154
2584
 
155
- const transformer = new GraphTransformerService({
156
- enableNative: true,
157
- modules: ['sublinear', 'causal', 'verified']
2585
+ // Login returns access + refresh token pair
2586
+ const { accessToken, refreshToken } = await auth.login(email, password);
2587
+
2588
+ // Token verification
2589
+ const payload = await auth.verifyAccessToken(accessToken);
2590
+
2591
+ // API key management
2592
+ const apiKey = await auth.generateApiKey(userId, {
2593
+ name: "prod-key",
2594
+ scopes: ["read", "write"],
158
2595
  });
2596
+ await auth.rotateApiKey(apiKey.id); // automatic rotation
2597
+ ```
159
2598
 
160
- await transformer.initialize();
2599
+ ### Audit Logging
161
2600
 
162
- // Use sublinear attention (O(n log n))
163
- const attended = await transformer.sublinearAttention(
164
- queryVector,
165
- keyMatrix,
166
- valueMatrix
167
- );
2601
+ ```typescript
2602
+ import { AuditLogger } from "agentdb/services/audit-logger";
168
2603
 
169
- // Verify training step
170
- const trainingProof = await transformer.verifiedTraining(
171
- weights,
172
- gradients,
173
- learningRate
174
- );
2604
+ const audit = new AuditLogger({
2605
+ retention: "90d", // log retention period
2606
+ compliance: ["SOC2", "GDPR"], // compliance frameworks
2607
+ autoRotate: true, // automatic log rotation
2608
+ });
2609
+
2610
+ // 13 audit event types tracked automatically:
2611
+ // - jwt_auth, api_key_create, api_key_rotate, api_key_revoke
2612
+ // - login_success, login_failure, registration
2613
+ // - config_change, permission_change
2614
+ // - rate_limit_exceeded, sensitive_data_access
2615
+ // - data_export, data_deletion
175
2616
  ```
176
2617
 
177
- ### 3. Twenty-One Active Controllers
2618
+ ### Security Utilities
178
2619
 
179
- All cognitive memory patterns are production-ready:
2620
+ ```typescript
2621
+ import {
2622
+ hashPassword,
2623
+ verifyPassword,
2624
+ generateApiKey,
2625
+ } from "agentdb/utils/crypto";
2626
+
2627
+ const hash = await hashPassword("user-password"); // Argon2id
2628
+ const valid = await verifyPassword("user-password", hash);
2629
+ const key = generateApiKey(); // cryptographically random
2630
+ ```
180
2631
 
181
- - **ReflexionMemory** — Self-critique and episodic replay
182
- - **SkillLibrary** — Lifelong learning with skill consolidation
183
- - **ReasoningBank** — Pattern learning and adaptive memory
184
- - **CausalMemoryGraph** — Intervention-based causality tracking
185
- - **CausalRecall** — Utility-based retrieval with uplift scoring
186
- - **ExplainableRecall** — Provenance certificates with Merkle proofs
187
- - **NightlyLearner** — Automated pattern discovery
188
- - **LearningSystem** — 9 RL algorithms (Q-Learning, DQN, PPO, MCTS, etc.)
189
- - **EmbeddingService** — Multi-provider embeddings (Transformers.js, OpenAI)
190
- - **WASMVectorSearch** — Browser-compatible vector search
191
- - **HNSWIndex** — HNSW graph indexing for approximate nearest neighbor
192
- - **AttentionService** — 5 attention mechanisms (causal, spiking, game-theoretic)
193
- - **And 9 more** — See [docs/CONTROLLERS.md](./docs/CONTROLLERS.md)
2632
+ </details>
194
2633
 
195
- ## Installation
2634
+ ---
196
2635
 
197
- ```bash
198
- # v3 Alpha (proof-gated mutations)
199
- npm install agentdb@v3
2636
+ <details>
2637
+ <summary><strong>Metadata Filtering</strong> 10 MongoDB-style query operators</summary>
200
2638
 
201
- # Stable v2 (production-ready)
202
- npm install agentdb@latest
2639
+ Filter search results and database queries using MongoDB-style operators:
203
2640
 
204
- # With optional native addons for 150x performance
205
- npm install agentdb@v3 ruvector@latest
2641
+ ```typescript
2642
+ import { MetadataFilter } from "agentdb";
2643
+
2644
+ const filter = new MetadataFilter();
2645
+
2646
+ // Episodes with reward > 0.8 and specific tags
2647
+ const episodes = await filter.filterEpisodes(db, {
2648
+ reward: { $gt: 0.8 },
2649
+ tags: { $contains: "security" },
2650
+ status: { $in: ["success", "partial"] },
2651
+ archived: { $exists: false },
2652
+ });
206
2653
 
207
- # For browser environments (WASM only)
208
- npm install agentdb@v3
209
- # Native addons will be skipped automatically
2654
+ // Patterns matching complex criteria
2655
+ const patterns = await filter.filterPatterns(db, {
2656
+ successRate: { $gte: 0.7, $lte: 1.0 },
2657
+ taskType: { $ne: "deprecated" },
2658
+ createdAt: { $gt: lastWeekTimestamp },
2659
+ });
210
2660
  ```
211
2661
 
212
- ## API Overview
2662
+ ### Supported Operators
2663
+
2664
+ | Operator | Description | Example |
2665
+ | ----------- | --------------------- | ----------------------------------- |
2666
+ | `$eq` | Equal | `{ status: { $eq: 'active' } }` |
2667
+ | `$ne` | Not equal | `{ role: { $ne: 'admin' } }` |
2668
+ | `$gt` | Greater than | `{ reward: { $gt: 0.5 } }` |
2669
+ | `$gte` | Greater than or equal | `{ score: { $gte: 0.8 } }` |
2670
+ | `$lt` | Less than | `{ age: { $lt: 90 } }` |
2671
+ | `$lte` | Less than or equal | `{ priority: { $lte: 3 } }` |
2672
+ | `$in` | In array | `{ type: { $in: ['a', 'b'] } }` |
2673
+ | `$nin` | Not in array | `{ status: { $nin: ['deleted'] } }` |
2674
+ | `$contains` | Contains substring | `{ tags: { $contains: 'auth' } }` |
2675
+ | `$exists` | Field exists | `{ metadata: { $exists: true } }` |
2676
+
2677
+ </details>
2678
+
2679
+ ---
2680
+
2681
+ <details>
2682
+ <summary><strong>AgentDBFast</strong> — 50-200x faster programmatic API (skip the CLI overhead)</summary>
213
2683
 
214
- ### Core Class
2684
+ The `AgentDBFast` wrapper provides direct programmatic access that's 50-200x faster than going through the CLI:
215
2685
 
216
2686
  ```typescript
217
- import { AgentDB } from 'agentdb';
2687
+ import { createFastAgentDB } from "agentdb/wrappers/agentdb-fast";
218
2688
 
219
- const db = new AgentDB({
220
- dbPath: './memory.db',
2689
+ const db = await createFastAgentDB({
2690
+ path: "./agent-memory.db",
221
2691
  dimension: 384,
222
- vectorBackend: 'ruvector', // or 'hnswlib' | 'sqlite'
223
- enableProofGate: true,
224
- strictMode: true
2692
+ model: "Xenova/all-MiniLM-L6-v2",
225
2693
  });
226
2694
 
227
- await db.initialize();
2695
+ // All operations bypass CLI parsing overhead
2696
+ await db.insert("doc-1", embedding, metadata);
2697
+ const results = await db.search(queryEmbedding, 10);
2698
+ await db.batchInsert(documents);
2699
+
2700
+ // Performance wrapper includes:
2701
+ // - Direct function calls (no CLI arg parsing)
2702
+ // - Pre-initialized connections (no startup cost per call)
2703
+ // - Batched operations
2704
+ // - Connection pooling
228
2705
  ```
229
2706
 
230
- ### Controller Access
2707
+ ### Wrapper Performance vs CLI
231
2708
 
232
- ```typescript
233
- // Get controllers by name
234
- const reflexion = db.getController('reflexion');
235
- const reasoning = db.getController('reasoning');
236
- const skills = db.getController('skills');
237
- const causalGraph = db.getController('causalGraph');
2709
+ | Operation | CLI | AgentDBFast | Speedup |
2710
+ | ------------------ | ------ | ----------- | ------- |
2711
+ | Single insert | ~20ms | ~0.1ms | 200x |
2712
+ | Search (k=10) | ~15ms | ~0.08ms | 187x |
2713
+ | Batch insert (100) | ~500ms | ~10ms | 50x |
238
2714
 
239
- // Access proof engine
240
- const guard = db.getMutationGuard();
241
- const stats = guard?.getStats();
242
- ```
2715
+ ### Attention Wrappers
243
2716
 
244
- ### Security Primitives
2717
+ Production-ready attention implementations with 11-22x speedup over naive:
245
2718
 
246
2719
  ```typescript
247
- import { MutationGuard, AttestationLog } from 'agentdb/security';
2720
+ import {
2721
+ MultiHeadAttention,
2722
+ FlashAttention,
2723
+ LinearAttention,
2724
+ HyperbolicAttention,
2725
+ MoEAttention,
2726
+ } from "agentdb/wrappers";
2727
+
2728
+ // Flash Attention — O(N) memory instead of O(N^2)
2729
+ const flash = new FlashAttention({ numHeads: 8 });
2730
+ const result = await flash.forward(query, keys, values);
2731
+
2732
+ // Mixture of Experts — routes to specialized attention heads
2733
+ const moe = new MoEAttention({ numExperts: 4, topK: 2 });
2734
+ const result = await moe.forward(query, keys, values);
2735
+ ```
2736
+
2737
+ ### Embedding Providers
248
2738
 
249
- // Create guard
250
- const guard = new MutationGuard({
251
- strictMode: true,
252
- enableNative: true,
253
- logPath: './attestations.log'
2739
+ Multiple embedding backends with automatic fallback:
2740
+
2741
+ ```typescript
2742
+ import {
2743
+ OpenAIEmbeddingService,
2744
+ TransformersEmbeddingService,
2745
+ MockEmbeddingService,
2746
+ } from "agentdb/wrappers";
2747
+
2748
+ // OpenAI (cloud)
2749
+ const openai = new OpenAIEmbeddingService({ apiKey: process.env.OPENAI_KEY });
2750
+
2751
+ // Transformers.js (local, free)
2752
+ const local = new TransformersEmbeddingService({
2753
+ model: "Xenova/all-MiniLM-L6-v2",
254
2754
  });
255
2755
 
256
- // Generate proof
257
- const proof = guard.generateProof({
258
- operation: 'insert',
259
- vectorId: 'vec-123',
260
- embedding: embedding,
261
- metadata: { source: 'test' }
2756
+ // Mock (testing)
2757
+ const mock = new MockEmbeddingService({ dimension: 384 });
2758
+ ```
2759
+
2760
+ </details>
2761
+
2762
+ ---
2763
+
2764
+ <details>
2765
+ <summary><strong>Benchmark Suite</strong> — 5 built-in benchmarks with custom benchmark support</summary>
2766
+
2767
+ Run performance benchmarks to validate your deployment:
2768
+
2769
+ ```typescript
2770
+ import { BenchmarkSuite, runBenchmarks, formatReportAsMarkdown } from "agentdb";
2771
+
2772
+ // Run all built-in benchmarks
2773
+ const report = await runBenchmarks({
2774
+ dimension: 384,
2775
+ iterations: 100,
2776
+ warmup: 10,
262
2777
  });
263
2778
 
264
- // Access attestation log
265
- const log = guard.getAttestationLog();
266
- const recentProofs = await log.query({ limit: 10 });
2779
+ console.log(formatReportAsMarkdown(report));
267
2780
  ```
268
2781
 
269
- ### Backend Integration
2782
+ ### Built-in Benchmarks
2783
+
2784
+ | Benchmark | Measures | Key Metrics |
2785
+ | ------------------------- | --------------------- | --------------------------------------- |
2786
+ | **VectorInsertBenchmark** | Insert throughput | ops/sec, p50/p99 latency |
2787
+ | **VectorSearchBenchmark** | Search performance | ops/sec, recall@k, latency distribution |
2788
+ | **MemoryUsageBenchmark** | RAM consumption | bytes per vector, total footprint |
2789
+ | **ConcurrencyBenchmark** | Parallel performance | throughput under load, contention |
2790
+ | **QuantizationBenchmark** | Compression tradeoffs | quality loss vs memory savings |
2791
+
2792
+ ### Custom Benchmarks
270
2793
 
271
2794
  ```typescript
272
- import { GuardedVectorBackend } from 'agentdb/backends';
2795
+ import { Benchmark, BenchmarkSuite } from "agentdb";
2796
+
2797
+ class MyBenchmark extends Benchmark {
2798
+ name = "my-custom-benchmark";
2799
+
2800
+ async setup() {
2801
+ /* prepare data */
2802
+ }
2803
+ async run() {
2804
+ /* measure this */
2805
+ }
2806
+ async teardown() {
2807
+ /* cleanup */
2808
+ }
2809
+ }
273
2810
 
274
- // Wrap any backend with proof validation
275
- const guardedBackend = new GuardedVectorBackend(rawBackend, guard);
2811
+ const suite = new BenchmarkSuite();
2812
+ suite.add(new MyBenchmark());
2813
+ const report = await suite.run({ iterations: 50 });
276
2814
 
277
- // All operations require proof
278
- await guardedBackend.insert(proof);
279
- await guardedBackend.search(query, k, proof);
2815
+ // Compare reports across runs
2816
+ import { formatComparisonAsMarkdown } from "agentdb";
2817
+ console.log(formatComparisonAsMarkdown(reportBefore, reportAfter));
280
2818
  ```
281
2819
 
282
- ## Performance
2820
+ ### CLI Benchmarks
283
2821
 
284
- **Proof Generation:**
285
- - Native (NAPI-RS): ~50μs per proof
286
- - WASM: ~200μs per proof
287
- - JavaScript: ~500μs per proof
2822
+ ```bash
2823
+ npm run benchmark # Quick benchmark
2824
+ npm run benchmark:full # Full suite
2825
+ npm run benchmark:attention # Attention mechanism performance
2826
+ npm run benchmark:backends # Compare all backends
2827
+ npm run benchmark:ruvector # RuVector-specific benchmarks
2828
+ npm run benchmark:all # Everything
2829
+ ```
288
2830
 
289
- **Vector Operations (with RuVector):**
290
- - Insert: 150x faster than JavaScript
291
- - Search: 61μs p50 latency (96.8% recall@10)
292
- - Pattern search: 32.6M ops/sec with caching
2831
+ </details>
293
2832
 
294
- **Package Size:**
295
- - v2: 50.1MB (with unused native binaries)
296
- - v3: 1.4MB (zero-native regression fixed)
2833
+ ---
297
2834
 
298
- ## Documentation
2835
+ ## Testing
299
2836
 
300
- - **[ADR-060: Proof-Gated Mutations](./docs/adr/ADR-060-agentdb-v3-proof-gated-graph-intelligence.md)** — Architecture decision record
301
- - **[Controllers Guide](./docs/CONTROLLERS.md)** All 21 controllers documented
302
- - **[MCP Tools Reference](./docs/MCP_TOOLS.md)** — 32 MCP tools for Claude Code
303
- - **[Migration Guide](./MIGRATION_v3.0.0.md)** — Upgrade from v2 to v3
304
- - **[Security Model](./docs/SECURITY.md)** — Proof validation and attestation
2837
+ <details>
2838
+ <summary><strong>Test Suite</strong>unit, integration, performance, security, and browser tests</summary>
305
2839
 
306
- ## MCP Integration (Claude Code)
2840
+ AgentDB ships with a comprehensive test suite covering every layer of the stack. All tests run via [Vitest](https://vitest.dev/) with parallel execution.
307
2841
 
308
- Zero-code integration with AI coding assistants:
2842
+ ### Quick Commands
309
2843
 
310
2844
  ```bash
311
- # One-command setup
312
- claude mcp add agentdb npx agentdb@v3 mcp start
2845
+ npm test # Run all tests (watch mode)
2846
+ npm run test:unit # Unit tests only (single run)
2847
+ npm run test:browser # Browser bundle + WASM tests
2848
+ npm run test:ci # CI pipeline: browser tests + build + bundle verification
2849
+ ```
313
2850
 
314
- # Now Claude Code can:
315
- # - Store reasoning patterns with proof validation
316
- # - Search 32.6M patterns/sec for relevant approaches
317
- # - Learn from successful task completions
318
- # - Build reusable skills with attestation logs
2851
+ ### What's Tested
2852
+
2853
+ | Suite | Coverage | What it validates |
2854
+ | --------------------- | ---------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
2855
+ | **Unit tests** | Core controllers, memory patterns, embedding service, quantization | All 6 cognitive memory patterns, 9 RL algorithms, filter expressions, security validators |
2856
+ | **Browser tests** | WASM store, attention mechanisms, product quantization, SIMD fallbacks | Full vector DB in browser, Flash/Hyperbolic/MoE attention, PQ8/PQ16/PQ32 compression |
2857
+ | **Integration tests** | End-to-end flows, backend auto-selection, MCP tool execution | Self-learning pipeline, Cognitive Container operations, federated aggregation |
2858
+ | **Performance tests** | Latency benchmarks, throughput, scaling behavior | 61us search target, 32.6M ops/sec pattern search, batch insert speedup |
2859
+ | **Security tests** | Input validation, injection prevention, witness chain verification | XSS patterns, SQL injection, path traversal, Cypher sanitization, SHAKE-256 |
2860
+
2861
+ ### Benchmarks
2862
+
2863
+ ```bash
2864
+ npm run benchmark # Quick benchmark (insert + search)
2865
+ npm run benchmark:full # Full suite with all backends
2866
+ npm run benchmark:attention # Attention mechanism performance
2867
+ npm run benchmark:backends # Compare RuVector vs RVF vs HNSWLib vs sql.js
2868
+ npm run benchmark:ruvector # RuVector-specific benchmarks
2869
+ npm run benchmark:all # Run everything
319
2870
  ```
320
2871
 
321
- ## License
2872
+ ### CI Pipeline
2873
+
2874
+ The CI pipeline runs `test:ci` which executes:
2875
+
2876
+ 1. **Browser bundle tests** — verifies WASM and JS fallbacks work
2877
+ 2. **TypeScript build** — full `tsc` compilation
2878
+ 3. **Bundle verification** — ensures all export paths resolve correctly
2879
+
2880
+ ### Writing Custom Tests
322
2881
 
323
- MIT OR Apache-2.0
2882
+ ```typescript
2883
+ import { describe, it, expect } from "vitest";
2884
+ import { createDatabase, ReasoningBank, EmbeddingService } from "agentdb";
2885
+
2886
+ describe("My Agent Memory", () => {
2887
+ it("stores and retrieves patterns", async () => {
2888
+ const db = await createDatabase(":memory:");
2889
+ const embedder = new EmbeddingService({ model: "Xenova/all-MiniLM-L6-v2" });
2890
+ await embedder.initialize();
2891
+
2892
+ const bank = new ReasoningBank(db, embedder);
2893
+ await bank.storePattern({
2894
+ taskType: "test",
2895
+ approach: "TDD",
2896
+ successRate: 0.95,
2897
+ });
2898
+
2899
+ const results = await bank.searchPatterns({ task: "testing", k: 5 });
2900
+ expect(results.length).toBeGreaterThan(0);
2901
+ });
2902
+ });
2903
+ ```
2904
+
2905
+ </details>
2906
+
2907
+ ---
2908
+
2909
+ ## Documentation
324
2910
 
325
- See [LICENSE-MIT](LICENSE-MIT) and [LICENSE-APACHE](LICENSE-APACHE) for details.
2911
+ | Document | Description |
2912
+ | ------------------------------------------------------------------------------------ | ------------------------------------------ |
2913
+ | [MCP Tool Optimization Guide](docs/guides/) | Comprehensive MCP patterns |
2914
+ | [Embedding Models Guide](docs/guides/) | Model selection and benchmarks |
2915
+ | [Simulation System](simulation/README.md) | 31 scenarios, interactive wizard |
2916
+ | [Security Hardening](docs/guides/) | Input validation and security patterns |
2917
+ | [Chat Ecosystem](../agentdb-chat/README.md) | `@agentdb/chat` integration guide |
2918
+ | [ADR-010: Solver Integration](docs/adrs/ADR-010-rvf-solver-v014-deep-integration.md) | SolverBandit + rvf-solver deep integration |
2919
+
2920
+ ---
326
2921
 
327
2922
  ## Contributing
328
2923
 
329
- We welcome contributions! See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
2924
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines. Areas of interest: additional RL algorithms, performance optimizations, new backend integrations, documentation improvements.
2925
+
2926
+ ---
330
2927
 
331
- ## Acknowledgments
2928
+ ## License
332
2929
 
333
- AgentDB v3 builds on research from:
334
- - **RuVector** — Native Rust vector database (150x faster)
335
- - **Reflexion** (Shinn et al., 2023) — Self-critique and episodic replay
336
- - **Causal Inference** (Pearl, Judea) — Intervention-based causality
337
- - **HNSW** (Malkov & Yashunin, 2018) — Approximate nearest neighbor search
338
- - **Graph Neural Networks** — Attention mechanisms for memory navigation
2930
+ MIT OR Apache-2.0 See [LICENSE-MIT](LICENSE-MIT) and [LICENSE-APACHE](LICENSE-APACHE).
339
2931
 
340
2932
  ---
341
2933
 
342
- **Built with ❤️ for the agentic era**
2934
+ **The only vector database that learns.** Start in 30 seconds:
2935
+
2936
+ ```bash
2937
+ npm install agentdb
2938
+ ```
343
2939
 
344
- [Documentation](./docs/) | [GitHub](https://github.com/ruvnet/agentic-flow/tree/main/packages/agentdb) | [npm](https://www.npmjs.com/package/agentdb)
2940
+ [Quick Start](#quick-start) | [Tutorials](#tutorials) | [MCP Integration](#mcp-integration) | [GitHub](https://github.com/ruvnet/agentic-flow/tree/main/packages/agentdb) | [npm](https://www.npmjs.com/package/agentdb)