agentdb 1.6.0 → 2.0.0-alpha.1
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/README.md +1098 -350
- package/dist/agentdb-advanced.js +2110 -0
- package/dist/agentdb-advanced.min.js +1 -0
- package/dist/agentdb.min.js +4 -4
- package/dist/backends/GraphBackend.d.ts +196 -0
- package/dist/backends/GraphBackend.d.ts.map +1 -0
- package/dist/backends/GraphBackend.js +33 -0
- package/dist/backends/GraphBackend.js.map +1 -0
- package/dist/backends/LearningBackend.d.ts +148 -0
- package/dist/backends/LearningBackend.d.ts.map +1 -0
- package/dist/backends/LearningBackend.js +27 -0
- package/dist/backends/LearningBackend.js.map +1 -0
- package/dist/backends/VectorBackend.d.ts +119 -0
- package/dist/backends/VectorBackend.d.ts.map +1 -0
- package/dist/backends/VectorBackend.js +14 -0
- package/dist/backends/VectorBackend.js.map +1 -0
- package/dist/backends/detector.d.ts +81 -0
- package/dist/backends/detector.d.ts.map +1 -0
- package/dist/backends/detector.js +192 -0
- package/dist/backends/detector.js.map +1 -0
- package/dist/backends/factory.d.ts +50 -0
- package/dist/backends/factory.d.ts.map +1 -0
- package/dist/backends/factory.js +161 -0
- package/dist/backends/factory.js.map +1 -0
- package/dist/backends/graph/GraphDatabaseAdapter.d.ts +139 -0
- package/dist/backends/graph/GraphDatabaseAdapter.d.ts.map +1 -0
- package/dist/backends/graph/GraphDatabaseAdapter.js +194 -0
- package/dist/backends/graph/GraphDatabaseAdapter.js.map +1 -0
- package/dist/backends/hnswlib/HNSWLibBackend.d.ts +92 -0
- package/dist/backends/hnswlib/HNSWLibBackend.d.ts.map +1 -0
- package/dist/backends/hnswlib/HNSWLibBackend.js +316 -0
- package/dist/backends/hnswlib/HNSWLibBackend.js.map +1 -0
- package/dist/backends/hnswlib/index.d.ts +7 -0
- package/dist/backends/hnswlib/index.d.ts.map +1 -0
- package/dist/backends/hnswlib/index.js +7 -0
- package/dist/backends/hnswlib/index.js.map +1 -0
- package/dist/backends/index.d.ts +14 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/index.js +13 -0
- package/dist/backends/index.js.map +1 -0
- package/dist/backends/ruvector/RuVectorBackend.d.ts +75 -0
- package/dist/backends/ruvector/RuVectorBackend.d.ts.map +1 -0
- package/dist/backends/ruvector/RuVectorBackend.js +198 -0
- package/dist/backends/ruvector/RuVectorBackend.js.map +1 -0
- package/dist/backends/ruvector/RuVectorLearning.d.ts +104 -0
- package/dist/backends/ruvector/RuVectorLearning.d.ts.map +1 -0
- package/dist/backends/ruvector/RuVectorLearning.js +177 -0
- package/dist/backends/ruvector/RuVectorLearning.js.map +1 -0
- package/dist/backends/ruvector/index.d.ts +9 -0
- package/dist/backends/ruvector/index.d.ts.map +1 -0
- package/dist/backends/ruvector/index.js +8 -0
- package/dist/backends/ruvector/index.js.map +1 -0
- package/dist/browser/AdvancedFeatures.d.ts +144 -0
- package/dist/browser/AdvancedFeatures.d.ts.map +1 -0
- package/dist/browser/AdvancedFeatures.js +430 -0
- package/dist/browser/AdvancedFeatures.js.map +1 -0
- package/dist/browser/HNSWIndex.d.ts +117 -0
- package/dist/browser/HNSWIndex.d.ts.map +1 -0
- package/dist/browser/HNSWIndex.js +402 -0
- package/dist/browser/HNSWIndex.js.map +1 -0
- package/dist/browser/ProductQuantization.d.ts +107 -0
- package/dist/browser/ProductQuantization.d.ts.map +1 -0
- package/dist/browser/ProductQuantization.js +337 -0
- package/dist/browser/ProductQuantization.js.map +1 -0
- package/dist/browser/browser/AdvancedFeatures.d.ts +144 -0
- package/dist/browser/browser/AdvancedFeatures.d.ts.map +1 -0
- package/dist/browser/browser/AdvancedFeatures.js +427 -0
- package/dist/browser/browser/HNSWIndex.d.ts +117 -0
- package/dist/browser/browser/HNSWIndex.d.ts.map +1 -0
- package/dist/browser/browser/HNSWIndex.js +402 -0
- package/dist/browser/browser/ProductQuantization.d.ts +107 -0
- package/dist/browser/browser/ProductQuantization.d.ts.map +1 -0
- package/dist/browser/browser/ProductQuantization.js +348 -0
- package/dist/browser/browser/index.d.ts +223 -0
- package/dist/browser/browser/index.d.ts.map +1 -0
- package/dist/browser/browser/index.js +233 -0
- package/dist/browser/index.d.ts +223 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +225 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/cli/agentdb-cli.d.ts.map +1 -1
- package/dist/cli/agentdb-cli.js +130 -8
- package/dist/cli/agentdb-cli.js.map +1 -1
- package/dist/cli/agentdb.db +0 -0
- package/dist/cli/commands/init.d.ts +12 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +115 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/commands/install-embeddings.d.ts +10 -0
- package/dist/cli/commands/install-embeddings.d.ts.map +1 -0
- package/dist/cli/commands/install-embeddings.js +68 -0
- package/dist/cli/commands/install-embeddings.js.map +1 -0
- package/dist/cli/commands/migrate.d.ts +15 -0
- package/dist/cli/commands/migrate.d.ts.map +1 -0
- package/dist/cli/commands/migrate.js +425 -0
- package/dist/cli/commands/migrate.js.map +1 -0
- package/dist/cli/commands/status.d.ts +10 -0
- package/dist/cli/commands/status.d.ts.map +1 -0
- package/dist/cli/commands/status.js +129 -0
- package/dist/cli/commands/status.js.map +1 -0
- package/dist/controllers/CausalRecall.d.ts +3 -1
- package/dist/controllers/CausalRecall.d.ts.map +1 -1
- package/dist/controllers/CausalRecall.js +35 -4
- package/dist/controllers/CausalRecall.js.map +1 -1
- package/dist/controllers/ExplainableRecall.d.ts +24 -0
- package/dist/controllers/ExplainableRecall.d.ts.map +1 -1
- package/dist/controllers/ExplainableRecall.js +102 -5
- package/dist/controllers/ExplainableRecall.js.map +1 -1
- package/dist/controllers/HNSWIndex.d.ts +128 -0
- package/dist/controllers/HNSWIndex.d.ts.map +1 -0
- package/dist/controllers/HNSWIndex.js +361 -0
- package/dist/controllers/HNSWIndex.js.map +1 -0
- package/dist/controllers/NightlyLearner.d.ts.map +1 -1
- package/dist/controllers/NightlyLearner.js +7 -4
- package/dist/controllers/NightlyLearner.js.map +1 -1
- package/dist/controllers/ReasoningBank.d.ts +101 -2
- package/dist/controllers/ReasoningBank.d.ts.map +1 -1
- package/dist/controllers/ReasoningBank.js +196 -4
- package/dist/controllers/ReasoningBank.js.map +1 -1
- package/dist/controllers/ReflexionMemory.d.ts +41 -1
- package/dist/controllers/ReflexionMemory.d.ts.map +1 -1
- package/dist/controllers/ReflexionMemory.js +282 -5
- package/dist/controllers/ReflexionMemory.js.map +1 -1
- package/dist/controllers/SkillLibrary.d.ts +27 -9
- package/dist/controllers/SkillLibrary.d.ts.map +1 -1
- package/dist/controllers/SkillLibrary.js +136 -47
- package/dist/controllers/SkillLibrary.js.map +1 -1
- package/dist/controllers/index.d.ts +2 -0
- package/dist/controllers/index.d.ts.map +1 -1
- package/dist/controllers/index.js +1 -0
- package/dist/controllers/index.js.map +1 -1
- package/dist/db-fallback.d.ts.map +1 -1
- package/dist/db-fallback.js +100 -29
- package/dist/db-fallback.js.map +1 -1
- package/dist/db-test.d.ts +13 -0
- package/dist/db-test.d.ts.map +1 -0
- package/dist/db-test.js +55 -0
- package/dist/db-test.js.map +1 -0
- package/dist/db-unified.d.ts +76 -0
- package/dist/db-unified.d.ts.map +1 -0
- package/dist/db-unified.js +278 -0
- package/dist/db-unified.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/malp/core/ccc.d.ts +99 -0
- package/dist/malp/core/ccc.d.ts.map +1 -0
- package/dist/malp/core/ccc.js +181 -0
- package/dist/malp/core/ccc.js.map +1 -0
- package/dist/malp/core/index.d.ts +9 -0
- package/dist/malp/core/index.d.ts.map +1 -0
- package/dist/malp/core/index.js +9 -0
- package/dist/malp/core/index.js.map +1 -0
- package/dist/malp/core/linalg.d.ts +101 -0
- package/dist/malp/core/linalg.d.ts.map +1 -0
- package/dist/malp/core/linalg.js +278 -0
- package/dist/malp/core/linalg.js.map +1 -0
- package/dist/malp/core/optimizer.d.ts +68 -0
- package/dist/malp/core/optimizer.d.ts.map +1 -0
- package/dist/malp/core/optimizer.js +160 -0
- package/dist/malp/core/optimizer.js.map +1 -0
- package/dist/malp/index.d.ts +33 -0
- package/dist/malp/index.d.ts.map +1 -0
- package/dist/malp/index.js +37 -0
- package/dist/malp/index.js.map +1 -0
- package/dist/malp/metrics/agreement.d.ts +106 -0
- package/dist/malp/metrics/agreement.d.ts.map +1 -0
- package/dist/malp/metrics/agreement.js +199 -0
- package/dist/malp/metrics/agreement.js.map +1 -0
- package/dist/malp/metrics/comparison.d.ts +93 -0
- package/dist/malp/metrics/comparison.d.ts.map +1 -0
- package/dist/malp/metrics/comparison.js +256 -0
- package/dist/malp/metrics/comparison.js.map +1 -0
- package/dist/malp/metrics/index.d.ts +8 -0
- package/dist/malp/metrics/index.d.ts.map +1 -0
- package/dist/malp/metrics/index.js +8 -0
- package/dist/malp/metrics/index.js.map +1 -0
- package/dist/malp/metrics/performance.d.ts +61 -0
- package/dist/malp/metrics/performance.d.ts.map +1 -0
- package/dist/malp/metrics/performance.js +190 -0
- package/dist/malp/metrics/performance.js.map +1 -0
- package/dist/malp/models/index.d.ts +7 -0
- package/dist/malp/models/index.d.ts.map +1 -0
- package/dist/malp/models/index.js +7 -0
- package/dist/malp/models/index.js.map +1 -0
- package/dist/malp/models/malp.d.ts +116 -0
- package/dist/malp/models/malp.d.ts.map +1 -0
- package/dist/malp/models/malp.js +206 -0
- package/dist/malp/models/malp.js.map +1 -0
- package/dist/malp/models/regressor.d.ts +80 -0
- package/dist/malp/models/regressor.d.ts.map +1 -0
- package/dist/malp/models/regressor.js +229 -0
- package/dist/malp/models/regressor.js.map +1 -0
- package/dist/malp/reasoningbank_validator.d.ts +187 -0
- package/dist/malp/reasoningbank_validator.d.ts.map +1 -0
- package/dist/malp/reasoningbank_validator.js +246 -0
- package/dist/malp/reasoningbank_validator.js.map +1 -0
- package/dist/malp/wasm_bindings.d.ts +344 -0
- package/dist/malp/wasm_bindings.d.ts.map +1 -0
- package/dist/malp/wasm_bindings.js +9 -0
- package/dist/malp/wasm_bindings.js.map +1 -0
- package/dist/mcp/agentdb-mcp-server.js +512 -33
- package/dist/mcp/agentdb-mcp-server.js.map +1 -1
- package/dist/optimizations/BatchOperations.d.ts +42 -0
- package/dist/optimizations/BatchOperations.d.ts.map +1 -1
- package/dist/optimizations/BatchOperations.js +181 -0
- package/dist/optimizations/BatchOperations.js.map +1 -1
- package/dist/optimizations/ToolCache.d.ts +137 -0
- package/dist/optimizations/ToolCache.d.ts.map +1 -0
- package/dist/optimizations/ToolCache.js +281 -0
- package/dist/optimizations/ToolCache.js.map +1 -0
- package/dist/security/input-validation.d.ts +24 -0
- package/dist/security/input-validation.d.ts.map +1 -1
- package/dist/security/input-validation.js +106 -0
- package/dist/security/input-validation.js.map +1 -1
- package/dist/security/limits.d.ts +150 -0
- package/dist/security/limits.d.ts.map +1 -0
- package/dist/security/limits.js +288 -0
- package/dist/security/limits.js.map +1 -0
- package/dist/security/path-security.d.ts +100 -0
- package/dist/security/path-security.d.ts.map +1 -0
- package/dist/security/path-security.js +337 -0
- package/dist/security/path-security.js.map +1 -0
- package/dist/security/validation.d.ts +95 -0
- package/dist/security/validation.d.ts.map +1 -0
- package/dist/security/validation.js +315 -0
- package/dist/security/validation.js.map +1 -0
- package/dist/simulation/cli.d.ts +9 -0
- package/dist/simulation/cli.d.ts.map +1 -0
- package/dist/simulation/cli.js +68 -0
- package/dist/simulation/cli.js.map +1 -0
- package/dist/simulation/runner.d.ts +21 -0
- package/dist/simulation/runner.d.ts.map +1 -0
- package/dist/simulation/runner.js +241 -0
- package/dist/simulation/runner.js.map +1 -0
- package/dist/simulation/scenarios/aidefence-integration.d.ts +24 -0
- package/dist/simulation/scenarios/aidefence-integration.d.ts.map +1 -0
- package/dist/simulation/scenarios/aidefence-integration.js +124 -0
- package/dist/simulation/scenarios/aidefence-integration.js.map +1 -0
- package/dist/simulation/scenarios/bmssp-integration.d.ts +23 -0
- package/dist/simulation/scenarios/bmssp-integration.d.ts.map +1 -0
- package/dist/simulation/scenarios/bmssp-integration.js +104 -0
- package/dist/simulation/scenarios/bmssp-integration.js.map +1 -0
- package/dist/simulation/scenarios/causal-reasoning.d.ts +16 -0
- package/dist/simulation/scenarios/causal-reasoning.d.ts.map +1 -0
- package/dist/simulation/scenarios/causal-reasoning.js +108 -0
- package/dist/simulation/scenarios/causal-reasoning.js.map +1 -0
- package/dist/simulation/scenarios/consciousness-explorer.d.ts +25 -0
- package/dist/simulation/scenarios/consciousness-explorer.d.ts.map +1 -0
- package/dist/simulation/scenarios/consciousness-explorer.js +108 -0
- package/dist/simulation/scenarios/consciousness-explorer.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.d.ts +135 -0
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.js +158 -0
- package/dist/simulation/scenarios/domain-examples/e-commerce-recommendations.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/index.d.ts +14 -0
- package/dist/simulation/scenarios/domain-examples/index.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/index.js +14 -0
- package/dist/simulation/scenarios/domain-examples/index.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.d.ts +178 -0
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.js +218 -0
- package/dist/simulation/scenarios/domain-examples/iot-sensor-networks.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/medical-imaging.d.ts +122 -0
- package/dist/simulation/scenarios/domain-examples/medical-imaging.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/medical-imaging.js +129 -0
- package/dist/simulation/scenarios/domain-examples/medical-imaging.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.d.ts +166 -0
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.js +161 -0
- package/dist/simulation/scenarios/domain-examples/robotics-navigation.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/scientific-research.d.ts +151 -0
- package/dist/simulation/scenarios/domain-examples/scientific-research.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/scientific-research.js +187 -0
- package/dist/simulation/scenarios/domain-examples/scientific-research.js.map +1 -0
- package/dist/simulation/scenarios/domain-examples/trading-systems.d.ts +102 -0
- package/dist/simulation/scenarios/domain-examples/trading-systems.d.ts.map +1 -0
- package/dist/simulation/scenarios/domain-examples/trading-systems.js +100 -0
- package/dist/simulation/scenarios/domain-examples/trading-systems.js.map +1 -0
- package/dist/simulation/scenarios/goalie-integration.d.ts +24 -0
- package/dist/simulation/scenarios/goalie-integration.d.ts.map +1 -0
- package/dist/simulation/scenarios/goalie-integration.js +121 -0
- package/dist/simulation/scenarios/goalie-integration.js.map +1 -0
- package/dist/simulation/scenarios/graph-traversal.d.ts +17 -0
- package/dist/simulation/scenarios/graph-traversal.d.ts.map +1 -0
- package/dist/simulation/scenarios/graph-traversal.js +101 -0
- package/dist/simulation/scenarios/graph-traversal.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/attention-analysis.d.ts +45 -0
- package/dist/simulation/scenarios/latent-space/attention-analysis.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/attention-analysis.js +435 -0
- package/dist/simulation/scenarios/latent-space/attention-analysis.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/clustering-analysis.d.ts +55 -0
- package/dist/simulation/scenarios/latent-space/clustering-analysis.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/clustering-analysis.js +606 -0
- package/dist/simulation/scenarios/latent-space/clustering-analysis.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.d.ts +74 -0
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.js +391 -0
- package/dist/simulation/scenarios/latent-space/hnsw-exploration.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.d.ts +51 -0
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.js +536 -0
- package/dist/simulation/scenarios/latent-space/hypergraph-exploration.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/index.d.ts +35 -0
- package/dist/simulation/scenarios/latent-space/index.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/index.js +35 -0
- package/dist/simulation/scenarios/latent-space/index.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/neural-augmentation.d.ts +52 -0
- package/dist/simulation/scenarios/latent-space/neural-augmentation.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/neural-augmentation.js +472 -0
- package/dist/simulation/scenarios/latent-space/neural-augmentation.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.d.ts +53 -0
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.js +391 -0
- package/dist/simulation/scenarios/latent-space/quantum-hybrid.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.d.ts +52 -0
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.js +514 -0
- package/dist/simulation/scenarios/latent-space/self-organizing-hnsw.js.map +1 -0
- package/dist/simulation/scenarios/latent-space/traversal-optimization.d.ts +53 -0
- package/dist/simulation/scenarios/latent-space/traversal-optimization.d.ts.map +1 -0
- package/dist/simulation/scenarios/latent-space/traversal-optimization.js +595 -0
- package/dist/simulation/scenarios/latent-space/traversal-optimization.js.map +1 -0
- package/dist/simulation/scenarios/lean-agentic-swarm.d.ts +18 -0
- package/dist/simulation/scenarios/lean-agentic-swarm.d.ts.map +1 -0
- package/dist/simulation/scenarios/lean-agentic-swarm.js +132 -0
- package/dist/simulation/scenarios/lean-agentic-swarm.js.map +1 -0
- package/dist/simulation/scenarios/multi-agent-swarm.d.ts +17 -0
- package/dist/simulation/scenarios/multi-agent-swarm.d.ts.map +1 -0
- package/dist/simulation/scenarios/multi-agent-swarm.js +111 -0
- package/dist/simulation/scenarios/multi-agent-swarm.js.map +1 -0
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.d.ts +23 -0
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.d.ts.map +1 -0
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.js +98 -0
- package/dist/simulation/scenarios/psycho-symbolic-reasoner.js.map +1 -0
- package/dist/simulation/scenarios/reflexion-learning.d.ts +16 -0
- package/dist/simulation/scenarios/reflexion-learning.d.ts.map +1 -0
- package/dist/simulation/scenarios/reflexion-learning.js +98 -0
- package/dist/simulation/scenarios/reflexion-learning.js.map +1 -0
- package/dist/simulation/scenarios/research-swarm.d.ts +24 -0
- package/dist/simulation/scenarios/research-swarm.d.ts.map +1 -0
- package/dist/simulation/scenarios/research-swarm.js +146 -0
- package/dist/simulation/scenarios/research-swarm.js.map +1 -0
- package/dist/simulation/scenarios/skill-evolution.d.ts +16 -0
- package/dist/simulation/scenarios/skill-evolution.d.ts.map +1 -0
- package/dist/simulation/scenarios/skill-evolution.js +109 -0
- package/dist/simulation/scenarios/skill-evolution.js.map +1 -0
- package/dist/simulation/scenarios/stock-market-emergence.d.ts +33 -0
- package/dist/simulation/scenarios/stock-market-emergence.d.ts.map +1 -0
- package/dist/simulation/scenarios/stock-market-emergence.js +246 -0
- package/dist/simulation/scenarios/stock-market-emergence.js.map +1 -0
- package/dist/simulation/scenarios/strange-loops.d.ts +18 -0
- package/dist/simulation/scenarios/strange-loops.d.ts.map +1 -0
- package/dist/simulation/scenarios/strange-loops.js +133 -0
- package/dist/simulation/scenarios/strange-loops.js.map +1 -0
- package/dist/simulation/scenarios/sublinear-solver.d.ts +22 -0
- package/dist/simulation/scenarios/sublinear-solver.d.ts.map +1 -0
- package/dist/simulation/scenarios/sublinear-solver.js +82 -0
- package/dist/simulation/scenarios/sublinear-solver.js.map +1 -0
- package/dist/simulation/scenarios/temporal-lead-solver.d.ts +23 -0
- package/dist/simulation/scenarios/temporal-lead-solver.d.ts.map +1 -0
- package/dist/simulation/scenarios/temporal-lead-solver.js +90 -0
- package/dist/simulation/scenarios/temporal-lead-solver.js.map +1 -0
- package/dist/simulation/scenarios/voting-system-consensus.d.ts +27 -0
- package/dist/simulation/scenarios/voting-system-consensus.d.ts.map +1 -0
- package/dist/simulation/scenarios/voting-system-consensus.js +175 -0
- package/dist/simulation/scenarios/voting-system-consensus.js.map +1 -0
- package/dist/simulation/types.d.ts +162 -0
- package/dist/simulation/types.d.ts.map +1 -0
- package/dist/simulation/types.js +5 -0
- package/dist/simulation/types.js.map +1 -0
- package/dist/simulation/utils/PerformanceOptimizer.d.ts +115 -0
- package/dist/simulation/utils/PerformanceOptimizer.d.ts.map +1 -0
- package/dist/simulation/utils/PerformanceOptimizer.js +223 -0
- package/dist/simulation/utils/PerformanceOptimizer.js.map +1 -0
- package/dist/src/backends/GraphBackend.d.ts +196 -0
- package/dist/src/backends/GraphBackend.d.ts.map +1 -0
- package/dist/src/backends/GraphBackend.js +33 -0
- package/dist/src/backends/GraphBackend.js.map +1 -0
- package/dist/src/backends/LearningBackend.d.ts +148 -0
- package/dist/src/backends/LearningBackend.d.ts.map +1 -0
- package/dist/src/backends/LearningBackend.js +27 -0
- package/dist/src/backends/LearningBackend.js.map +1 -0
- package/dist/src/backends/VectorBackend.d.ts +119 -0
- package/dist/src/backends/VectorBackend.d.ts.map +1 -0
- package/dist/src/backends/VectorBackend.js +14 -0
- package/dist/src/backends/VectorBackend.js.map +1 -0
- package/dist/src/backends/detector.d.ts +81 -0
- package/dist/src/backends/detector.d.ts.map +1 -0
- package/dist/src/backends/detector.js +192 -0
- package/dist/src/backends/detector.js.map +1 -0
- package/dist/src/backends/factory.d.ts +50 -0
- package/dist/src/backends/factory.d.ts.map +1 -0
- package/dist/src/backends/factory.js +161 -0
- package/dist/src/backends/factory.js.map +1 -0
- package/dist/src/backends/graph/GraphDatabaseAdapter.d.ts +151 -0
- package/dist/src/backends/graph/GraphDatabaseAdapter.d.ts.map +1 -0
- package/dist/src/backends/graph/GraphDatabaseAdapter.js +224 -0
- package/dist/src/backends/graph/GraphDatabaseAdapter.js.map +1 -0
- package/dist/src/backends/hnswlib/HNSWLibBackend.d.ts +92 -0
- package/dist/src/backends/hnswlib/HNSWLibBackend.d.ts.map +1 -0
- package/dist/src/backends/hnswlib/HNSWLibBackend.js +316 -0
- package/dist/src/backends/hnswlib/HNSWLibBackend.js.map +1 -0
- package/dist/src/backends/hnswlib/index.d.ts +7 -0
- package/dist/src/backends/hnswlib/index.d.ts.map +1 -0
- package/dist/src/backends/hnswlib/index.js +7 -0
- package/dist/src/backends/hnswlib/index.js.map +1 -0
- package/dist/src/backends/index.d.ts +14 -0
- package/dist/src/backends/index.d.ts.map +1 -0
- package/dist/src/backends/index.js +13 -0
- package/dist/src/backends/index.js.map +1 -0
- package/dist/src/backends/ruvector/RuVectorBackend.d.ts +75 -0
- package/dist/src/backends/ruvector/RuVectorBackend.d.ts.map +1 -0
- package/dist/src/backends/ruvector/RuVectorBackend.js +198 -0
- package/dist/src/backends/ruvector/RuVectorBackend.js.map +1 -0
- package/dist/src/backends/ruvector/RuVectorLearning.d.ts +104 -0
- package/dist/src/backends/ruvector/RuVectorLearning.d.ts.map +1 -0
- package/dist/src/backends/ruvector/RuVectorLearning.js +177 -0
- package/dist/src/backends/ruvector/RuVectorLearning.js.map +1 -0
- package/dist/src/backends/ruvector/index.d.ts +9 -0
- package/dist/src/backends/ruvector/index.d.ts.map +1 -0
- package/dist/src/backends/ruvector/index.js +8 -0
- package/dist/src/backends/ruvector/index.js.map +1 -0
- package/dist/src/benchmarks/wasm-vector-benchmark.d.ts +10 -0
- package/dist/src/benchmarks/wasm-vector-benchmark.d.ts.map +1 -0
- package/dist/src/benchmarks/wasm-vector-benchmark.js +196 -0
- package/dist/src/benchmarks/wasm-vector-benchmark.js.map +1 -0
- package/dist/src/browser/AdvancedFeatures.d.ts +144 -0
- package/dist/src/browser/AdvancedFeatures.d.ts.map +1 -0
- package/dist/src/browser/AdvancedFeatures.js +430 -0
- package/dist/src/browser/AdvancedFeatures.js.map +1 -0
- package/dist/src/browser/HNSWIndex.d.ts +117 -0
- package/dist/src/browser/HNSWIndex.d.ts.map +1 -0
- package/dist/src/browser/HNSWIndex.js +402 -0
- package/dist/src/browser/HNSWIndex.js.map +1 -0
- package/dist/src/browser/ProductQuantization.d.ts +107 -0
- package/dist/src/browser/ProductQuantization.d.ts.map +1 -0
- package/dist/src/browser/ProductQuantization.js +337 -0
- package/dist/src/browser/ProductQuantization.js.map +1 -0
- package/dist/src/browser/index.d.ts +223 -0
- package/dist/src/browser/index.d.ts.map +1 -0
- package/dist/src/browser/index.js +225 -0
- package/dist/src/browser/index.js.map +1 -0
- package/dist/src/cli/agentdb-cli.d.ts +154 -0
- package/dist/src/cli/agentdb-cli.d.ts.map +1 -0
- package/dist/src/cli/agentdb-cli.js +2273 -0
- package/dist/src/cli/agentdb-cli.js.map +1 -0
- package/dist/src/cli/commands/init.d.ts +12 -0
- package/dist/src/cli/commands/init.d.ts.map +1 -0
- package/dist/src/cli/commands/init.js +115 -0
- package/dist/src/cli/commands/init.js.map +1 -0
- package/dist/src/cli/commands/install-embeddings.d.ts +10 -0
- package/dist/src/cli/commands/install-embeddings.d.ts.map +1 -0
- package/dist/src/cli/commands/install-embeddings.js +68 -0
- package/dist/src/cli/commands/install-embeddings.js.map +1 -0
- package/dist/src/cli/commands/migrate.d.ts +15 -0
- package/dist/src/cli/commands/migrate.d.ts.map +1 -0
- package/dist/src/cli/commands/migrate.js +425 -0
- package/dist/src/cli/commands/migrate.js.map +1 -0
- package/dist/src/cli/commands/simulate-custom.d.ts +26 -0
- package/dist/src/cli/commands/simulate-custom.d.ts.map +1 -0
- package/dist/src/cli/commands/simulate-custom.js +207 -0
- package/dist/src/cli/commands/simulate-custom.js.map +1 -0
- package/dist/src/cli/commands/simulate-report.d.ts +15 -0
- package/dist/src/cli/commands/simulate-report.d.ts.map +1 -0
- package/dist/src/cli/commands/simulate-report.js +136 -0
- package/dist/src/cli/commands/simulate-report.js.map +1 -0
- package/dist/src/cli/commands/simulate-wizard.d.ts +6 -0
- package/dist/src/cli/commands/simulate-wizard.d.ts.map +1 -0
- package/dist/src/cli/commands/simulate-wizard.js +352 -0
- package/dist/src/cli/commands/simulate-wizard.js.map +1 -0
- package/dist/src/cli/commands/simulate.d.ts +7 -0
- package/dist/src/cli/commands/simulate.d.ts.map +1 -0
- package/dist/src/cli/commands/simulate.js +100 -0
- package/dist/src/cli/commands/simulate.js.map +1 -0
- package/dist/src/cli/commands/status.d.ts +10 -0
- package/dist/src/cli/commands/status.d.ts.map +1 -0
- package/dist/src/cli/commands/status.js +129 -0
- package/dist/src/cli/commands/status.js.map +1 -0
- package/dist/src/cli/lib/config-manager.d.ts +110 -0
- package/dist/src/cli/lib/config-manager.d.ts.map +1 -0
- package/dist/src/cli/lib/config-manager.js +512 -0
- package/dist/src/cli/lib/config-manager.js.map +1 -0
- package/dist/src/cli/lib/config-validator.d.ts +43 -0
- package/dist/src/cli/lib/config-validator.d.ts.map +1 -0
- package/dist/src/cli/lib/config-validator.js +217 -0
- package/dist/src/cli/lib/config-validator.js.map +1 -0
- package/dist/src/cli/lib/health-monitor.d.ts +149 -0
- package/dist/src/cli/lib/health-monitor.d.ts.map +1 -0
- package/dist/src/cli/lib/health-monitor.js +380 -0
- package/dist/src/cli/lib/health-monitor.js.map +1 -0
- package/dist/src/cli/lib/help-formatter.d.ts +38 -0
- package/dist/src/cli/lib/help-formatter.d.ts.map +1 -0
- package/dist/src/cli/lib/help-formatter.js +357 -0
- package/dist/src/cli/lib/help-formatter.js.map +1 -0
- package/dist/src/cli/lib/history-tracker.d.ts +103 -0
- package/dist/src/cli/lib/history-tracker.d.ts.map +1 -0
- package/dist/src/cli/lib/history-tracker.js +346 -0
- package/dist/src/cli/lib/history-tracker.js.map +1 -0
- package/dist/src/cli/lib/report-generator.d.ts +24 -0
- package/dist/src/cli/lib/report-generator.d.ts.map +1 -0
- package/dist/src/cli/lib/report-generator.js +417 -0
- package/dist/src/cli/lib/report-generator.js.map +1 -0
- package/dist/src/cli/lib/report-store.d.ts +116 -0
- package/dist/src/cli/lib/report-store.d.ts.map +1 -0
- package/dist/src/cli/lib/report-store.js +464 -0
- package/dist/src/cli/lib/report-store.js.map +1 -0
- package/dist/src/cli/lib/simulation-registry.d.ts +165 -0
- package/dist/src/cli/lib/simulation-registry.d.ts.map +1 -0
- package/dist/src/cli/lib/simulation-registry.js +332 -0
- package/dist/src/cli/lib/simulation-registry.js.map +1 -0
- package/dist/src/cli/lib/simulation-runner.d.ts +90 -0
- package/dist/src/cli/lib/simulation-runner.d.ts.map +1 -0
- package/dist/src/cli/lib/simulation-runner.js +211 -0
- package/dist/src/cli/lib/simulation-runner.js.map +1 -0
- package/dist/src/controllers/CausalMemoryGraph.d.ts +127 -0
- package/dist/src/controllers/CausalMemoryGraph.d.ts.map +1 -0
- package/dist/src/controllers/CausalMemoryGraph.js +354 -0
- package/dist/src/controllers/CausalMemoryGraph.js.map +1 -0
- package/dist/src/controllers/CausalRecall.d.ts +139 -0
- package/dist/src/controllers/CausalRecall.d.ts.map +1 -0
- package/dist/src/controllers/CausalRecall.js +356 -0
- package/dist/src/controllers/CausalRecall.js.map +1 -0
- package/dist/src/controllers/ContextSynthesizer.d.ts +65 -0
- package/dist/src/controllers/ContextSynthesizer.d.ts.map +1 -0
- package/dist/src/controllers/ContextSynthesizer.js +208 -0
- package/dist/src/controllers/ContextSynthesizer.js.map +1 -0
- package/dist/src/controllers/EmbeddingService.d.ts +37 -0
- package/dist/src/controllers/EmbeddingService.d.ts.map +1 -0
- package/dist/src/controllers/EmbeddingService.js +136 -0
- package/dist/src/controllers/EmbeddingService.js.map +1 -0
- package/dist/src/controllers/EnhancedEmbeddingService.d.ts +50 -0
- package/dist/src/controllers/EnhancedEmbeddingService.d.ts.map +1 -0
- package/dist/src/controllers/EnhancedEmbeddingService.js +119 -0
- package/dist/src/controllers/EnhancedEmbeddingService.js.map +1 -0
- package/dist/src/controllers/ExplainableRecall.d.ts +163 -0
- package/dist/src/controllers/ExplainableRecall.d.ts.map +1 -0
- package/dist/src/controllers/ExplainableRecall.js +485 -0
- package/dist/src/controllers/ExplainableRecall.js.map +1 -0
- package/dist/src/controllers/HNSWIndex.d.ts +128 -0
- package/dist/src/controllers/HNSWIndex.d.ts.map +1 -0
- package/dist/src/controllers/HNSWIndex.js +361 -0
- package/dist/src/controllers/HNSWIndex.js.map +1 -0
- package/dist/src/controllers/LearningSystem.d.ts +195 -0
- package/dist/src/controllers/LearningSystem.d.ts.map +1 -0
- package/dist/src/controllers/LearningSystem.js +929 -0
- package/dist/src/controllers/LearningSystem.js.map +1 -0
- package/dist/src/controllers/MMRDiversityRanker.d.ts +50 -0
- package/dist/src/controllers/MMRDiversityRanker.d.ts.map +1 -0
- package/dist/src/controllers/MMRDiversityRanker.js +130 -0
- package/dist/src/controllers/MMRDiversityRanker.js.map +1 -0
- package/dist/src/controllers/MetadataFilter.d.ts +70 -0
- package/dist/src/controllers/MetadataFilter.d.ts.map +1 -0
- package/dist/src/controllers/MetadataFilter.js +243 -0
- package/dist/src/controllers/MetadataFilter.js.map +1 -0
- package/dist/src/controllers/NightlyLearner.d.ts +114 -0
- package/dist/src/controllers/NightlyLearner.d.ts.map +1 -0
- package/dist/src/controllers/NightlyLearner.js +394 -0
- package/dist/src/controllers/NightlyLearner.js.map +1 -0
- package/dist/src/controllers/QUICClient.d.ts +109 -0
- package/dist/src/controllers/QUICClient.d.ts.map +1 -0
- package/dist/src/controllers/QUICClient.js +299 -0
- package/dist/src/controllers/QUICClient.js.map +1 -0
- package/dist/src/controllers/QUICServer.d.ts +121 -0
- package/dist/src/controllers/QUICServer.d.ts.map +1 -0
- package/dist/src/controllers/QUICServer.js +383 -0
- package/dist/src/controllers/QUICServer.js.map +1 -0
- package/dist/src/controllers/ReasoningBank.d.ts +196 -0
- package/dist/src/controllers/ReasoningBank.d.ts.map +1 -0
- package/dist/src/controllers/ReasoningBank.js +494 -0
- package/dist/src/controllers/ReasoningBank.js.map +1 -0
- package/dist/src/controllers/ReflexionMemory.d.ts +125 -0
- package/dist/src/controllers/ReflexionMemory.d.ts.map +1 -0
- package/dist/src/controllers/ReflexionMemory.js +654 -0
- package/dist/src/controllers/ReflexionMemory.js.map +1 -0
- package/dist/src/controllers/SkillLibrary.d.ts +150 -0
- package/dist/src/controllers/SkillLibrary.d.ts.map +1 -0
- package/dist/src/controllers/SkillLibrary.js +608 -0
- package/dist/src/controllers/SkillLibrary.js.map +1 -0
- package/dist/src/controllers/SyncCoordinator.d.ts +120 -0
- package/dist/src/controllers/SyncCoordinator.d.ts.map +1 -0
- package/dist/src/controllers/SyncCoordinator.js +441 -0
- package/dist/src/controllers/SyncCoordinator.js.map +1 -0
- package/dist/src/controllers/WASMVectorSearch.d.ts +89 -0
- package/dist/src/controllers/WASMVectorSearch.d.ts.map +1 -0
- package/dist/src/controllers/WASMVectorSearch.js +234 -0
- package/dist/src/controllers/WASMVectorSearch.js.map +1 -0
- package/dist/src/controllers/frontier-index.d.ts +14 -0
- package/dist/src/controllers/frontier-index.d.ts.map +1 -0
- package/dist/src/controllers/frontier-index.js +10 -0
- package/dist/src/controllers/frontier-index.js.map +1 -0
- package/dist/src/controllers/index.d.ts +30 -0
- package/dist/src/controllers/index.d.ts.map +1 -0
- package/dist/src/controllers/index.js +18 -0
- package/dist/src/controllers/index.js.map +1 -0
- package/dist/src/db-fallback.d.ts +26 -0
- package/dist/src/db-fallback.d.ts.map +1 -0
- package/dist/src/db-fallback.js +264 -0
- package/dist/src/db-fallback.js.map +1 -0
- package/dist/src/db-test.d.ts +13 -0
- package/dist/src/db-test.d.ts.map +1 -0
- package/dist/src/db-test.js +55 -0
- package/dist/src/db-test.js.map +1 -0
- package/dist/src/db-unified.d.ts +76 -0
- package/dist/src/db-unified.d.ts.map +1 -0
- package/dist/src/db-unified.js +279 -0
- package/dist/src/db-unified.js.map +1 -0
- package/dist/src/examples/quic-sync-example.d.ts +9 -0
- package/dist/src/examples/quic-sync-example.d.ts.map +1 -0
- package/dist/src/examples/quic-sync-example.js +169 -0
- package/dist/src/examples/quic-sync-example.js.map +1 -0
- package/dist/src/examples/wasm-vector-usage.d.ts +12 -0
- package/dist/src/examples/wasm-vector-usage.d.ts.map +1 -0
- package/dist/src/examples/wasm-vector-usage.js +190 -0
- package/dist/src/examples/wasm-vector-usage.js.map +1 -0
- package/dist/src/index.d.ts +28 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +35 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/mcp/agentdb-mcp-server.d.ts +8 -0
- package/dist/src/mcp/agentdb-mcp-server.d.ts.map +1 -0
- package/dist/src/mcp/agentdb-mcp-server.js +2116 -0
- package/dist/src/mcp/agentdb-mcp-server.js.map +1 -0
- package/dist/src/mcp/learning-tools-handlers.d.ts +16 -0
- package/dist/src/mcp/learning-tools-handlers.d.ts.map +1 -0
- package/dist/src/mcp/learning-tools-handlers.js +105 -0
- package/dist/src/mcp/learning-tools-handlers.js.map +1 -0
- package/dist/src/optimizations/BatchOperations.d.ts +109 -0
- package/dist/src/optimizations/BatchOperations.d.ts.map +1 -0
- package/dist/src/optimizations/BatchOperations.js +407 -0
- package/dist/src/optimizations/BatchOperations.js.map +1 -0
- package/dist/src/optimizations/QueryOptimizer.d.ts +83 -0
- package/dist/src/optimizations/QueryOptimizer.d.ts.map +1 -0
- package/dist/src/optimizations/QueryOptimizer.js +228 -0
- package/dist/src/optimizations/QueryOptimizer.js.map +1 -0
- package/dist/src/optimizations/ToolCache.d.ts +137 -0
- package/dist/src/optimizations/ToolCache.d.ts.map +1 -0
- package/dist/src/optimizations/ToolCache.js +281 -0
- package/dist/src/optimizations/ToolCache.js.map +1 -0
- package/dist/src/optimizations/index.d.ts +10 -0
- package/dist/src/optimizations/index.d.ts.map +1 -0
- package/dist/src/optimizations/index.js +8 -0
- package/dist/src/optimizations/index.js.map +1 -0
- package/dist/src/security/input-validation.d.ts +109 -0
- package/dist/src/security/input-validation.d.ts.map +1 -0
- package/dist/src/security/input-validation.js +398 -0
- package/dist/src/security/input-validation.js.map +1 -0
- package/dist/src/security/limits.d.ts +150 -0
- package/dist/src/security/limits.d.ts.map +1 -0
- package/dist/src/security/limits.js +288 -0
- package/dist/src/security/limits.js.map +1 -0
- package/dist/src/security/path-security.d.ts +100 -0
- package/dist/src/security/path-security.d.ts.map +1 -0
- package/dist/src/security/path-security.js +337 -0
- package/dist/src/security/path-security.js.map +1 -0
- package/dist/src/security/validation.d.ts +95 -0
- package/dist/src/security/validation.d.ts.map +1 -0
- package/dist/src/security/validation.js +315 -0
- package/dist/src/security/validation.js.map +1 -0
- package/dist/src/services/LLMRouter.d.ts +84 -0
- package/dist/src/services/LLMRouter.d.ts.map +1 -0
- package/dist/src/services/LLMRouter.js +329 -0
- package/dist/src/services/LLMRouter.js.map +1 -0
- package/dist/src/types/quic.d.ts +518 -0
- package/dist/src/types/quic.d.ts.map +1 -0
- package/dist/src/types/quic.js +272 -0
- package/dist/src/types/quic.js.map +1 -0
- package/dist/src/utils/NodeIdMapper.d.ts +38 -0
- package/dist/src/utils/NodeIdMapper.d.ts.map +1 -0
- package/dist/src/utils/NodeIdMapper.js +57 -0
- package/dist/src/utils/NodeIdMapper.js.map +1 -0
- package/package.json +15 -3
- package/scripts/README.md +314 -0
- package/src/backends/GraphBackend.ts +290 -0
- package/src/backends/LearningBackend.ts +210 -0
- package/src/backends/README.md +389 -0
- package/src/backends/VectorBackend.ts +145 -0
- package/src/backends/detector.ts +283 -0
- package/src/backends/factory.ts +193 -0
- package/src/backends/graph/GraphDatabaseAdapter.ts +334 -0
- package/src/backends/hnswlib/HNSWLibBackend.ts +413 -0
- package/src/backends/hnswlib/index.ts +7 -0
- package/src/backends/index.ts +32 -0
- package/src/backends/ruvector/RuVectorBackend.ts +232 -0
- package/src/backends/ruvector/RuVectorLearning.ts +242 -0
- package/src/backends/ruvector/index.ts +9 -0
- package/src/backends/ruvector/types.d.ts +64 -0
- package/src/browser/AdvancedFeatures.ts +565 -0
- package/src/browser/HNSWIndex.ts +494 -0
- package/src/browser/ProductQuantization.ts +419 -0
- package/src/browser/index.ts +301 -0
- package/src/cli/agentdb-cli.ts +131 -8
- package/src/cli/commands/init.ts +148 -0
- package/src/cli/commands/install-embeddings.ts +81 -0
- package/src/cli/commands/migrate.ts +545 -0
- package/src/cli/commands/simulate-custom.ts +232 -0
- package/src/cli/commands/simulate-report.ts +171 -0
- package/src/cli/commands/simulate-wizard.ts +379 -0
- package/src/cli/commands/simulate.ts +115 -0
- package/src/cli/commands/status.ts +156 -0
- package/src/cli/lib/config-manager.ts +627 -0
- package/src/cli/lib/config-validator.ts +261 -0
- package/src/cli/lib/health-monitor.ts +513 -0
- package/src/cli/lib/help-formatter.ts +406 -0
- package/src/cli/lib/history-tracker.ts +497 -0
- package/src/cli/lib/report-generator.ts +455 -0
- package/src/cli/lib/report-store.ts +582 -0
- package/src/cli/lib/simulation-registry.ts +502 -0
- package/src/cli/lib/simulation-runner.ts +291 -0
- package/src/cli/tests/agentdb-cli.test.ts +58 -0
- package/src/controllers/CausalMemoryGraph.ts +42 -2
- package/src/controllers/CausalRecall.ts +41 -4
- package/src/controllers/ExplainableRecall.ts +123 -5
- package/src/controllers/HNSWIndex.ts +495 -0
- package/src/controllers/NightlyLearner.ts +8 -4
- package/src/controllers/ReasoningBank.ts +268 -5
- package/src/controllers/ReflexionMemory.ts +531 -6
- package/src/controllers/SkillLibrary.ts +234 -60
- package/src/controllers/index.ts +2 -0
- package/src/db-fallback.ts +103 -35
- package/src/db-test.ts +59 -0
- package/src/db-unified.ts +327 -0
- package/src/index.ts +2 -1
- package/src/mcp/agentdb-mcp-server.ts +544 -38
- package/src/optimizations/BatchOperations.ts +270 -0
- package/src/optimizations/ToolCache.ts +355 -0
- package/src/security/input-validation.ts +166 -0
- package/src/security/limits.ts +375 -0
- package/src/security/path-security.ts +436 -0
- package/src/security/validation.ts +556 -0
- package/src/services/LLMRouter.ts +406 -0
- package/src/types/xenova-transformers.d.ts +26 -0
- package/src/utils/NodeIdMapper.ts +64 -0
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
// Database type from db-fallback
|
|
12
12
|
type Database = any;
|
|
13
13
|
import { EmbeddingService } from './EmbeddingService.js';
|
|
14
|
+
import type { VectorBackend } from '../backends/VectorBackend.js';
|
|
15
|
+
import type { LearningBackend } from '../backends/LearningBackend.js';
|
|
16
|
+
import type { GraphBackend, GraphNode } from '../backends/GraphBackend.js';
|
|
17
|
+
import type { GraphDatabaseAdapter } from '../backends/graph/GraphDatabaseAdapter.js';
|
|
18
|
+
import { NodeIdMapper } from '../utils/NodeIdMapper.js';
|
|
14
19
|
|
|
15
20
|
export interface Episode {
|
|
16
21
|
id?: number;
|
|
@@ -46,16 +51,102 @@ export interface ReflexionQuery {
|
|
|
46
51
|
export class ReflexionMemory {
|
|
47
52
|
private db: Database;
|
|
48
53
|
private embedder: EmbeddingService;
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
private vectorBackend?: VectorBackend;
|
|
55
|
+
private learningBackend?: LearningBackend;
|
|
56
|
+
private graphBackend?: GraphBackend;
|
|
57
|
+
|
|
58
|
+
constructor(
|
|
59
|
+
db: Database,
|
|
60
|
+
embedder: EmbeddingService,
|
|
61
|
+
vectorBackend?: VectorBackend,
|
|
62
|
+
learningBackend?: LearningBackend,
|
|
63
|
+
graphBackend?: GraphBackend
|
|
64
|
+
) {
|
|
51
65
|
this.db = db;
|
|
52
66
|
this.embedder = embedder;
|
|
67
|
+
this.vectorBackend = vectorBackend;
|
|
68
|
+
this.learningBackend = learningBackend;
|
|
69
|
+
this.graphBackend = graphBackend;
|
|
53
70
|
}
|
|
54
71
|
|
|
55
72
|
/**
|
|
56
73
|
* Store a new episode with its critique and outcome
|
|
57
74
|
*/
|
|
58
75
|
async storeEpisode(episode: Episode): Promise<number> {
|
|
76
|
+
// Use GraphDatabaseAdapter if available (AgentDB v2)
|
|
77
|
+
if (this.graphBackend && 'storeEpisode' in this.graphBackend) {
|
|
78
|
+
// GraphDatabaseAdapter has specialized storeEpisode method
|
|
79
|
+
const graphAdapter = this.graphBackend as any as GraphDatabaseAdapter;
|
|
80
|
+
|
|
81
|
+
// Generate embedding for the task
|
|
82
|
+
const taskEmbedding = await this.embedder.embed(episode.task);
|
|
83
|
+
|
|
84
|
+
// Create episode node using GraphDatabaseAdapter
|
|
85
|
+
const nodeId = await graphAdapter.storeEpisode({
|
|
86
|
+
id: episode.id ? `episode-${episode.id}` : `episode-${Date.now()}-${Math.random()}`,
|
|
87
|
+
sessionId: episode.sessionId,
|
|
88
|
+
task: episode.task,
|
|
89
|
+
reward: episode.reward,
|
|
90
|
+
success: episode.success,
|
|
91
|
+
input: episode.input,
|
|
92
|
+
output: episode.output,
|
|
93
|
+
critique: episode.critique,
|
|
94
|
+
createdAt: episode.ts ? episode.ts * 1000 : Date.now(),
|
|
95
|
+
tokensUsed: episode.tokensUsed,
|
|
96
|
+
latencyMs: episode.latencyMs
|
|
97
|
+
}, taskEmbedding);
|
|
98
|
+
|
|
99
|
+
// Return a numeric ID (parse from string ID)
|
|
100
|
+
const numericId = parseInt(nodeId.split('-').pop() || '0', 36);
|
|
101
|
+
|
|
102
|
+
// Register mapping for later use by CausalMemoryGraph
|
|
103
|
+
NodeIdMapper.getInstance().register(numericId, nodeId);
|
|
104
|
+
|
|
105
|
+
return numericId;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Use generic GraphBackend if available
|
|
109
|
+
if (this.graphBackend) {
|
|
110
|
+
// Generate embedding for the task
|
|
111
|
+
const taskEmbedding = await this.embedder.embed(episode.task);
|
|
112
|
+
|
|
113
|
+
// Create episode node ID
|
|
114
|
+
const nodeId = await this.graphBackend.createNode(
|
|
115
|
+
['Episode'],
|
|
116
|
+
{
|
|
117
|
+
sessionId: episode.sessionId,
|
|
118
|
+
task: episode.task,
|
|
119
|
+
input: episode.input || '',
|
|
120
|
+
output: episode.output || '',
|
|
121
|
+
critique: episode.critique || '',
|
|
122
|
+
reward: episode.reward,
|
|
123
|
+
success: episode.success,
|
|
124
|
+
latencyMs: episode.latencyMs || 0,
|
|
125
|
+
tokensUsed: episode.tokensUsed || 0,
|
|
126
|
+
tags: episode.tags ? JSON.stringify(episode.tags) : '[]',
|
|
127
|
+
metadata: episode.metadata ? JSON.stringify(episode.metadata) : '{}',
|
|
128
|
+
createdAt: Date.now()
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
// Store embedding using vectorBackend if available
|
|
133
|
+
if (this.vectorBackend && taskEmbedding) {
|
|
134
|
+
this.vectorBackend.insert(nodeId, taskEmbedding, {
|
|
135
|
+
type: 'episode',
|
|
136
|
+
sessionId: episode.sessionId
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Return a numeric ID (parse from string ID)
|
|
141
|
+
const numericId = parseInt(nodeId.split('-').pop() || '0', 36);
|
|
142
|
+
|
|
143
|
+
// Register mapping for later use by CausalMemoryGraph
|
|
144
|
+
NodeIdMapper.getInstance().register(numericId, nodeId);
|
|
145
|
+
|
|
146
|
+
return numericId;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Fallback to SQLite (v1 compatibility)
|
|
59
150
|
const stmt = this.db.prepare(`
|
|
60
151
|
INSERT INTO episodes (
|
|
61
152
|
session_id, task, input, output, critique, reward, success,
|
|
@@ -86,8 +177,34 @@ export class ReflexionMemory {
|
|
|
86
177
|
const text = this.buildEpisodeText(episode);
|
|
87
178
|
const embedding = await this.embedder.embed(text);
|
|
88
179
|
|
|
180
|
+
// Use vector backend if available (150x faster retrieval)
|
|
181
|
+
if (this.vectorBackend) {
|
|
182
|
+
this.vectorBackend.insert(episodeId.toString(), embedding);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Also store in SQL for fallback
|
|
89
186
|
this.storeEmbedding(episodeId, embedding);
|
|
90
187
|
|
|
188
|
+
// Create graph node for episode if graph backend available
|
|
189
|
+
if (this.graphBackend) {
|
|
190
|
+
await this.createEpisodeGraphNode(episodeId, episode, embedding);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Add training sample if learning backend available
|
|
194
|
+
if (this.learningBackend && episode.success !== undefined) {
|
|
195
|
+
this.learningBackend.addSample({
|
|
196
|
+
embedding,
|
|
197
|
+
label: episode.success ? 1 : 0,
|
|
198
|
+
weight: Math.abs(episode.reward),
|
|
199
|
+
context: {
|
|
200
|
+
task: episode.task,
|
|
201
|
+
sessionId: episode.sessionId,
|
|
202
|
+
latencyMs: episode.latencyMs,
|
|
203
|
+
tokensUsed: episode.tokensUsed
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
91
208
|
return episodeId;
|
|
92
209
|
}
|
|
93
210
|
|
|
@@ -107,9 +224,152 @@ export class ReflexionMemory {
|
|
|
107
224
|
|
|
108
225
|
// Generate query embedding
|
|
109
226
|
const queryText = currentState ? `${task}\n${currentState}` : task;
|
|
110
|
-
|
|
227
|
+
let queryEmbedding = await this.embedder.embed(queryText);
|
|
228
|
+
|
|
229
|
+
// Enhance query with GNN if learning backend available
|
|
230
|
+
if (this.learningBackend) {
|
|
231
|
+
queryEmbedding = await this.enhanceQueryWithGNN(queryEmbedding, k);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Use GraphDatabaseAdapter if available (AgentDB v2)
|
|
235
|
+
if (this.graphBackend && 'searchSimilarEpisodes' in this.graphBackend) {
|
|
236
|
+
const graphAdapter = this.graphBackend as any as GraphDatabaseAdapter;
|
|
237
|
+
|
|
238
|
+
// Search using vector similarity
|
|
239
|
+
const results = await graphAdapter.searchSimilarEpisodes(queryEmbedding, k * 3);
|
|
240
|
+
|
|
241
|
+
// Apply filters
|
|
242
|
+
const filtered = results.filter((ep: any) => {
|
|
243
|
+
if (minReward !== undefined && ep.reward < minReward) return false;
|
|
244
|
+
if (onlyFailures && ep.success) return false;
|
|
245
|
+
if (onlySuccesses && !ep.success) return false;
|
|
246
|
+
if (timeWindowDays && ep.createdAt < (Date.now() - timeWindowDays * 86400000)) return false;
|
|
247
|
+
return true;
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// Convert to EpisodeWithEmbedding format
|
|
251
|
+
const episodes: EpisodeWithEmbedding[] = filtered.slice(0, k).map((ep: any) => ({
|
|
252
|
+
id: parseInt(ep.id.split('-').pop() || '0', 36),
|
|
253
|
+
sessionId: ep.sessionId,
|
|
254
|
+
task: ep.task,
|
|
255
|
+
input: ep.input,
|
|
256
|
+
output: ep.output,
|
|
257
|
+
critique: ep.critique,
|
|
258
|
+
reward: ep.reward,
|
|
259
|
+
success: ep.success,
|
|
260
|
+
latencyMs: ep.latencyMs,
|
|
261
|
+
tokensUsed: ep.tokensUsed,
|
|
262
|
+
ts: Math.floor(ep.createdAt / 1000)
|
|
263
|
+
}));
|
|
264
|
+
|
|
265
|
+
return episodes;
|
|
266
|
+
}
|
|
111
267
|
|
|
112
|
-
//
|
|
268
|
+
// Use generic GraphBackend if available
|
|
269
|
+
if (this.graphBackend && 'execute' in this.graphBackend) {
|
|
270
|
+
// Build Cypher query with filters
|
|
271
|
+
let cypherQuery = 'MATCH (e:Episode) WHERE 1=1';
|
|
272
|
+
|
|
273
|
+
if (minReward !== undefined) {
|
|
274
|
+
cypherQuery += ` AND e.reward >= ${minReward}`;
|
|
275
|
+
}
|
|
276
|
+
if (onlyFailures) {
|
|
277
|
+
cypherQuery += ` AND e.success = false`;
|
|
278
|
+
}
|
|
279
|
+
if (onlySuccesses) {
|
|
280
|
+
cypherQuery += ` AND e.success = true`;
|
|
281
|
+
}
|
|
282
|
+
if (timeWindowDays) {
|
|
283
|
+
const cutoff = Date.now() - timeWindowDays * 86400000;
|
|
284
|
+
cypherQuery += ` AND e.createdAt >= ${cutoff}`;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
cypherQuery += ` RETURN e LIMIT ${k * 3}`;
|
|
288
|
+
|
|
289
|
+
const result = await this.graphBackend.execute(cypherQuery);
|
|
290
|
+
|
|
291
|
+
// Convert to EpisodeWithEmbedding format
|
|
292
|
+
const episodes: EpisodeWithEmbedding[] = result.rows.map((row: any) => {
|
|
293
|
+
const node = row.e;
|
|
294
|
+
return {
|
|
295
|
+
id: parseInt(node.id.split('-').pop() || '0', 36),
|
|
296
|
+
sessionId: node.properties.sessionId,
|
|
297
|
+
task: node.properties.task,
|
|
298
|
+
input: node.properties.input,
|
|
299
|
+
output: node.properties.output,
|
|
300
|
+
critique: node.properties.critique,
|
|
301
|
+
reward: typeof node.properties.reward === 'string' ? parseFloat(node.properties.reward) : node.properties.reward,
|
|
302
|
+
success: typeof node.properties.success === 'string' ? node.properties.success === 'true' : node.properties.success,
|
|
303
|
+
latencyMs: node.properties.latencyMs,
|
|
304
|
+
tokensUsed: node.properties.tokensUsed,
|
|
305
|
+
tags: node.properties.tags ? JSON.parse(node.properties.tags) : [],
|
|
306
|
+
metadata: node.properties.metadata ? JSON.parse(node.properties.metadata) : {},
|
|
307
|
+
ts: Math.floor(node.properties.createdAt / 1000)
|
|
308
|
+
};
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
return episodes.slice(0, k);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// Use optimized vector backend if available (150x faster)
|
|
315
|
+
if (this.vectorBackend) {
|
|
316
|
+
// Get candidates from vector backend
|
|
317
|
+
const searchResults = this.vectorBackend.search(queryEmbedding, k * 3, {
|
|
318
|
+
threshold: 0.0
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
// Fetch full episode data from DB
|
|
322
|
+
const episodeIds = searchResults.map(r => parseInt(r.id));
|
|
323
|
+
if (episodeIds.length === 0) {
|
|
324
|
+
return [];
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const placeholders = episodeIds.map(() => '?').join(',');
|
|
328
|
+
const stmt = this.db.prepare(`
|
|
329
|
+
SELECT * FROM episodes
|
|
330
|
+
WHERE id IN (${placeholders})
|
|
331
|
+
`);
|
|
332
|
+
|
|
333
|
+
const rows = stmt.all(...episodeIds) as any[];
|
|
334
|
+
const episodeMap = new Map(rows.map(r => [r.id.toString(), r]));
|
|
335
|
+
|
|
336
|
+
// Map results back with similarity scores and apply filters
|
|
337
|
+
const episodes: EpisodeWithEmbedding[] = [];
|
|
338
|
+
|
|
339
|
+
for (const result of searchResults) {
|
|
340
|
+
const row = episodeMap.get(result.id);
|
|
341
|
+
if (!row) continue;
|
|
342
|
+
|
|
343
|
+
// Apply additional filters
|
|
344
|
+
if (minReward !== undefined && row.reward < minReward) continue;
|
|
345
|
+
if (onlyFailures && row.success === 1) continue;
|
|
346
|
+
if (onlySuccesses && row.success === 0) continue;
|
|
347
|
+
if (timeWindowDays && row.ts < (Date.now() / 1000 - timeWindowDays * 86400)) continue;
|
|
348
|
+
|
|
349
|
+
episodes.push({
|
|
350
|
+
id: row.id,
|
|
351
|
+
ts: row.ts,
|
|
352
|
+
sessionId: row.session_id,
|
|
353
|
+
task: row.task,
|
|
354
|
+
input: row.input,
|
|
355
|
+
output: row.output,
|
|
356
|
+
critique: row.critique,
|
|
357
|
+
reward: row.reward,
|
|
358
|
+
success: row.success === 1,
|
|
359
|
+
latencyMs: row.latency_ms,
|
|
360
|
+
tokensUsed: row.tokens_used,
|
|
361
|
+
tags: row.tags ? JSON.parse(row.tags) : undefined,
|
|
362
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
|
363
|
+
similarity: result.similarity
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
if (episodes.length >= k) break;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return episodes;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// Fallback to SQL-based similarity search
|
|
113
373
|
const filters: string[] = [];
|
|
114
374
|
const params: any[] = [];
|
|
115
375
|
|
|
@@ -133,7 +393,6 @@ export class ReflexionMemory {
|
|
|
133
393
|
|
|
134
394
|
const whereClause = filters.length > 0 ? `WHERE ${filters.join(' AND ')}` : '';
|
|
135
395
|
|
|
136
|
-
// Retrieve all candidates
|
|
137
396
|
const stmt = this.db.prepare(`
|
|
138
397
|
SELECT
|
|
139
398
|
e.*,
|
|
@@ -146,7 +405,7 @@ export class ReflexionMemory {
|
|
|
146
405
|
|
|
147
406
|
const rows = stmt.all(...params) as any[];
|
|
148
407
|
|
|
149
|
-
// Calculate similarities
|
|
408
|
+
// Calculate similarities manually
|
|
150
409
|
const episodes: EpisodeWithEmbedding[] = rows.map(row => {
|
|
151
410
|
const embedding = this.deserializeEmbedding(row.embedding);
|
|
152
411
|
const similarity = this.cosineSimilarity(queryEmbedding, embedding);
|
|
@@ -275,6 +534,36 @@ export class ReflexionMemory {
|
|
|
275
534
|
return `Successful strategies:\n${strategies}`;
|
|
276
535
|
}
|
|
277
536
|
|
|
537
|
+
/**
|
|
538
|
+
* Get recent episodes for a session
|
|
539
|
+
*/
|
|
540
|
+
async getRecentEpisodes(sessionId: string, limit: number = 10): Promise<Episode[]> {
|
|
541
|
+
const stmt = this.db.prepare(`
|
|
542
|
+
SELECT * FROM episodes
|
|
543
|
+
WHERE session_id = ?
|
|
544
|
+
ORDER BY ts DESC
|
|
545
|
+
LIMIT ?
|
|
546
|
+
`);
|
|
547
|
+
|
|
548
|
+
const rows = stmt.all(sessionId, limit) as any[];
|
|
549
|
+
|
|
550
|
+
return rows.map(row => ({
|
|
551
|
+
id: row.id,
|
|
552
|
+
ts: row.ts,
|
|
553
|
+
sessionId: row.session_id,
|
|
554
|
+
task: row.task,
|
|
555
|
+
input: row.input,
|
|
556
|
+
output: row.output,
|
|
557
|
+
critique: row.critique,
|
|
558
|
+
reward: row.reward,
|
|
559
|
+
success: row.success === 1,
|
|
560
|
+
latencyMs: row.latency_ms,
|
|
561
|
+
tokensUsed: row.tokens_used,
|
|
562
|
+
tags: row.tags ? JSON.parse(row.tags) : undefined,
|
|
563
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : undefined
|
|
564
|
+
}));
|
|
565
|
+
}
|
|
566
|
+
|
|
278
567
|
/**
|
|
279
568
|
* Prune low-quality episodes based on TTL and quality threshold
|
|
280
569
|
*/
|
|
@@ -351,4 +640,240 @@ export class ReflexionMemory {
|
|
|
351
640
|
|
|
352
641
|
return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));
|
|
353
642
|
}
|
|
643
|
+
|
|
644
|
+
// ========================================================================
|
|
645
|
+
// GNN and Graph Integration Methods
|
|
646
|
+
// ========================================================================
|
|
647
|
+
|
|
648
|
+
/**
|
|
649
|
+
* Create graph node for episode with relationships
|
|
650
|
+
*/
|
|
651
|
+
private async createEpisodeGraphNode(
|
|
652
|
+
episodeId: number,
|
|
653
|
+
episode: Episode,
|
|
654
|
+
embedding: Float32Array
|
|
655
|
+
): Promise<void> {
|
|
656
|
+
if (!this.graphBackend) return;
|
|
657
|
+
|
|
658
|
+
// Create episode node
|
|
659
|
+
const nodeId = await this.graphBackend.createNode(
|
|
660
|
+
['Episode', episode.success ? 'Success' : 'Failure'],
|
|
661
|
+
{
|
|
662
|
+
episodeId,
|
|
663
|
+
sessionId: episode.sessionId,
|
|
664
|
+
task: episode.task,
|
|
665
|
+
reward: episode.reward,
|
|
666
|
+
success: episode.success,
|
|
667
|
+
timestamp: episode.ts || Date.now(),
|
|
668
|
+
latencyMs: episode.latencyMs,
|
|
669
|
+
tokensUsed: episode.tokensUsed
|
|
670
|
+
}
|
|
671
|
+
);
|
|
672
|
+
|
|
673
|
+
// Find similar episodes using graph vector search
|
|
674
|
+
const similarEpisodes = await this.graphBackend.vectorSearch(embedding, 5, nodeId);
|
|
675
|
+
|
|
676
|
+
// Create similarity relationships to similar episodes
|
|
677
|
+
for (const similar of similarEpisodes) {
|
|
678
|
+
if (similar.id !== nodeId && similar.properties.episodeId !== episodeId) {
|
|
679
|
+
await this.graphBackend.createRelationship(
|
|
680
|
+
nodeId,
|
|
681
|
+
similar.id,
|
|
682
|
+
'SIMILAR_TO',
|
|
683
|
+
{
|
|
684
|
+
similarity: this.cosineSimilarity(
|
|
685
|
+
embedding,
|
|
686
|
+
similar.embedding || new Float32Array()
|
|
687
|
+
),
|
|
688
|
+
createdAt: Date.now()
|
|
689
|
+
}
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// Create session relationship
|
|
695
|
+
const sessionNodes = await this.graphBackend.execute(
|
|
696
|
+
'MATCH (s:Session {sessionId: $sessionId}) RETURN s',
|
|
697
|
+
{ sessionId: episode.sessionId }
|
|
698
|
+
);
|
|
699
|
+
|
|
700
|
+
let sessionNodeId: string;
|
|
701
|
+
if (sessionNodes.rows.length === 0) {
|
|
702
|
+
// Create session node if doesn't exist
|
|
703
|
+
sessionNodeId = await this.graphBackend.createNode(
|
|
704
|
+
['Session'],
|
|
705
|
+
{
|
|
706
|
+
sessionId: episode.sessionId,
|
|
707
|
+
startTime: episode.ts || Date.now()
|
|
708
|
+
}
|
|
709
|
+
);
|
|
710
|
+
} else {
|
|
711
|
+
sessionNodeId = sessionNodes.rows[0].s.id;
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
await this.graphBackend.createRelationship(
|
|
715
|
+
nodeId,
|
|
716
|
+
sessionNodeId,
|
|
717
|
+
'BELONGS_TO_SESSION',
|
|
718
|
+
{ timestamp: episode.ts || Date.now() }
|
|
719
|
+
);
|
|
720
|
+
|
|
721
|
+
// If episode has critique, create causal relationship to previous failures
|
|
722
|
+
if (episode.critique && !episode.success) {
|
|
723
|
+
const previousFailures = await this.graphBackend.execute(
|
|
724
|
+
`MATCH (e:Episode:Failure {sessionId: $sessionId})
|
|
725
|
+
WHERE e.timestamp < $timestamp
|
|
726
|
+
RETURN e
|
|
727
|
+
ORDER BY e.timestamp DESC
|
|
728
|
+
LIMIT 3`,
|
|
729
|
+
{ sessionId: episode.sessionId, timestamp: episode.ts || Date.now() }
|
|
730
|
+
);
|
|
731
|
+
|
|
732
|
+
for (const prevFailure of previousFailures.rows) {
|
|
733
|
+
await this.graphBackend.createRelationship(
|
|
734
|
+
nodeId,
|
|
735
|
+
prevFailure.e.id,
|
|
736
|
+
'LEARNED_FROM',
|
|
737
|
+
{
|
|
738
|
+
critique: episode.critique,
|
|
739
|
+
improvementAttempt: true
|
|
740
|
+
}
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Enhance query embedding using GNN attention mechanism
|
|
748
|
+
*/
|
|
749
|
+
private async enhanceQueryWithGNN(
|
|
750
|
+
queryEmbedding: Float32Array,
|
|
751
|
+
k: number
|
|
752
|
+
): Promise<Float32Array> {
|
|
753
|
+
if (!this.learningBackend || !this.vectorBackend) {
|
|
754
|
+
return queryEmbedding;
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
try {
|
|
758
|
+
// Get initial neighbors
|
|
759
|
+
const initialResults = this.vectorBackend.search(queryEmbedding, k * 2, {
|
|
760
|
+
threshold: 0.0
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
if (initialResults.length === 0) {
|
|
764
|
+
return queryEmbedding;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Fetch neighbor embeddings
|
|
768
|
+
const neighborEmbeddings: Float32Array[] = [];
|
|
769
|
+
const weights: number[] = [];
|
|
770
|
+
|
|
771
|
+
const episodeIds = initialResults.map(r => r.id);
|
|
772
|
+
const placeholders = episodeIds.map(() => '?').join(',');
|
|
773
|
+
const episodes = this.db.prepare(`
|
|
774
|
+
SELECT ee.embedding, e.reward
|
|
775
|
+
FROM episode_embeddings ee
|
|
776
|
+
JOIN episodes e ON e.id = ee.episode_id
|
|
777
|
+
WHERE ee.episode_id IN (${placeholders})
|
|
778
|
+
`).all(...episodeIds) as any[];
|
|
779
|
+
|
|
780
|
+
for (const ep of episodes) {
|
|
781
|
+
const embedding = this.deserializeEmbedding(ep.embedding);
|
|
782
|
+
neighborEmbeddings.push(embedding);
|
|
783
|
+
// Use reward as weight (higher reward = more important)
|
|
784
|
+
weights.push(Math.max(0.1, ep.reward));
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// Enhance query using GNN
|
|
788
|
+
const enhanced = this.learningBackend.enhance(
|
|
789
|
+
queryEmbedding,
|
|
790
|
+
neighborEmbeddings,
|
|
791
|
+
weights
|
|
792
|
+
);
|
|
793
|
+
|
|
794
|
+
return enhanced;
|
|
795
|
+
} catch (error) {
|
|
796
|
+
console.warn('[ReflexionMemory] GNN enhancement failed:', error);
|
|
797
|
+
return queryEmbedding;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Get graph-based episode relationships
|
|
803
|
+
*/
|
|
804
|
+
async getEpisodeRelationships(episodeId: number): Promise<{
|
|
805
|
+
similar: number[];
|
|
806
|
+
session: string;
|
|
807
|
+
learnedFrom: number[];
|
|
808
|
+
}> {
|
|
809
|
+
if (!this.graphBackend) {
|
|
810
|
+
return { similar: [], session: '', learnedFrom: [] };
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
const result = await this.graphBackend.execute(
|
|
814
|
+
`MATCH (e:Episode {episodeId: $episodeId})
|
|
815
|
+
OPTIONAL MATCH (e)-[:SIMILAR_TO]->(similar:Episode)
|
|
816
|
+
OPTIONAL MATCH (e)-[:BELONGS_TO_SESSION]->(s:Session)
|
|
817
|
+
OPTIONAL MATCH (e)-[:LEARNED_FROM]->(learned:Episode)
|
|
818
|
+
RETURN e, collect(DISTINCT similar.episodeId) as similar,
|
|
819
|
+
s.sessionId as session,
|
|
820
|
+
collect(DISTINCT learned.episodeId) as learnedFrom`,
|
|
821
|
+
{ episodeId }
|
|
822
|
+
);
|
|
823
|
+
|
|
824
|
+
if (result.rows.length === 0) {
|
|
825
|
+
return { similar: [], session: '', learnedFrom: [] };
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
const row = result.rows[0];
|
|
829
|
+
return {
|
|
830
|
+
similar: (row.similar || []).filter((id: any) => id != null),
|
|
831
|
+
session: row.session || '',
|
|
832
|
+
learnedFrom: (row.learnedFrom || []).filter((id: any) => id != null)
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Train GNN model on accumulated samples
|
|
838
|
+
*/
|
|
839
|
+
async trainGNN(options?: { epochs?: number }): Promise<void> {
|
|
840
|
+
if (!this.learningBackend) {
|
|
841
|
+
console.warn('[ReflexionMemory] No learning backend available for training');
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
const stats = this.learningBackend.getStats();
|
|
846
|
+
if (stats.samplesCollected < 10) {
|
|
847
|
+
console.warn('[ReflexionMemory] Not enough samples for training (need at least 10)');
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
const result = await this.learningBackend.train(options);
|
|
852
|
+
console.log('[ReflexionMemory] GNN training complete:', {
|
|
853
|
+
epochs: result.epochs,
|
|
854
|
+
finalLoss: result.finalLoss.toFixed(4),
|
|
855
|
+
improvement: `${(result.improvement * 100).toFixed(1)}%`,
|
|
856
|
+
duration: `${result.duration}ms`
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
/**
|
|
861
|
+
* Get learning backend statistics
|
|
862
|
+
*/
|
|
863
|
+
getLearningStats() {
|
|
864
|
+
if (!this.learningBackend) {
|
|
865
|
+
return null;
|
|
866
|
+
}
|
|
867
|
+
return this.learningBackend.getStats();
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Get graph backend statistics
|
|
872
|
+
*/
|
|
873
|
+
getGraphStats() {
|
|
874
|
+
if (!this.graphBackend) {
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
return this.graphBackend.getStats();
|
|
878
|
+
}
|
|
354
879
|
}
|