@ninebix/nmt-system 1.0.2 → 1.0.3

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 (430) hide show
  1. package/README.md +288 -213
  2. package/dashboard-lite/index.html +1083 -762
  3. package/dist/bin/nmt.js +171 -40
  4. package/dist/bin/nmt.js.map +1 -1
  5. package/dist/src/api/cli-server.d.ts.map +1 -1
  6. package/dist/src/api/cli-server.js +156 -0
  7. package/dist/src/api/cli-server.js.map +1 -1
  8. package/dist/src/core/attractor-model.d.ts +5 -2
  9. package/dist/src/core/attractor-model.d.ts.map +1 -1
  10. package/dist/src/core/attractor-model.js +7 -4
  11. package/dist/src/core/attractor-model.js.map +1 -1
  12. package/dist/src/core/neuron-graph.d.ts.map +1 -1
  13. package/dist/src/core/neuron-graph.js +41 -7
  14. package/dist/src/core/neuron-graph.js.map +1 -1
  15. package/dist/src/mcp/server.d.ts.map +1 -1
  16. package/dist/src/mcp/server.js +168 -34
  17. package/dist/src/mcp/server.js.map +1 -1
  18. package/dist/src/services/four-stage-learning.d.ts +19 -0
  19. package/dist/src/services/four-stage-learning.d.ts.map +1 -1
  20. package/dist/src/services/four-stage-learning.js +113 -17
  21. package/dist/src/services/four-stage-learning.js.map +1 -1
  22. package/dist/src/storage/neuron-store.d.ts +2 -0
  23. package/dist/src/storage/neuron-store.d.ts.map +1 -1
  24. package/dist/src/storage/neuron-store.js +22 -14
  25. package/dist/src/storage/neuron-store.js.map +1 -1
  26. package/package.json +1 -1
  27. package/dist/api/cli-server.d.ts +0 -83
  28. package/dist/api/cli-server.d.ts.map +0 -1
  29. package/dist/api/cli-server.js +0 -597
  30. package/dist/api/cli-server.js.map +0 -1
  31. package/dist/api/index.d.ts +0 -6
  32. package/dist/api/index.d.ts.map +0 -1
  33. package/dist/api/index.js +0 -6
  34. package/dist/api/index.js.map +0 -1
  35. package/dist/api/middleware/index.d.ts +0 -12
  36. package/dist/api/middleware/index.d.ts.map +0 -1
  37. package/dist/api/middleware/index.js +0 -13
  38. package/dist/api/middleware/index.js.map +0 -1
  39. package/dist/api/middleware/logger.d.ts +0 -21
  40. package/dist/api/middleware/logger.d.ts.map +0 -1
  41. package/dist/api/middleware/logger.js +0 -134
  42. package/dist/api/middleware/logger.js.map +0 -1
  43. package/dist/api/middleware/rate-limit.d.ts +0 -26
  44. package/dist/api/middleware/rate-limit.d.ts.map +0 -1
  45. package/dist/api/middleware/rate-limit.js +0 -107
  46. package/dist/api/middleware/rate-limit.js.map +0 -1
  47. package/dist/api/middleware/response.d.ts +0 -61
  48. package/dist/api/middleware/response.d.ts.map +0 -1
  49. package/dist/api/middleware/response.js +0 -86
  50. package/dist/api/middleware/response.js.map +0 -1
  51. package/dist/api/middleware/validation.d.ts +0 -43
  52. package/dist/api/middleware/validation.d.ts.map +0 -1
  53. package/dist/api/middleware/validation.js +0 -257
  54. package/dist/api/middleware/validation.js.map +0 -1
  55. package/dist/api/server.d.ts +0 -79
  56. package/dist/api/server.d.ts.map +0 -1
  57. package/dist/api/server.js +0 -2011
  58. package/dist/api/server.js.map +0 -1
  59. package/dist/cli/commands/attractor.d.ts +0 -6
  60. package/dist/cli/commands/attractor.d.ts.map +0 -1
  61. package/dist/cli/commands/attractor.js +0 -167
  62. package/dist/cli/commands/attractor.js.map +0 -1
  63. package/dist/cli/commands/dimension.d.ts +0 -6
  64. package/dist/cli/commands/dimension.d.ts.map +0 -1
  65. package/dist/cli/commands/dimension.js +0 -85
  66. package/dist/cli/commands/dimension.js.map +0 -1
  67. package/dist/cli/commands/index.d.ts +0 -11
  68. package/dist/cli/commands/index.d.ts.map +0 -1
  69. package/dist/cli/commands/index.js +0 -11
  70. package/dist/cli/commands/index.js.map +0 -1
  71. package/dist/cli/commands/infer.d.ts +0 -6
  72. package/dist/cli/commands/infer.d.ts.map +0 -1
  73. package/dist/cli/commands/infer.js +0 -139
  74. package/dist/cli/commands/infer.js.map +0 -1
  75. package/dist/cli/commands/learn.d.ts +0 -6
  76. package/dist/cli/commands/learn.d.ts.map +0 -1
  77. package/dist/cli/commands/learn.js +0 -87
  78. package/dist/cli/commands/learn.js.map +0 -1
  79. package/dist/cli/commands/orchestrate.d.ts +0 -6
  80. package/dist/cli/commands/orchestrate.d.ts.map +0 -1
  81. package/dist/cli/commands/orchestrate.js +0 -279
  82. package/dist/cli/commands/orchestrate.js.map +0 -1
  83. package/dist/cli/commands/prob.d.ts +0 -6
  84. package/dist/cli/commands/prob.d.ts.map +0 -1
  85. package/dist/cli/commands/prob.js +0 -256
  86. package/dist/cli/commands/prob.js.map +0 -1
  87. package/dist/cli/commands/quantum.d.ts +0 -6
  88. package/dist/cli/commands/quantum.d.ts.map +0 -1
  89. package/dist/cli/commands/quantum.js +0 -150
  90. package/dist/cli/commands/quantum.js.map +0 -1
  91. package/dist/cli/commands/sync.d.ts +0 -65
  92. package/dist/cli/commands/sync.d.ts.map +0 -1
  93. package/dist/cli/commands/sync.js +0 -338
  94. package/dist/cli/commands/sync.js.map +0 -1
  95. package/dist/cli/index.d.ts +0 -9
  96. package/dist/cli/index.d.ts.map +0 -1
  97. package/dist/cli/index.js +0 -9
  98. package/dist/cli/index.js.map +0 -1
  99. package/dist/cli/probabilistic-commands.d.ts +0 -39
  100. package/dist/cli/probabilistic-commands.d.ts.map +0 -1
  101. package/dist/cli/probabilistic-commands.js +0 -112
  102. package/dist/cli/probabilistic-commands.js.map +0 -1
  103. package/dist/cli/types.d.ts +0 -69
  104. package/dist/cli/types.d.ts.map +0 -1
  105. package/dist/cli/types.js +0 -5
  106. package/dist/cli/types.js.map +0 -1
  107. package/dist/cli/utils/formatters.d.ts +0 -51
  108. package/dist/cli/utils/formatters.d.ts.map +0 -1
  109. package/dist/cli/utils/formatters.js +0 -79
  110. package/dist/cli/utils/formatters.js.map +0 -1
  111. package/dist/cli/utils/helpers.d.ts +0 -21
  112. package/dist/cli/utils/helpers.d.ts.map +0 -1
  113. package/dist/cli/utils/helpers.js +0 -51
  114. package/dist/cli/utils/helpers.js.map +0 -1
  115. package/dist/cli/utils/index.d.ts +0 -7
  116. package/dist/cli/utils/index.d.ts.map +0 -1
  117. package/dist/cli/utils/index.js +0 -13
  118. package/dist/cli/utils/index.js.map +0 -1
  119. package/dist/cli/utils/validators.d.ts +0 -162
  120. package/dist/cli/utils/validators.d.ts.map +0 -1
  121. package/dist/cli/utils/validators.js +0 -351
  122. package/dist/cli/utils/validators.js.map +0 -1
  123. package/dist/core/advanced-embedding.d.ts +0 -154
  124. package/dist/core/advanced-embedding.d.ts.map +0 -1
  125. package/dist/core/advanced-embedding.js +0 -367
  126. package/dist/core/advanced-embedding.js.map +0 -1
  127. package/dist/core/attractor-model.d.ts +0 -381
  128. package/dist/core/attractor-model.d.ts.map +0 -1
  129. package/dist/core/attractor-model.js +0 -821
  130. package/dist/core/attractor-model.js.map +0 -1
  131. package/dist/core/bidirectional-inference.d.ts +0 -143
  132. package/dist/core/bidirectional-inference.d.ts.map +0 -1
  133. package/dist/core/bidirectional-inference.js +0 -501
  134. package/dist/core/bidirectional-inference.js.map +0 -1
  135. package/dist/core/chunk-engine.d.ts +0 -78
  136. package/dist/core/chunk-engine.d.ts.map +0 -1
  137. package/dist/core/chunk-engine.js +0 -192
  138. package/dist/core/chunk-engine.js.map +0 -1
  139. package/dist/core/dynamic-embedding.d.ts +0 -327
  140. package/dist/core/dynamic-embedding.d.ts.map +0 -1
  141. package/dist/core/dynamic-embedding.js +0 -527
  142. package/dist/core/dynamic-embedding.js.map +0 -1
  143. package/dist/core/embedding-similarity.d.ts +0 -68
  144. package/dist/core/embedding-similarity.d.ts.map +0 -1
  145. package/dist/core/embedding-similarity.js +0 -291
  146. package/dist/core/embedding-similarity.js.map +0 -1
  147. package/dist/core/evolution-scheduler.d.ts +0 -101
  148. package/dist/core/evolution-scheduler.d.ts.map +0 -1
  149. package/dist/core/evolution-scheduler.js +0 -235
  150. package/dist/core/evolution-scheduler.js.map +0 -1
  151. package/dist/core/hierarchical-chunker.d.ts +0 -108
  152. package/dist/core/hierarchical-chunker.d.ts.map +0 -1
  153. package/dist/core/hierarchical-chunker.js +0 -296
  154. package/dist/core/hierarchical-chunker.js.map +0 -1
  155. package/dist/core/hnsw-index.d.ts +0 -111
  156. package/dist/core/hnsw-index.d.ts.map +0 -1
  157. package/dist/core/hnsw-index.js +0 -466
  158. package/dist/core/hnsw-index.js.map +0 -1
  159. package/dist/core/index.d.ts +0 -23
  160. package/dist/core/index.d.ts.map +0 -1
  161. package/dist/core/index.js +0 -25
  162. package/dist/core/index.js.map +0 -1
  163. package/dist/core/language-analyzers.d.ts +0 -124
  164. package/dist/core/language-analyzers.d.ts.map +0 -1
  165. package/dist/core/language-analyzers.js +0 -365
  166. package/dist/core/language-analyzers.js.map +0 -1
  167. package/dist/core/local-embedding.d.ts +0 -109
  168. package/dist/core/local-embedding.d.ts.map +0 -1
  169. package/dist/core/local-embedding.js +0 -222
  170. package/dist/core/local-embedding.js.map +0 -1
  171. package/dist/core/merkle-engine.d.ts +0 -263
  172. package/dist/core/merkle-engine.d.ts.map +0 -1
  173. package/dist/core/merkle-engine.js +0 -528
  174. package/dist/core/merkle-engine.js.map +0 -1
  175. package/dist/core/multi-layer-reasoning.d.ts +0 -178
  176. package/dist/core/multi-layer-reasoning.d.ts.map +0 -1
  177. package/dist/core/multi-layer-reasoning.js +0 -607
  178. package/dist/core/multi-layer-reasoning.js.map +0 -1
  179. package/dist/core/neuron-graph.d.ts +0 -134
  180. package/dist/core/neuron-graph.d.ts.map +0 -1
  181. package/dist/core/neuron-graph.js +0 -436
  182. package/dist/core/neuron-graph.js.map +0 -1
  183. package/dist/core/probabilistic-neuron.d.ts +0 -251
  184. package/dist/core/probabilistic-neuron.d.ts.map +0 -1
  185. package/dist/core/probabilistic-neuron.js +0 -618
  186. package/dist/core/probabilistic-neuron.js.map +0 -1
  187. package/dist/core/probabilistic-orchestrator.d.ts +0 -408
  188. package/dist/core/probabilistic-orchestrator.d.ts.map +0 -1
  189. package/dist/core/probabilistic-orchestrator.js +0 -798
  190. package/dist/core/probabilistic-orchestrator.js.map +0 -1
  191. package/dist/core/semantic-chunker.d.ts +0 -117
  192. package/dist/core/semantic-chunker.d.ts.map +0 -1
  193. package/dist/core/semantic-chunker.js +0 -464
  194. package/dist/core/semantic-chunker.js.map +0 -1
  195. package/dist/events/event-bus.d.ts +0 -166
  196. package/dist/events/event-bus.d.ts.map +0 -1
  197. package/dist/events/event-bus.js +0 -228
  198. package/dist/events/event-bus.js.map +0 -1
  199. package/dist/events/index.d.ts +0 -7
  200. package/dist/events/index.d.ts.map +0 -1
  201. package/dist/events/index.js +0 -7
  202. package/dist/events/index.js.map +0 -1
  203. package/dist/events/progress-tracker.d.ts +0 -150
  204. package/dist/events/progress-tracker.d.ts.map +0 -1
  205. package/dist/events/progress-tracker.js +0 -290
  206. package/dist/events/progress-tracker.js.map +0 -1
  207. package/dist/extensions/clustering/community-detection.d.ts +0 -90
  208. package/dist/extensions/clustering/community-detection.d.ts.map +0 -1
  209. package/dist/extensions/clustering/community-detection.js +0 -470
  210. package/dist/extensions/clustering/community-detection.js.map +0 -1
  211. package/dist/extensions/clustering/index.d.ts +0 -114
  212. package/dist/extensions/clustering/index.d.ts.map +0 -1
  213. package/dist/extensions/clustering/index.js +0 -468
  214. package/dist/extensions/clustering/index.js.map +0 -1
  215. package/dist/extensions/clustering/topic-modeling.d.ts +0 -86
  216. package/dist/extensions/clustering/topic-modeling.d.ts.map +0 -1
  217. package/dist/extensions/clustering/topic-modeling.js +0 -355
  218. package/dist/extensions/clustering/topic-modeling.js.map +0 -1
  219. package/dist/extensions/distributed/coordinator.d.ts +0 -114
  220. package/dist/extensions/distributed/coordinator.d.ts.map +0 -1
  221. package/dist/extensions/distributed/coordinator.js +0 -319
  222. package/dist/extensions/distributed/coordinator.js.map +0 -1
  223. package/dist/extensions/distributed/index.d.ts +0 -10
  224. package/dist/extensions/distributed/index.d.ts.map +0 -1
  225. package/dist/extensions/distributed/index.js +0 -10
  226. package/dist/extensions/distributed/index.js.map +0 -1
  227. package/dist/extensions/distributed/queue.d.ts +0 -157
  228. package/dist/extensions/distributed/queue.d.ts.map +0 -1
  229. package/dist/extensions/distributed/queue.js +0 -326
  230. package/dist/extensions/distributed/queue.js.map +0 -1
  231. package/dist/extensions/distributed/scheduler.d.ts +0 -107
  232. package/dist/extensions/distributed/scheduler.d.ts.map +0 -1
  233. package/dist/extensions/distributed/scheduler.js +0 -301
  234. package/dist/extensions/distributed/scheduler.js.map +0 -1
  235. package/dist/extensions/distributed/worker.d.ts +0 -112
  236. package/dist/extensions/distributed/worker.d.ts.map +0 -1
  237. package/dist/extensions/distributed/worker.js +0 -260
  238. package/dist/extensions/distributed/worker.js.map +0 -1
  239. package/dist/index.d.ts +0 -14
  240. package/dist/index.d.ts.map +0 -1
  241. package/dist/index.js +0 -20
  242. package/dist/index.js.map +0 -1
  243. package/dist/mcp/server.d.ts +0 -43
  244. package/dist/mcp/server.d.ts.map +0 -1
  245. package/dist/mcp/server.js +0 -494
  246. package/dist/mcp/server.js.map +0 -1
  247. package/dist/services/adaptive-fallback.d.ts +0 -140
  248. package/dist/services/adaptive-fallback.d.ts.map +0 -1
  249. package/dist/services/adaptive-fallback.js +0 -273
  250. package/dist/services/adaptive-fallback.js.map +0 -1
  251. package/dist/services/answer-gate.d.ts +0 -112
  252. package/dist/services/answer-gate.d.ts.map +0 -1
  253. package/dist/services/answer-gate.js +0 -299
  254. package/dist/services/answer-gate.js.map +0 -1
  255. package/dist/services/auto-learning.d.ts +0 -135
  256. package/dist/services/auto-learning.d.ts.map +0 -1
  257. package/dist/services/auto-learning.js +0 -413
  258. package/dist/services/auto-learning.js.map +0 -1
  259. package/dist/services/context-compressor.d.ts +0 -77
  260. package/dist/services/context-compressor.d.ts.map +0 -1
  261. package/dist/services/context-compressor.js +0 -234
  262. package/dist/services/context-compressor.js.map +0 -1
  263. package/dist/services/efficient-rag.d.ts +0 -140
  264. package/dist/services/efficient-rag.d.ts.map +0 -1
  265. package/dist/services/efficient-rag.js +0 -311
  266. package/dist/services/efficient-rag.js.map +0 -1
  267. package/dist/services/embedding-provider.d.ts +0 -72
  268. package/dist/services/embedding-provider.d.ts.map +0 -1
  269. package/dist/services/embedding-provider.js +0 -176
  270. package/dist/services/embedding-provider.js.map +0 -1
  271. package/dist/services/file-ingestion.d.ts +0 -72
  272. package/dist/services/file-ingestion.d.ts.map +0 -1
  273. package/dist/services/file-ingestion.js +0 -237
  274. package/dist/services/file-ingestion.js.map +0 -1
  275. package/dist/services/four-stage-learning.d.ts +0 -552
  276. package/dist/services/four-stage-learning.d.ts.map +0 -1
  277. package/dist/services/four-stage-learning.js +0 -1110
  278. package/dist/services/four-stage-learning.js.map +0 -1
  279. package/dist/services/graph.d.ts +0 -94
  280. package/dist/services/graph.d.ts.map +0 -1
  281. package/dist/services/graph.js +0 -292
  282. package/dist/services/graph.js.map +0 -1
  283. package/dist/services/index.d.ts +0 -15
  284. package/dist/services/index.d.ts.map +0 -1
  285. package/dist/services/index.js +0 -18
  286. package/dist/services/index.js.map +0 -1
  287. package/dist/services/ingestion.d.ts +0 -98
  288. package/dist/services/ingestion.d.ts.map +0 -1
  289. package/dist/services/ingestion.js +0 -259
  290. package/dist/services/ingestion.js.map +0 -1
  291. package/dist/services/learning.d.ts +0 -67
  292. package/dist/services/learning.d.ts.map +0 -1
  293. package/dist/services/learning.js +0 -262
  294. package/dist/services/learning.js.map +0 -1
  295. package/dist/services/llm-router.d.ts +0 -143
  296. package/dist/services/llm-router.d.ts.map +0 -1
  297. package/dist/services/llm-router.js +0 -284
  298. package/dist/services/llm-router.js.map +0 -1
  299. package/dist/services/llm.d.ts +0 -86
  300. package/dist/services/llm.d.ts.map +0 -1
  301. package/dist/services/llm.js +0 -283
  302. package/dist/services/llm.js.map +0 -1
  303. package/dist/services/metrics-dashboard.d.ts +0 -262
  304. package/dist/services/metrics-dashboard.d.ts.map +0 -1
  305. package/dist/services/metrics-dashboard.js +0 -417
  306. package/dist/services/metrics-dashboard.js.map +0 -1
  307. package/dist/services/neuron-lifecycle.d.ts +0 -137
  308. package/dist/services/neuron-lifecycle.d.ts.map +0 -1
  309. package/dist/services/neuron-lifecycle.js +0 -422
  310. package/dist/services/neuron-lifecycle.js.map +0 -1
  311. package/dist/services/nmt-pipeline.d.ts +0 -219
  312. package/dist/services/nmt-pipeline.d.ts.map +0 -1
  313. package/dist/services/nmt-pipeline.js +0 -449
  314. package/dist/services/nmt-pipeline.js.map +0 -1
  315. package/dist/services/query-cache.d.ts +0 -136
  316. package/dist/services/query-cache.d.ts.map +0 -1
  317. package/dist/services/query-cache.js +0 -255
  318. package/dist/services/query-cache.js.map +0 -1
  319. package/dist/services/query-normalize.d.ts +0 -107
  320. package/dist/services/query-normalize.d.ts.map +0 -1
  321. package/dist/services/query-normalize.js +0 -366
  322. package/dist/services/query-normalize.js.map +0 -1
  323. package/dist/services/query.d.ts +0 -102
  324. package/dist/services/query.d.ts.map +0 -1
  325. package/dist/services/query.js +0 -227
  326. package/dist/services/query.js.map +0 -1
  327. package/dist/services/text-embedding.d.ts +0 -183
  328. package/dist/services/text-embedding.d.ts.map +0 -1
  329. package/dist/services/text-embedding.js +0 -633
  330. package/dist/services/text-embedding.js.map +0 -1
  331. package/dist/services/verification-gate.d.ts +0 -147
  332. package/dist/services/verification-gate.d.ts.map +0 -1
  333. package/dist/services/verification-gate.js +0 -344
  334. package/dist/services/verification-gate.js.map +0 -1
  335. package/dist/services/verify.d.ts +0 -114
  336. package/dist/services/verify.d.ts.map +0 -1
  337. package/dist/services/verify.js +0 -237
  338. package/dist/services/verify.js.map +0 -1
  339. package/dist/services/web-search.d.ts +0 -145
  340. package/dist/services/web-search.d.ts.map +0 -1
  341. package/dist/services/web-search.js +0 -534
  342. package/dist/services/web-search.js.map +0 -1
  343. package/dist/storage/chunk-store.d.ts +0 -107
  344. package/dist/storage/chunk-store.d.ts.map +0 -1
  345. package/dist/storage/chunk-store.js +0 -293
  346. package/dist/storage/chunk-store.js.map +0 -1
  347. package/dist/storage/hybrid-adapters.d.ts +0 -111
  348. package/dist/storage/hybrid-adapters.d.ts.map +0 -1
  349. package/dist/storage/hybrid-adapters.js +0 -223
  350. package/dist/storage/hybrid-adapters.js.map +0 -1
  351. package/dist/storage/hybrid-store.d.ts +0 -125
  352. package/dist/storage/hybrid-store.d.ts.map +0 -1
  353. package/dist/storage/hybrid-store.js +0 -655
  354. package/dist/storage/hybrid-store.js.map +0 -1
  355. package/dist/storage/index-store.d.ts +0 -126
  356. package/dist/storage/index-store.d.ts.map +0 -1
  357. package/dist/storage/index-store.js +0 -316
  358. package/dist/storage/index-store.js.map +0 -1
  359. package/dist/storage/index.d.ts +0 -45
  360. package/dist/storage/index.d.ts.map +0 -1
  361. package/dist/storage/index.js +0 -52
  362. package/dist/storage/index.js.map +0 -1
  363. package/dist/storage/neuron-store.d.ts +0 -121
  364. package/dist/storage/neuron-store.d.ts.map +0 -1
  365. package/dist/storage/neuron-store.js +0 -466
  366. package/dist/storage/neuron-store.js.map +0 -1
  367. package/dist/storage/ontology-store.d.ts +0 -132
  368. package/dist/storage/ontology-store.d.ts.map +0 -1
  369. package/dist/storage/ontology-store.js +0 -319
  370. package/dist/storage/ontology-store.js.map +0 -1
  371. package/dist/storage/probabilistic-store.d.ts +0 -104
  372. package/dist/storage/probabilistic-store.d.ts.map +0 -1
  373. package/dist/storage/probabilistic-store.js +0 -257
  374. package/dist/storage/probabilistic-store.js.map +0 -1
  375. package/dist/storage/redis-adapters.d.ts +0 -102
  376. package/dist/storage/redis-adapters.d.ts.map +0 -1
  377. package/dist/storage/redis-adapters.js +0 -205
  378. package/dist/storage/redis-adapters.js.map +0 -1
  379. package/dist/storage/redis-ontology-store.d.ts +0 -146
  380. package/dist/storage/redis-ontology-store.d.ts.map +0 -1
  381. package/dist/storage/redis-ontology-store.js +0 -384
  382. package/dist/storage/redis-ontology-store.js.map +0 -1
  383. package/dist/storage/redis-store.d.ts +0 -174
  384. package/dist/storage/redis-store.d.ts.map +0 -1
  385. package/dist/storage/redis-store.js +0 -506
  386. package/dist/storage/redis-store.js.map +0 -1
  387. package/dist/sync/change-journal.d.ts +0 -171
  388. package/dist/sync/change-journal.d.ts.map +0 -1
  389. package/dist/sync/change-journal.js +0 -362
  390. package/dist/sync/change-journal.js.map +0 -1
  391. package/dist/sync/index.d.ts +0 -8
  392. package/dist/sync/index.d.ts.map +0 -1
  393. package/dist/sync/index.js +0 -8
  394. package/dist/sync/index.js.map +0 -1
  395. package/dist/sync/state-sync.d.ts +0 -241
  396. package/dist/sync/state-sync.d.ts.map +0 -1
  397. package/dist/sync/state-sync.js +0 -396
  398. package/dist/sync/state-sync.js.map +0 -1
  399. package/dist/sync/vector-clock.d.ts +0 -144
  400. package/dist/sync/vector-clock.d.ts.map +0 -1
  401. package/dist/sync/vector-clock.js +0 -266
  402. package/dist/sync/vector-clock.js.map +0 -1
  403. package/dist/types/index.d.ts +0 -224
  404. package/dist/types/index.d.ts.map +0 -1
  405. package/dist/types/index.js +0 -24
  406. package/dist/types/index.js.map +0 -1
  407. package/dist/utils/hash.d.ts +0 -39
  408. package/dist/utils/hash.d.ts.map +0 -1
  409. package/dist/utils/hash.js +0 -56
  410. package/dist/utils/hash.js.map +0 -1
  411. package/dist/utils/index.d.ts +0 -26
  412. package/dist/utils/index.d.ts.map +0 -1
  413. package/dist/utils/index.js +0 -50
  414. package/dist/utils/index.js.map +0 -1
  415. package/dist/utils/logger.d.ts +0 -88
  416. package/dist/utils/logger.d.ts.map +0 -1
  417. package/dist/utils/logger.js +0 -157
  418. package/dist/utils/logger.js.map +0 -1
  419. package/dist/utils/metrics.d.ts +0 -232
  420. package/dist/utils/metrics.d.ts.map +0 -1
  421. package/dist/utils/metrics.js +0 -387
  422. package/dist/utils/metrics.js.map +0 -1
  423. package/dist/utils/similarity.d.ts +0 -64
  424. package/dist/utils/similarity.d.ts.map +0 -1
  425. package/dist/utils/similarity.js +0 -151
  426. package/dist/utils/similarity.js.map +0 -1
  427. package/dist/utils/uuid.d.ts +0 -23
  428. package/dist/utils/uuid.d.ts.map +0 -1
  429. package/dist/utils/uuid.js +0 -29
  430. package/dist/utils/uuid.js.map +0 -1
@@ -1,1110 +0,0 @@
1
- /**
2
- * Four-Stage Learning System
3
- *
4
- * Based on Probabilistic Ontology Framework:
5
- * Stage 1: Extract Meaningful - 유의미 추출
6
- * Stage 2: Learn Patterns - 패턴 학습
7
- * Stage 3: Learn Process - 과정 학습 (AI reasoning process)
8
- * Stage 4: Learn Outcomes - 결과 학습
9
- *
10
- * Extended with:
11
- * - EventEmitter for real-time progress updates
12
- * - Streaming session support
13
- * - Auto-persistence
14
- *
15
- * @module services/four-stage-learning
16
- */
17
- import { EventEmitter } from 'events';
18
- import { cosineSimilarity } from '../utils/similarity.js';
19
- import { generateUUID } from '../utils/uuid.js';
20
- import { TextEmbeddingService } from './text-embedding.js';
21
- /**
22
- * Four-Stage Learning System
23
- *
24
- * Implements the complete learning loop based on probabilistic ontology:
25
- * 1. **Extract Meaningful (유의미 추출)**: Identify important content segments
26
- * 2. **Learn Patterns (패턴 학습)**: Discover recurring patterns from extracts
27
- * 3. **Learn Process (과정 학습)**: Capture AI reasoning chains
28
- * 4. **Learn Outcomes (결과 학습)**: Record and reinforce successful paths
29
- *
30
- * @example
31
- * ```typescript
32
- * const learning = new FourStageLearningSystem({
33
- * neuronStore: store,
34
- * graphManager: graph
35
- * });
36
- *
37
- * // Start a learning session
38
- * const session = learning.startSession();
39
- *
40
- * // Stage 1: Extract meaningful content
41
- * const extracts = await learning.extractMeaningful(neuronId, content);
42
- *
43
- * // Stage 2: Learn patterns from extracts
44
- * const patterns = await learning.learnPatterns(extracts.map(e => e.id));
45
- *
46
- * // Stage 3: Learn the reasoning process
47
- * const process = await learning.learnProcess('search', processSteps);
48
- *
49
- * // Stage 4: Record outcome
50
- * const outcome = await learning.learnOutcome(
51
- * process.id, inputId, outputId, true, 0.9
52
- * );
53
- *
54
- * // End session and get metrics
55
- * const finalSession = learning.endSession();
56
- * console.log(`Patterns discovered: ${finalSession.metrics.patternsDiscovered}`);
57
- * ```
58
- *
59
- * @see {@link MeaningfulExtract} for extract structure
60
- * @see {@link LearnedPattern} for pattern structure
61
- * @see {@link LearnedProcess} for process structure
62
- */
63
- export class FourStageLearningSystem extends EventEmitter {
64
- store;
65
- graphManager;
66
- importanceThreshold;
67
- patternMinInstances;
68
- processLearningEnabled;
69
- // Real embedding service
70
- embeddingService;
71
- useRealEmbeddings;
72
- // Storage for learned components
73
- extracts = new Map();
74
- patterns = new Map();
75
- processes = new Map();
76
- outcomes = new Map();
77
- // Current learning session
78
- currentSession = null;
79
- // Auto-persistence
80
- autoPersistStore = null;
81
- autoPersistInterval = null;
82
- autoPersistEnabled = false;
83
- constructor(options) {
84
- super();
85
- this.store = options.neuronStore;
86
- this.graphManager = options.graphManager;
87
- this.importanceThreshold = options.importanceThreshold ?? 0.3;
88
- this.patternMinInstances = options.patternMinInstances ?? 3;
89
- this.processLearningEnabled = options.enableProcessLearning ?? true;
90
- this.useRealEmbeddings = options.useRealEmbeddings ?? true;
91
- // Initialize embedding service
92
- this.embeddingService = new TextEmbeddingService(options.embeddingConfig ?? {
93
- type: 'local'
94
- });
95
- this.setMaxListeners(50);
96
- }
97
- /**
98
- * Start a new learning session.
99
- *
100
- * A session tracks all learning activities (extracts, patterns,
101
- * processes, outcomes) and provides metrics upon completion.
102
- *
103
- * @returns The new LearningSession object
104
- *
105
- * @example
106
- * ```typescript
107
- * const session = learning.startSession();
108
- * // ... perform learning activities ...
109
- * const endedSession = learning.endSession();
110
- * ```
111
- */
112
- startSession() {
113
- this.currentSession = {
114
- id: generateUUID(),
115
- startedAt: new Date().toISOString(),
116
- stages: {
117
- extract: [],
118
- patterns: [],
119
- processes: [],
120
- outcomes: []
121
- },
122
- metrics: {
123
- totalExtracts: 0,
124
- patternsDiscovered: 0,
125
- processesLearned: 0,
126
- outcomeSuccess: 0
127
- }
128
- };
129
- this.emit('session:start', this.currentSession);
130
- return this.currentSession;
131
- }
132
- /**
133
- * Emit a progress event
134
- */
135
- emitProgress(stage, current, total, message, data) {
136
- if (!this.currentSession)
137
- return;
138
- const event = {
139
- sessionId: this.currentSession.id,
140
- stage,
141
- current,
142
- total,
143
- percentage: total > 0 ? (current / total) * 100 : 0,
144
- message,
145
- data,
146
- };
147
- this.emit('progress', event);
148
- }
149
- /**
150
- * End current learning session
151
- */
152
- endSession() {
153
- if (!this.currentSession)
154
- return null;
155
- this.currentSession.endedAt = new Date().toISOString();
156
- // Calculate final metrics
157
- this.currentSession.metrics = {
158
- totalExtracts: this.currentSession.stages.extract.length,
159
- patternsDiscovered: this.currentSession.stages.patterns.length,
160
- processesLearned: this.currentSession.stages.processes.length,
161
- outcomeSuccess: this.calculateSuccessRate(this.currentSession.stages.outcomes)
162
- };
163
- const session = this.currentSession;
164
- this.currentSession = null;
165
- this.emit('session:end', session);
166
- // Auto-persist if enabled
167
- if (this.autoPersistEnabled) {
168
- this.persistNow().catch(err => {
169
- this.emit('error', { error: err });
170
- });
171
- }
172
- return session;
173
- }
174
- // ==================== Stage 1: Extract Meaningful ====================
175
- /**
176
- * Stage 1: Extract meaningful content from a neuron.
177
- *
178
- * Segments content into semantic units and evaluates importance.
179
- * Only segments exceeding the importance threshold are extracted.
180
- * Categories include: causal, conditional, procedural, definitional, general.
181
- *
182
- * @param neuronId - Source neuron ID
183
- * @param content - Text content to extract meaningful segments from
184
- * @returns Array of meaningful extracts with embeddings and keywords
185
- *
186
- * @example
187
- * ```typescript
188
- * const extracts = await learning.extractMeaningful(
189
- * 'neuron-1',
190
- * 'TypeScript is a typed superset of JavaScript. Because it adds static typing, it helps catch errors at compile time.'
191
- * );
192
- * // May return:
193
- * // [{ category: 'definitional', content: 'TypeScript is...' },
194
- * // { category: 'causal', content: 'Because it adds...' }]
195
- * ```
196
- */
197
- async extractMeaningful(neuronId, content) {
198
- const neuron = await this.store.getNeuron(neuronId);
199
- if (!neuron)
200
- return [];
201
- const extracts = [];
202
- // Segment content into meaningful units
203
- const segments = this.segmentContent(content);
204
- const total = segments.length;
205
- this.emitProgress('extract', 0, total, 'Starting extraction...');
206
- for (let i = 0; i < segments.length; i++) {
207
- const segment = segments[i];
208
- // Calculate importance
209
- const importance = this.calculateImportance(segment, neuron);
210
- if (importance >= this.importanceThreshold) {
211
- const extract = {
212
- id: generateUUID(),
213
- content: segment.text,
214
- embedding: await this.generateSegmentEmbedding(segment.text, neuron.embedding),
215
- importance,
216
- category: segment.category,
217
- sourceNeuronId: neuronId,
218
- extractedAt: new Date().toISOString(),
219
- keywords: this.extractKeywords(segment.text)
220
- };
221
- this.extracts.set(extract.id, extract);
222
- extracts.push(extract);
223
- this.emit('extract', extract);
224
- if (this.currentSession) {
225
- this.currentSession.stages.extract.push(extract);
226
- }
227
- }
228
- this.emitProgress('extract', i + 1, total, `Processed segment ${i + 1}/${total}`);
229
- }
230
- return extracts;
231
- }
232
- // ==================== Stage 2: Learn Patterns ====================
233
- /**
234
- * Stage 2: Learn patterns from extracts.
235
- *
236
- * Clusters similar extracts and identifies recurring patterns.
237
- * Existing patterns are updated with new instances; new patterns
238
- * are created when clusters don't match existing ones.
239
- *
240
- * @param extractIds - Array of MeaningfulExtract IDs to analyze
241
- * @returns Array of learned or updated patterns
242
- *
243
- * @example
244
- * ```typescript
245
- * const patterns = await learning.learnPatterns([
246
- * 'extract-1', 'extract-2', 'extract-3'
247
- * ]);
248
- *
249
- * for (const pattern of patterns) {
250
- * console.log(`${pattern.name}: ${pattern.instances.length} instances`);
251
- * console.log(`Confidence: ${(pattern.confidence * 100).toFixed(1)}%`);
252
- * }
253
- * ```
254
- */
255
- async learnPatterns(extractIds) {
256
- const extracts = extractIds
257
- .map(id => this.extracts.get(id))
258
- .filter((e) => e !== undefined);
259
- if (extracts.length < this.patternMinInstances) {
260
- return [];
261
- }
262
- this.emitProgress('patterns', 0, 1, 'Clustering extracts...');
263
- // Cluster extracts by similarity
264
- const clusters = this.clusterExtracts(extracts);
265
- const newPatterns = [];
266
- const total = clusters.length;
267
- for (let i = 0; i < clusters.length; i++) {
268
- const cluster = clusters[i];
269
- if (cluster.length < this.patternMinInstances)
270
- continue;
271
- // Check if pattern already exists
272
- const existingPattern = this.findSimilarPattern(cluster);
273
- if (existingPattern) {
274
- // Update existing pattern
275
- existingPattern.instances.push(...cluster.map(e => e.id));
276
- existingPattern.frequency = existingPattern.instances.length;
277
- existingPattern.lastSeenAt = new Date().toISOString();
278
- existingPattern.centroid = this.calculateCentroid(cluster.map(e => e.embedding));
279
- newPatterns.push(existingPattern);
280
- this.emit('pattern', existingPattern);
281
- }
282
- else {
283
- // Create new pattern
284
- const pattern = {
285
- id: generateUUID(),
286
- name: this.generatePatternName(cluster),
287
- description: this.generatePatternDescription(cluster),
288
- instances: cluster.map(e => e.id),
289
- centroid: this.calculateCentroid(cluster.map(e => e.embedding)),
290
- frequency: cluster.length,
291
- confidence: this.calculatePatternConfidence(cluster),
292
- createdAt: new Date().toISOString(),
293
- lastSeenAt: new Date().toISOString()
294
- };
295
- this.patterns.set(pattern.id, pattern);
296
- newPatterns.push(pattern);
297
- this.emit('pattern', pattern);
298
- if (this.currentSession) {
299
- this.currentSession.stages.patterns.push(pattern);
300
- }
301
- }
302
- this.emitProgress('patterns', i + 1, total, `Analyzed cluster ${i + 1}/${total}`);
303
- }
304
- return newPatterns;
305
- }
306
- // ==================== Stage 3: Learn Process ====================
307
- /**
308
- * Stage 3: Learn reasoning process from execution trace.
309
- *
310
- * Captures the AI's reasoning chain as a reusable process template.
311
- * Similar processes are merged to increase confidence; new task
312
- * types create new process templates.
313
- *
314
- * @param taskType - Type of task (e.g., 'search', 'create', 'explain')
315
- * @param steps - Array of ProcessStep objects from execution
316
- * @param inputPatternId - Optional ID of triggering pattern
317
- * @returns The learned or updated process, or null if disabled/empty
318
- *
319
- * @example
320
- * ```typescript
321
- * const process = await learning.learnProcess('explain', [
322
- * { stepNumber: 1, action: 'analyze', input: 'question', output: 'concepts', reasoning: '...', duration: 100, success: true },
323
- * { stepNumber: 2, action: 'synthesize', input: 'concepts', output: 'explanation', reasoning: '...', duration: 200, success: true }
324
- * ]);
325
- *
326
- * if (process) {
327
- * console.log(`Success rate: ${(process.successRate * 100).toFixed(0)}%`);
328
- * }
329
- * ```
330
- */
331
- async learnProcess(taskType, steps, inputPatternId) {
332
- if (!this.processLearningEnabled)
333
- return null;
334
- if (steps.length === 0)
335
- return null;
336
- // Check if similar process exists
337
- const existingProcess = this.findSimilarProcess(taskType, steps);
338
- if (existingProcess) {
339
- // Update existing process
340
- existingProcess.totalExecutions++;
341
- existingProcess.successRate = this.updateSuccessRate(existingProcess, steps.every(s => s.success));
342
- existingProcess.averageDuration = this.updateAverageDuration(existingProcess, steps.reduce((sum, s) => sum + s.duration, 0));
343
- existingProcess.updatedAt = new Date().toISOString();
344
- return existingProcess;
345
- }
346
- // Create new process
347
- const process = {
348
- id: generateUUID(),
349
- name: `${taskType}_process_${Date.now()}`,
350
- taskType,
351
- steps: this.normalizeSteps(steps),
352
- inputPattern: inputPatternId ?? generateUUID(),
353
- successRate: steps.every(s => s.success) ? 1.0 : 0.0,
354
- totalExecutions: 1,
355
- averageDuration: steps.reduce((sum, s) => sum + s.duration, 0),
356
- createdAt: new Date().toISOString(),
357
- updatedAt: new Date().toISOString()
358
- };
359
- this.processes.set(process.id, process);
360
- if (this.currentSession) {
361
- this.currentSession.stages.processes.push(process);
362
- }
363
- return process;
364
- }
365
- // ==================== Stage 4: Learn Outcomes ====================
366
- /**
367
- * Stage 4: Learn from outcomes.
368
- *
369
- * Records the result of a process execution and reinforces
370
- * successful paths in the neuron graph. This creates a feedback
371
- * loop for continuous improvement.
372
- *
373
- * @param processId - ID of the executed process
374
- * @param inputNeuronId - Input neuron that triggered the process
375
- * @param outputNeuronId - Output neuron (if any) produced
376
- * @param success - Whether the outcome was successful
377
- * @param quality - Quality score (0-1)
378
- * @param feedback - Optional textual feedback
379
- * @returns The recorded OutcomeRecord
380
- *
381
- * @example
382
- * ```typescript
383
- * const outcome = await learning.learnOutcome(
384
- * 'process-1',
385
- * 'input-neuron',
386
- * 'output-neuron',
387
- * true,
388
- * 0.95,
389
- * 'Excellent response'
390
- * );
391
- * ```
392
- */
393
- async learnOutcome(processId, inputNeuronId, outputNeuronId, success, quality, feedback) {
394
- const outcome = {
395
- id: generateUUID(),
396
- processId,
397
- inputNeuronId,
398
- outputNeuronId,
399
- success,
400
- quality,
401
- feedback,
402
- timestamp: new Date().toISOString()
403
- };
404
- this.outcomes.set(outcome.id, outcome);
405
- // Update process success rate
406
- const process = this.processes.get(processId);
407
- if (process) {
408
- process.successRate = this.updateSuccessRate(process, success);
409
- process.updatedAt = new Date().toISOString();
410
- }
411
- // If successful, strengthen connections
412
- if (success && outputNeuronId) {
413
- await this.reinforceSuccessfulPath(inputNeuronId, outputNeuronId);
414
- }
415
- if (this.currentSession) {
416
- this.currentSession.stages.outcomes.push(outcome);
417
- }
418
- return outcome;
419
- }
420
- // ==================== Full Learning Loop ====================
421
- /**
422
- * Execute full 4-stage learning loop.
423
- *
424
- * Convenience method that runs all four stages sequentially:
425
- * extract → patterns → process → outcome. Use this for
426
- * complete interaction learning with a single call.
427
- *
428
- * @param inputNeuronId - ID of the input neuron
429
- * @param inputContent - Input text content
430
- * @param processSteps - Reasoning steps taken
431
- * @param outputNeuronId - Optional output neuron ID
432
- * @param outputContent - Optional output text content
433
- * @param success - Optional success indicator
434
- * @param quality - Optional quality score (0-1)
435
- * @returns Complete learning results from all four stages
436
- *
437
- * @example
438
- * ```typescript
439
- * const result = await learning.learnFromInteraction(
440
- * inputNeuronId,
441
- * 'How do I sort an array?',
442
- * [{ action: 'search', ... }, { action: 'explain', ... }],
443
- * outputNeuronId,
444
- * 'Here is how to sort...',
445
- * true,
446
- * 0.9
447
- * );
448
- *
449
- * console.log(`Extracts: ${result.extracts.length}`);
450
- * console.log(`Patterns: ${result.patterns.length}`);
451
- * ```
452
- */
453
- async learnFromInteraction(inputNeuronId, inputContent, processSteps, outputNeuronId, outputContent, success, quality) {
454
- // Stage 1: Extract meaningful from input
455
- const inputExtracts = await this.extractMeaningful(inputNeuronId, inputContent);
456
- // Stage 1b: Extract from output if available
457
- let outputExtracts = [];
458
- if (outputNeuronId && outputContent) {
459
- outputExtracts = await this.extractMeaningful(outputNeuronId, outputContent);
460
- }
461
- const allExtracts = [...inputExtracts, ...outputExtracts];
462
- // Stage 2: Learn patterns
463
- const patterns = await this.learnPatterns(allExtracts.map(e => e.id));
464
- // Stage 3: Learn process
465
- const process = await this.learnProcess(this.inferTaskType(inputContent), processSteps, patterns[0]?.id);
466
- // Stage 4: Learn outcome
467
- let outcome = null;
468
- if (process && success !== undefined) {
469
- outcome = await this.learnOutcome(process.id, inputNeuronId, outputNeuronId, success, quality ?? (success ? 0.8 : 0.2));
470
- }
471
- return {
472
- extracts: allExtracts,
473
- patterns,
474
- process,
475
- outcome
476
- };
477
- }
478
- // ==================== Query Methods ====================
479
- /**
480
- * Get patterns relevant to a query
481
- */
482
- async findRelevantPatterns(queryEmbedding, topK = 5) {
483
- const scored = Array.from(this.patterns.values())
484
- .map(pattern => ({
485
- pattern,
486
- score: cosineSimilarity(queryEmbedding, pattern.centroid)
487
- }))
488
- .sort((a, b) => b.score - a.score);
489
- return scored.slice(0, topK).map(s => s.pattern);
490
- }
491
- /**
492
- * Get process for a task type
493
- */
494
- getProcessForTask(taskType) {
495
- for (const process of this.processes.values()) {
496
- if (process.taskType === taskType && process.successRate > 0.7) {
497
- return process;
498
- }
499
- }
500
- return null;
501
- }
502
- /**
503
- * Get learning statistics
504
- */
505
- getStats() {
506
- let totalConfidence = 0;
507
- for (const pattern of this.patterns.values()) {
508
- totalConfidence += pattern.confidence;
509
- }
510
- let totalSuccess = 0;
511
- for (const process of this.processes.values()) {
512
- totalSuccess += process.successRate;
513
- }
514
- return {
515
- extracts: this.extracts.size,
516
- patterns: this.patterns.size,
517
- processes: this.processes.size,
518
- outcomes: this.outcomes.size,
519
- averagePatternConfidence: this.patterns.size > 0
520
- ? totalConfidence / this.patterns.size
521
- : 0,
522
- averageProcessSuccess: this.processes.size > 0
523
- ? totalSuccess / this.processes.size
524
- : 0
525
- };
526
- }
527
- // ==================== Private Methods ====================
528
- segmentContent(content) {
529
- // Split by sentences and meaningful boundaries
530
- const segments = [];
531
- // Split by paragraphs first
532
- const paragraphs = content.split(/\n\n+/);
533
- for (const para of paragraphs) {
534
- // Split by sentences
535
- const sentences = para.split(/(?<=[.!?。!?])\s+/);
536
- for (const sentence of sentences) {
537
- if (sentence.trim().length < 10)
538
- continue;
539
- segments.push({
540
- text: sentence.trim(),
541
- category: this.categorizeSegment(sentence)
542
- });
543
- }
544
- }
545
- return segments;
546
- }
547
- categorizeSegment(text) {
548
- const lower = text.toLowerCase();
549
- if (/\b(because|therefore|thus|hence|so)\b/.test(lower) ||
550
- /때문에|따라서|그러므로/.test(text)) {
551
- return 'causal';
552
- }
553
- if (/\b(if|when|unless|condition)\b/.test(lower) ||
554
- /만약|조건|경우/.test(text)) {
555
- return 'conditional';
556
- }
557
- if (/\b(how to|steps|process|method)\b/.test(lower) ||
558
- /방법|절차|과정/.test(text)) {
559
- return 'procedural';
560
- }
561
- if (/\b(is|are|was|were|definition)\b/.test(lower) ||
562
- /은|는|이다|정의/.test(text)) {
563
- return 'definitional';
564
- }
565
- return 'general';
566
- }
567
- calculateImportance(segment, neuron) {
568
- let importance = 0.5;
569
- // Category bonus
570
- const categoryWeights = {
571
- 'causal': 0.3,
572
- 'procedural': 0.25,
573
- 'conditional': 0.2,
574
- 'definitional': 0.15,
575
- 'general': 0
576
- };
577
- importance += categoryWeights[segment.category] ?? 0;
578
- // Length bonus (longer usually more informative, up to a point)
579
- const wordCount = segment.text.split(/\s+/).length;
580
- importance += Math.min(0.2, wordCount / 100);
581
- // Access count bonus from source neuron
582
- importance += Math.min(0.1, neuron.metadata.accessCount / 100);
583
- return Math.min(1, importance);
584
- }
585
- /**
586
- * Generate semantic embedding for a text segment.
587
- *
588
- * Uses the TextEmbeddingService with multiple strategies:
589
- * 1. TF-IDF weighted word vectors
590
- * 2. Character n-gram hashing
591
- * 3. Positional encoding
592
- * 4. Semantic category detection
593
- * 5. Context blending with base embedding
594
- *
595
- * Falls back to simple hash-based embedding if disabled.
596
- */
597
- async generateSegmentEmbedding(segmentText, baseEmbedding) {
598
- // Use real embedding service if enabled
599
- if (this.useRealEmbeddings) {
600
- try {
601
- const response = await this.embeddingService.embed({
602
- text: segmentText,
603
- contextEmbedding: baseEmbedding
604
- });
605
- // Blend with context for coherence
606
- const blended = new Float32Array(baseEmbedding.length);
607
- for (let i = 0; i < blended.length; i++) {
608
- // 80% from embedding service, 20% context
609
- blended[i] = response.embedding[i] * 0.8 + baseEmbedding[i] * 0.2;
610
- }
611
- // Normalize
612
- let norm = 0;
613
- for (let i = 0; i < blended.length; i++) {
614
- norm += blended[i] * blended[i];
615
- }
616
- norm = Math.sqrt(norm);
617
- if (norm > 0) {
618
- for (let i = 0; i < blended.length; i++) {
619
- blended[i] /= norm;
620
- }
621
- }
622
- return blended;
623
- }
624
- catch (error) {
625
- // Fallback to hash-based embedding on error
626
- this.emit('error', {
627
- error: error,
628
- stage: 'extract'
629
- });
630
- }
631
- }
632
- // Fallback: hash-based embedding
633
- const embedding = new Float32Array(baseEmbedding.length);
634
- let hash = 0;
635
- for (let i = 0; i < segmentText.length; i++) {
636
- hash = ((hash << 5) - hash) + segmentText.charCodeAt(i);
637
- hash |= 0;
638
- }
639
- for (let i = 0; i < embedding.length; i++) {
640
- // Mix base embedding with text-derived values
641
- embedding[i] = baseEmbedding[i] * 0.7 +
642
- (((hash >> (i % 32)) & 0xFF) / 255 - 0.5) * 0.3;
643
- }
644
- // Normalize
645
- let norm = 0;
646
- for (let i = 0; i < embedding.length; i++) {
647
- norm += embedding[i] * embedding[i];
648
- }
649
- norm = Math.sqrt(norm);
650
- for (let i = 0; i < embedding.length; i++) {
651
- embedding[i] /= norm;
652
- }
653
- return embedding;
654
- }
655
- /**
656
- * Update embedding service vocabulary from corpus
657
- */
658
- updateEmbeddingVocabulary(documents) {
659
- this.embeddingService.updateVocabulary(documents);
660
- }
661
- /**
662
- * Get embedding service statistics
663
- */
664
- getEmbeddingStats() {
665
- return this.embeddingService.getStats();
666
- }
667
- /**
668
- * Configure embedding provider (for API-based embeddings)
669
- */
670
- configureEmbeddingProvider(config) {
671
- this.embeddingService = new TextEmbeddingService(config);
672
- }
673
- extractKeywords(text) {
674
- const words = text
675
- .toLowerCase()
676
- .replace(/[^\w\s가-힣]/g, '')
677
- .split(/\s+/)
678
- .filter(w => w.length > 2);
679
- const stopwords = new Set([
680
- 'the', 'a', 'an', 'is', 'are', 'was', 'were', 'be', 'been',
681
- '이', '가', '은', '는', '을', '를', '의', '에', '에서'
682
- ]);
683
- return words.filter(w => !stopwords.has(w)).slice(0, 10);
684
- }
685
- clusterExtracts(extracts) {
686
- // Simple greedy clustering by similarity
687
- const clusters = [];
688
- const assigned = new Set();
689
- for (const extract of extracts) {
690
- if (assigned.has(extract.id))
691
- continue;
692
- const cluster = [extract];
693
- assigned.add(extract.id);
694
- for (const other of extracts) {
695
- if (assigned.has(other.id))
696
- continue;
697
- const similarity = cosineSimilarity(extract.embedding, other.embedding);
698
- if (similarity > 0.7) {
699
- cluster.push(other);
700
- assigned.add(other.id);
701
- }
702
- }
703
- clusters.push(cluster);
704
- }
705
- return clusters;
706
- }
707
- findSimilarPattern(cluster) {
708
- const centroid = this.calculateCentroid(cluster.map(e => e.embedding));
709
- for (const pattern of this.patterns.values()) {
710
- const similarity = cosineSimilarity(centroid, pattern.centroid);
711
- if (similarity > 0.85) {
712
- return pattern;
713
- }
714
- }
715
- return null;
716
- }
717
- calculateCentroid(embeddings) {
718
- if (embeddings.length === 0) {
719
- return new Float32Array(384);
720
- }
721
- const centroid = new Float32Array(embeddings[0].length);
722
- for (const embedding of embeddings) {
723
- for (let i = 0; i < centroid.length; i++) {
724
- centroid[i] += embedding[i];
725
- }
726
- }
727
- for (let i = 0; i < centroid.length; i++) {
728
- centroid[i] /= embeddings.length;
729
- }
730
- return centroid;
731
- }
732
- generatePatternName(cluster) {
733
- // Use most frequent keywords
734
- const keywordCounts = new Map();
735
- for (const extract of cluster) {
736
- for (const keyword of extract.keywords) {
737
- keywordCounts.set(keyword, (keywordCounts.get(keyword) ?? 0) + 1);
738
- }
739
- }
740
- const topKeywords = Array.from(keywordCounts.entries())
741
- .sort((a, b) => b[1] - a[1])
742
- .slice(0, 3)
743
- .map(([k]) => k);
744
- return topKeywords.join('_') || 'unnamed_pattern';
745
- }
746
- generatePatternDescription(cluster) {
747
- const categories = [...new Set(cluster.map(e => e.category))];
748
- return `Pattern from ${cluster.length} instances, categories: ${categories.join(', ')}`;
749
- }
750
- calculatePatternConfidence(cluster) {
751
- if (cluster.length < this.patternMinInstances)
752
- return 0;
753
- // Higher confidence with more instances and higher importance
754
- const avgImportance = cluster.reduce((sum, e) => sum + e.importance, 0) / cluster.length;
755
- const sizeBonus = Math.min(0.3, cluster.length / 20);
756
- return Math.min(1, avgImportance * 0.7 + sizeBonus);
757
- }
758
- findSimilarProcess(taskType, steps) {
759
- for (const process of this.processes.values()) {
760
- if (process.taskType !== taskType)
761
- continue;
762
- // Compare step structure
763
- if (Math.abs(process.steps.length - steps.length) <= 2) {
764
- const actionMatch = this.compareStepActions(process.steps, steps);
765
- if (actionMatch > 0.7) {
766
- return process;
767
- }
768
- }
769
- }
770
- return null;
771
- }
772
- compareStepActions(stepsA, stepsB) {
773
- const actionsA = new Set(stepsA.map(s => s.action.toLowerCase()));
774
- const actionsB = new Set(stepsB.map(s => s.action.toLowerCase()));
775
- const intersection = new Set([...actionsA].filter(x => actionsB.has(x)));
776
- const union = new Set([...actionsA, ...actionsB]);
777
- return intersection.size / union.size;
778
- }
779
- normalizeSteps(steps) {
780
- return steps.map((step, index) => ({
781
- ...step,
782
- stepNumber: index + 1
783
- }));
784
- }
785
- updateSuccessRate(process, success) {
786
- const totalSuccess = process.successRate * process.totalExecutions + (success ? 1 : 0);
787
- return totalSuccess / (process.totalExecutions + 1);
788
- }
789
- updateAverageDuration(process, duration) {
790
- const totalDuration = process.averageDuration * process.totalExecutions + duration;
791
- return totalDuration / (process.totalExecutions + 1);
792
- }
793
- async reinforceSuccessfulPath(inputId, outputId) {
794
- // Strengthen connection between input and output
795
- const existingConnection = await this.graphManager.getConnection(inputId, outputId);
796
- if (existingConnection) {
797
- await this.graphManager.strengthenSynapse(existingConnection.id, 0.05);
798
- }
799
- else {
800
- // Create new connection
801
- await this.graphManager.connect(inputId, outputId, 'CAUSAL', 0.5, true);
802
- }
803
- }
804
- inferTaskType(content) {
805
- const lower = content.toLowerCase();
806
- if (/search|find|look|검색|찾/.test(lower))
807
- return 'search';
808
- if (/create|make|build|생성|만들/.test(lower))
809
- return 'create';
810
- if (/fix|debug|repair|수정|고치/.test(lower))
811
- return 'fix';
812
- if (/explain|describe|설명/.test(lower))
813
- return 'explain';
814
- if (/analyze|분석/.test(lower))
815
- return 'analyze';
816
- return 'general';
817
- }
818
- calculateSuccessRate(outcomes) {
819
- if (outcomes.length === 0)
820
- return 0;
821
- const successes = outcomes.filter(o => o.success).length;
822
- return successes / outcomes.length;
823
- }
824
- // ==================== Streaming Methods ====================
825
- /**
826
- * Stream a learning session with real-time progress updates
827
- *
828
- * Yields progress events as the learning progresses through all stages.
829
- *
830
- * @param inputNeuronId - Input neuron ID
831
- * @param inputContent - Input content to learn from
832
- * @param processSteps - Optional reasoning steps
833
- * @yields LearningProgressEvent for each stage
834
- *
835
- * @example
836
- * ```typescript
837
- * for await (const progress of learning.streamSession(neuronId, content)) {
838
- * console.log(`${progress.stage}: ${progress.percentage.toFixed(0)}%`);
839
- * }
840
- * ```
841
- */
842
- async *streamSession(inputNeuronId, inputContent, processSteps) {
843
- // Start session
844
- const session = this.startSession();
845
- const createProgress = (stage, current, total, message) => ({
846
- sessionId: session.id,
847
- stage,
848
- current,
849
- total,
850
- percentage: total > 0 ? (current / total) * 100 : 0,
851
- message,
852
- });
853
- try {
854
- // Stage 1: Extract
855
- yield createProgress('extract', 0, 100, 'Starting extraction...');
856
- const extracts = await this.extractMeaningful(inputNeuronId, inputContent);
857
- yield createProgress('extract', 100, 100, `Extracted ${extracts.length} meaningful segments`);
858
- // Stage 2: Patterns
859
- yield createProgress('patterns', 0, 100, 'Learning patterns...');
860
- const patterns = await this.learnPatterns(extracts.map(e => e.id));
861
- yield createProgress('patterns', 100, 100, `Discovered ${patterns.length} patterns`);
862
- // Stage 3: Process (if steps provided)
863
- if (processSteps && processSteps.length > 0) {
864
- yield createProgress('process', 0, 100, 'Learning process...');
865
- const process = await this.learnProcess(this.inferTaskType(inputContent), processSteps, patterns[0]?.id);
866
- yield createProgress('process', 100, 100, process ? 'Process learned' : 'Process skipped');
867
- }
868
- // Stage 4: Outcomes (recorded separately)
869
- yield createProgress('outcomes', 0, 100, 'Finalizing...');
870
- // End session
871
- this.endSession();
872
- yield createProgress('outcomes', 100, 100, 'Session complete');
873
- }
874
- catch (error) {
875
- this.emit('error', {
876
- sessionId: session.id,
877
- error: error,
878
- });
879
- throw error;
880
- }
881
- }
882
- /**
883
- * Get current session ID if any
884
- */
885
- getCurrentSessionId() {
886
- return this.currentSession?.id ?? null;
887
- }
888
- /**
889
- * Check if a session is active
890
- */
891
- hasActiveSession() {
892
- return this.currentSession !== null;
893
- }
894
- // ==================== Auto-Persistence Methods ====================
895
- /**
896
- * Enable auto-persistence
897
- *
898
- * @param store - ProbabilisticStore to persist to
899
- * @param intervalMs - Interval between auto-saves (default: 60000 = 1 minute)
900
- *
901
- * @example
902
- * ```typescript
903
- * learning.enableAutoPersist(store, 30000); // Save every 30 seconds
904
- * ```
905
- */
906
- enableAutoPersist(store, intervalMs = 60000) {
907
- this.autoPersistStore = store;
908
- this.autoPersistEnabled = true;
909
- // Clear existing interval if any
910
- if (this.autoPersistInterval) {
911
- clearInterval(this.autoPersistInterval);
912
- }
913
- // Start auto-persist interval
914
- this.autoPersistInterval = setInterval(() => {
915
- this.persistNow().catch(err => {
916
- this.emit('error', { error: err });
917
- });
918
- }, intervalMs);
919
- }
920
- /**
921
- * Disable auto-persistence
922
- */
923
- disableAutoPersist() {
924
- this.autoPersistEnabled = false;
925
- if (this.autoPersistInterval) {
926
- clearInterval(this.autoPersistInterval);
927
- this.autoPersistInterval = null;
928
- }
929
- }
930
- /**
931
- * Persist current state immediately
932
- */
933
- async persistNow() {
934
- if (!this.autoPersistStore) {
935
- throw new Error('Auto-persist store not configured');
936
- }
937
- const data = this.serialize();
938
- await this.autoPersistStore.saveLearning(data);
939
- }
940
- /**
941
- * Load state from persistent store
942
- */
943
- async loadFromStore(store) {
944
- const data = await store.loadLearning();
945
- if (data) {
946
- this.load(data);
947
- return true;
948
- }
949
- return false;
950
- }
951
- // ==================== Persistence Methods ====================
952
- /**
953
- * Serialize learning system state for persistence.
954
- *
955
- * Converts all extracts, patterns, processes, outcomes, and
956
- * the current session to a JSON-serializable format.
957
- *
958
- * @returns Serialized state object for storage
959
- * @see {@link load} for restoring state
960
- */
961
- serialize() {
962
- return {
963
- extracts: Array.from(this.extracts.entries()).map(([id, extract]) => ({
964
- ...extract,
965
- embedding: Array.from(extract.embedding)
966
- })),
967
- patterns: Array.from(this.patterns.entries()).map(([id, pattern]) => ({
968
- ...pattern,
969
- centroid: Array.from(pattern.centroid)
970
- })),
971
- processes: Array.from(this.processes.entries()),
972
- outcomes: Array.from(this.outcomes.entries()),
973
- currentSession: this.currentSession ? {
974
- ...this.currentSession,
975
- stages: {
976
- extract: this.currentSession.stages.extract.map(e => ({
977
- ...e,
978
- embedding: Array.from(e.embedding)
979
- })),
980
- patterns: this.currentSession.stages.patterns.map(p => ({
981
- ...p,
982
- centroid: Array.from(p.centroid)
983
- })),
984
- processes: this.currentSession.stages.processes,
985
- outcomes: this.currentSession.stages.outcomes
986
- }
987
- } : null
988
- };
989
- }
990
- /**
991
- * Load learning system state from serialized data.
992
- *
993
- * Restores all extracts, patterns, processes, outcomes, and
994
- * session state. Embeddings/centroids are converted to Float32Array.
995
- *
996
- * @param data - Previously serialized learning system state
997
- * @see {@link serialize} for creating serialized state
998
- */
999
- load(data) {
1000
- // Restore extracts with Float32Array embeddings
1001
- this.extracts.clear();
1002
- for (const extractData of data.extracts ?? []) {
1003
- const item = extractData;
1004
- const entry = Array.isArray(item) ? item : [item.id, item];
1005
- const id = entry[0];
1006
- const extract = entry[1];
1007
- this.extracts.set(id, {
1008
- ...extract,
1009
- embedding: extract.embedding instanceof Float32Array
1010
- ? extract.embedding
1011
- : new Float32Array(extract.embedding)
1012
- });
1013
- }
1014
- // Restore patterns with Float32Array centroids
1015
- this.patterns.clear();
1016
- for (const patternData of data.patterns ?? []) {
1017
- const item = patternData;
1018
- const entry = Array.isArray(item) ? item : [item.id, item];
1019
- const id = entry[0];
1020
- const pattern = entry[1];
1021
- this.patterns.set(id, {
1022
- ...pattern,
1023
- centroid: pattern.centroid instanceof Float32Array
1024
- ? pattern.centroid
1025
- : new Float32Array(pattern.centroid)
1026
- });
1027
- }
1028
- // Restore processes
1029
- this.processes.clear();
1030
- for (const processData of data.processes ?? []) {
1031
- const item = processData;
1032
- const entry = Array.isArray(item) ? item : [item.id, item];
1033
- const id = entry[0];
1034
- const process = entry[1];
1035
- this.processes.set(id, process);
1036
- }
1037
- // Restore outcomes
1038
- this.outcomes.clear();
1039
- for (const outcomeData of data.outcomes ?? []) {
1040
- const item = outcomeData;
1041
- const entry = Array.isArray(item) ? item : [item.id, item];
1042
- const id = entry[0];
1043
- const outcome = entry[1];
1044
- this.outcomes.set(id, outcome);
1045
- }
1046
- // Restore current session if exists
1047
- if (data.currentSession) {
1048
- this.currentSession = {
1049
- ...data.currentSession,
1050
- stages: {
1051
- extract: (data.currentSession.stages?.extract ?? []).map((e) => ({
1052
- ...e,
1053
- embedding: e.embedding instanceof Float32Array
1054
- ? e.embedding
1055
- : new Float32Array(e.embedding)
1056
- })),
1057
- patterns: (data.currentSession.stages?.patterns ?? []).map((p) => ({
1058
- ...p,
1059
- centroid: p.centroid instanceof Float32Array
1060
- ? p.centroid
1061
- : new Float32Array(p.centroid)
1062
- })),
1063
- processes: data.currentSession.stages?.processes ?? [],
1064
- outcomes: data.currentSession.stages?.outcomes ?? []
1065
- }
1066
- };
1067
- }
1068
- }
1069
- // ==================== Cleanup Methods ====================
1070
- /**
1071
- * Dispose of all resources held by the learning system.
1072
- *
1073
- * Call this when the learning system is no longer needed to:
1074
- * - Stop auto-persistence intervals
1075
- * - Remove all event listeners
1076
- * - Clear all stored data
1077
- *
1078
- * After calling dispose(), the instance should not be used again.
1079
- *
1080
- * @example
1081
- * ```typescript
1082
- * const learning = new FourStageLearningSystem(options);
1083
- * // ... use the learning system ...
1084
- *
1085
- * // Clean up when done
1086
- * learning.dispose();
1087
- * ```
1088
- */
1089
- dispose() {
1090
- // Stop auto-persistence
1091
- this.disableAutoPersist();
1092
- this.autoPersistStore = null;
1093
- // Remove all event listeners
1094
- this.removeAllListeners();
1095
- // Clear all data
1096
- this.extracts.clear();
1097
- this.patterns.clear();
1098
- this.processes.clear();
1099
- this.outcomes.clear();
1100
- // End current session if any
1101
- this.currentSession = null;
1102
- }
1103
- }
1104
- /**
1105
- * Create a FourStageLearningSystem instance
1106
- */
1107
- export function createFourStageLearningSystem(options) {
1108
- return new FourStageLearningSystem(options);
1109
- }
1110
- //# sourceMappingURL=four-stage-learning.js.map