@ninebix/nmt-system 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.
- package/LICENSE +70 -0
- package/README.md +465 -0
- package/dist/api/cli-server.d.ts +83 -0
- package/dist/api/cli-server.d.ts.map +1 -0
- package/dist/api/cli-server.js +597 -0
- package/dist/api/cli-server.js.map +1 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +6 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/middleware/index.d.ts +12 -0
- package/dist/api/middleware/index.d.ts.map +1 -0
- package/dist/api/middleware/index.js +13 -0
- package/dist/api/middleware/index.js.map +1 -0
- package/dist/api/middleware/logger.d.ts +21 -0
- package/dist/api/middleware/logger.d.ts.map +1 -0
- package/dist/api/middleware/logger.js +134 -0
- package/dist/api/middleware/logger.js.map +1 -0
- package/dist/api/middleware/rate-limit.d.ts +26 -0
- package/dist/api/middleware/rate-limit.d.ts.map +1 -0
- package/dist/api/middleware/rate-limit.js +107 -0
- package/dist/api/middleware/rate-limit.js.map +1 -0
- package/dist/api/middleware/response.d.ts +61 -0
- package/dist/api/middleware/response.d.ts.map +1 -0
- package/dist/api/middleware/response.js +86 -0
- package/dist/api/middleware/response.js.map +1 -0
- package/dist/api/middleware/validation.d.ts +43 -0
- package/dist/api/middleware/validation.d.ts.map +1 -0
- package/dist/api/middleware/validation.js +257 -0
- package/dist/api/middleware/validation.js.map +1 -0
- package/dist/api/server.d.ts +79 -0
- package/dist/api/server.d.ts.map +1 -0
- package/dist/api/server.js +2011 -0
- package/dist/api/server.js.map +1 -0
- package/dist/bin/nmt.d.ts +9 -0
- package/dist/bin/nmt.d.ts.map +1 -0
- package/dist/bin/nmt.js +1142 -0
- package/dist/bin/nmt.js.map +1 -0
- package/dist/cli/commands/attractor.d.ts +6 -0
- package/dist/cli/commands/attractor.d.ts.map +1 -0
- package/dist/cli/commands/attractor.js +167 -0
- package/dist/cli/commands/attractor.js.map +1 -0
- package/dist/cli/commands/dimension.d.ts +6 -0
- package/dist/cli/commands/dimension.d.ts.map +1 -0
- package/dist/cli/commands/dimension.js +85 -0
- package/dist/cli/commands/dimension.js.map +1 -0
- package/dist/cli/commands/index.d.ts +11 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +11 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/commands/infer.d.ts +6 -0
- package/dist/cli/commands/infer.d.ts.map +1 -0
- package/dist/cli/commands/infer.js +139 -0
- package/dist/cli/commands/infer.js.map +1 -0
- package/dist/cli/commands/learn.d.ts +6 -0
- package/dist/cli/commands/learn.d.ts.map +1 -0
- package/dist/cli/commands/learn.js +87 -0
- package/dist/cli/commands/learn.js.map +1 -0
- package/dist/cli/commands/orchestrate.d.ts +6 -0
- package/dist/cli/commands/orchestrate.d.ts.map +1 -0
- package/dist/cli/commands/orchestrate.js +279 -0
- package/dist/cli/commands/orchestrate.js.map +1 -0
- package/dist/cli/commands/prob.d.ts +6 -0
- package/dist/cli/commands/prob.d.ts.map +1 -0
- package/dist/cli/commands/prob.js +256 -0
- package/dist/cli/commands/prob.js.map +1 -0
- package/dist/cli/commands/quantum.d.ts +6 -0
- package/dist/cli/commands/quantum.d.ts.map +1 -0
- package/dist/cli/commands/quantum.js +150 -0
- package/dist/cli/commands/quantum.js.map +1 -0
- package/dist/cli/commands/sync.d.ts +65 -0
- package/dist/cli/commands/sync.d.ts.map +1 -0
- package/dist/cli/commands/sync.js +338 -0
- package/dist/cli/commands/sync.js.map +1 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +9 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/probabilistic-commands.d.ts +39 -0
- package/dist/cli/probabilistic-commands.d.ts.map +1 -0
- package/dist/cli/probabilistic-commands.js +112 -0
- package/dist/cli/probabilistic-commands.js.map +1 -0
- package/dist/cli/types.d.ts +69 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +5 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/utils/formatters.d.ts +51 -0
- package/dist/cli/utils/formatters.d.ts.map +1 -0
- package/dist/cli/utils/formatters.js +79 -0
- package/dist/cli/utils/formatters.js.map +1 -0
- package/dist/cli/utils/helpers.d.ts +21 -0
- package/dist/cli/utils/helpers.d.ts.map +1 -0
- package/dist/cli/utils/helpers.js +51 -0
- package/dist/cli/utils/helpers.js.map +1 -0
- package/dist/cli/utils/index.d.ts +7 -0
- package/dist/cli/utils/index.d.ts.map +1 -0
- package/dist/cli/utils/index.js +13 -0
- package/dist/cli/utils/index.js.map +1 -0
- package/dist/cli/utils/validators.d.ts +162 -0
- package/dist/cli/utils/validators.d.ts.map +1 -0
- package/dist/cli/utils/validators.js +351 -0
- package/dist/cli/utils/validators.js.map +1 -0
- package/dist/core/advanced-embedding.d.ts +154 -0
- package/dist/core/advanced-embedding.d.ts.map +1 -0
- package/dist/core/advanced-embedding.js +367 -0
- package/dist/core/advanced-embedding.js.map +1 -0
- package/dist/core/attractor-model.d.ts +381 -0
- package/dist/core/attractor-model.d.ts.map +1 -0
- package/dist/core/attractor-model.js +821 -0
- package/dist/core/attractor-model.js.map +1 -0
- package/dist/core/bidirectional-inference.d.ts +143 -0
- package/dist/core/bidirectional-inference.d.ts.map +1 -0
- package/dist/core/bidirectional-inference.js +501 -0
- package/dist/core/bidirectional-inference.js.map +1 -0
- package/dist/core/chunk-engine.d.ts +78 -0
- package/dist/core/chunk-engine.d.ts.map +1 -0
- package/dist/core/chunk-engine.js +192 -0
- package/dist/core/chunk-engine.js.map +1 -0
- package/dist/core/dynamic-embedding.d.ts +327 -0
- package/dist/core/dynamic-embedding.d.ts.map +1 -0
- package/dist/core/dynamic-embedding.js +527 -0
- package/dist/core/dynamic-embedding.js.map +1 -0
- package/dist/core/embedding-similarity.d.ts +68 -0
- package/dist/core/embedding-similarity.d.ts.map +1 -0
- package/dist/core/embedding-similarity.js +291 -0
- package/dist/core/embedding-similarity.js.map +1 -0
- package/dist/core/evolution-scheduler.d.ts +101 -0
- package/dist/core/evolution-scheduler.d.ts.map +1 -0
- package/dist/core/evolution-scheduler.js +235 -0
- package/dist/core/evolution-scheduler.js.map +1 -0
- package/dist/core/hierarchical-chunker.d.ts +108 -0
- package/dist/core/hierarchical-chunker.d.ts.map +1 -0
- package/dist/core/hierarchical-chunker.js +296 -0
- package/dist/core/hierarchical-chunker.js.map +1 -0
- package/dist/core/hnsw-index.d.ts +111 -0
- package/dist/core/hnsw-index.d.ts.map +1 -0
- package/dist/core/hnsw-index.js +466 -0
- package/dist/core/hnsw-index.js.map +1 -0
- package/dist/core/index.d.ts +23 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +25 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/language-analyzers.d.ts +124 -0
- package/dist/core/language-analyzers.d.ts.map +1 -0
- package/dist/core/language-analyzers.js +365 -0
- package/dist/core/language-analyzers.js.map +1 -0
- package/dist/core/local-embedding.d.ts +109 -0
- package/dist/core/local-embedding.d.ts.map +1 -0
- package/dist/core/local-embedding.js +222 -0
- package/dist/core/local-embedding.js.map +1 -0
- package/dist/core/merkle-engine.d.ts +263 -0
- package/dist/core/merkle-engine.d.ts.map +1 -0
- package/dist/core/merkle-engine.js +528 -0
- package/dist/core/merkle-engine.js.map +1 -0
- package/dist/core/multi-layer-reasoning.d.ts +178 -0
- package/dist/core/multi-layer-reasoning.d.ts.map +1 -0
- package/dist/core/multi-layer-reasoning.js +607 -0
- package/dist/core/multi-layer-reasoning.js.map +1 -0
- package/dist/core/neuron-graph.d.ts +134 -0
- package/dist/core/neuron-graph.d.ts.map +1 -0
- package/dist/core/neuron-graph.js +436 -0
- package/dist/core/neuron-graph.js.map +1 -0
- package/dist/core/probabilistic-neuron.d.ts +251 -0
- package/dist/core/probabilistic-neuron.d.ts.map +1 -0
- package/dist/core/probabilistic-neuron.js +618 -0
- package/dist/core/probabilistic-neuron.js.map +1 -0
- package/dist/core/probabilistic-orchestrator.d.ts +408 -0
- package/dist/core/probabilistic-orchestrator.d.ts.map +1 -0
- package/dist/core/probabilistic-orchestrator.js +798 -0
- package/dist/core/probabilistic-orchestrator.js.map +1 -0
- package/dist/core/semantic-chunker.d.ts +117 -0
- package/dist/core/semantic-chunker.d.ts.map +1 -0
- package/dist/core/semantic-chunker.js +464 -0
- package/dist/core/semantic-chunker.js.map +1 -0
- package/dist/events/event-bus.d.ts +166 -0
- package/dist/events/event-bus.d.ts.map +1 -0
- package/dist/events/event-bus.js +228 -0
- package/dist/events/event-bus.js.map +1 -0
- package/dist/events/index.d.ts +7 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +7 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/progress-tracker.d.ts +150 -0
- package/dist/events/progress-tracker.d.ts.map +1 -0
- package/dist/events/progress-tracker.js +290 -0
- package/dist/events/progress-tracker.js.map +1 -0
- package/dist/extensions/clustering/community-detection.d.ts +90 -0
- package/dist/extensions/clustering/community-detection.d.ts.map +1 -0
- package/dist/extensions/clustering/community-detection.js +470 -0
- package/dist/extensions/clustering/community-detection.js.map +1 -0
- package/dist/extensions/clustering/index.d.ts +114 -0
- package/dist/extensions/clustering/index.d.ts.map +1 -0
- package/dist/extensions/clustering/index.js +468 -0
- package/dist/extensions/clustering/index.js.map +1 -0
- package/dist/extensions/clustering/topic-modeling.d.ts +86 -0
- package/dist/extensions/clustering/topic-modeling.d.ts.map +1 -0
- package/dist/extensions/clustering/topic-modeling.js +355 -0
- package/dist/extensions/clustering/topic-modeling.js.map +1 -0
- package/dist/extensions/distributed/coordinator.d.ts +114 -0
- package/dist/extensions/distributed/coordinator.d.ts.map +1 -0
- package/dist/extensions/distributed/coordinator.js +319 -0
- package/dist/extensions/distributed/coordinator.js.map +1 -0
- package/dist/extensions/distributed/index.d.ts +10 -0
- package/dist/extensions/distributed/index.d.ts.map +1 -0
- package/dist/extensions/distributed/index.js +10 -0
- package/dist/extensions/distributed/index.js.map +1 -0
- package/dist/extensions/distributed/queue.d.ts +157 -0
- package/dist/extensions/distributed/queue.d.ts.map +1 -0
- package/dist/extensions/distributed/queue.js +326 -0
- package/dist/extensions/distributed/queue.js.map +1 -0
- package/dist/extensions/distributed/scheduler.d.ts +107 -0
- package/dist/extensions/distributed/scheduler.d.ts.map +1 -0
- package/dist/extensions/distributed/scheduler.js +301 -0
- package/dist/extensions/distributed/scheduler.js.map +1 -0
- package/dist/extensions/distributed/worker.d.ts +112 -0
- package/dist/extensions/distributed/worker.d.ts.map +1 -0
- package/dist/extensions/distributed/worker.js +260 -0
- package/dist/extensions/distributed/worker.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/server.d.ts +43 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +494 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/services/adaptive-fallback.d.ts +140 -0
- package/dist/services/adaptive-fallback.d.ts.map +1 -0
- package/dist/services/adaptive-fallback.js +273 -0
- package/dist/services/adaptive-fallback.js.map +1 -0
- package/dist/services/answer-gate.d.ts +112 -0
- package/dist/services/answer-gate.d.ts.map +1 -0
- package/dist/services/answer-gate.js +299 -0
- package/dist/services/answer-gate.js.map +1 -0
- package/dist/services/auto-learning.d.ts +135 -0
- package/dist/services/auto-learning.d.ts.map +1 -0
- package/dist/services/auto-learning.js +413 -0
- package/dist/services/auto-learning.js.map +1 -0
- package/dist/services/context-compressor.d.ts +77 -0
- package/dist/services/context-compressor.d.ts.map +1 -0
- package/dist/services/context-compressor.js +234 -0
- package/dist/services/context-compressor.js.map +1 -0
- package/dist/services/efficient-rag.d.ts +140 -0
- package/dist/services/efficient-rag.d.ts.map +1 -0
- package/dist/services/efficient-rag.js +311 -0
- package/dist/services/efficient-rag.js.map +1 -0
- package/dist/services/embedding-provider.d.ts +72 -0
- package/dist/services/embedding-provider.d.ts.map +1 -0
- package/dist/services/embedding-provider.js +176 -0
- package/dist/services/embedding-provider.js.map +1 -0
- package/dist/services/file-ingestion.d.ts +72 -0
- package/dist/services/file-ingestion.d.ts.map +1 -0
- package/dist/services/file-ingestion.js +237 -0
- package/dist/services/file-ingestion.js.map +1 -0
- package/dist/services/four-stage-learning.d.ts +552 -0
- package/dist/services/four-stage-learning.d.ts.map +1 -0
- package/dist/services/four-stage-learning.js +1110 -0
- package/dist/services/four-stage-learning.js.map +1 -0
- package/dist/services/graph.d.ts +94 -0
- package/dist/services/graph.d.ts.map +1 -0
- package/dist/services/graph.js +292 -0
- package/dist/services/graph.js.map +1 -0
- package/dist/services/index.d.ts +15 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +18 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/ingestion.d.ts +98 -0
- package/dist/services/ingestion.d.ts.map +1 -0
- package/dist/services/ingestion.js +259 -0
- package/dist/services/ingestion.js.map +1 -0
- package/dist/services/learning.d.ts +67 -0
- package/dist/services/learning.d.ts.map +1 -0
- package/dist/services/learning.js +262 -0
- package/dist/services/learning.js.map +1 -0
- package/dist/services/llm-router.d.ts +143 -0
- package/dist/services/llm-router.d.ts.map +1 -0
- package/dist/services/llm-router.js +284 -0
- package/dist/services/llm-router.js.map +1 -0
- package/dist/services/llm.d.ts +86 -0
- package/dist/services/llm.d.ts.map +1 -0
- package/dist/services/llm.js +283 -0
- package/dist/services/llm.js.map +1 -0
- package/dist/services/metrics-dashboard.d.ts +262 -0
- package/dist/services/metrics-dashboard.d.ts.map +1 -0
- package/dist/services/metrics-dashboard.js +417 -0
- package/dist/services/metrics-dashboard.js.map +1 -0
- package/dist/services/neuron-lifecycle.d.ts +137 -0
- package/dist/services/neuron-lifecycle.d.ts.map +1 -0
- package/dist/services/neuron-lifecycle.js +422 -0
- package/dist/services/neuron-lifecycle.js.map +1 -0
- package/dist/services/nmt-pipeline.d.ts +219 -0
- package/dist/services/nmt-pipeline.d.ts.map +1 -0
- package/dist/services/nmt-pipeline.js +449 -0
- package/dist/services/nmt-pipeline.js.map +1 -0
- package/dist/services/query-cache.d.ts +136 -0
- package/dist/services/query-cache.d.ts.map +1 -0
- package/dist/services/query-cache.js +255 -0
- package/dist/services/query-cache.js.map +1 -0
- package/dist/services/query-normalize.d.ts +107 -0
- package/dist/services/query-normalize.d.ts.map +1 -0
- package/dist/services/query-normalize.js +366 -0
- package/dist/services/query-normalize.js.map +1 -0
- package/dist/services/query.d.ts +102 -0
- package/dist/services/query.d.ts.map +1 -0
- package/dist/services/query.js +227 -0
- package/dist/services/query.js.map +1 -0
- package/dist/services/text-embedding.d.ts +183 -0
- package/dist/services/text-embedding.d.ts.map +1 -0
- package/dist/services/text-embedding.js +633 -0
- package/dist/services/text-embedding.js.map +1 -0
- package/dist/services/verification-gate.d.ts +147 -0
- package/dist/services/verification-gate.d.ts.map +1 -0
- package/dist/services/verification-gate.js +344 -0
- package/dist/services/verification-gate.js.map +1 -0
- package/dist/services/verify.d.ts +114 -0
- package/dist/services/verify.d.ts.map +1 -0
- package/dist/services/verify.js +237 -0
- package/dist/services/verify.js.map +1 -0
- package/dist/services/web-search.d.ts +145 -0
- package/dist/services/web-search.d.ts.map +1 -0
- package/dist/services/web-search.js +534 -0
- package/dist/services/web-search.js.map +1 -0
- package/dist/src/api/cli-server.d.ts +83 -0
- package/dist/src/api/cli-server.d.ts.map +1 -0
- package/dist/src/api/cli-server.js +597 -0
- package/dist/src/api/cli-server.js.map +1 -0
- package/dist/src/api/index.d.ts +6 -0
- package/dist/src/api/index.d.ts.map +1 -0
- package/dist/src/api/index.js +6 -0
- package/dist/src/api/index.js.map +1 -0
- package/dist/src/cli/commands/attractor.d.ts +6 -0
- package/dist/src/cli/commands/attractor.d.ts.map +1 -0
- package/dist/src/cli/commands/attractor.js +167 -0
- package/dist/src/cli/commands/attractor.js.map +1 -0
- package/dist/src/cli/commands/dimension.d.ts +6 -0
- package/dist/src/cli/commands/dimension.d.ts.map +1 -0
- package/dist/src/cli/commands/dimension.js +85 -0
- package/dist/src/cli/commands/dimension.js.map +1 -0
- package/dist/src/cli/commands/index.d.ts +11 -0
- package/dist/src/cli/commands/index.d.ts.map +1 -0
- package/dist/src/cli/commands/index.js +11 -0
- package/dist/src/cli/commands/index.js.map +1 -0
- package/dist/src/cli/commands/infer.d.ts +6 -0
- package/dist/src/cli/commands/infer.d.ts.map +1 -0
- package/dist/src/cli/commands/infer.js +139 -0
- package/dist/src/cli/commands/infer.js.map +1 -0
- package/dist/src/cli/commands/learn.d.ts +6 -0
- package/dist/src/cli/commands/learn.d.ts.map +1 -0
- package/dist/src/cli/commands/learn.js +87 -0
- package/dist/src/cli/commands/learn.js.map +1 -0
- package/dist/src/cli/commands/orchestrate.d.ts +6 -0
- package/dist/src/cli/commands/orchestrate.d.ts.map +1 -0
- package/dist/src/cli/commands/orchestrate.js +279 -0
- package/dist/src/cli/commands/orchestrate.js.map +1 -0
- package/dist/src/cli/commands/prob.d.ts +6 -0
- package/dist/src/cli/commands/prob.d.ts.map +1 -0
- package/dist/src/cli/commands/prob.js +256 -0
- package/dist/src/cli/commands/prob.js.map +1 -0
- package/dist/src/cli/commands/sync.d.ts +65 -0
- package/dist/src/cli/commands/sync.d.ts.map +1 -0
- package/dist/src/cli/commands/sync.js +338 -0
- package/dist/src/cli/commands/sync.js.map +1 -0
- package/dist/src/cli/index.d.ts +9 -0
- package/dist/src/cli/index.d.ts.map +1 -0
- package/dist/src/cli/index.js +9 -0
- package/dist/src/cli/index.js.map +1 -0
- package/dist/src/cli/probabilistic-commands.d.ts +39 -0
- package/dist/src/cli/probabilistic-commands.d.ts.map +1 -0
- package/dist/src/cli/probabilistic-commands.js +112 -0
- package/dist/src/cli/probabilistic-commands.js.map +1 -0
- package/dist/src/cli/types.d.ts +69 -0
- package/dist/src/cli/types.d.ts.map +1 -0
- package/dist/src/cli/types.js +5 -0
- package/dist/src/cli/types.js.map +1 -0
- package/dist/src/cli/utils/formatters.d.ts +51 -0
- package/dist/src/cli/utils/formatters.d.ts.map +1 -0
- package/dist/src/cli/utils/formatters.js +79 -0
- package/dist/src/cli/utils/formatters.js.map +1 -0
- package/dist/src/cli/utils/helpers.d.ts +21 -0
- package/dist/src/cli/utils/helpers.d.ts.map +1 -0
- package/dist/src/cli/utils/helpers.js +51 -0
- package/dist/src/cli/utils/helpers.js.map +1 -0
- package/dist/src/cli/utils/index.d.ts +7 -0
- package/dist/src/cli/utils/index.d.ts.map +1 -0
- package/dist/src/cli/utils/index.js +13 -0
- package/dist/src/cli/utils/index.js.map +1 -0
- package/dist/src/cli/utils/validators.d.ts +162 -0
- package/dist/src/cli/utils/validators.d.ts.map +1 -0
- package/dist/src/cli/utils/validators.js +351 -0
- package/dist/src/cli/utils/validators.js.map +1 -0
- package/dist/src/core/attractor-model.d.ts +381 -0
- package/dist/src/core/attractor-model.d.ts.map +1 -0
- package/dist/src/core/attractor-model.js +821 -0
- package/dist/src/core/attractor-model.js.map +1 -0
- package/dist/src/core/bidirectional-inference.d.ts +143 -0
- package/dist/src/core/bidirectional-inference.d.ts.map +1 -0
- package/dist/src/core/bidirectional-inference.js +501 -0
- package/dist/src/core/bidirectional-inference.js.map +1 -0
- package/dist/src/core/chunk-engine.d.ts +78 -0
- package/dist/src/core/chunk-engine.d.ts.map +1 -0
- package/dist/src/core/chunk-engine.js +192 -0
- package/dist/src/core/chunk-engine.js.map +1 -0
- package/dist/src/core/dynamic-embedding.d.ts +327 -0
- package/dist/src/core/dynamic-embedding.d.ts.map +1 -0
- package/dist/src/core/dynamic-embedding.js +527 -0
- package/dist/src/core/dynamic-embedding.js.map +1 -0
- package/dist/src/core/evolution-scheduler.d.ts +101 -0
- package/dist/src/core/evolution-scheduler.d.ts.map +1 -0
- package/dist/src/core/evolution-scheduler.js +235 -0
- package/dist/src/core/evolution-scheduler.js.map +1 -0
- package/dist/src/core/hnsw-index.d.ts +111 -0
- package/dist/src/core/hnsw-index.d.ts.map +1 -0
- package/dist/src/core/hnsw-index.js +466 -0
- package/dist/src/core/hnsw-index.js.map +1 -0
- package/dist/src/core/index.d.ts +23 -0
- package/dist/src/core/index.d.ts.map +1 -0
- package/dist/src/core/index.js +25 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/merkle-engine.d.ts +263 -0
- package/dist/src/core/merkle-engine.d.ts.map +1 -0
- package/dist/src/core/merkle-engine.js +528 -0
- package/dist/src/core/merkle-engine.js.map +1 -0
- package/dist/src/core/neuron-graph.d.ts +134 -0
- package/dist/src/core/neuron-graph.d.ts.map +1 -0
- package/dist/src/core/neuron-graph.js +436 -0
- package/dist/src/core/neuron-graph.js.map +1 -0
- package/dist/src/core/probabilistic-neuron.d.ts +251 -0
- package/dist/src/core/probabilistic-neuron.d.ts.map +1 -0
- package/dist/src/core/probabilistic-neuron.js +618 -0
- package/dist/src/core/probabilistic-neuron.js.map +1 -0
- package/dist/src/core/probabilistic-orchestrator.d.ts +408 -0
- package/dist/src/core/probabilistic-orchestrator.d.ts.map +1 -0
- package/dist/src/core/probabilistic-orchestrator.js +798 -0
- package/dist/src/core/probabilistic-orchestrator.js.map +1 -0
- package/dist/src/events/event-bus.d.ts +166 -0
- package/dist/src/events/event-bus.d.ts.map +1 -0
- package/dist/src/events/event-bus.js +228 -0
- package/dist/src/events/event-bus.js.map +1 -0
- package/dist/src/events/index.d.ts +7 -0
- package/dist/src/events/index.d.ts.map +1 -0
- package/dist/src/events/index.js +7 -0
- package/dist/src/events/index.js.map +1 -0
- package/dist/src/events/progress-tracker.d.ts +150 -0
- package/dist/src/events/progress-tracker.d.ts.map +1 -0
- package/dist/src/events/progress-tracker.js +290 -0
- package/dist/src/events/progress-tracker.js.map +1 -0
- package/dist/src/extensions/clustering/index.d.ts +114 -0
- package/dist/src/extensions/clustering/index.d.ts.map +1 -0
- package/dist/src/extensions/clustering/index.js +468 -0
- package/dist/src/extensions/clustering/index.js.map +1 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +20 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp/server.d.ts +43 -0
- package/dist/src/mcp/server.d.ts.map +1 -0
- package/dist/src/mcp/server.js +494 -0
- package/dist/src/mcp/server.js.map +1 -0
- package/dist/src/services/embedding-provider.d.ts +72 -0
- package/dist/src/services/embedding-provider.d.ts.map +1 -0
- package/dist/src/services/embedding-provider.js +176 -0
- package/dist/src/services/embedding-provider.js.map +1 -0
- package/dist/src/services/four-stage-learning.d.ts +552 -0
- package/dist/src/services/four-stage-learning.d.ts.map +1 -0
- package/dist/src/services/four-stage-learning.js +1110 -0
- package/dist/src/services/four-stage-learning.js.map +1 -0
- package/dist/src/services/index.d.ts +15 -0
- package/dist/src/services/index.d.ts.map +1 -0
- package/dist/src/services/index.js +18 -0
- package/dist/src/services/index.js.map +1 -0
- package/dist/src/services/ingestion.d.ts +98 -0
- package/dist/src/services/ingestion.d.ts.map +1 -0
- package/dist/src/services/ingestion.js +259 -0
- package/dist/src/services/ingestion.js.map +1 -0
- package/dist/src/services/query.d.ts +102 -0
- package/dist/src/services/query.d.ts.map +1 -0
- package/dist/src/services/query.js +227 -0
- package/dist/src/services/query.js.map +1 -0
- package/dist/src/services/text-embedding.d.ts +183 -0
- package/dist/src/services/text-embedding.d.ts.map +1 -0
- package/dist/src/services/text-embedding.js +633 -0
- package/dist/src/services/text-embedding.js.map +1 -0
- package/dist/src/services/verify.d.ts +114 -0
- package/dist/src/services/verify.d.ts.map +1 -0
- package/dist/src/services/verify.js +237 -0
- package/dist/src/services/verify.js.map +1 -0
- package/dist/src/storage/chunk-store.d.ts +107 -0
- package/dist/src/storage/chunk-store.d.ts.map +1 -0
- package/dist/src/storage/chunk-store.js +293 -0
- package/dist/src/storage/chunk-store.js.map +1 -0
- package/dist/src/storage/index-store.d.ts +126 -0
- package/dist/src/storage/index-store.d.ts.map +1 -0
- package/dist/src/storage/index-store.js +316 -0
- package/dist/src/storage/index-store.js.map +1 -0
- package/dist/src/storage/index.d.ts +45 -0
- package/dist/src/storage/index.d.ts.map +1 -0
- package/dist/src/storage/index.js +52 -0
- package/dist/src/storage/index.js.map +1 -0
- package/dist/src/storage/neuron-store.d.ts +121 -0
- package/dist/src/storage/neuron-store.d.ts.map +1 -0
- package/dist/src/storage/neuron-store.js +466 -0
- package/dist/src/storage/neuron-store.js.map +1 -0
- package/dist/src/storage/probabilistic-store.d.ts +104 -0
- package/dist/src/storage/probabilistic-store.d.ts.map +1 -0
- package/dist/src/storage/probabilistic-store.js +257 -0
- package/dist/src/storage/probabilistic-store.js.map +1 -0
- package/dist/src/sync/change-journal.d.ts +171 -0
- package/dist/src/sync/change-journal.d.ts.map +1 -0
- package/dist/src/sync/change-journal.js +362 -0
- package/dist/src/sync/change-journal.js.map +1 -0
- package/dist/src/sync/index.d.ts +8 -0
- package/dist/src/sync/index.d.ts.map +1 -0
- package/dist/src/sync/index.js +8 -0
- package/dist/src/sync/index.js.map +1 -0
- package/dist/src/sync/state-sync.d.ts +241 -0
- package/dist/src/sync/state-sync.d.ts.map +1 -0
- package/dist/src/sync/state-sync.js +396 -0
- package/dist/src/sync/state-sync.js.map +1 -0
- package/dist/src/sync/vector-clock.d.ts +144 -0
- package/dist/src/sync/vector-clock.d.ts.map +1 -0
- package/dist/src/sync/vector-clock.js +266 -0
- package/dist/src/sync/vector-clock.js.map +1 -0
- package/dist/src/types/index.d.ts +224 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +24 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/utils/hash.d.ts +39 -0
- package/dist/src/utils/hash.d.ts.map +1 -0
- package/dist/src/utils/hash.js +56 -0
- package/dist/src/utils/hash.js.map +1 -0
- package/dist/src/utils/index.d.ts +26 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +50 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/logger.d.ts +88 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/utils/logger.js +157 -0
- package/dist/src/utils/logger.js.map +1 -0
- package/dist/src/utils/metrics.d.ts +232 -0
- package/dist/src/utils/metrics.d.ts.map +1 -0
- package/dist/src/utils/metrics.js +387 -0
- package/dist/src/utils/metrics.js.map +1 -0
- package/dist/src/utils/similarity.d.ts +64 -0
- package/dist/src/utils/similarity.d.ts.map +1 -0
- package/dist/src/utils/similarity.js +151 -0
- package/dist/src/utils/similarity.js.map +1 -0
- package/dist/src/utils/uuid.d.ts +23 -0
- package/dist/src/utils/uuid.d.ts.map +1 -0
- package/dist/src/utils/uuid.js +29 -0
- package/dist/src/utils/uuid.js.map +1 -0
- package/dist/storage/chunk-store.d.ts +107 -0
- package/dist/storage/chunk-store.d.ts.map +1 -0
- package/dist/storage/chunk-store.js +293 -0
- package/dist/storage/chunk-store.js.map +1 -0
- package/dist/storage/hybrid-adapters.d.ts +111 -0
- package/dist/storage/hybrid-adapters.d.ts.map +1 -0
- package/dist/storage/hybrid-adapters.js +223 -0
- package/dist/storage/hybrid-adapters.js.map +1 -0
- package/dist/storage/hybrid-store.d.ts +125 -0
- package/dist/storage/hybrid-store.d.ts.map +1 -0
- package/dist/storage/hybrid-store.js +655 -0
- package/dist/storage/hybrid-store.js.map +1 -0
- package/dist/storage/index-store.d.ts +126 -0
- package/dist/storage/index-store.d.ts.map +1 -0
- package/dist/storage/index-store.js +316 -0
- package/dist/storage/index-store.js.map +1 -0
- package/dist/storage/index.d.ts +45 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +52 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/neuron-store.d.ts +121 -0
- package/dist/storage/neuron-store.d.ts.map +1 -0
- package/dist/storage/neuron-store.js +466 -0
- package/dist/storage/neuron-store.js.map +1 -0
- package/dist/storage/ontology-store.d.ts +132 -0
- package/dist/storage/ontology-store.d.ts.map +1 -0
- package/dist/storage/ontology-store.js +319 -0
- package/dist/storage/ontology-store.js.map +1 -0
- package/dist/storage/probabilistic-store.d.ts +104 -0
- package/dist/storage/probabilistic-store.d.ts.map +1 -0
- package/dist/storage/probabilistic-store.js +257 -0
- package/dist/storage/probabilistic-store.js.map +1 -0
- package/dist/storage/redis-adapters.d.ts +102 -0
- package/dist/storage/redis-adapters.d.ts.map +1 -0
- package/dist/storage/redis-adapters.js +205 -0
- package/dist/storage/redis-adapters.js.map +1 -0
- package/dist/storage/redis-ontology-store.d.ts +146 -0
- package/dist/storage/redis-ontology-store.d.ts.map +1 -0
- package/dist/storage/redis-ontology-store.js +384 -0
- package/dist/storage/redis-ontology-store.js.map +1 -0
- package/dist/storage/redis-store.d.ts +174 -0
- package/dist/storage/redis-store.d.ts.map +1 -0
- package/dist/storage/redis-store.js +506 -0
- package/dist/storage/redis-store.js.map +1 -0
- package/dist/sync/change-journal.d.ts +171 -0
- package/dist/sync/change-journal.d.ts.map +1 -0
- package/dist/sync/change-journal.js +362 -0
- package/dist/sync/change-journal.js.map +1 -0
- package/dist/sync/index.d.ts +8 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +8 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/state-sync.d.ts +241 -0
- package/dist/sync/state-sync.d.ts.map +1 -0
- package/dist/sync/state-sync.js +396 -0
- package/dist/sync/state-sync.js.map +1 -0
- package/dist/sync/vector-clock.d.ts +144 -0
- package/dist/sync/vector-clock.d.ts.map +1 -0
- package/dist/sync/vector-clock.js +266 -0
- package/dist/sync/vector-clock.js.map +1 -0
- package/dist/types/index.d.ts +224 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +24 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/hash.d.ts +39 -0
- package/dist/utils/hash.d.ts.map +1 -0
- package/dist/utils/hash.js +56 -0
- package/dist/utils/hash.js.map +1 -0
- package/dist/utils/index.d.ts +26 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +50 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/logger.d.ts +88 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +157 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/metrics.d.ts +232 -0
- package/dist/utils/metrics.d.ts.map +1 -0
- package/dist/utils/metrics.js +387 -0
- package/dist/utils/metrics.js.map +1 -0
- package/dist/utils/similarity.d.ts +64 -0
- package/dist/utils/similarity.d.ts.map +1 -0
- package/dist/utils/similarity.js +151 -0
- package/dist/utils/similarity.js.map +1 -0
- package/dist/utils/uuid.d.ts +23 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/uuid.js +29 -0
- package/dist/utils/uuid.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,821 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Future Attractor Model - Goal-Driven Probability Steering
|
|
3
|
+
*
|
|
4
|
+
* Based on Probabilistic Ontology Framework - Teleological Determinism:
|
|
5
|
+
* - Future states act as "attractors" that influence present choices
|
|
6
|
+
* - Current state probabilities are shaped by potential futures
|
|
7
|
+
* - Goals create probability gradients that guide decision paths
|
|
8
|
+
*
|
|
9
|
+
* @module core/attractor-model
|
|
10
|
+
*/
|
|
11
|
+
import { cosineSimilarity } from '../utils/similarity.js';
|
|
12
|
+
/**
|
|
13
|
+
* Priority Queue for A* algorithm
|
|
14
|
+
*/
|
|
15
|
+
class PriorityQueue {
|
|
16
|
+
items = [];
|
|
17
|
+
enqueue(item) {
|
|
18
|
+
this.items.push(item);
|
|
19
|
+
this.bubbleUp(this.items.length - 1);
|
|
20
|
+
}
|
|
21
|
+
dequeue() {
|
|
22
|
+
if (this.items.length === 0)
|
|
23
|
+
return undefined;
|
|
24
|
+
if (this.items.length === 1)
|
|
25
|
+
return this.items.pop();
|
|
26
|
+
const result = this.items[0];
|
|
27
|
+
this.items[0] = this.items.pop();
|
|
28
|
+
this.bubbleDown(0);
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
isEmpty() {
|
|
32
|
+
return this.items.length === 0;
|
|
33
|
+
}
|
|
34
|
+
has(predicate) {
|
|
35
|
+
return this.items.some(predicate);
|
|
36
|
+
}
|
|
37
|
+
update(predicate, newItem) {
|
|
38
|
+
const index = this.items.findIndex(predicate);
|
|
39
|
+
if (index >= 0) {
|
|
40
|
+
this.items[index] = newItem;
|
|
41
|
+
this.bubbleUp(index);
|
|
42
|
+
this.bubbleDown(index);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
bubbleUp(index) {
|
|
46
|
+
while (index > 0) {
|
|
47
|
+
const parentIndex = Math.floor((index - 1) / 2);
|
|
48
|
+
if (this.items[parentIndex].f <= this.items[index].f)
|
|
49
|
+
break;
|
|
50
|
+
[this.items[parentIndex], this.items[index]] = [this.items[index], this.items[parentIndex]];
|
|
51
|
+
index = parentIndex;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
bubbleDown(index) {
|
|
55
|
+
while (true) {
|
|
56
|
+
const left = 2 * index + 1;
|
|
57
|
+
const right = 2 * index + 2;
|
|
58
|
+
let smallest = index;
|
|
59
|
+
if (left < this.items.length && this.items[left].f < this.items[smallest].f) {
|
|
60
|
+
smallest = left;
|
|
61
|
+
}
|
|
62
|
+
if (right < this.items.length && this.items[right].f < this.items[smallest].f) {
|
|
63
|
+
smallest = right;
|
|
64
|
+
}
|
|
65
|
+
if (smallest === index)
|
|
66
|
+
break;
|
|
67
|
+
[this.items[index], this.items[smallest]] = [this.items[smallest], this.items[index]];
|
|
68
|
+
index = smallest;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Attractor Model - Goal-Driven Probability Steering
|
|
74
|
+
*
|
|
75
|
+
* Implements teleological determinism where future goals (attractors)
|
|
76
|
+
* influence present state probabilities through probability fields.
|
|
77
|
+
*
|
|
78
|
+
* Key Concepts:
|
|
79
|
+
* - **Attractors**: Future goal states that "pull" the system towards them
|
|
80
|
+
* - **Probability Fields**: Gradients that guide state transitions
|
|
81
|
+
* - **Influence**: How strongly an attractor affects current decisions
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const model = new AttractorModel({ neuronStore: store });
|
|
86
|
+
*
|
|
87
|
+
* // Create a goal attractor
|
|
88
|
+
* const attractor = model.createAttractor(
|
|
89
|
+
* 'goal-1',
|
|
90
|
+
* 'Complete Project',
|
|
91
|
+
* 'Finish all remaining tasks',
|
|
92
|
+
* goalEmbedding,
|
|
93
|
+
* { strength: 0.8, priority: 10 }
|
|
94
|
+
* );
|
|
95
|
+
*
|
|
96
|
+
* // Calculate influence on current state
|
|
97
|
+
* const influence = model.calculateInfluence(currentStateEmbedding);
|
|
98
|
+
* console.log(`Goal influence: ${influence.get('goal-1')}`);
|
|
99
|
+
*
|
|
100
|
+
* // Find path to goal
|
|
101
|
+
* const path = await model.findPathToAttractor('current-neuron', 'goal-1');
|
|
102
|
+
* console.log(`Path probability: ${path?.probability}`);
|
|
103
|
+
* ```
|
|
104
|
+
*
|
|
105
|
+
* @see {@link Attractor} for attractor state structure
|
|
106
|
+
* @see {@link ProbabilityField} for field configuration
|
|
107
|
+
*/
|
|
108
|
+
export class AttractorModel {
|
|
109
|
+
store;
|
|
110
|
+
maxAttractors;
|
|
111
|
+
defaultStrength;
|
|
112
|
+
decayRate;
|
|
113
|
+
influenceRadius;
|
|
114
|
+
// A* algorithm options
|
|
115
|
+
heuristicWeight;
|
|
116
|
+
maxSearchNodes;
|
|
117
|
+
// Attractor storage
|
|
118
|
+
attractors = new Map();
|
|
119
|
+
// Probability fields
|
|
120
|
+
fields = new Map();
|
|
121
|
+
// State history
|
|
122
|
+
stateHistory = [];
|
|
123
|
+
transitions = [];
|
|
124
|
+
// Current dominant attractor
|
|
125
|
+
dominantAttractor = null;
|
|
126
|
+
// Caching for A* heuristics
|
|
127
|
+
embeddingCache = new Map();
|
|
128
|
+
constructor(options) {
|
|
129
|
+
this.store = options.neuronStore;
|
|
130
|
+
this.maxAttractors = options.maxAttractors ?? 100;
|
|
131
|
+
this.defaultStrength = options.defaultStrength ?? 0.5;
|
|
132
|
+
this.decayRate = options.decayRate ?? 0.95;
|
|
133
|
+
this.influenceRadius = options.influenceRadius ?? 0.7;
|
|
134
|
+
this.heuristicWeight = options.heuristicWeight ?? 1.0;
|
|
135
|
+
this.maxSearchNodes = options.maxSearchNodes ?? 1000;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create a new attractor (future goal state).
|
|
139
|
+
*
|
|
140
|
+
* Attractors represent desired future states that influence present
|
|
141
|
+
* probability distributions. The strength and priority determine how
|
|
142
|
+
* much pull the attractor has on state transitions.
|
|
143
|
+
*
|
|
144
|
+
* @param id - Unique identifier for the attractor
|
|
145
|
+
* @param name - Human-readable name for the goal
|
|
146
|
+
* @param description - Detailed description of the goal state
|
|
147
|
+
* @param embedding - Semantic embedding representing the goal
|
|
148
|
+
* @param options - Configuration options
|
|
149
|
+
* @param options.strength - Pull strength (0-1), default: 0.5
|
|
150
|
+
* @param options.probability - Initial probability of reaching (0-1), default: 0.5
|
|
151
|
+
* @param options.priority - User-defined priority (1-10), default: 5
|
|
152
|
+
* @param options.deadline - Optional ISO8601 deadline
|
|
153
|
+
* @param options.prerequisites - IDs of required states before this
|
|
154
|
+
* @returns The created Attractor object
|
|
155
|
+
*
|
|
156
|
+
* @example
|
|
157
|
+
* ```typescript
|
|
158
|
+
* const attractor = model.createAttractor(
|
|
159
|
+
* 'learn-typescript',
|
|
160
|
+
* 'Master TypeScript',
|
|
161
|
+
* 'Become proficient in TypeScript development',
|
|
162
|
+
* tsEmbedding,
|
|
163
|
+
* { strength: 0.9, priority: 8, deadline: '2024-12-31' }
|
|
164
|
+
* );
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
createAttractor(id, name, description, embedding, options = {}) {
|
|
168
|
+
if (this.attractors.size >= this.maxAttractors) {
|
|
169
|
+
// Remove least activated attractor
|
|
170
|
+
this.pruneWeakestAttractor();
|
|
171
|
+
}
|
|
172
|
+
const attractor = {
|
|
173
|
+
id,
|
|
174
|
+
name,
|
|
175
|
+
description,
|
|
176
|
+
embedding,
|
|
177
|
+
strength: options.strength ?? this.defaultStrength,
|
|
178
|
+
probability: options.probability ?? 0.5,
|
|
179
|
+
priority: options.priority ?? 5,
|
|
180
|
+
deadline: options.deadline,
|
|
181
|
+
prerequisites: options.prerequisites ?? [],
|
|
182
|
+
createdAt: new Date().toISOString(),
|
|
183
|
+
updatedAt: new Date().toISOString(),
|
|
184
|
+
activations: 0
|
|
185
|
+
};
|
|
186
|
+
this.attractors.set(id, attractor);
|
|
187
|
+
this.updateProbabilityField(attractor);
|
|
188
|
+
return attractor;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get attractor by ID
|
|
192
|
+
*/
|
|
193
|
+
getAttractor(id) {
|
|
194
|
+
return this.attractors.get(id);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Update attractor properties
|
|
198
|
+
*/
|
|
199
|
+
updateAttractor(id, updates) {
|
|
200
|
+
const attractor = this.attractors.get(id);
|
|
201
|
+
if (!attractor)
|
|
202
|
+
return null;
|
|
203
|
+
Object.assign(attractor, updates, { updatedAt: new Date().toISOString() });
|
|
204
|
+
this.updateProbabilityField(attractor);
|
|
205
|
+
return attractor;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Calculate influence of all attractors on a given state.
|
|
209
|
+
*
|
|
210
|
+
* Influence is calculated using exponential decay based on semantic
|
|
211
|
+
* distance, multiplied by attractor strength and priority.
|
|
212
|
+
*
|
|
213
|
+
* @param stateEmbedding - The current state's embedding vector
|
|
214
|
+
* @returns Map of attractor IDs to their influence values (0-1)
|
|
215
|
+
*
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* const influences = model.calculateInfluence(currentEmbedding);
|
|
219
|
+
* for (const [attractorId, influence] of influences) {
|
|
220
|
+
* if (influence > 0.5) {
|
|
221
|
+
* console.log(`Strong pull from ${attractorId}: ${influence}`);
|
|
222
|
+
* }
|
|
223
|
+
* }
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
calculateInfluence(stateEmbedding) {
|
|
227
|
+
const influences = new Map();
|
|
228
|
+
for (const [id, attractor] of this.attractors) {
|
|
229
|
+
const similarity = cosineSimilarity(stateEmbedding, attractor.embedding);
|
|
230
|
+
// Influence decreases with distance but increases with strength
|
|
231
|
+
const distance = 1 - similarity;
|
|
232
|
+
const influence = attractor.strength * Math.exp(-distance / this.influenceRadius);
|
|
233
|
+
// Apply priority multiplier
|
|
234
|
+
const priorityMultiplier = attractor.priority / 10;
|
|
235
|
+
influences.set(id, influence * priorityMultiplier);
|
|
236
|
+
}
|
|
237
|
+
return influences;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Get the dominant attractor for a state
|
|
241
|
+
*/
|
|
242
|
+
getDominantAttractor(stateEmbedding) {
|
|
243
|
+
const influences = this.calculateInfluence(stateEmbedding);
|
|
244
|
+
let maxInfluence = 0;
|
|
245
|
+
let dominant = null;
|
|
246
|
+
for (const [id, influence] of influences) {
|
|
247
|
+
if (influence > maxInfluence) {
|
|
248
|
+
maxInfluence = influence;
|
|
249
|
+
dominant = this.attractors.get(id) ?? null;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return dominant;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Calculate transition probabilities from current state
|
|
256
|
+
*/
|
|
257
|
+
async calculateTransitionProbabilities(currentNeuronId, candidateIds) {
|
|
258
|
+
const current = await this.store.getNeuron(currentNeuronId);
|
|
259
|
+
if (!current)
|
|
260
|
+
return new Map();
|
|
261
|
+
const probabilities = new Map();
|
|
262
|
+
const currentInfluences = this.calculateInfluence(current.embedding);
|
|
263
|
+
for (const candidateId of candidateIds) {
|
|
264
|
+
const candidate = await this.store.getNeuron(candidateId);
|
|
265
|
+
if (!candidate)
|
|
266
|
+
continue;
|
|
267
|
+
// Base probability from semantic similarity
|
|
268
|
+
const baseSimilarity = cosineSimilarity(current.embedding, candidate.embedding);
|
|
269
|
+
// Attractor boost: how much better is candidate for reaching attractors?
|
|
270
|
+
let attractorBoost = 0;
|
|
271
|
+
const candidateInfluences = this.calculateInfluence(candidate.embedding);
|
|
272
|
+
for (const [attractorId, currentInf] of currentInfluences) {
|
|
273
|
+
const candidateInf = candidateInfluences.get(attractorId) ?? 0;
|
|
274
|
+
// Positive if candidate is closer to attractor
|
|
275
|
+
attractorBoost += (candidateInf - currentInf);
|
|
276
|
+
}
|
|
277
|
+
// Normalize attractor boost
|
|
278
|
+
attractorBoost = Math.tanh(attractorBoost);
|
|
279
|
+
// Combined probability
|
|
280
|
+
const probability = baseSimilarity * 0.4 + (0.5 + attractorBoost * 0.5) * 0.6;
|
|
281
|
+
probabilities.set(candidateId, Math.max(0, Math.min(1, probability)));
|
|
282
|
+
}
|
|
283
|
+
// Normalize probabilities
|
|
284
|
+
const total = Array.from(probabilities.values()).reduce((a, b) => a + b, 0);
|
|
285
|
+
if (total > 0) {
|
|
286
|
+
for (const [id, prob] of probabilities) {
|
|
287
|
+
probabilities.set(id, prob / total);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return probabilities;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Find optimal path from current state to an attractor using A* algorithm.
|
|
294
|
+
*
|
|
295
|
+
* A* guarantees the optimal path by combining:
|
|
296
|
+
* - g(n): Actual cost from start to node n
|
|
297
|
+
* - h(n): Heuristic estimate from n to goal (semantic distance)
|
|
298
|
+
* - f(n) = g(n) + h(n): Total estimated cost
|
|
299
|
+
*
|
|
300
|
+
* The heuristic uses semantic distance (1 - cosine similarity) which is
|
|
301
|
+
* admissible (never overestimates) for semantic spaces.
|
|
302
|
+
*
|
|
303
|
+
* @param currentNeuronId - Starting neuron ID
|
|
304
|
+
* @param attractorId - Target attractor ID
|
|
305
|
+
* @param maxDepth - Maximum search depth, default: 10
|
|
306
|
+
* @returns Path information including probability and bottlenecks, or null if not found
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* const result = await model.findPathToAttractor('start', 'goal', 10);
|
|
311
|
+
* if (result.found) {
|
|
312
|
+
* console.log(`Optimal path: ${result.path.join(' → ')}`);
|
|
313
|
+
* console.log(`Path probability: ${(result.pathProbability * 100).toFixed(1)}%`);
|
|
314
|
+
* console.log(`Nodes explored: ${result.nodesExplored}`);
|
|
315
|
+
* for (const bottleneck of result.bottlenecks) {
|
|
316
|
+
* console.log(`Bottleneck: ${bottleneck.nodeId} (cost: ${bottleneck.costContribution})`);
|
|
317
|
+
* }
|
|
318
|
+
* }
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
async findPathToAttractor(currentNeuronId, attractorId, maxDepth = 10) {
|
|
322
|
+
const attractor = this.attractors.get(attractorId);
|
|
323
|
+
if (!attractor)
|
|
324
|
+
return null;
|
|
325
|
+
const result = await this.aStarSearch(currentNeuronId, attractor, maxDepth);
|
|
326
|
+
if (!result.found)
|
|
327
|
+
return null;
|
|
328
|
+
return {
|
|
329
|
+
path: result.path,
|
|
330
|
+
probability: result.pathProbability,
|
|
331
|
+
estimatedSteps: result.path.length - 1,
|
|
332
|
+
bottlenecks: result.bottlenecks.map(b => b.nodeId)
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* A* Search Algorithm Implementation
|
|
337
|
+
*
|
|
338
|
+
* Uses:
|
|
339
|
+
* - g(n) = sum of edge costs (1 - synapse.weight) from start
|
|
340
|
+
* - h(n) = semantic distance (1 - cosine_similarity) to goal
|
|
341
|
+
* - f(n) = g(n) + w * h(n) where w is heuristicWeight
|
|
342
|
+
*
|
|
343
|
+
* @param startId - Starting neuron ID
|
|
344
|
+
* @param goal - Target attractor
|
|
345
|
+
* @param maxDepth - Maximum path length
|
|
346
|
+
* @returns A* search result with path, cost, and bottlenecks
|
|
347
|
+
*/
|
|
348
|
+
async aStarSearch(startId, goal, maxDepth = 10) {
|
|
349
|
+
// Initialize result
|
|
350
|
+
const result = {
|
|
351
|
+
found: false,
|
|
352
|
+
path: [],
|
|
353
|
+
totalCost: Infinity,
|
|
354
|
+
nodesExplored: 0,
|
|
355
|
+
pathProbability: 0,
|
|
356
|
+
bottlenecks: []
|
|
357
|
+
};
|
|
358
|
+
// Get start node
|
|
359
|
+
const startNode = await this.store.getNeuron(startId);
|
|
360
|
+
if (!startNode)
|
|
361
|
+
return result;
|
|
362
|
+
// Cache start embedding
|
|
363
|
+
this.embeddingCache.set(startId, startNode.embedding);
|
|
364
|
+
// Calculate initial heuristic
|
|
365
|
+
const startH = this.calculateHeuristic(startNode.embedding, goal.embedding);
|
|
366
|
+
// Check if already at goal
|
|
367
|
+
if (startH < 0.1) {
|
|
368
|
+
result.found = true;
|
|
369
|
+
result.path = [startId];
|
|
370
|
+
result.totalCost = 0;
|
|
371
|
+
result.pathProbability = 1;
|
|
372
|
+
return result;
|
|
373
|
+
}
|
|
374
|
+
// Initialize open set (priority queue)
|
|
375
|
+
const openSet = new PriorityQueue();
|
|
376
|
+
openSet.enqueue({
|
|
377
|
+
id: startId,
|
|
378
|
+
parent: null,
|
|
379
|
+
g: 0,
|
|
380
|
+
h: startH,
|
|
381
|
+
f: this.heuristicWeight * startH
|
|
382
|
+
});
|
|
383
|
+
// Initialize closed set
|
|
384
|
+
const closedSet = new Set();
|
|
385
|
+
// Track best g values
|
|
386
|
+
const gScores = new Map();
|
|
387
|
+
gScores.set(startId, 0);
|
|
388
|
+
// Track parent pointers for path reconstruction
|
|
389
|
+
const cameFrom = new Map();
|
|
390
|
+
// Track edge costs for bottleneck analysis
|
|
391
|
+
const edgeCosts = new Map();
|
|
392
|
+
// Main A* loop
|
|
393
|
+
while (!openSet.isEmpty() && result.nodesExplored < this.maxSearchNodes) {
|
|
394
|
+
const current = openSet.dequeue();
|
|
395
|
+
result.nodesExplored++;
|
|
396
|
+
// Skip if already processed
|
|
397
|
+
if (closedSet.has(current.id))
|
|
398
|
+
continue;
|
|
399
|
+
// Get current node embedding
|
|
400
|
+
let currentEmbedding = this.embeddingCache.get(current.id);
|
|
401
|
+
if (!currentEmbedding) {
|
|
402
|
+
const node = await this.store.getNeuron(current.id);
|
|
403
|
+
if (!node)
|
|
404
|
+
continue;
|
|
405
|
+
currentEmbedding = node.embedding;
|
|
406
|
+
this.embeddingCache.set(current.id, currentEmbedding);
|
|
407
|
+
}
|
|
408
|
+
// Check if goal reached (similarity > 0.9)
|
|
409
|
+
const similarity = cosineSimilarity(currentEmbedding, goal.embedding);
|
|
410
|
+
if (similarity > 0.9) {
|
|
411
|
+
result.found = true;
|
|
412
|
+
result.totalCost = current.g;
|
|
413
|
+
result.path = this.reconstructPath(current.id, cameFrom);
|
|
414
|
+
result.pathProbability = this.calculatePathProbability(result.path, edgeCosts);
|
|
415
|
+
result.bottlenecks = this.identifyAStarBottlenecks(result.path, edgeCosts);
|
|
416
|
+
return result;
|
|
417
|
+
}
|
|
418
|
+
// Add to closed set
|
|
419
|
+
closedSet.add(current.id);
|
|
420
|
+
// Check depth limit
|
|
421
|
+
const depth = this.reconstructPath(current.id, cameFrom).length - 1;
|
|
422
|
+
if (depth >= maxDepth)
|
|
423
|
+
continue;
|
|
424
|
+
// Expand neighbors
|
|
425
|
+
const outgoing = await this.store.getOutgoingSynapses(current.id);
|
|
426
|
+
for (const synapse of outgoing) {
|
|
427
|
+
if (closedSet.has(synapse.targetId))
|
|
428
|
+
continue;
|
|
429
|
+
// Get neighbor embedding
|
|
430
|
+
let neighborEmbedding = this.embeddingCache.get(synapse.targetId);
|
|
431
|
+
if (!neighborEmbedding) {
|
|
432
|
+
const neighborNode = await this.store.getNeuron(synapse.targetId);
|
|
433
|
+
if (!neighborNode)
|
|
434
|
+
continue;
|
|
435
|
+
neighborEmbedding = neighborNode.embedding;
|
|
436
|
+
this.embeddingCache.set(synapse.targetId, neighborEmbedding);
|
|
437
|
+
}
|
|
438
|
+
// Calculate edge cost (lower weight = higher cost)
|
|
439
|
+
// Cost = 1 - weight, so strong connections are cheap
|
|
440
|
+
const edgeCost = 1 - synapse.weight;
|
|
441
|
+
// Factor in attractor pull (moving towards attractor reduces cost)
|
|
442
|
+
const currentToGoal = 1 - cosineSimilarity(currentEmbedding, goal.embedding);
|
|
443
|
+
const neighborToGoal = 1 - cosineSimilarity(neighborEmbedding, goal.embedding);
|
|
444
|
+
const attractorBonus = Math.max(0, currentToGoal - neighborToGoal) * 0.5;
|
|
445
|
+
const adjustedCost = Math.max(0.01, edgeCost - attractorBonus);
|
|
446
|
+
// Calculate tentative g score
|
|
447
|
+
const tentativeG = current.g + adjustedCost;
|
|
448
|
+
// Check if this path is better
|
|
449
|
+
const existingG = gScores.get(synapse.targetId) ?? Infinity;
|
|
450
|
+
if (tentativeG < existingG) {
|
|
451
|
+
// Record this path
|
|
452
|
+
cameFrom.set(synapse.targetId, current.id);
|
|
453
|
+
gScores.set(synapse.targetId, tentativeG);
|
|
454
|
+
edgeCosts.set(`${current.id}:${synapse.targetId}`, adjustedCost);
|
|
455
|
+
// Calculate heuristic
|
|
456
|
+
const h = this.calculateHeuristic(neighborEmbedding, goal.embedding);
|
|
457
|
+
const f = tentativeG + this.heuristicWeight * h;
|
|
458
|
+
// Add to open set
|
|
459
|
+
openSet.enqueue({
|
|
460
|
+
id: synapse.targetId,
|
|
461
|
+
parent: current.id,
|
|
462
|
+
g: tentativeG,
|
|
463
|
+
h,
|
|
464
|
+
f
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return result;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Calculate heuristic for A* (semantic distance to goal)
|
|
473
|
+
*
|
|
474
|
+
* Uses 1 - cosine_similarity as distance metric.
|
|
475
|
+
* This heuristic is admissible for semantic spaces.
|
|
476
|
+
*/
|
|
477
|
+
calculateHeuristic(embedding, goalEmbedding) {
|
|
478
|
+
const similarity = cosineSimilarity(embedding, goalEmbedding);
|
|
479
|
+
// Distance = 1 - similarity, bounded [0, 2] for cosine
|
|
480
|
+
return 1 - similarity;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Reconstruct path from A* search
|
|
484
|
+
*/
|
|
485
|
+
reconstructPath(goalId, cameFrom) {
|
|
486
|
+
const path = [goalId];
|
|
487
|
+
let current = goalId;
|
|
488
|
+
while (cameFrom.has(current)) {
|
|
489
|
+
current = cameFrom.get(current);
|
|
490
|
+
path.unshift(current);
|
|
491
|
+
}
|
|
492
|
+
return path;
|
|
493
|
+
}
|
|
494
|
+
/**
|
|
495
|
+
* Calculate path probability (product of edge weights)
|
|
496
|
+
*/
|
|
497
|
+
calculatePathProbability(path, edgeCosts) {
|
|
498
|
+
if (path.length < 2)
|
|
499
|
+
return 1;
|
|
500
|
+
let probability = 1;
|
|
501
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
502
|
+
const edgeKey = `${path[i]}:${path[i + 1]}`;
|
|
503
|
+
const cost = edgeCosts.get(edgeKey) ?? 0.5;
|
|
504
|
+
// Convert cost back to probability-like value
|
|
505
|
+
// cost = 1 - weight, so weight = 1 - cost
|
|
506
|
+
probability *= (1 - cost);
|
|
507
|
+
}
|
|
508
|
+
return probability;
|
|
509
|
+
}
|
|
510
|
+
/**
|
|
511
|
+
* Identify bottlenecks from A* search (high-cost edges)
|
|
512
|
+
*/
|
|
513
|
+
identifyAStarBottlenecks(path, edgeCosts) {
|
|
514
|
+
const bottlenecks = [];
|
|
515
|
+
// Calculate average edge cost
|
|
516
|
+
let totalCost = 0;
|
|
517
|
+
let edgeCount = 0;
|
|
518
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
519
|
+
const edgeKey = `${path[i]}:${path[i + 1]}`;
|
|
520
|
+
const cost = edgeCosts.get(edgeKey) ?? 0;
|
|
521
|
+
totalCost += cost;
|
|
522
|
+
edgeCount++;
|
|
523
|
+
}
|
|
524
|
+
const avgCost = edgeCount > 0 ? totalCost / edgeCount : 0;
|
|
525
|
+
// Bottlenecks are edges with above-average cost
|
|
526
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
527
|
+
const edgeKey = `${path[i]}:${path[i + 1]}`;
|
|
528
|
+
const cost = edgeCosts.get(edgeKey) ?? 0;
|
|
529
|
+
if (cost > avgCost * 1.5) {
|
|
530
|
+
bottlenecks.push({
|
|
531
|
+
nodeId: path[i + 1],
|
|
532
|
+
costContribution: cost
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
// Sort by cost contribution (highest first)
|
|
537
|
+
bottlenecks.sort((a, b) => b.costContribution - a.costContribution);
|
|
538
|
+
return bottlenecks;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Find multiple alternative paths to attractor
|
|
542
|
+
*
|
|
543
|
+
* Uses A* with path exclusion to find k-best paths
|
|
544
|
+
*/
|
|
545
|
+
async findAlternativePaths(currentNeuronId, attractorId, k = 3, maxDepth = 10) {
|
|
546
|
+
const attractor = this.attractors.get(attractorId);
|
|
547
|
+
if (!attractor)
|
|
548
|
+
return [];
|
|
549
|
+
const results = [];
|
|
550
|
+
const usedPaths = new Set();
|
|
551
|
+
for (let i = 0; i < k; i++) {
|
|
552
|
+
const result = await this.aStarSearchWithExclusion(currentNeuronId, attractor, maxDepth, usedPaths);
|
|
553
|
+
if (!result.found)
|
|
554
|
+
break;
|
|
555
|
+
results.push(result);
|
|
556
|
+
usedPaths.add(result.path.join(':'));
|
|
557
|
+
}
|
|
558
|
+
return results;
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* A* search with path exclusion for k-best paths
|
|
562
|
+
*/
|
|
563
|
+
async aStarSearchWithExclusion(startId, goal, maxDepth, excludedPaths) {
|
|
564
|
+
// Similar to aStarSearch but with path exclusion
|
|
565
|
+
const result = await this.aStarSearch(startId, goal, maxDepth);
|
|
566
|
+
// If the found path is excluded, try again with penalty
|
|
567
|
+
if (result.found && excludedPaths.has(result.path.join(':'))) {
|
|
568
|
+
// Add penalty and retry - this is simplified
|
|
569
|
+
result.found = false;
|
|
570
|
+
}
|
|
571
|
+
return result;
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Bidirectional A* search for faster pathfinding
|
|
575
|
+
*
|
|
576
|
+
* Searches from both start and goal simultaneously
|
|
577
|
+
*/
|
|
578
|
+
async bidirectionalAStarSearch(startId, attractorId, maxDepth = 10) {
|
|
579
|
+
const attractor = this.attractors.get(attractorId);
|
|
580
|
+
if (!attractor) {
|
|
581
|
+
return { found: false, path: [], totalCost: Infinity, nodesExplored: 0, pathProbability: 0, bottlenecks: [] };
|
|
582
|
+
}
|
|
583
|
+
// For now, delegate to standard A* (full bidirectional needs goal node ID)
|
|
584
|
+
// In a full implementation, you'd need to identify goal nodes first
|
|
585
|
+
return this.aStarSearch(startId, attractor, maxDepth);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Clear embedding cache to free memory
|
|
589
|
+
*/
|
|
590
|
+
clearCache() {
|
|
591
|
+
this.embeddingCache.clear();
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Record a state transition between neurons.
|
|
595
|
+
*
|
|
596
|
+
* Tracks how state transitions are influenced by attractors,
|
|
597
|
+
* updating attractor activation counts when transitions move
|
|
598
|
+
* towards them.
|
|
599
|
+
*
|
|
600
|
+
* @param fromId - Source neuron ID
|
|
601
|
+
* @param toId - Target neuron ID
|
|
602
|
+
* @returns The recorded transition with attractor influences
|
|
603
|
+
* @throws Error if either neuron ID is invalid
|
|
604
|
+
*/
|
|
605
|
+
async recordTransition(fromId, toId) {
|
|
606
|
+
const from = await this.store.getNeuron(fromId);
|
|
607
|
+
const to = await this.store.getNeuron(toId);
|
|
608
|
+
if (!from || !to) {
|
|
609
|
+
throw new Error('Invalid neuron IDs for transition');
|
|
610
|
+
}
|
|
611
|
+
// Calculate probability based on attractor influences
|
|
612
|
+
const fromInfluences = this.calculateInfluence(from.embedding);
|
|
613
|
+
const toInfluences = this.calculateInfluence(to.embedding);
|
|
614
|
+
let probability = cosineSimilarity(from.embedding, to.embedding);
|
|
615
|
+
// Track attractor contribution
|
|
616
|
+
const attractorInfluence = new Map();
|
|
617
|
+
for (const [attractorId, fromInf] of fromInfluences) {
|
|
618
|
+
const toInf = toInfluences.get(attractorId) ?? 0;
|
|
619
|
+
const contribution = toInf - fromInf;
|
|
620
|
+
attractorInfluence.set(attractorId, contribution);
|
|
621
|
+
// If moving towards an attractor, increase that attractor's activation
|
|
622
|
+
if (contribution > 0) {
|
|
623
|
+
const attractor = this.attractors.get(attractorId);
|
|
624
|
+
if (attractor) {
|
|
625
|
+
attractor.activations++;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
const transition = {
|
|
630
|
+
from: fromId,
|
|
631
|
+
to: toId,
|
|
632
|
+
probability,
|
|
633
|
+
attractorInfluence,
|
|
634
|
+
timestamp: new Date().toISOString()
|
|
635
|
+
};
|
|
636
|
+
this.transitions.push(transition);
|
|
637
|
+
// Update state history
|
|
638
|
+
this.stateHistory.push({
|
|
639
|
+
neuronId: toId,
|
|
640
|
+
embedding: to.embedding,
|
|
641
|
+
timestamp: transition.timestamp,
|
|
642
|
+
activeAttractors: Array.from(attractorInfluence.keys()).filter(id => (attractorInfluence.get(id) ?? 0) > 0),
|
|
643
|
+
dominantAttractor: this.getDominantAttractor(to.embedding)?.id,
|
|
644
|
+
transitionProbabilities: new Map()
|
|
645
|
+
});
|
|
646
|
+
return transition;
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Update attractor probabilities based on current state
|
|
650
|
+
*/
|
|
651
|
+
async updateAttractorProbabilities(currentNeuronId) {
|
|
652
|
+
const current = await this.store.getNeuron(currentNeuronId);
|
|
653
|
+
if (!current)
|
|
654
|
+
return;
|
|
655
|
+
for (const [id, attractor] of this.attractors) {
|
|
656
|
+
const similarity = cosineSimilarity(current.embedding, attractor.embedding);
|
|
657
|
+
// Update probability with exponential smoothing
|
|
658
|
+
const newProb = 0.8 * attractor.probability + 0.2 * similarity;
|
|
659
|
+
attractor.probability = Math.max(0, Math.min(1, newProb));
|
|
660
|
+
attractor.updatedAt = new Date().toISOString();
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
/**
|
|
664
|
+
* Decay attractor strengths over time.
|
|
665
|
+
*
|
|
666
|
+
* Applies exponential decay to attractors that haven't been
|
|
667
|
+
* updated in 24+ hours. Very weak attractors with few activations
|
|
668
|
+
* are automatically removed.
|
|
669
|
+
*
|
|
670
|
+
* Call this periodically (e.g., hourly) to maintain attractor health.
|
|
671
|
+
*/
|
|
672
|
+
decayAttractors() {
|
|
673
|
+
const now = Date.now();
|
|
674
|
+
for (const attractor of this.attractors.values()) {
|
|
675
|
+
const lastUpdated = new Date(attractor.updatedAt).getTime();
|
|
676
|
+
const hoursSinceUpdate = (now - lastUpdated) / (1000 * 60 * 60);
|
|
677
|
+
if (hoursSinceUpdate > 24) {
|
|
678
|
+
// Apply decay
|
|
679
|
+
attractor.strength *= this.decayRate;
|
|
680
|
+
// Remove very weak attractors
|
|
681
|
+
if (attractor.strength < 0.01 && attractor.activations < 5) {
|
|
682
|
+
this.attractors.delete(attractor.id);
|
|
683
|
+
this.fields.delete(attractor.id);
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Get all active attractors
|
|
690
|
+
*/
|
|
691
|
+
getActiveAttractors() {
|
|
692
|
+
return Array.from(this.attractors.values())
|
|
693
|
+
.filter(a => a.strength > 0.1)
|
|
694
|
+
.sort((a, b) => b.priority * b.strength - a.priority * a.strength);
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Get statistics
|
|
698
|
+
*/
|
|
699
|
+
getStats() {
|
|
700
|
+
let totalStrength = 0;
|
|
701
|
+
let totalActivations = 0;
|
|
702
|
+
let activeCount = 0;
|
|
703
|
+
for (const attractor of this.attractors.values()) {
|
|
704
|
+
totalStrength += attractor.strength;
|
|
705
|
+
totalActivations += attractor.activations;
|
|
706
|
+
if (attractor.strength > 0.1)
|
|
707
|
+
activeCount++;
|
|
708
|
+
}
|
|
709
|
+
return {
|
|
710
|
+
totalAttractors: this.attractors.size,
|
|
711
|
+
activeAttractors: activeCount,
|
|
712
|
+
transitions: this.transitions.length,
|
|
713
|
+
stateHistory: this.stateHistory.length,
|
|
714
|
+
averageStrength: this.attractors.size > 0 ? totalStrength / this.attractors.size : 0,
|
|
715
|
+
averageActivations: this.attractors.size > 0 ? totalActivations / this.attractors.size : 0
|
|
716
|
+
};
|
|
717
|
+
}
|
|
718
|
+
/**
|
|
719
|
+
* Serialize attractor model state for persistence.
|
|
720
|
+
*
|
|
721
|
+
* Converts all attractors, transitions, and state to a JSON-serializable
|
|
722
|
+
* object. Embeddings are converted to plain arrays.
|
|
723
|
+
*
|
|
724
|
+
* @returns Serialized state object for storage
|
|
725
|
+
* @see {@link load} for restoring state
|
|
726
|
+
*/
|
|
727
|
+
serialize() {
|
|
728
|
+
return {
|
|
729
|
+
attractors: Array.from(this.attractors.entries()).map(([id, a]) => ({
|
|
730
|
+
...a,
|
|
731
|
+
embedding: Array.from(a.embedding)
|
|
732
|
+
})),
|
|
733
|
+
transitions: this.transitions.slice(-1000), // Keep last 1000 transitions
|
|
734
|
+
dominantAttractor: this.dominantAttractor
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
/**
|
|
738
|
+
* Load attractor model from serialized data.
|
|
739
|
+
*
|
|
740
|
+
* Restores all attractors, transitions, and state from previously
|
|
741
|
+
* serialized data. Embeddings are converted back to Float32Array.
|
|
742
|
+
*
|
|
743
|
+
* @param data - Previously serialized attractor model state
|
|
744
|
+
* @see {@link serialize} for creating serialized state
|
|
745
|
+
*/
|
|
746
|
+
load(data) {
|
|
747
|
+
this.attractors.clear();
|
|
748
|
+
for (const a of data.attractors ?? []) {
|
|
749
|
+
const attractor = {
|
|
750
|
+
...a,
|
|
751
|
+
embedding: new Float32Array(a.embedding)
|
|
752
|
+
};
|
|
753
|
+
this.attractors.set(a.id, attractor);
|
|
754
|
+
this.updateProbabilityField(attractor);
|
|
755
|
+
}
|
|
756
|
+
this.transitions = data.transitions ?? [];
|
|
757
|
+
this.dominantAttractor = data.dominantAttractor ?? null;
|
|
758
|
+
}
|
|
759
|
+
// ==================== Private Methods ====================
|
|
760
|
+
updateProbabilityField(attractor) {
|
|
761
|
+
const field = {
|
|
762
|
+
attractor,
|
|
763
|
+
gradient: new Map(),
|
|
764
|
+
reachableStates: [],
|
|
765
|
+
pathProbabilities: []
|
|
766
|
+
};
|
|
767
|
+
this.fields.set(attractor.id, field);
|
|
768
|
+
}
|
|
769
|
+
pruneWeakestAttractor() {
|
|
770
|
+
let weakest = null;
|
|
771
|
+
let weakestScore = Infinity;
|
|
772
|
+
for (const attractor of this.attractors.values()) {
|
|
773
|
+
const score = attractor.strength * attractor.priority * (1 + attractor.activations / 100);
|
|
774
|
+
if (score < weakestScore) {
|
|
775
|
+
weakestScore = score;
|
|
776
|
+
weakest = attractor;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (weakest) {
|
|
780
|
+
this.attractors.delete(weakest.id);
|
|
781
|
+
this.fields.delete(weakest.id);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Simple bottleneck identification for legacy compatibility
|
|
786
|
+
* @deprecated Use identifyAStarBottlenecks for accurate bottleneck detection
|
|
787
|
+
*/
|
|
788
|
+
identifyBottlenecks(path) {
|
|
789
|
+
// Bottlenecks are nodes where probability drops significantly
|
|
790
|
+
// For now, return middle nodes as potential bottlenecks
|
|
791
|
+
if (path.length <= 2)
|
|
792
|
+
return [];
|
|
793
|
+
return path.slice(1, -1);
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Get path cost breakdown
|
|
797
|
+
*/
|
|
798
|
+
async analyzePathCost(path) {
|
|
799
|
+
const edgeCosts = [];
|
|
800
|
+
let totalCost = 0;
|
|
801
|
+
for (let i = 0; i < path.length - 1; i++) {
|
|
802
|
+
const synapses = await this.store.getOutgoingSynapses(path[i]);
|
|
803
|
+
const synapse = synapses.find(s => s.targetId === path[i + 1]);
|
|
804
|
+
const cost = synapse ? 1 - synapse.weight : 0.5;
|
|
805
|
+
edgeCosts.push({ from: path[i], to: path[i + 1], cost });
|
|
806
|
+
totalCost += cost;
|
|
807
|
+
}
|
|
808
|
+
return {
|
|
809
|
+
totalCost,
|
|
810
|
+
edgeCosts,
|
|
811
|
+
avgCost: edgeCosts.length > 0 ? totalCost / edgeCosts.length : 0
|
|
812
|
+
};
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Create an AttractorModel instance
|
|
817
|
+
*/
|
|
818
|
+
export function createAttractorModel(options) {
|
|
819
|
+
return new AttractorModel(options);
|
|
820
|
+
}
|
|
821
|
+
//# sourceMappingURL=attractor-model.js.map
|