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,374 @@
1
+ /**
2
+ * Neural Architecture Search (NAS) Plugin
3
+ *
4
+ * Implements automated neural architecture optimization using
5
+ * evolutionary algorithms and reinforcement learning.
6
+ *
7
+ * Key features:
8
+ * - Architecture encoding and mutation
9
+ * - Population-based search
10
+ * - Performance prediction
11
+ * - Efficient architecture evaluation
12
+ * - Transfer learning from meta-architectures
13
+ */
14
+ import { BasePlugin } from '../base-plugin.mjs';
15
+ /**
16
+ * Neural Architecture Search Plugin Implementation
17
+ */
18
+ export class NeuralArchitectureSearchPlugin extends BasePlugin {
19
+ constructor(config) {
20
+ super();
21
+ this.name = 'neural-architecture-search';
22
+ this.version = '1.0.0';
23
+ this.experiences = [];
24
+ this.strategy = 'evolutionary';
25
+ this.population = [];
26
+ this.populationSize = 20;
27
+ this.eliteSize = 5;
28
+ this.mutationRate = 0.2;
29
+ this.crossoverRate = 0.7;
30
+ // Search space constraints
31
+ this.maxLayers = 10;
32
+ this.maxNodesPerLayer = 512;
33
+ this.layerTypes = ['dense', 'conv', 'dropout', 'batchnorm'];
34
+ // Performance tracking
35
+ this.bestArchitecture = null;
36
+ this.generation = 0;
37
+ this.evaluationHistory = new Map();
38
+ if (config) {
39
+ this.strategy = config.strategy || 'evolutionary';
40
+ this.populationSize = config.populationSize || 20;
41
+ this.mutationRate = config.mutationRate || 0.2;
42
+ this.maxLayers = config.maxLayers || 10;
43
+ }
44
+ this.initializePopulation();
45
+ // Mark as initialized for in-memory operation
46
+ this.initialized = true;
47
+ }
48
+ /**
49
+ * Override to skip initialization check for in-memory operation
50
+ */
51
+ checkInitialized() {
52
+ // No-op for NAS - operates in-memory
53
+ }
54
+ /**
55
+ * Override to store experiences in-memory without vectorDB
56
+ */
57
+ /**
58
+ * Override selectAction to provide base implementation
59
+ */
60
+ async selectAction(state, context) {
61
+ // Simple default action selection
62
+ const stateArray = Array.isArray(state) ? state : [state];
63
+ const stateSum = stateArray.reduce((a, b) => a + b, 0);
64
+ const value = Math.tanh(stateSum / stateArray.length);
65
+ return {
66
+ id: String(Math.floor(Math.abs(value) * 10)),
67
+ embedding: stateArray,
68
+ confidence: Math.abs(value),
69
+ };
70
+ }
71
+ async storeExperience(experience) {
72
+ this.experiences.push(experience);
73
+ }
74
+ /**
75
+ * Override to retrieve from local experiences
76
+ */
77
+ async retrieveSimilar(state, k) {
78
+ return this.experiences.slice(0, k).map((exp, idx) => ({
79
+ id: exp.id || `exp-${idx}`,
80
+ embedding: exp.state,
81
+ metadata: exp,
82
+ score: 1.0 - (idx * 0.1),
83
+ }));
84
+ }
85
+ /**
86
+ * Initialize random population
87
+ */
88
+ initializePopulation() {
89
+ for (let i = 0; i < this.populationSize; i++) {
90
+ this.population.push(this.generateRandomArchitecture());
91
+ }
92
+ }
93
+ /**
94
+ * Generate random architecture
95
+ */
96
+ generateRandomArchitecture() {
97
+ // Ensure numLayers is between 2 and maxLayers (inclusive)
98
+ const numLayers = 2 + Math.floor(Math.random() * (this.maxLayers - 1));
99
+ const layers = [];
100
+ for (let i = 0; i < numLayers; i++) {
101
+ layers.push(this.generateRandomLayer());
102
+ }
103
+ return {
104
+ id: this.generateArchitectureId(layers),
105
+ layers,
106
+ fitness: 0,
107
+ complexity: this.calculateComplexity(layers),
108
+ generation: this.generation,
109
+ };
110
+ }
111
+ /**
112
+ * Generate random layer
113
+ */
114
+ generateRandomLayer() {
115
+ const type = this.layerTypes[Math.floor(Math.random() * this.layerTypes.length)];
116
+ const spec = { type };
117
+ switch (type) {
118
+ case 'dense':
119
+ spec.size = Math.pow(2, Math.floor(Math.random() * 6) + 5); // 32 to 512
120
+ spec.activation = ['relu', 'tanh', 'sigmoid', 'leaky_relu'][Math.floor(Math.random() * 4)];
121
+ break;
122
+ case 'conv':
123
+ spec.size = Math.pow(2, Math.floor(Math.random() * 5) + 4); // 16 to 256
124
+ spec.kernelSize = [3, 5, 7][Math.floor(Math.random() * 3)];
125
+ spec.activation = 'relu';
126
+ break;
127
+ case 'dropout':
128
+ spec.dropout = 0.1 + Math.random() * 0.4; // 0.1 to 0.5
129
+ break;
130
+ case 'batchnorm':
131
+ // No additional params
132
+ break;
133
+ }
134
+ return spec;
135
+ }
136
+ /**
137
+ * Generate unique ID for architecture
138
+ */
139
+ generateArchitectureId(layers) {
140
+ const signature = layers.map(l => `${l.type}-${l.size || 0}-${l.activation || 'none'}`).join('|');
141
+ return Buffer.from(signature).toString('base64').substring(0, 16);
142
+ }
143
+ /**
144
+ * Calculate architecture complexity
145
+ */
146
+ calculateComplexity(layers) {
147
+ let params = 0;
148
+ for (let i = 0; i < layers.length - 1; i++) {
149
+ const current = layers[i];
150
+ const next = layers[i + 1];
151
+ if (current.type === 'dense' && next.type === 'dense') {
152
+ params += (current.size || 128) * (next.size || 128);
153
+ }
154
+ else if (current.type === 'conv') {
155
+ const kernelSize = current.kernelSize || 3;
156
+ params += kernelSize * kernelSize * (current.size || 64);
157
+ }
158
+ }
159
+ // Ensure minimum complexity: count layer sizes or base complexity per layer
160
+ if (params === 0 && layers.length > 0) {
161
+ const totalSize = layers.reduce((sum, layer) => sum + (layer.size || 0), 0);
162
+ // If no sized layers, use layer count as base complexity
163
+ params = totalSize > 0 ? totalSize : layers.length * 10;
164
+ }
165
+ return params;
166
+ }
167
+ /**
168
+ * Evaluate architecture fitness
169
+ */
170
+ async evaluateArchitecture(arch) {
171
+ // Check cache
172
+ if (this.evaluationHistory.has(arch.id)) {
173
+ return this.evaluationHistory.get(arch.id);
174
+ }
175
+ // Simplified fitness: combination of performance and complexity
176
+ const performanceScore = await this.estimatePerformance(arch);
177
+ const complexityPenalty = Math.log(arch.complexity + 1) / 20;
178
+ const fitness = performanceScore - complexityPenalty;
179
+ this.evaluationHistory.set(arch.id, fitness);
180
+ return fitness;
181
+ }
182
+ /**
183
+ * Estimate architecture performance (simplified)
184
+ */
185
+ async estimatePerformance(arch) {
186
+ // In real NAS: would train architecture and evaluate
187
+ // Here: simplified heuristic
188
+ let score = 0.5;
189
+ // Favor architectures with reasonable depth
190
+ const optimalDepth = 5;
191
+ const depthScore = 1 - Math.abs(arch.layers.length - optimalDepth) / optimalDepth;
192
+ score += depthScore * 0.2;
193
+ // Favor architectures with batch norm
194
+ const hasBatchNorm = arch.layers.some(l => l.type === 'batchnorm');
195
+ if (hasBatchNorm)
196
+ score += 0.1;
197
+ // Favor ReLU activations
198
+ const reluLayers = arch.layers.filter(l => l.activation === 'relu').length;
199
+ score += (reluLayers / arch.layers.length) * 0.1;
200
+ // Favor dropout for regularization
201
+ const hasDropout = arch.layers.some(l => l.type === 'dropout');
202
+ if (hasDropout)
203
+ score += 0.1;
204
+ // Add randomness to simulate training variance
205
+ score += (Math.random() - 0.5) * 0.1;
206
+ return Math.max(0, Math.min(1, score));
207
+ }
208
+ /**
209
+ * Mutate architecture
210
+ */
211
+ mutate(arch) {
212
+ const layers = [...arch.layers];
213
+ const mutationType = Math.random();
214
+ if (mutationType < 0.33 && layers.length < this.maxLayers) {
215
+ // Add layer
216
+ const position = Math.floor(Math.random() * layers.length);
217
+ layers.splice(position, 0, this.generateRandomLayer());
218
+ }
219
+ else if (mutationType < 0.66 && layers.length > 2) {
220
+ // Remove layer
221
+ const position = Math.floor(Math.random() * layers.length);
222
+ layers.splice(position, 1);
223
+ }
224
+ else {
225
+ // Modify layer
226
+ const position = Math.floor(Math.random() * layers.length);
227
+ layers[position] = this.generateRandomLayer();
228
+ }
229
+ return {
230
+ id: this.generateArchitectureId(layers),
231
+ layers,
232
+ fitness: 0,
233
+ complexity: this.calculateComplexity(layers),
234
+ generation: this.generation + 1,
235
+ };
236
+ }
237
+ /**
238
+ * Crossover two architectures
239
+ */
240
+ crossover(parent1, parent2) {
241
+ const point = Math.floor(Math.random() * Math.min(parent1.layers.length, parent2.layers.length));
242
+ const layers = [
243
+ ...parent1.layers.slice(0, point),
244
+ ...parent2.layers.slice(point),
245
+ ];
246
+ return {
247
+ id: this.generateArchitectureId(layers),
248
+ layers,
249
+ fitness: 0,
250
+ complexity: this.calculateComplexity(layers),
251
+ generation: this.generation + 1,
252
+ };
253
+ }
254
+ /**
255
+ * Select parent using tournament selection
256
+ */
257
+ selectParent() {
258
+ const tournamentSize = 3;
259
+ const tournament = [];
260
+ for (let i = 0; i < tournamentSize; i++) {
261
+ const idx = Math.floor(Math.random() * this.population.length);
262
+ tournament.push(this.population[idx]);
263
+ }
264
+ tournament.sort((a, b) => b.fitness - a.fitness);
265
+ return tournament[0];
266
+ }
267
+ /**
268
+ * Evolve population for one generation
269
+ */
270
+ async evolveGeneration() {
271
+ // Evaluate all architectures
272
+ for (const arch of this.population) {
273
+ arch.fitness = await this.evaluateArchitecture(arch);
274
+ }
275
+ // Sort by fitness
276
+ this.population.sort((a, b) => b.fitness - a.fitness);
277
+ // Update best
278
+ if (!this.bestArchitecture || this.population[0].fitness > this.bestArchitecture.fitness) {
279
+ this.bestArchitecture = { ...this.population[0] };
280
+ }
281
+ // Create next generation
282
+ const nextGeneration = [];
283
+ // Elitism: keep best architectures
284
+ const eliteCount = Math.min(this.eliteSize, this.population.length);
285
+ for (let i = 0; i < eliteCount; i++) {
286
+ nextGeneration.push({ ...this.population[i] });
287
+ }
288
+ // Generate offspring
289
+ while (nextGeneration.length < this.populationSize) {
290
+ if (Math.random() < this.crossoverRate) {
291
+ // Crossover
292
+ const parent1 = this.selectParent();
293
+ const parent2 = this.selectParent();
294
+ let offspring = this.crossover(parent1, parent2);
295
+ if (Math.random() < this.mutationRate) {
296
+ offspring = this.mutate(offspring);
297
+ }
298
+ nextGeneration.push(offspring);
299
+ }
300
+ else {
301
+ // Mutation only
302
+ const parent = this.selectParent();
303
+ nextGeneration.push(this.mutate(parent));
304
+ }
305
+ }
306
+ this.population = nextGeneration;
307
+ this.generation++;
308
+ }
309
+ /**
310
+ * Train using NAS
311
+ */
312
+ async train(options) {
313
+ const startTime = Date.now();
314
+ const generations = options?.epochs !== undefined ? options.epochs : 20;
315
+ for (let gen = 0; gen < generations; gen++) {
316
+ await this.evolveGeneration();
317
+ }
318
+ const duration = Date.now() - startTime;
319
+ return {
320
+ loss: this.bestArchitecture ? 1 - this.bestArchitecture.fitness : 1,
321
+ experiencesProcessed: this.evaluationHistory.size,
322
+ duration,
323
+ generation: this.generation,
324
+ bestFitness: this.bestArchitecture?.fitness || 0,
325
+ bestComplexity: this.bestArchitecture?.complexity || 0,
326
+ populationDiversity: this.calculatePopulationDiversity(),
327
+ };
328
+ }
329
+ /**
330
+ * Calculate population diversity
331
+ */
332
+ calculatePopulationDiversity() {
333
+ const uniqueIds = new Set(this.population.map((a) => a.id));
334
+ return uniqueIds.size / this.population.length;
335
+ }
336
+ /**
337
+ * Get best architecture
338
+ */
339
+ getBestArchitecture() {
340
+ return this.bestArchitecture;
341
+ }
342
+ /**
343
+ * Export architecture as JSON
344
+ */
345
+ exportArchitecture(arch) {
346
+ return JSON.stringify({
347
+ id: arch.id,
348
+ layers: arch.layers,
349
+ fitness: arch.fitness,
350
+ complexity: arch.complexity,
351
+ generation: arch.generation,
352
+ }, null, 2);
353
+ }
354
+ /**
355
+ * Import architecture from JSON
356
+ */
357
+ importArchitecture(json) {
358
+ return JSON.parse(json);
359
+ }
360
+ /**
361
+ * Get search statistics
362
+ */
363
+ getSearchStats() {
364
+ const avgComplexity = this.population.reduce((sum, a) => sum + a.complexity, 0)
365
+ / this.population.length;
366
+ return {
367
+ generation: this.generation,
368
+ evaluations: this.evaluationHistory.size,
369
+ bestFitness: this.bestArchitecture?.fitness || 0,
370
+ populationDiversity: this.calculatePopulationDiversity(),
371
+ avgComplexity,
372
+ };
373
+ }
374
+ }
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Q-Learning Plugin
3
+ *
4
+ * Implements the Q-Learning algorithm with experience replay.
5
+ * Q-Learning is a model-free, off-policy RL algorithm that learns
6
+ * the optimal action-value function (Q-function).
7
+ *
8
+ * Key features:
9
+ * - Epsilon-greedy exploration
10
+ * - Experience replay buffer
11
+ * - Optional prioritized experience replay
12
+ * - Temporal difference learning
13
+ */
14
+ import { BasePlugin } from '../base-plugin';
15
+ import { Action, Context, Experience, TrainOptions, TrainingMetrics } from '../learning-plugin.interface';
16
+ /**
17
+ * Q-Learning Plugin Implementation
18
+ */
19
+ export declare class QLearningPlugin extends BasePlugin {
20
+ name: string;
21
+ version: string;
22
+ private qTable;
23
+ private epsilon;
24
+ private epsilonMin;
25
+ private epsilonDecay;
26
+ private replayBuffer;
27
+ private usePrioritized;
28
+ private trainCounter;
29
+ /**
30
+ * Initialize Q-Learning plugin
31
+ */
32
+ protected onInitialize(): Promise<void>;
33
+ /**
34
+ * Select action using epsilon-greedy policy
35
+ *
36
+ * @param state - Current state vector
37
+ * @param context - Optional context
38
+ * @returns Selected action
39
+ */
40
+ selectAction(state: number[], context?: Context): Promise<Action>;
41
+ /**
42
+ * Select random action (exploration)
43
+ */
44
+ private randomAction;
45
+ /**
46
+ * Select greedy action (exploitation)
47
+ */
48
+ private greedyAction;
49
+ /**
50
+ * Store experience and update Q-table
51
+ */
52
+ protected onStoreExperience(experience: Experience): Promise<void>;
53
+ /**
54
+ * Train Q-Learning on replay buffer
55
+ */
56
+ train(options?: TrainOptions): Promise<TrainingMetrics>;
57
+ /**
58
+ * Compute TD error for prioritized replay
59
+ */
60
+ private computeTDError;
61
+ /**
62
+ * Get Q-value for state-action pair
63
+ */
64
+ private getQValue;
65
+ /**
66
+ * Set Q-value for state-action pair
67
+ */
68
+ private setQValue;
69
+ /**
70
+ * Get maximum Q-value for a state
71
+ */
72
+ private getMaxQValue;
73
+ /**
74
+ * Hash state vector to string key
75
+ */
76
+ private hashState;
77
+ /**
78
+ * Hash action to string key
79
+ */
80
+ private hashAction;
81
+ /**
82
+ * Get action embedding from ID
83
+ */
84
+ private getActionEmbedding;
85
+ /**
86
+ * Normalize Q-value to 0-1 confidence
87
+ */
88
+ private normalizeQValue;
89
+ /**
90
+ * Save Q-table
91
+ */
92
+ protected onSave(path: string): Promise<void>;
93
+ /**
94
+ * Load Q-table
95
+ */
96
+ protected onLoad(path: string): Promise<void>;
97
+ }
98
+ //# sourceMappingURL=q-learning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"q-learning.d.ts","sourceRoot":"","sources":["../../../src/plugins/implementations/q-learning.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,MAAM,EACN,OAAO,EACP,UAAU,EACV,YAAY,EACZ,eAAe,EAChB,MAAM,8BAA8B,CAAC;AA8ItC;;GAEG;AACH,qBAAa,eAAgB,SAAQ,UAAU;IACtC,IAAI,SAAgB;IACpB,OAAO,SAAW;IAEzB,OAAO,CAAC,MAAM,CAA+C;IAC7D,OAAO,CAAC,OAAO,CAAe;IAC9B,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,YAAY,CAAiB;IACrC,OAAO,CAAC,YAAY,CAA0C;IAC9D,OAAO,CAAC,cAAc,CAAkB;IACxC,OAAO,CAAC,YAAY,CAAa;IAEjC;;OAEG;cACa,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB7C;;;;;;OAMG;IACG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAYvE;;OAEG;YACW,YAAY;IAuC1B;;OAEG;YACW,YAAY;IA+C1B;;OAEG;cACa,iBAAiB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAsBxE;;OAEG;IACG,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC;IA+E7D;;OAEG;IACH,OAAO,CAAC,cAAc;IAatB;;OAEG;IACH,OAAO,CAAC,SAAS;IAKjB;;OAEG;IACH,OAAO,CAAC,SAAS;IAOjB;;OAEG;IACH,OAAO,CAAC,YAAY;IAUpB;;OAEG;IACH,OAAO,CAAC,SAAS;IAKjB;;OAEG;IACH,OAAO,CAAC,UAAU;IAYlB;;OAEG;YACW,kBAAkB;IAMhC;;OAEG;IACH,OAAO,CAAC,eAAe;IAIvB;;OAEG;cACa,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKnD;;OAEG;cACa,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAIpD"}