agentdb 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (361) hide show
  1. package/LICENSE +38 -0
  2. package/LICENSE-APACHE +190 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +953 -0
  5. package/bin/agentdb.js +485 -0
  6. package/bin/plugin-cli-wrapper.mjs +21 -0
  7. package/dist/cache/query-cache.d.ts +105 -0
  8. package/dist/cache/query-cache.d.ts.map +1 -0
  9. package/dist/cache/query-cache.js +224 -0
  10. package/dist/cache/query-cache.js.map +1 -0
  11. package/dist/cache/query-cache.mjs +219 -0
  12. package/dist/cli/cache/query-cache.d.ts +104 -0
  13. package/dist/cli/cache/query-cache.js +244 -0
  14. package/dist/cli/cli/db-commands.d.ts +48 -0
  15. package/dist/cli/cli/db-commands.js +613 -0
  16. package/dist/cli/commands.d.ts +7 -0
  17. package/dist/cli/commands.d.ts.map +1 -0
  18. package/dist/cli/commands.js +113 -0
  19. package/dist/cli/commands.js.map +1 -0
  20. package/dist/cli/commands.mjs +104 -0
  21. package/dist/cli/core/backend-interface.d.ts +70 -0
  22. package/dist/cli/core/backend-interface.js +15 -0
  23. package/dist/cli/core/native-backend.d.ts +140 -0
  24. package/dist/cli/core/native-backend.js +432 -0
  25. package/dist/cli/core/vector-db.d.ts +126 -0
  26. package/dist/cli/core/vector-db.js +338 -0
  27. package/dist/cli/core/wasm-backend.d.ts +95 -0
  28. package/dist/cli/core/wasm-backend.js +418 -0
  29. package/dist/cli/db-commands.d.ts +49 -0
  30. package/dist/cli/db-commands.d.ts.map +1 -0
  31. package/dist/cli/db-commands.js +533 -0
  32. package/dist/cli/db-commands.js.map +1 -0
  33. package/dist/cli/db-commands.mjs +522 -0
  34. package/dist/cli/generator.d.ts +11 -0
  35. package/dist/cli/generator.d.ts.map +1 -0
  36. package/dist/cli/generator.js +567 -0
  37. package/dist/cli/generator.js.map +1 -0
  38. package/dist/cli/generator.mjs +527 -0
  39. package/dist/cli/help.d.ts +18 -0
  40. package/dist/cli/help.d.ts.map +1 -0
  41. package/dist/cli/help.js +676 -0
  42. package/dist/cli/help.js.map +1 -0
  43. package/dist/cli/help.mjs +667 -0
  44. package/dist/cli/index/hnsw.d.ts +164 -0
  45. package/dist/cli/index/hnsw.js +558 -0
  46. package/dist/cli/plugin-cli.d.ts +7 -0
  47. package/dist/cli/plugin-cli.d.ts.map +1 -0
  48. package/dist/cli/plugin-cli.js +295 -0
  49. package/dist/cli/plugin-cli.js.map +1 -0
  50. package/dist/cli/plugin-cli.mjs +289 -0
  51. package/dist/cli/quantization/product-quantization.d.ts +108 -0
  52. package/dist/cli/quantization/product-quantization.js +350 -0
  53. package/dist/cli/query/query-builder.d.ts +322 -0
  54. package/dist/cli/query/query-builder.js +600 -0
  55. package/dist/cli/templates.d.ts +14 -0
  56. package/dist/cli/templates.d.ts.map +1 -0
  57. package/dist/cli/templates.js +182 -0
  58. package/dist/cli/templates.js.map +1 -0
  59. package/dist/cli/templates.mjs +176 -0
  60. package/dist/cli/types/index.d.ts +116 -0
  61. package/dist/cli/types/index.js +5 -0
  62. package/dist/cli/types.d.ts +91 -0
  63. package/dist/cli/types.d.ts.map +1 -0
  64. package/dist/cli/types.js +6 -0
  65. package/dist/cli/types.js.map +1 -0
  66. package/dist/cli/types.mjs +4 -0
  67. package/dist/cli/wizard/index.d.ts +6 -0
  68. package/dist/cli/wizard/index.d.ts.map +1 -0
  69. package/dist/cli/wizard/index.js +138 -0
  70. package/dist/cli/wizard/index.js.map +1 -0
  71. package/dist/cli/wizard/index.mjs +131 -0
  72. package/dist/cli/wizard/prompts.d.ts +11 -0
  73. package/dist/cli/wizard/prompts.d.ts.map +1 -0
  74. package/dist/cli/wizard/prompts.js +482 -0
  75. package/dist/cli/wizard/prompts.js.map +1 -0
  76. package/dist/cli/wizard/prompts.mjs +470 -0
  77. package/dist/cli/wizard/validator.d.ts +13 -0
  78. package/dist/cli/wizard/validator.d.ts.map +1 -0
  79. package/dist/cli/wizard/validator.js +234 -0
  80. package/dist/cli/wizard/validator.js.map +1 -0
  81. package/dist/cli/wizard/validator.mjs +224 -0
  82. package/dist/core/backend-interface.d.ts +71 -0
  83. package/dist/core/backend-interface.d.ts.map +1 -0
  84. package/dist/core/backend-interface.js +16 -0
  85. package/dist/core/backend-interface.js.map +1 -0
  86. package/dist/core/backend-interface.mjs +12 -0
  87. package/dist/core/native-backend.d.ts +141 -0
  88. package/dist/core/native-backend.d.ts.map +1 -0
  89. package/dist/core/native-backend.js +457 -0
  90. package/dist/core/native-backend.js.map +1 -0
  91. package/dist/core/native-backend.mjs +449 -0
  92. package/dist/core/vector-db.d.ts +127 -0
  93. package/dist/core/vector-db.d.ts.map +1 -0
  94. package/dist/core/vector-db.js +266 -0
  95. package/dist/core/vector-db.js.map +1 -0
  96. package/dist/core/vector-db.mjs +261 -0
  97. package/dist/core/wasm-backend.d.ts +96 -0
  98. package/dist/core/wasm-backend.d.ts.map +1 -0
  99. package/dist/core/wasm-backend.js +393 -0
  100. package/dist/core/wasm-backend.js.map +1 -0
  101. package/dist/core/wasm-backend.mjs +385 -0
  102. package/dist/index/hnsw-optimized.d.ts +75 -0
  103. package/dist/index/hnsw-optimized.d.ts.map +1 -0
  104. package/dist/index/hnsw-optimized.js +412 -0
  105. package/dist/index/hnsw-optimized.js.map +1 -0
  106. package/dist/index/hnsw-optimized.mjs +407 -0
  107. package/dist/index/hnsw.d.ts +165 -0
  108. package/dist/index/hnsw.d.ts.map +1 -0
  109. package/dist/index/hnsw.js +521 -0
  110. package/dist/index/hnsw.js.map +1 -0
  111. package/dist/index/hnsw.mjs +516 -0
  112. package/dist/index.d.ts +57 -0
  113. package/dist/index.d.ts.map +1 -0
  114. package/dist/index.js +82 -0
  115. package/dist/index.js.map +1 -0
  116. package/dist/index.mjs +63 -0
  117. package/dist/mcp-server.d.ts +27 -0
  118. package/dist/mcp-server.d.ts.map +1 -0
  119. package/dist/mcp-server.js +789 -0
  120. package/dist/mcp-server.js.map +1 -0
  121. package/dist/mcp-server.mjs +784 -0
  122. package/dist/plugins/base-plugin.d.ts +114 -0
  123. package/dist/plugins/base-plugin.d.ts.map +1 -0
  124. package/dist/plugins/base-plugin.js +313 -0
  125. package/dist/plugins/base-plugin.js.map +1 -0
  126. package/dist/plugins/base-plugin.mjs +275 -0
  127. package/dist/plugins/implementations/active-learning.d.ts +135 -0
  128. package/dist/plugins/implementations/active-learning.d.ts.map +1 -0
  129. package/dist/plugins/implementations/active-learning.js +372 -0
  130. package/dist/plugins/implementations/active-learning.js.map +1 -0
  131. package/dist/plugins/implementations/active-learning.mjs +367 -0
  132. package/dist/plugins/implementations/actor-critic.d.ts +64 -0
  133. package/dist/plugins/implementations/actor-critic.d.ts.map +1 -0
  134. package/dist/plugins/implementations/actor-critic.js +363 -0
  135. package/dist/plugins/implementations/actor-critic.js.map +1 -0
  136. package/dist/plugins/implementations/actor-critic.mjs +358 -0
  137. package/dist/plugins/implementations/adversarial-training.d.ts +133 -0
  138. package/dist/plugins/implementations/adversarial-training.d.ts.map +1 -0
  139. package/dist/plugins/implementations/adversarial-training.js +409 -0
  140. package/dist/plugins/implementations/adversarial-training.js.map +1 -0
  141. package/dist/plugins/implementations/adversarial-training.mjs +404 -0
  142. package/dist/plugins/implementations/curriculum-learning.d.ts +132 -0
  143. package/dist/plugins/implementations/curriculum-learning.d.ts.map +1 -0
  144. package/dist/plugins/implementations/curriculum-learning.js +354 -0
  145. package/dist/plugins/implementations/curriculum-learning.js.map +1 -0
  146. package/dist/plugins/implementations/curriculum-learning.mjs +349 -0
  147. package/dist/plugins/implementations/decision-transformer.d.ts +77 -0
  148. package/dist/plugins/implementations/decision-transformer.d.ts.map +1 -0
  149. package/dist/plugins/implementations/decision-transformer.js +422 -0
  150. package/dist/plugins/implementations/decision-transformer.js.map +1 -0
  151. package/dist/plugins/implementations/decision-transformer.mjs +417 -0
  152. package/dist/plugins/implementations/federated-learning.d.ts +126 -0
  153. package/dist/plugins/implementations/federated-learning.d.ts.map +1 -0
  154. package/dist/plugins/implementations/federated-learning.js +436 -0
  155. package/dist/plugins/implementations/federated-learning.js.map +1 -0
  156. package/dist/plugins/implementations/federated-learning.mjs +431 -0
  157. package/dist/plugins/implementations/index.d.ts +30 -0
  158. package/dist/plugins/implementations/index.d.ts.map +1 -0
  159. package/dist/plugins/implementations/index.js +45 -0
  160. package/dist/plugins/implementations/index.js.map +1 -0
  161. package/dist/plugins/implementations/index.mjs +31 -0
  162. package/dist/plugins/implementations/multi-task-learning.d.ts +115 -0
  163. package/dist/plugins/implementations/multi-task-learning.d.ts.map +1 -0
  164. package/dist/plugins/implementations/multi-task-learning.js +369 -0
  165. package/dist/plugins/implementations/multi-task-learning.js.map +1 -0
  166. package/dist/plugins/implementations/multi-task-learning.mjs +364 -0
  167. package/dist/plugins/implementations/neural-architecture-search.d.ts +148 -0
  168. package/dist/plugins/implementations/neural-architecture-search.d.ts.map +1 -0
  169. package/dist/plugins/implementations/neural-architecture-search.js +379 -0
  170. package/dist/plugins/implementations/neural-architecture-search.js.map +1 -0
  171. package/dist/plugins/implementations/neural-architecture-search.mjs +374 -0
  172. package/dist/plugins/implementations/q-learning.d.ts +98 -0
  173. package/dist/plugins/implementations/q-learning.d.ts.map +1 -0
  174. package/dist/plugins/implementations/q-learning.js +435 -0
  175. package/dist/plugins/implementations/q-learning.js.map +1 -0
  176. package/dist/plugins/implementations/q-learning.mjs +430 -0
  177. package/dist/plugins/implementations/sarsa.d.ts +103 -0
  178. package/dist/plugins/implementations/sarsa.d.ts.map +1 -0
  179. package/dist/plugins/implementations/sarsa.js +347 -0
  180. package/dist/plugins/implementations/sarsa.js.map +1 -0
  181. package/dist/plugins/implementations/sarsa.mjs +342 -0
  182. package/dist/plugins/index.d.ts +107 -0
  183. package/dist/plugins/index.d.ts.map +1 -0
  184. package/dist/plugins/index.js +179 -0
  185. package/dist/plugins/index.js.map +1 -0
  186. package/dist/plugins/index.mjs +168 -0
  187. package/dist/plugins/interface.d.ts +439 -0
  188. package/dist/plugins/interface.d.ts.map +1 -0
  189. package/dist/plugins/interface.js +12 -0
  190. package/dist/plugins/interface.js.map +1 -0
  191. package/dist/plugins/interface.mjs +10 -0
  192. package/dist/plugins/learning-plugin.interface.d.ts +257 -0
  193. package/dist/plugins/learning-plugin.interface.d.ts.map +1 -0
  194. package/dist/plugins/learning-plugin.interface.js +7 -0
  195. package/dist/plugins/learning-plugin.interface.js.map +1 -0
  196. package/dist/plugins/learning-plugin.interface.mjs +5 -0
  197. package/dist/plugins/plugin-exports.d.ts +71 -0
  198. package/dist/plugins/plugin-exports.d.ts.map +1 -0
  199. package/dist/plugins/plugin-exports.js +78 -0
  200. package/dist/plugins/plugin-exports.js.map +1 -0
  201. package/dist/plugins/plugin-exports.mjs +69 -0
  202. package/dist/plugins/registry.d.ts +206 -0
  203. package/dist/plugins/registry.d.ts.map +1 -0
  204. package/dist/plugins/registry.js +365 -0
  205. package/dist/plugins/registry.js.map +1 -0
  206. package/dist/plugins/registry.mjs +356 -0
  207. package/dist/plugins/validator.d.ts +63 -0
  208. package/dist/plugins/validator.d.ts.map +1 -0
  209. package/dist/plugins/validator.js +464 -0
  210. package/dist/plugins/validator.js.map +1 -0
  211. package/dist/plugins/validator.mjs +458 -0
  212. package/dist/quantization/binary-quantization.d.ts +104 -0
  213. package/dist/quantization/binary-quantization.d.ts.map +1 -0
  214. package/dist/quantization/binary-quantization.js +246 -0
  215. package/dist/quantization/binary-quantization.js.map +1 -0
  216. package/dist/quantization/binary-quantization.mjs +240 -0
  217. package/dist/quantization/optimized-pq.d.ts +138 -0
  218. package/dist/quantization/optimized-pq.d.ts.map +1 -0
  219. package/dist/quantization/optimized-pq.js +320 -0
  220. package/dist/quantization/optimized-pq.js.map +1 -0
  221. package/dist/quantization/optimized-pq.mjs +313 -0
  222. package/dist/quantization/product-quantization.d.ts +109 -0
  223. package/dist/quantization/product-quantization.d.ts.map +1 -0
  224. package/dist/quantization/product-quantization.js +287 -0
  225. package/dist/quantization/product-quantization.js.map +1 -0
  226. package/dist/quantization/product-quantization.mjs +282 -0
  227. package/dist/quantization/scalar-quantization.d.ts +100 -0
  228. package/dist/quantization/scalar-quantization.d.ts.map +1 -0
  229. package/dist/quantization/scalar-quantization.js +324 -0
  230. package/dist/quantization/scalar-quantization.js.map +1 -0
  231. package/dist/quantization/scalar-quantization.mjs +319 -0
  232. package/dist/query/index.d.ts +6 -0
  233. package/dist/query/index.d.ts.map +1 -0
  234. package/dist/query/index.js +9 -0
  235. package/dist/query/index.js.map +1 -0
  236. package/dist/query/index.mjs +4 -0
  237. package/dist/query/query-builder.d.ts +323 -0
  238. package/dist/query/query-builder.d.ts.map +1 -0
  239. package/dist/query/query-builder.js +524 -0
  240. package/dist/query/query-builder.js.map +1 -0
  241. package/dist/query/query-builder.mjs +519 -0
  242. package/dist/reasoning/context-synthesizer.d.ts +57 -0
  243. package/dist/reasoning/context-synthesizer.d.ts.map +1 -0
  244. package/dist/reasoning/context-synthesizer.js +224 -0
  245. package/dist/reasoning/context-synthesizer.js.map +1 -0
  246. package/dist/reasoning/context-synthesizer.mjs +219 -0
  247. package/dist/reasoning/experience-curator.d.ts +66 -0
  248. package/dist/reasoning/experience-curator.d.ts.map +1 -0
  249. package/dist/reasoning/experience-curator.js +288 -0
  250. package/dist/reasoning/experience-curator.js.map +1 -0
  251. package/dist/reasoning/experience-curator.mjs +283 -0
  252. package/dist/reasoning/memory-optimizer.d.ts +69 -0
  253. package/dist/reasoning/memory-optimizer.d.ts.map +1 -0
  254. package/dist/reasoning/memory-optimizer.js +331 -0
  255. package/dist/reasoning/memory-optimizer.js.map +1 -0
  256. package/dist/reasoning/memory-optimizer.mjs +326 -0
  257. package/dist/reasoning/pattern-matcher.d.ts +59 -0
  258. package/dist/reasoning/pattern-matcher.d.ts.map +1 -0
  259. package/dist/reasoning/pattern-matcher.js +229 -0
  260. package/dist/reasoning/pattern-matcher.js.map +1 -0
  261. package/dist/reasoning/pattern-matcher.mjs +224 -0
  262. package/dist/reasoningbank/adapter/agentdb-adapter.d.ts +118 -0
  263. package/dist/reasoningbank/adapter/agentdb-adapter.d.ts.map +1 -0
  264. package/dist/reasoningbank/adapter/agentdb-adapter.js +477 -0
  265. package/dist/reasoningbank/adapter/agentdb-adapter.js.map +1 -0
  266. package/dist/reasoningbank/adapter/types.d.ts +113 -0
  267. package/dist/reasoningbank/adapter/types.d.ts.map +1 -0
  268. package/dist/reasoningbank/adapter/types.js +9 -0
  269. package/dist/reasoningbank/adapter/types.js.map +1 -0
  270. package/dist/reasoningbank/cli/commands.d.ts +16 -0
  271. package/dist/reasoningbank/cli/commands.d.ts.map +1 -0
  272. package/dist/reasoningbank/cli/commands.js +272 -0
  273. package/dist/reasoningbank/cli/commands.js.map +1 -0
  274. package/dist/reasoningbank/mcp/agentdb-tools.d.ts +319 -0
  275. package/dist/reasoningbank/mcp/agentdb-tools.d.ts.map +1 -0
  276. package/dist/reasoningbank/mcp/agentdb-tools.js +301 -0
  277. package/dist/reasoningbank/mcp/agentdb-tools.js.map +1 -0
  278. package/dist/reasoningbank/migration/migrate.d.ts +25 -0
  279. package/dist/reasoningbank/migration/migrate.d.ts.map +1 -0
  280. package/dist/reasoningbank/migration/migrate.js +178 -0
  281. package/dist/reasoningbank/migration/migrate.js.map +1 -0
  282. package/dist/reasoningbank/reasoning/context-synthesizer.d.ts +37 -0
  283. package/dist/reasoningbank/reasoning/context-synthesizer.d.ts.map +1 -0
  284. package/dist/reasoningbank/reasoning/context-synthesizer.js +114 -0
  285. package/dist/reasoningbank/reasoning/context-synthesizer.js.map +1 -0
  286. package/dist/reasoningbank/reasoning/experience-curator.d.ts +39 -0
  287. package/dist/reasoningbank/reasoning/experience-curator.d.ts.map +1 -0
  288. package/dist/reasoningbank/reasoning/experience-curator.js +98 -0
  289. package/dist/reasoningbank/reasoning/experience-curator.js.map +1 -0
  290. package/dist/reasoningbank/reasoning/memory-optimizer.d.ts +44 -0
  291. package/dist/reasoningbank/reasoning/memory-optimizer.d.ts.map +1 -0
  292. package/dist/reasoningbank/reasoning/memory-optimizer.js +184 -0
  293. package/dist/reasoningbank/reasoning/memory-optimizer.js.map +1 -0
  294. package/dist/reasoningbank/reasoning/pattern-matcher.d.ts +40 -0
  295. package/dist/reasoningbank/reasoning/pattern-matcher.d.ts.map +1 -0
  296. package/dist/reasoningbank/reasoning/pattern-matcher.js +87 -0
  297. package/dist/reasoningbank/reasoning/pattern-matcher.js.map +1 -0
  298. package/dist/reasoningbank/sync/quic-sync.d.ts +77 -0
  299. package/dist/reasoningbank/sync/quic-sync.d.ts.map +1 -0
  300. package/dist/reasoningbank/sync/quic-sync.js +165 -0
  301. package/dist/reasoningbank/sync/quic-sync.js.map +1 -0
  302. package/dist/sync/conflict.d.ts +78 -0
  303. package/dist/sync/conflict.d.ts.map +1 -0
  304. package/dist/sync/conflict.js +202 -0
  305. package/dist/sync/conflict.js.map +1 -0
  306. package/dist/sync/conflict.mjs +196 -0
  307. package/dist/sync/coordinator.d.ts +111 -0
  308. package/dist/sync/coordinator.d.ts.map +1 -0
  309. package/dist/sync/coordinator.js +256 -0
  310. package/dist/sync/coordinator.js.map +1 -0
  311. package/dist/sync/coordinator.mjs +250 -0
  312. package/dist/sync/delta.d.ts +81 -0
  313. package/dist/sync/delta.d.ts.map +1 -0
  314. package/dist/sync/delta.js +245 -0
  315. package/dist/sync/delta.js.map +1 -0
  316. package/dist/sync/delta.mjs +238 -0
  317. package/dist/sync/index.d.ts +11 -0
  318. package/dist/sync/index.d.ts.map +1 -0
  319. package/dist/sync/index.js +22 -0
  320. package/dist/sync/index.js.map +1 -0
  321. package/dist/sync/index.mjs +9 -0
  322. package/dist/sync/quic-sync.d.ts +81 -0
  323. package/dist/sync/quic-sync.d.ts.map +1 -0
  324. package/dist/sync/quic-sync.js +329 -0
  325. package/dist/sync/quic-sync.js.map +1 -0
  326. package/dist/sync/quic-sync.mjs +323 -0
  327. package/dist/sync/types.d.ts +168 -0
  328. package/dist/sync/types.d.ts.map +1 -0
  329. package/dist/sync/types.js +8 -0
  330. package/dist/sync/types.js.map +1 -0
  331. package/dist/sync/types.mjs +6 -0
  332. package/dist/types/index.d.ts +117 -0
  333. package/dist/types/index.d.ts.map +1 -0
  334. package/dist/types/index.js +6 -0
  335. package/dist/types/index.js.map +1 -0
  336. package/dist/types/index.mjs +4 -0
  337. package/dist/wasm-loader.d.ts +32 -0
  338. package/dist/wasm-loader.d.ts.map +1 -0
  339. package/dist/wasm-loader.js +75 -0
  340. package/dist/wasm-loader.js.map +1 -0
  341. package/dist/wasm-loader.mjs +64 -0
  342. package/examples/adaptive-learning.ts +284 -0
  343. package/examples/browser/README.md +732 -0
  344. package/examples/browser/adaptive-recommendations/index.html +427 -0
  345. package/examples/browser/collaborative-filtering/index.html +310 -0
  346. package/examples/browser/continual-learning/index.html +736 -0
  347. package/examples/browser/experience-replay/index.html +616 -0
  348. package/examples/browser/index.html +369 -0
  349. package/examples/browser/meta-learning/index.html +789 -0
  350. package/examples/browser/neuro-symbolic/index.html +692 -0
  351. package/examples/browser/pattern-learning/index.html +620 -0
  352. package/examples/browser/quantum-inspired/index.html +728 -0
  353. package/examples/browser/rag/index.html +624 -0
  354. package/examples/browser/swarm-intelligence/index.html +811 -0
  355. package/examples/browser-basic.html +170 -0
  356. package/examples/hnsw-example.ts +148 -0
  357. package/examples/node-basic.js +70 -0
  358. package/examples/quic-sync-example.ts +310 -0
  359. package/examples/quick-start.js +68 -0
  360. package/examples/wasm-example.ts +222 -0
  361. package/package.json +118 -0
@@ -0,0 +1,519 @@
1
+ /**
2
+ * VectorQueryBuilder - Fluent API for building complex vector search queries
3
+ * Provides type-safe filtering, sorting, and pagination with SQL injection protection
4
+ */
5
+ /**
6
+ * VectorQueryBuilder - Fluent API for complex vector queries
7
+ *
8
+ * @template T - Type of metadata object
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const results = await db.query()
13
+ * .similarTo(queryVector)
14
+ * .where('metadata.category', '=', 'tech')
15
+ * .whereBetween('metadata.year', 2020, 2024)
16
+ * .orderBySimilarity('asc')
17
+ * .limit(10)
18
+ * .execute();
19
+ * ```
20
+ */
21
+ export class VectorQueryBuilder {
22
+ constructor(db) {
23
+ this.k = 10;
24
+ this.filters = [];
25
+ this.orders = [];
26
+ this.offsetValue = 0;
27
+ this.metric = 'cosine';
28
+ this.threshold = 0.0;
29
+ this.db = db;
30
+ }
31
+ /**
32
+ * Search for vectors similar to the given vector
33
+ *
34
+ * @param vector - Query vector
35
+ * @param k - Number of results to retrieve (default: 10)
36
+ * @returns this for chaining
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * db.query().similarTo([0.1, 0.2, 0.3], 5)
41
+ * ```
42
+ */
43
+ similarTo(vector, k) {
44
+ this.queryVector = vector;
45
+ if (k !== undefined) {
46
+ this.k = k;
47
+ }
48
+ return this;
49
+ }
50
+ /**
51
+ * Search for vectors similar to a vector already in the database
52
+ *
53
+ * @param id - ID of the reference vector
54
+ * @param k - Number of results to retrieve (default: 10)
55
+ * @returns this for chaining
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * db.query().similarToId('vector-123', 5)
60
+ * ```
61
+ */
62
+ similarToId(id, k) {
63
+ this.queryId = id;
64
+ if (k !== undefined) {
65
+ this.k = k;
66
+ }
67
+ return this;
68
+ }
69
+ /**
70
+ * Add a filter condition
71
+ *
72
+ * @param field - Field name (use 'metadata.field' for metadata)
73
+ * @param op - Comparison operator
74
+ * @param value - Value to compare against
75
+ * @returns this for chaining
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * db.query()
80
+ * .similarTo(vector)
81
+ * .where('metadata.category', '=', 'tech')
82
+ * .where('metadata.year', '>', 2020)
83
+ * ```
84
+ */
85
+ where(field, op, value) {
86
+ const isMetadata = field.startsWith('metadata.');
87
+ this.filters.push({
88
+ field: isMetadata ? field.substring(9) : field, // Remove 'metadata.' prefix
89
+ operator: op,
90
+ value,
91
+ isMetadata
92
+ });
93
+ return this;
94
+ }
95
+ /**
96
+ * Filter where field is IN a set of values
97
+ *
98
+ * @param field - Field name
99
+ * @param values - Array of values
100
+ * @returns this for chaining
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * db.query()
105
+ * .similarTo(vector)
106
+ * .whereIn('metadata.tags', ['typescript', 'javascript'])
107
+ * ```
108
+ */
109
+ whereIn(field, values) {
110
+ return this.where(field, 'IN', values);
111
+ }
112
+ /**
113
+ * Filter where field is between min and max (inclusive)
114
+ *
115
+ * @param field - Field name
116
+ * @param min - Minimum value
117
+ * @param max - Maximum value
118
+ * @returns this for chaining
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * db.query()
123
+ * .similarTo(vector)
124
+ * .whereBetween('metadata.year', 2020, 2024)
125
+ * ```
126
+ */
127
+ whereBetween(field, min, max) {
128
+ this.where(field, '>=', min);
129
+ this.where(field, '<=', max);
130
+ return this;
131
+ }
132
+ /**
133
+ * Filter metadata field (alias for where with 'metadata.' prefix)
134
+ *
135
+ * @param path - Metadata field path
136
+ * @param op - Comparison operator
137
+ * @param value - Value to compare against
138
+ * @returns this for chaining
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * db.query()
143
+ * .similarTo(vector)
144
+ * .whereMetadata('author.verified', '=', true)
145
+ * ```
146
+ */
147
+ whereMetadata(path, op, value) {
148
+ return this.where(`metadata.${path}`, op, value);
149
+ }
150
+ /**
151
+ * Set similarity metric
152
+ *
153
+ * @param metric - Similarity metric ('cosine', 'euclidean', 'dot')
154
+ * @returns this for chaining
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * db.query().similarTo(vector).useSimilarityMetric('euclidean')
159
+ * ```
160
+ */
161
+ useSimilarityMetric(metric) {
162
+ this.metric = metric;
163
+ return this;
164
+ }
165
+ /**
166
+ * Set minimum similarity threshold
167
+ *
168
+ * @param threshold - Minimum score threshold
169
+ * @returns this for chaining
170
+ *
171
+ * @example
172
+ * ```typescript
173
+ * db.query().similarTo(vector).withThreshold(0.7)
174
+ * ```
175
+ */
176
+ withThreshold(threshold) {
177
+ this.threshold = threshold;
178
+ return this;
179
+ }
180
+ /**
181
+ * Order results by a field
182
+ *
183
+ * @param field - Field name
184
+ * @param direction - Sort direction ('asc' or 'desc')
185
+ * @returns this for chaining
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * db.query()
190
+ * .similarTo(vector)
191
+ * .orderBy('metadata.timestamp', 'desc')
192
+ * ```
193
+ */
194
+ orderBy(field, direction = 'asc') {
195
+ this.orders.push({
196
+ field,
197
+ direction,
198
+ bySimilarity: false
199
+ });
200
+ return this;
201
+ }
202
+ /**
203
+ * Order results by similarity score
204
+ *
205
+ * @param direction - Sort direction ('asc' or 'desc', default: 'desc')
206
+ * @returns this for chaining
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * db.query()
211
+ * .similarTo(vector)
212
+ * .orderBySimilarity('asc') // Least similar first
213
+ * ```
214
+ */
215
+ orderBySimilarity(direction = 'desc') {
216
+ this.orders.push({
217
+ field: 'score',
218
+ direction,
219
+ bySimilarity: true
220
+ });
221
+ return this;
222
+ }
223
+ /**
224
+ * Limit number of results
225
+ *
226
+ * @param n - Maximum number of results
227
+ * @returns this for chaining
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * db.query().similarTo(vector).limit(10)
232
+ * ```
233
+ */
234
+ limit(n) {
235
+ if (n < 0) {
236
+ throw new Error('Limit must be non-negative');
237
+ }
238
+ this.limitValue = n;
239
+ return this;
240
+ }
241
+ /**
242
+ * Skip first n results
243
+ *
244
+ * @param n - Number of results to skip
245
+ * @returns this for chaining
246
+ *
247
+ * @example
248
+ * ```typescript
249
+ * db.query().similarTo(vector).offset(20).limit(10) // Get results 21-30
250
+ * ```
251
+ */
252
+ offset(n) {
253
+ if (n < 0) {
254
+ throw new Error('Offset must be non-negative');
255
+ }
256
+ this.offsetValue = n;
257
+ return this;
258
+ }
259
+ /**
260
+ * Alias for offset
261
+ */
262
+ skip(n) {
263
+ return this.offset(n);
264
+ }
265
+ /**
266
+ * Alias for limit
267
+ */
268
+ take(n) {
269
+ return this.limit(n);
270
+ }
271
+ /**
272
+ * Execute raw SQL query (advanced usage)
273
+ *
274
+ * @param sql - Raw SQL query
275
+ * @param params - Query parameters
276
+ * @returns this for chaining
277
+ *
278
+ * @example
279
+ * ```typescript
280
+ * db.query()
281
+ * .raw('SELECT * FROM vectors WHERE metadata->>"$.category" = ?', ['tech'])
282
+ * .execute()
283
+ * ```
284
+ */
285
+ raw(sql, params) {
286
+ this.rawSQL = sql;
287
+ this.rawParams = params;
288
+ return this;
289
+ }
290
+ /**
291
+ * Type-safe metadata wrapper
292
+ *
293
+ * @returns QueryBuilder with typed metadata
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * interface BlogPost {
298
+ * title: string;
299
+ * author: string;
300
+ * }
301
+ *
302
+ * const posts = await db.query()
303
+ * .withMetadata<BlogPost>()
304
+ * .similarTo(vector)
305
+ * .execute();
306
+ *
307
+ * // posts[0].metadata.title is typed as string
308
+ * ```
309
+ */
310
+ withMetadata() {
311
+ return this;
312
+ }
313
+ /**
314
+ * Execute the query and return all results
315
+ *
316
+ * @returns Promise resolving to array of search results
317
+ *
318
+ * @example
319
+ * ```typescript
320
+ * const results = await db.query()
321
+ * .similarTo(vector)
322
+ * .where('metadata.category', '=', 'tech')
323
+ * .limit(10)
324
+ * .execute();
325
+ * ```
326
+ */
327
+ async execute() {
328
+ // If raw SQL is provided, use it (advanced usage)
329
+ if (this.rawSQL) {
330
+ return this.executeRaw();
331
+ }
332
+ // Get query vector
333
+ let vector = this.queryVector;
334
+ if (this.queryId) {
335
+ const refVector = this.db.get(this.queryId);
336
+ if (!refVector) {
337
+ throw new Error(`Vector with ID ${this.queryId} not found`);
338
+ }
339
+ vector = refVector.embedding;
340
+ }
341
+ if (!vector) {
342
+ throw new Error('Must specify query vector using similarTo() or similarToId()');
343
+ }
344
+ // Perform initial vector search
345
+ let results = this.db.search(vector, this.k, this.metric, this.threshold);
346
+ // Apply filters
347
+ results = this.applyFilters(results);
348
+ // Apply sorting
349
+ results = this.applySorting(results);
350
+ // Apply pagination
351
+ results = this.applyPagination(results);
352
+ return results;
353
+ }
354
+ /**
355
+ * Execute query and return first result
356
+ *
357
+ * @returns Promise resolving to first result or null
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * const best = await db.query()
362
+ * .similarTo(vector)
363
+ * .first();
364
+ * ```
365
+ */
366
+ async first() {
367
+ const results = await this.limit(1).execute();
368
+ return results.length > 0 ? results[0] : null;
369
+ }
370
+ /**
371
+ * Count results without retrieving them
372
+ *
373
+ * @returns Promise resolving to count
374
+ *
375
+ * @example
376
+ * ```typescript
377
+ * const count = await db.query()
378
+ * .similarTo(vector)
379
+ * .where('metadata.category', '=', 'tech')
380
+ * .count();
381
+ * ```
382
+ */
383
+ async count() {
384
+ const results = await this.execute();
385
+ return results.length;
386
+ }
387
+ /**
388
+ * Apply filters to results
389
+ */
390
+ applyFilters(results) {
391
+ if (this.filters.length === 0) {
392
+ return results;
393
+ }
394
+ return results.filter(result => {
395
+ return this.filters.every(filter => {
396
+ const value = filter.isMetadata
397
+ ? this.getNestedValue(result.metadata, filter.field)
398
+ : result[filter.field];
399
+ return this.matchesCondition(value, filter.operator, filter.value);
400
+ });
401
+ });
402
+ }
403
+ /**
404
+ * Get nested object value by path
405
+ */
406
+ getNestedValue(obj, path) {
407
+ if (!obj)
408
+ return undefined;
409
+ const parts = path.split('.');
410
+ let current = obj;
411
+ for (const part of parts) {
412
+ if (current === undefined || current === null) {
413
+ return undefined;
414
+ }
415
+ current = current[part];
416
+ }
417
+ return current;
418
+ }
419
+ /**
420
+ * Check if value matches condition
421
+ */
422
+ matchesCondition(value, operator, target) {
423
+ if (value === undefined || value === null) {
424
+ return operator === '!=' && target !== undefined && target !== null;
425
+ }
426
+ switch (operator) {
427
+ case '=':
428
+ return value === target;
429
+ case '!=':
430
+ return value !== target;
431
+ case '>':
432
+ return value > target;
433
+ case '>=':
434
+ return value >= target;
435
+ case '<':
436
+ return value < target;
437
+ case '<=':
438
+ return value <= target;
439
+ case 'LIKE':
440
+ if (typeof value !== 'string' || typeof target !== 'string') {
441
+ return false;
442
+ }
443
+ const pattern = target.replace(/%/g, '.*').replace(/_/g, '.');
444
+ return new RegExp(`^${pattern}$`, 'i').test(value);
445
+ case 'IN':
446
+ if (!Array.isArray(target)) {
447
+ throw new Error('IN operator requires array value');
448
+ }
449
+ return target.includes(value);
450
+ default:
451
+ return false;
452
+ }
453
+ }
454
+ /**
455
+ * Apply sorting to results
456
+ */
457
+ applySorting(results) {
458
+ if (this.orders.length === 0) {
459
+ return results;
460
+ }
461
+ return [...results].sort((a, b) => {
462
+ for (const order of this.orders) {
463
+ let aVal;
464
+ let bVal;
465
+ if (order.bySimilarity) {
466
+ aVal = a.score;
467
+ bVal = b.score;
468
+ }
469
+ else if (order.field.startsWith('metadata.')) {
470
+ const field = order.field.substring(9);
471
+ aVal = this.getNestedValue(a.metadata, field);
472
+ bVal = this.getNestedValue(b.metadata, field);
473
+ }
474
+ else {
475
+ aVal = a[order.field];
476
+ bVal = b[order.field];
477
+ }
478
+ // Handle null/undefined
479
+ if (aVal === undefined || aVal === null) {
480
+ return order.direction === 'asc' ? 1 : -1;
481
+ }
482
+ if (bVal === undefined || bVal === null) {
483
+ return order.direction === 'asc' ? -1 : 1;
484
+ }
485
+ // Compare values
486
+ let comparison = 0;
487
+ if (aVal < bVal)
488
+ comparison = -1;
489
+ else if (aVal > bVal)
490
+ comparison = 1;
491
+ if (comparison !== 0) {
492
+ return order.direction === 'asc' ? comparison : -comparison;
493
+ }
494
+ }
495
+ return 0;
496
+ });
497
+ }
498
+ /**
499
+ * Apply pagination to results
500
+ */
501
+ applyPagination(results) {
502
+ let paginated = results;
503
+ if (this.offsetValue > 0) {
504
+ paginated = paginated.slice(this.offsetValue);
505
+ }
506
+ if (this.limitValue !== undefined) {
507
+ paginated = paginated.slice(0, this.limitValue);
508
+ }
509
+ return paginated;
510
+ }
511
+ /**
512
+ * Execute raw SQL query (advanced)
513
+ */
514
+ async executeRaw() {
515
+ // This would require direct database access
516
+ // For now, throw an error - can be implemented later with backend support
517
+ throw new Error('Raw SQL queries not yet implemented. Use standard query methods.');
518
+ }
519
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * ContextSynthesizer - Combine multiple memory sources into coherent context
3
+ *
4
+ * Synthesizes context from patterns, experiences, and session history
5
+ * to provide comprehensive context for task execution.
6
+ */
7
+ import { SQLiteVectorDB } from '../core/vector-db';
8
+ import { PatternMatcher } from './pattern-matcher';
9
+ import { ExperienceCurator } from './experience-curator';
10
+ import { Context } from '../types';
11
+ export interface MemorySource {
12
+ type: 'patterns' | 'experiences' | 'recent' | 'session';
13
+ k?: number;
14
+ filters?: any;
15
+ }
16
+ export declare class ContextSynthesizer {
17
+ private db;
18
+ private patternMatcher;
19
+ private experienceCurator;
20
+ private sessionTable;
21
+ constructor(db: SQLiteVectorDB, patternMatcher: PatternMatcher, experienceCurator: ExperienceCurator);
22
+ private initializeSessionStorage;
23
+ /**
24
+ * Synthesize context from multiple memory sources
25
+ *
26
+ * @param taskEmbedding - Vector embedding of current task
27
+ * @param sources - Memory sources to combine
28
+ * @returns Synthesized context with patterns, experiences, and metadata
29
+ */
30
+ synthesizeContext(taskEmbedding: number[], sources?: MemorySource[]): Promise<Context>;
31
+ /**
32
+ * Build human-readable text context from patterns and experiences
33
+ */
34
+ private buildTextContext;
35
+ /**
36
+ * Calculate confidence score for synthesized context
37
+ */
38
+ private calculateConfidence;
39
+ /**
40
+ * Store context for a task execution
41
+ */
42
+ storeContextExecution(sessionId: string, taskDescription: string, context: Context): Promise<void>;
43
+ /**
44
+ * Get session history
45
+ */
46
+ private getSessionHistory;
47
+ /**
48
+ * Remove duplicate patterns (keep highest similarity)
49
+ */
50
+ private deduplicatePatterns;
51
+ /**
52
+ * Remove duplicate experiences (keep highest relevance)
53
+ */
54
+ private deduplicateExperiences;
55
+ private generateContextId;
56
+ }
57
+ //# sourceMappingURL=context-synthesizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-synthesizer.d.ts","sourceRoot":"","sources":["../../src/reasoning/context-synthesizer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,OAAO,EAAuB,MAAM,UAAU,CAAC;AAExD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,UAAU,GAAG,aAAa,GAAG,QAAQ,GAAG,SAAS,CAAC;IACxD,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,EAAE,CAAiB;IAC3B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,iBAAiB,CAAoB;IAC7C,OAAO,CAAC,YAAY,CAAsB;gBAGxC,EAAE,EAAE,cAAc,EAClB,cAAc,EAAE,cAAc,EAC9B,iBAAiB,EAAE,iBAAiB;IAQtC,OAAO,CAAC,wBAAwB;IAiBhC;;;;;;OAMG;IACG,iBAAiB,CACrB,aAAa,EAAE,MAAM,EAAE,EACvB,OAAO,GAAE,YAAY,EAIpB,GACA,OAAO,CAAC,OAAO,CAAC;IAqEnB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IA+CxB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA8B3B;;OAEG;IACG,qBAAqB,CACzB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,IAAI,CAAC;IAuBhB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAazB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAa3B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAe9B,OAAO,CAAC,iBAAiB;CAG1B"}