agentdb 3.0.0-alpha.2 → 3.0.0-alpha.4
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 +978 -2342
- package/dist/agentdb.browser.js +1492 -0
- package/dist/agentdb.browser.js.map +7 -0
- package/dist/agentdb.browser.min.js +3 -0
- package/dist/agentdb.browser.min.js.map +7 -0
- package/dist/agentdb.wasm-loader.js +207 -0
- package/dist/schemas/frontier-schema.sql +0 -7
- package/dist/schemas/schema.sql +0 -7
- 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 +8 -8
- package/dist/src/backends/GraphBackend.d.ts.map +1 -1
- package/dist/src/backends/GraphBackend.js +15 -16
- package/dist/src/backends/GraphBackend.js.map +1 -1
- package/dist/src/backends/LearningBackend.d.ts +2 -2
- package/dist/src/backends/LearningBackend.d.ts.map +1 -1
- package/dist/src/backends/LearningBackend.js +10 -11
- package/dist/src/backends/LearningBackend.js.map +1 -1
- package/dist/src/backends/VectorBackend.d.ts +6 -31
- package/dist/src/backends/VectorBackend.d.ts.map +1 -1
- package/dist/src/backends/detector.d.ts +3 -25
- package/dist/src/backends/detector.d.ts.map +1 -1
- package/dist/src/backends/detector.js +15 -119
- package/dist/src/backends/detector.js.map +1 -1
- package/dist/src/backends/factory.d.ts +32 -16
- package/dist/src/backends/factory.d.ts.map +1 -1
- package/dist/src/backends/factory.js +70 -133
- package/dist/src/backends/factory.js.map +1 -1
- package/dist/src/backends/graph/GraphDatabaseAdapter.d.ts +1 -1
- package/dist/src/backends/graph/GraphDatabaseAdapter.d.ts.map +1 -1
- package/dist/src/backends/graph/GraphDatabaseAdapter.js +1 -5
- package/dist/src/backends/graph/GraphDatabaseAdapter.js.map +1 -1
- package/dist/src/backends/hnswlib/HNSWLibBackend.d.ts +2 -2
- package/dist/src/backends/hnswlib/HNSWLibBackend.d.ts.map +1 -1
- package/dist/src/backends/hnswlib/HNSWLibBackend.js +13 -49
- package/dist/src/backends/hnswlib/HNSWLibBackend.js.map +1 -1
- package/dist/src/backends/index.d.ts +3 -25
- package/dist/src/backends/index.d.ts.map +1 -1
- package/dist/src/backends/index.js +1 -23
- package/dist/src/backends/index.js.map +1 -1
- package/dist/src/backends/ruvector/GuardedVectorBackend.d.ts +93 -0
- package/dist/src/backends/ruvector/GuardedVectorBackend.d.ts.map +1 -0
- package/dist/src/backends/ruvector/GuardedVectorBackend.js +182 -0
- package/dist/src/backends/ruvector/GuardedVectorBackend.js.map +1 -0
- package/dist/src/backends/ruvector/RuVectorBackend.d.ts +16 -187
- package/dist/src/backends/ruvector/RuVectorBackend.d.ts.map +1 -1
- package/dist/src/backends/ruvector/RuVectorBackend.js +94 -576
- package/dist/src/backends/ruvector/RuVectorBackend.js.map +1 -1
- package/dist/src/backends/ruvector/RuVectorLearning.d.ts +4 -0
- package/dist/src/backends/ruvector/RuVectorLearning.d.ts.map +1 -1
- package/dist/src/backends/ruvector/RuVectorLearning.js +11 -10
- package/dist/src/backends/ruvector/RuVectorLearning.js.map +1 -1
- 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.map +1 -1
- package/dist/src/browser/AdvancedFeatures.js +10 -3
- package/dist/src/browser/AdvancedFeatures.js.map +1 -1
- package/dist/src/browser/AttentionBrowser.d.ts.map +1 -1
- package/dist/src/browser/AttentionBrowser.js +12 -5
- package/dist/src/browser/AttentionBrowser.js.map +1 -1
- package/dist/src/browser/HNSWIndex.d.ts +1 -31
- package/dist/src/browser/HNSWIndex.d.ts.map +1 -1
- package/dist/src/browser/HNSWIndex.js +18 -136
- package/dist/src/browser/HNSWIndex.js.map +1 -1
- package/dist/src/browser/ProductQuantization.d.ts.map +1 -1
- package/dist/src/browser/ProductQuantization.js +1 -0
- package/dist/src/browser/ProductQuantization.js.map +1 -1
- package/dist/src/browser/index.d.ts +3 -3
- package/dist/src/browser/index.d.ts.map +1 -1
- package/dist/src/browser/index.js +1 -2
- package/dist/src/browser/index.js.map +1 -1
- package/dist/src/cli/agentdb-cli.d.ts +2 -16
- package/dist/src/cli/agentdb-cli.d.ts.map +1 -1
- package/dist/src/cli/agentdb-cli.js +216 -853
- package/dist/src/cli/agentdb-cli.js.map +1 -1
- package/dist/src/cli/commands/attention.js +3 -3
- package/dist/src/cli/commands/attention.js.map +1 -1
- package/dist/src/cli/commands/doctor.d.ts +0 -2
- package/dist/src/cli/commands/doctor.d.ts.map +1 -1
- package/dist/src/cli/commands/doctor.js +1 -106
- package/dist/src/cli/commands/doctor.js.map +1 -1
- package/dist/src/cli/commands/init.d.ts +1 -2
- package/dist/src/cli/commands/init.d.ts.map +1 -1
- package/dist/src/cli/commands/init.js +7 -30
- package/dist/src/cli/commands/init.js.map +1 -1
- package/dist/src/cli/commands/install-embeddings.d.ts.map +1 -1
- package/dist/src/cli/commands/install-embeddings.js.map +1 -1
- package/dist/src/cli/commands/migrate.d.ts +0 -15
- package/dist/src/cli/commands/migrate.d.ts.map +1 -1
- package/dist/src/cli/commands/migrate.js +5 -164
- package/dist/src/cli/commands/migrate.js.map +1 -1
- package/dist/src/cli/commands/simulate-report.js.map +1 -1
- package/dist/src/cli/commands/simulate-wizard.js.map +1 -1
- 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.js +1 -5
- package/dist/src/cli/commands/status.js.map +1 -1
- package/dist/src/cli/lib/attention-config.d.ts +2 -2
- package/dist/src/cli/lib/attention-config.d.ts.map +1 -1
- package/dist/src/cli/lib/attention-config.js +1 -2
- package/dist/src/cli/lib/attention-config.js.map +1 -1
- 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 +1 -1
- package/dist/src/cli/lib/config-validator.d.ts.map +1 -1
- 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/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 +352 -0
- package/dist/src/cli/lib/history-tracker.js.map +1 -0
- package/dist/src/cli/lib/report-store.d.ts +1 -2
- package/dist/src/cli/lib/report-store.d.ts.map +1 -1
- package/dist/src/cli/lib/report-store.js +65 -87
- package/dist/src/cli/lib/report-store.js.map +1 -1
- package/dist/src/cli/lib/simulation-registry.d.ts +1 -1
- package/dist/src/cli/lib/simulation-registry.d.ts.map +1 -1
- package/dist/src/cli/lib/simulation-registry.js +0 -1
- package/dist/src/cli/lib/simulation-registry.js.map +1 -1
- package/dist/src/cli/lib/simulation-runner.d.ts +4 -41
- package/dist/src/cli/lib/simulation-runner.d.ts.map +1 -1
- package/dist/src/cli/lib/simulation-runner.js +6 -251
- package/dist/src/cli/lib/simulation-runner.js.map +1 -1
- package/dist/src/controllers/AttentionService.d.ts.map +1 -1
- package/dist/src/controllers/AttentionService.js +5 -3
- package/dist/src/controllers/AttentionService.js.map +1 -1
- package/dist/src/controllers/CausalMemoryGraph.d.ts +8 -33
- package/dist/src/controllers/CausalMemoryGraph.d.ts.map +1 -1
- package/dist/src/controllers/CausalMemoryGraph.js +16 -93
- package/dist/src/controllers/CausalMemoryGraph.js.map +1 -1
- package/dist/src/controllers/CausalRecall.d.ts +3 -6
- package/dist/src/controllers/CausalRecall.d.ts.map +1 -1
- package/dist/src/controllers/CausalRecall.js +8 -14
- package/dist/src/controllers/CausalRecall.js.map +1 -1
- package/dist/src/controllers/ContextSynthesizer.d.ts +1 -1
- package/dist/src/controllers/ContextSynthesizer.d.ts.map +1 -1
- package/dist/src/controllers/EmbeddingService.d.ts.map +1 -1
- package/dist/src/controllers/EmbeddingService.js +3 -10
- package/dist/src/controllers/EmbeddingService.js.map +1 -1
- package/dist/src/controllers/EnhancedEmbeddingService.d.ts +0 -4
- package/dist/src/controllers/EnhancedEmbeddingService.d.ts.map +1 -1
- package/dist/src/controllers/EnhancedEmbeddingService.js +3 -10
- package/dist/src/controllers/EnhancedEmbeddingService.js.map +1 -1
- package/dist/src/controllers/ExplainableRecall.d.ts +6 -5
- package/dist/src/controllers/ExplainableRecall.d.ts.map +1 -1
- package/dist/src/controllers/ExplainableRecall.js +13 -21
- package/dist/src/controllers/ExplainableRecall.js.map +1 -1
- package/dist/src/controllers/HNSWIndex.d.ts +7 -24
- package/dist/src/controllers/HNSWIndex.d.ts.map +1 -1
- package/dist/src/controllers/HNSWIndex.js +10 -89
- package/dist/src/controllers/HNSWIndex.js.map +1 -1
- package/dist/src/controllers/LearningSystem.d.ts +10 -106
- package/dist/src/controllers/LearningSystem.d.ts.map +1 -1
- package/dist/src/controllers/LearningSystem.js +14 -39
- package/dist/src/controllers/LearningSystem.js.map +1 -1
- package/dist/src/controllers/MMRDiversityRanker.d.ts +1 -1
- package/dist/src/controllers/MMRDiversityRanker.d.ts.map +1 -1
- package/dist/src/controllers/MetadataFilter.d.ts +3 -3
- package/dist/src/controllers/MetadataFilter.d.ts.map +1 -1
- package/dist/src/controllers/MetadataFilter.js +6 -9
- package/dist/src/controllers/MetadataFilter.js.map +1 -1
- package/dist/src/controllers/NightlyLearner.d.ts +4 -9
- package/dist/src/controllers/NightlyLearner.d.ts.map +1 -1
- package/dist/src/controllers/NightlyLearner.js +9 -28
- package/dist/src/controllers/NightlyLearner.js.map +1 -1
- package/dist/src/controllers/QUICClient.d.ts +2 -50
- package/dist/src/controllers/QUICClient.d.ts.map +1 -1
- package/dist/src/controllers/QUICClient.js +3 -193
- package/dist/src/controllers/QUICClient.js.map +1 -1
- package/dist/src/controllers/QUICServer.d.ts +4 -4
- package/dist/src/controllers/QUICServer.d.ts.map +1 -1
- package/dist/src/controllers/QUICServer.js +14 -22
- package/dist/src/controllers/QUICServer.js.map +1 -1
- package/dist/src/controllers/ReasoningBank.d.ts +4 -14
- package/dist/src/controllers/ReasoningBank.d.ts.map +1 -1
- package/dist/src/controllers/ReasoningBank.js +46 -59
- package/dist/src/controllers/ReasoningBank.js.map +1 -1
- package/dist/src/controllers/ReflexionMemory.d.ts +7 -80
- package/dist/src/controllers/ReflexionMemory.d.ts.map +1 -1
- package/dist/src/controllers/ReflexionMemory.js +214 -372
- package/dist/src/controllers/ReflexionMemory.js.map +1 -1
- package/dist/src/controllers/SkillLibrary.d.ts +7 -37
- package/dist/src/controllers/SkillLibrary.d.ts.map +1 -1
- package/dist/src/controllers/SkillLibrary.js +96 -212
- package/dist/src/controllers/SkillLibrary.js.map +1 -1
- package/dist/src/controllers/SyncCoordinator.d.ts +3 -2
- package/dist/src/controllers/SyncCoordinator.d.ts.map +1 -1
- package/dist/src/controllers/SyncCoordinator.js +5 -117
- package/dist/src/controllers/SyncCoordinator.js.map +1 -1
- package/dist/src/controllers/WASMVectorSearch.d.ts +9 -20
- package/dist/src/controllers/WASMVectorSearch.d.ts.map +1 -1
- package/dist/src/controllers/WASMVectorSearch.js +29 -154
- package/dist/src/controllers/WASMVectorSearch.js.map +1 -1
- 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 +17 -8
- package/dist/src/controllers/index.d.ts.map +1 -1
- package/dist/src/controllers/index.js +12 -6
- package/dist/src/controllers/index.js.map +1 -1
- package/dist/src/core/AgentDB.d.ts +25 -57
- package/dist/src/core/AgentDB.d.ts.map +1 -1
- package/dist/src/core/AgentDB.js +115 -137
- package/dist/src/core/AgentDB.js.map +1 -1
- package/dist/src/db-fallback.d.ts +1 -10
- package/dist/src/db-fallback.d.ts.map +1 -1
- package/dist/src/db-fallback.js +4 -171
- package/dist/src/db-fallback.js.map +1 -1
- 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 +12 -38
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +11 -46
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/agentdb-mcp-server.js +63 -219
- package/dist/src/mcp/agentdb-mcp-server.js.map +1 -1
- 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 +5 -52
- package/dist/src/optimizations/BatchOperations.d.ts.map +1 -1
- package/dist/src/optimizations/BatchOperations.js +33 -186
- package/dist/src/optimizations/BatchOperations.js.map +1 -1
- package/dist/src/optimizations/QueryOptimizer.d.ts +4 -4
- package/dist/src/optimizations/QueryOptimizer.d.ts.map +1 -1
- package/dist/src/optimizations/QueryOptimizer.js +1 -3
- package/dist/src/optimizations/QueryOptimizer.js.map +1 -1
- package/dist/src/optimizations/ToolCache.d.ts +4 -4
- package/dist/src/optimizations/ToolCache.d.ts.map +1 -1
- package/dist/src/optimizations/ToolCache.js.map +1 -1
- package/dist/src/optimizations/index.d.ts +1 -1
- package/dist/src/optimizations/index.d.ts.map +1 -1
- package/dist/src/security/AttestationLog.d.ts +70 -0
- package/dist/src/security/AttestationLog.d.ts.map +1 -0
- package/dist/src/security/AttestationLog.js +174 -0
- package/dist/src/security/AttestationLog.js.map +1 -0
- package/dist/src/security/MutationGuard.d.ts +83 -0
- package/dist/src/security/MutationGuard.d.ts.map +1 -0
- package/dist/src/security/MutationGuard.js +379 -0
- package/dist/src/security/MutationGuard.js.map +1 -0
- package/dist/src/security/index.d.ts +15 -0
- package/dist/src/security/index.d.ts.map +1 -0
- package/dist/src/security/index.js +18 -0
- package/dist/src/security/index.js.map +1 -0
- package/dist/src/security/input-validation.d.ts +12 -12
- package/dist/src/security/input-validation.d.ts.map +1 -1
- package/dist/src/security/input-validation.js +0 -1
- package/dist/src/security/input-validation.js.map +1 -1
- 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/GraphTransformerService.d.ts +79 -0
- package/dist/src/services/GraphTransformerService.d.ts.map +1 -0
- package/dist/src/services/GraphTransformerService.js +331 -0
- package/dist/src/services/GraphTransformerService.js.map +1 -0
- package/dist/src/services/LLMRouter.d.ts +7 -61
- package/dist/src/services/LLMRouter.d.ts.map +1 -1
- package/dist/src/services/LLMRouter.js +25 -295
- package/dist/src/services/LLMRouter.js.map +1 -1
- package/dist/src/services/SemanticRouter.d.ts +78 -0
- package/dist/src/services/SemanticRouter.d.ts.map +1 -0
- package/dist/src/services/SemanticRouter.js +149 -0
- package/dist/src/services/SemanticRouter.js.map +1 -0
- package/dist/src/services/SonaTrajectoryService.d.ts +100 -0
- package/dist/src/services/SonaTrajectoryService.d.ts.map +1 -0
- package/dist/src/services/SonaTrajectoryService.js +231 -0
- package/dist/src/services/SonaTrajectoryService.js.map +1 -0
- package/dist/src/types/attention.d.ts +249 -0
- package/dist/src/types/attention.d.ts.map +1 -0
- package/dist/src/types/attention.js +43 -0
- package/dist/src/types/attention.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/LegacyAttentionAdapter.d.ts +93 -0
- package/dist/src/utils/LegacyAttentionAdapter.d.ts.map +1 -0
- package/dist/src/utils/LegacyAttentionAdapter.js +241 -0
- package/dist/src/utils/LegacyAttentionAdapter.js.map +1 -0
- package/dist/src/utils/attention-metrics.d.ts +76 -0
- package/dist/src/utils/attention-metrics.d.ts.map +1 -0
- package/dist/src/utils/attention-metrics.js +178 -0
- package/dist/src/utils/attention-metrics.js.map +1 -0
- package/dist/src/utils/vector-math.d.ts +29 -0
- package/dist/src/utils/vector-math.d.ts.map +1 -0
- package/dist/src/utils/vector-math.js +66 -0
- package/dist/src/utils/vector-math.js.map +1 -0
- package/examples/README.md +105 -0
- package/examples/browser/attention-demo.html +499 -0
- package/examples/browser/flash-consolidation.html +598 -0
- package/examples/browser/hyperbolic-hierarchy.html +497 -0
- package/examples/quickstart.js +43 -0
- package/package.json +53 -56
- package/simulation/.claude-flow/metrics/agent-metrics.json +1 -0
- package/simulation/.claude-flow/metrics/performance.json +87 -0
- package/simulation/.claude-flow/metrics/task-metrics.json +10 -0
- package/simulation/COMPLETION-STATUS.md +139 -0
- package/simulation/FINAL-RESULTS.md +414 -0
- package/simulation/FINAL-STATUS.md +281 -0
- package/simulation/INTEGRATION-COMPLETE.md +452 -0
- package/simulation/MIGRATION-STATUS.md +231 -0
- package/simulation/OPTIMIZATION-RESULTS.md +397 -0
- package/simulation/PHASE1-COMPLETE.md +163 -0
- package/simulation/README.md +848 -0
- package/simulation/SIMULATION-RESULTS.md +239 -0
- package/simulation/cli.ts +78 -0
- package/simulation/configs/default.json +37 -0
- package/simulation/data/advanced/aidefence.graph +0 -0
- package/simulation/data/advanced/bmssp.graph +0 -0
- package/simulation/data/advanced/consciousness.graph +0 -0
- package/simulation/data/advanced/goalie.graph +0 -0
- package/simulation/data/advanced/psycho-symbolic.graph +0 -0
- package/simulation/data/advanced/research-swarm.graph +0 -0
- package/simulation/data/advanced/sublinear.graph +0 -0
- package/simulation/data/advanced/temporal.graph +0 -0
- package/simulation/data/causal.graph +0 -0
- package/simulation/data/graph-traversal.graph +0 -0
- package/simulation/data/lean-agentic.graph +0 -0
- package/simulation/data/reflexion.graph +0 -0
- package/simulation/data/skills.graph +0 -0
- package/simulation/data/stock-market.graph +0 -0
- package/simulation/data/strange-loops.graph +0 -0
- package/simulation/data/swarm.graph +0 -0
- package/simulation/data/voting-consensus.graph +0 -0
- package/simulation/docs/CLI-INTEGRATION-PLAN.md +1038 -0
- package/simulation/docs/COMPREHENSIVE-LATENT-SPACE-COMPLETION.md +354 -0
- package/simulation/docs/DOCUMENTATION-INDEX.md +226 -0
- package/simulation/docs/IMPLEMENTATION-COMPLETE.md +521 -0
- package/simulation/docs/OPTIMIZATION-SUMMARY.md +279 -0
- package/simulation/docs/README.md +229 -0
- package/simulation/docs/SWARM-5-INTEGRATION-SUMMARY.md +528 -0
- package/simulation/docs/TESTING-SUMMARY.md +304 -0
- package/simulation/docs/architecture/EXTENSION-API.md +868 -0
- package/simulation/docs/architecture/INTEGRATION-ARCHITECTURE.md +1138 -0
- package/simulation/docs/architecture/OPTIMIZATION-STRATEGY.md +778 -0
- package/simulation/docs/architecture/SIMULATION-ARCHITECTURE.md +892 -0
- package/simulation/docs/guides/CLI-REFERENCE.md +896 -0
- package/simulation/docs/guides/CUSTOM-SIMULATIONS.md +931 -0
- package/simulation/docs/guides/DEPLOYMENT.md +832 -0
- package/simulation/docs/guides/IMPLEMENTATION-SUMMARY.md +544 -0
- package/simulation/docs/guides/MIGRATION-GUIDE.md +591 -0
- package/simulation/docs/guides/QUICK-START.md +361 -0
- package/simulation/docs/guides/README.md +736 -0
- package/simulation/docs/guides/TROUBLESHOOTING.md +817 -0
- package/simulation/docs/guides/WIZARD-GUIDE.md +869 -0
- package/simulation/docs/reports/latent-space/MASTER-SYNTHESIS.md +345 -0
- package/simulation/docs/reports/latent-space/README.md +132 -0
- package/simulation/docs/reports/latent-space/attention-analysis-RESULTS.md +238 -0
- package/simulation/docs/reports/latent-space/clustering-analysis-RESULTS.md +210 -0
- package/simulation/docs/reports/latent-space/hnsw-exploration-RESULTS.md +332 -0
- package/simulation/docs/reports/latent-space/hypergraph-exploration-RESULTS.md +37 -0
- package/simulation/docs/reports/latent-space/neural-augmentation-RESULTS.md +69 -0
- package/simulation/docs/reports/latent-space/quantum-hybrid-RESULTS.md +91 -0
- package/simulation/docs/reports/latent-space/self-organizing-hnsw-RESULTS.md +51 -0
- package/simulation/docs/reports/latent-space/traversal-optimization-RESULTS.md +238 -0
- package/simulation/reports/README.md +397 -0
- package/simulation/reports/advanced-simulations-performance.md +1241 -0
- package/simulation/reports/aidefence-integration-2025-11-30T01-36-53-486Z.json +30 -0
- package/simulation/reports/architecture-analysis.md +1396 -0
- package/simulation/reports/basic-scenarios-performance.md +1840 -0
- package/simulation/reports/bmssp-integration-2025-11-30T01-36-27-193Z.json +30 -0
- package/simulation/reports/bmssp-integration-2025-11-30T03-38-12-887Z.json +30 -0
- package/simulation/reports/causal-reasoning-2025-11-29T23-35-21-795Z.json +36 -0
- package/simulation/reports/causal-reasoning-2025-11-30T00-58-42-862Z.json +30 -0
- package/simulation/reports/causal-reasoning-2025-11-30T00-59-12-546Z.json +40 -0
- package/simulation/reports/consciousness-explorer-2025-11-30T01-36-51-269Z.json +31 -0
- package/simulation/reports/core-benchmarks.md +727 -0
- package/simulation/reports/goalie-integration-2025-11-30T01-36-52-377Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-29T23-35-35-279Z.json +78 -0
- package/simulation/reports/graph-traversal-2025-11-29T23-37-36-697Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-03-59-716Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-05-10-984Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-06-16-334Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-06-53-312Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-07-51-075Z.json +24 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-08-22-179Z.json +42 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-29T23-37-23-804Z.json +148 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-30T01-31-24-401Z.json +31 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-30T03-38-01-470Z.json +31 -0
- package/simulation/reports/multi-agent-swarm-2025-11-29T23-35-28-093Z.json +78 -0
- package/simulation/reports/multi-agent-swarm-2025-11-30T01-03-54-062Z.json +42 -0
- package/simulation/reports/multi-agent-swarm-2025-11-30T01-05-06-092Z.json +42 -0
- package/simulation/reports/psycho-symbolic-reasoner-2025-11-30T01-36-50-180Z.json +30 -0
- package/simulation/reports/quality-metrics.md +727 -0
- package/simulation/reports/reflexion-learning-2025-11-29T23-35-09-774Z.json +48 -0
- package/simulation/reports/reflexion-learning-2025-11-29T23-37-16-934Z.json +36 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-07-49-259Z.json +30 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-09-29-319Z.json +51 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-28-37-659Z.json +51 -0
- package/simulation/reports/reflexion-learning-2025-11-30T01-31-30-690Z.json +29 -0
- package/simulation/reports/reflexion-learning-2025-11-30T03-38-06-937Z.json +29 -0
- package/simulation/reports/research-foundations.md +2004 -0
- package/simulation/reports/research-swarm-2025-11-30T01-36-54-647Z.json +30 -0
- package/simulation/reports/scalability-deployment.md +2404 -0
- package/simulation/reports/skill-evolution-2025-11-29T23-35-15-945Z.json +36 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-03-17-995Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-03-48-441Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-05-00-554Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-06-11-436Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-06-51-979Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-07-32-695Z.json +40 -0
- package/simulation/reports/stock-market-emergence-2025-11-30T00-11-43-865Z.json +56 -0
- package/simulation/reports/stock-market-emergence-2025-11-30T00-28-57-495Z.json +56 -0
- package/simulation/reports/strange-loops-2025-11-29T23-37-30-621Z.json +78 -0
- package/simulation/reports/strange-loops-2025-11-30T00-07-55-415Z.json +30 -0
- package/simulation/reports/strange-loops-2025-11-30T00-09-35-133Z.json +30 -0
- package/simulation/reports/strange-loops-2025-11-30T00-48-50-744Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-54-48-044Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-57-27-633Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-57-59-135Z.json +42 -0
- package/simulation/reports/sublinear-solver-2025-11-30T01-36-33-134Z.json +30 -0
- package/simulation/reports/temporal-lead-solver-2025-11-30T01-36-38-628Z.json +30 -0
- package/simulation/reports/use-cases-applications.md +2212 -0
- package/simulation/reports/voting-system-consensus-2025-11-30T00-11-37-199Z.json +58 -0
- package/simulation/reports/voting-system-consensus-2025-11-30T00-28-47-735Z.json +58 -0
- package/simulation/runner.ts +300 -0
- package/simulation/scenarios/README-advanced/aidefence-integration.md +63 -0
- package/simulation/scenarios/README-advanced/bmssp-integration.md +58 -0
- package/simulation/scenarios/README-advanced/consciousness-explorer.md +53 -0
- package/simulation/scenarios/README-advanced/goalie-integration.md +61 -0
- package/simulation/scenarios/README-advanced/psycho-symbolic-reasoner.md +55 -0
- package/simulation/scenarios/README-advanced/research-swarm.md +63 -0
- package/simulation/scenarios/README-advanced/sublinear-solver.md +58 -0
- package/simulation/scenarios/README-advanced/temporal-lead-solver.md +55 -0
- package/simulation/scenarios/README-basic/causal-reasoning.md +39 -0
- package/simulation/scenarios/README-basic/graph-traversal.md +41 -0
- package/simulation/scenarios/README-basic/lean-agentic-swarm.md +122 -0
- package/simulation/scenarios/README-basic/multi-agent-swarm.md +34 -0
- package/simulation/scenarios/README-basic/reflexion-learning.md +41 -0
- package/simulation/scenarios/README-basic/skill-evolution.md +38 -0
- package/simulation/scenarios/README-basic/stock-market-emergence.md +28 -0
- package/simulation/scenarios/README-basic/strange-loops.md +36 -0
- package/simulation/scenarios/README-basic/voting-system-consensus.md +28 -0
- package/simulation/scenarios/README.md +438 -0
- package/simulation/scenarios/aidefence-integration.ts +165 -0
- package/simulation/scenarios/bmssp-integration.ts +137 -0
- package/simulation/scenarios/causal-reasoning.ts +143 -0
- package/simulation/scenarios/consciousness-explorer.ts +139 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/agent-metrics.json +1 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/performance.json +87 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/task-metrics.json +10 -0
- package/simulation/scenarios/domain-examples/README.md +525 -0
- package/simulation/scenarios/domain-examples/e-commerce-recommendations.ts +220 -0
- package/simulation/scenarios/domain-examples/index.ts +81 -0
- package/simulation/scenarios/domain-examples/iot-sensor-networks.ts +290 -0
- package/simulation/scenarios/domain-examples/medical-imaging.ts +181 -0
- package/simulation/scenarios/domain-examples/robotics-navigation.ts +214 -0
- package/simulation/scenarios/domain-examples/scientific-research.ts +250 -0
- package/simulation/scenarios/domain-examples/trading-systems.ts +138 -0
- package/simulation/scenarios/goalie-integration.ts +161 -0
- package/simulation/scenarios/graph-traversal.ts +129 -0
- package/simulation/scenarios/latent-space/OPTIMIZATION-COMPLETE.md +287 -0
- package/simulation/scenarios/latent-space/README-attention-analysis.md +170 -0
- package/simulation/scenarios/latent-space/README-clustering-analysis.md +239 -0
- package/simulation/scenarios/latent-space/README-hnsw-exploration.md +199 -0
- package/simulation/scenarios/latent-space/README-hypergraph-exploration.md +279 -0
- package/simulation/scenarios/latent-space/README-neural-augmentation.md +267 -0
- package/simulation/scenarios/latent-space/README-quantum-hybrid.md +276 -0
- package/simulation/scenarios/latent-space/README-self-organizing-hnsw.md +244 -0
- package/simulation/scenarios/latent-space/README-traversal-optimization.md +212 -0
- package/simulation/scenarios/latent-space/attention-analysis.ts +598 -0
- package/simulation/scenarios/latent-space/clustering-analysis.ts +796 -0
- package/simulation/scenarios/latent-space/hnsw-exploration.ts +526 -0
- package/simulation/scenarios/latent-space/hypergraph-exploration.ts +706 -0
- package/simulation/scenarios/latent-space/index.ts +47 -0
- package/simulation/scenarios/latent-space/neural-augmentation.ts +604 -0
- package/simulation/scenarios/latent-space/quantum-hybrid.ts +508 -0
- package/simulation/scenarios/latent-space/self-organizing-hnsw.ts +680 -0
- package/simulation/scenarios/latent-space/traversal-optimization.ts +782 -0
- package/simulation/scenarios/lean-agentic-swarm.ts +182 -0
- package/simulation/scenarios/multi-agent-swarm.ts +146 -0
- package/simulation/scenarios/psycho-symbolic-reasoner.ts +136 -0
- package/simulation/scenarios/reflexion-learning.ts +132 -0
- package/simulation/scenarios/research-swarm.ts +187 -0
- package/simulation/scenarios/skill-evolution.ts +135 -0
- package/simulation/scenarios/stock-market-emergence.ts +323 -0
- package/simulation/scenarios/strange-loops.ts +175 -0
- package/simulation/scenarios/sublinear-solver.ts +108 -0
- package/simulation/scenarios/temporal-lead-solver.ts +121 -0
- package/simulation/scenarios/voting-system-consensus.ts +251 -0
- package/simulation/tests/latent-space/attention-analysis.test.ts +204 -0
- package/simulation/tests/latent-space/clustering-analysis.test.ts +281 -0
- package/simulation/tests/latent-space/hnsw-exploration.test.ts +253 -0
- package/simulation/tests/latent-space/hypergraph-exploration.test.ts +295 -0
- package/simulation/tests/latent-space/neural-augmentation.test.ts +326 -0
- package/simulation/tests/latent-space/quantum-hybrid.test.ts +307 -0
- package/simulation/tests/latent-space/self-organizing-hnsw.test.ts +291 -0
- package/simulation/tests/latent-space/traversal-optimization.test.ts +261 -0
- package/simulation/types.ts +177 -0
- package/simulation/utils/PerformanceOptimizer.ts +269 -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 +147 -0
- package/src/backends/detector.ts +283 -0
- package/src/backends/factory.ts +279 -0
- package/src/backends/graph/GraphDatabaseAdapter.ts +334 -0
- package/src/backends/hnswlib/HNSWLibBackend.ts +419 -0
- package/src/backends/hnswlib/index.ts +7 -0
- package/src/backends/index.ts +32 -0
- package/src/backends/ruvector/GuardedVectorBackend.ts +219 -0
- package/src/backends/ruvector/RuVectorBackend.ts +343 -0
- package/src/backends/ruvector/RuVectorLearning.ts +254 -0
- package/src/backends/ruvector/index.ts +9 -0
- package/src/benchmarks/wasm-vector-benchmark.ts +250 -0
- package/src/browser/AdvancedFeatures.ts +565 -0
- package/src/browser/AttentionBrowser.ts +387 -0
- package/src/browser/HNSWIndex.ts +494 -0
- package/src/browser/ProductQuantization.ts +419 -0
- package/src/browser/index.ts +317 -0
- package/src/cli/agentdb-cli.ts +2712 -0
- package/src/cli/attention-cli-integration.ts +91 -0
- package/src/cli/commands/attention.ts +656 -0
- package/src/cli/commands/doctor.ts +322 -0
- package/src/cli/commands/init.ts +176 -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/examples.sh +83 -0
- package/src/cli/lib/attention-config.ts +326 -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 +503 -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 +503 -0
- package/src/cli/lib/simulation-runner.ts +291 -0
- package/src/cli/tests/agentdb-cli.test.ts +58 -0
- package/src/cli/tests/attention-cli.test.ts +335 -0
- package/src/controllers/AttentionService.ts +770 -0
- package/src/controllers/CausalMemoryGraph.ts +773 -0
- package/src/controllers/CausalRecall.ts +484 -0
- package/src/controllers/ContextSynthesizer.ts +285 -0
- package/src/controllers/EmbeddingService.ts +161 -0
- package/src/controllers/EnhancedEmbeddingService.ts +143 -0
- package/src/controllers/ExplainableRecall.ts +746 -0
- package/src/controllers/HNSWIndex.ts +495 -0
- package/src/controllers/LearningSystem.ts +1270 -0
- package/src/controllers/MMRDiversityRanker.ts +187 -0
- package/src/controllers/MetadataFilter.ts +280 -0
- package/src/controllers/NightlyLearner.ts +647 -0
- package/src/controllers/QUICClient.ts +413 -0
- package/src/controllers/QUICServer.ts +498 -0
- package/src/controllers/ReasoningBank.ts +665 -0
- package/src/controllers/ReflexionMemory.ts +872 -0
- package/src/controllers/SkillLibrary.ts +795 -0
- package/src/controllers/SyncCoordinator.ts +597 -0
- package/src/controllers/WASMVectorSearch.ts +292 -0
- package/src/controllers/frontier-index.ts +35 -0
- package/src/controllers/index.ts +57 -0
- package/src/coordination/MultiDatabaseCoordinator.ts +1107 -0
- package/src/coordination/index.ts +24 -0
- package/src/core/AgentDB.ts +211 -0
- package/src/db-fallback.ts +296 -0
- package/src/db-test.ts +59 -0
- package/src/db-unified.ts +327 -0
- package/src/examples/quic-sync-example.ts +198 -0
- package/src/examples/wasm-vector-usage.ts +245 -0
- package/src/index.ts +69 -0
- package/src/mcp/agentdb-mcp-server.ts +2318 -0
- package/src/mcp/attention-mcp-integration.ts +145 -0
- package/src/mcp/attention-tools-handlers.ts +586 -0
- package/src/mcp/learning-tools-handlers.ts +106 -0
- package/src/optimizations/BatchOperations.ts +594 -0
- package/src/optimizations/QueryOptimizer.ts +297 -0
- package/src/optimizations/ToolCache.ts +355 -0
- package/src/optimizations/index.ts +11 -0
- package/src/schemas/frontier-schema.sql +378 -0
- package/src/schemas/schema.sql +382 -0
- package/src/security/AttestationLog.ts +252 -0
- package/src/security/MutationGuard.ts +420 -0
- package/src/security/index.ts +52 -0
- package/src/security/input-validation.ts +543 -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/GraphTransformerService.ts +389 -0
- package/src/services/LLMRouter.ts +380 -0
- package/src/services/SemanticRouter.ts +169 -0
- package/src/services/SonaTrajectoryService.ts +264 -0
- package/src/tests/attention-service.test.ts +492 -0
- package/src/tests/wasm-vector-search.test.ts +240 -0
- package/src/types/attention.ts +392 -0
- package/src/types/quic.ts +772 -0
- package/src/utils/LegacyAttentionAdapter.ts +393 -0
- package/src/utils/NodeIdMapper.ts +64 -0
- package/src/utils/attention-metrics.ts +253 -0
- package/src/utils/vector-math.ts +71 -0
- package/LICENSE +0 -21
- package/dist/src/backends/rvf/AdaptiveIndexTuner.d.ts +0 -175
- package/dist/src/backends/rvf/AdaptiveIndexTuner.d.ts.map +0 -1
- package/dist/src/backends/rvf/AdaptiveIndexTuner.js +0 -559
- package/dist/src/backends/rvf/AdaptiveIndexTuner.js.map +0 -1
- package/dist/src/backends/rvf/ContrastiveTrainer.d.ts +0 -148
- package/dist/src/backends/rvf/ContrastiveTrainer.d.ts.map +0 -1
- package/dist/src/backends/rvf/ContrastiveTrainer.js +0 -438
- package/dist/src/backends/rvf/ContrastiveTrainer.js.map +0 -1
- package/dist/src/backends/rvf/FederatedSessionManager.d.ts +0 -211
- package/dist/src/backends/rvf/FederatedSessionManager.d.ts.map +0 -1
- package/dist/src/backends/rvf/FederatedSessionManager.js +0 -389
- package/dist/src/backends/rvf/FederatedSessionManager.js.map +0 -1
- package/dist/src/backends/rvf/FilterBuilder.d.ts +0 -136
- package/dist/src/backends/rvf/FilterBuilder.d.ts.map +0 -1
- package/dist/src/backends/rvf/FilterBuilder.js +0 -157
- package/dist/src/backends/rvf/FilterBuilder.js.map +0 -1
- package/dist/src/backends/rvf/NativeAccelerator.d.ts +0 -140
- package/dist/src/backends/rvf/NativeAccelerator.d.ts.map +0 -1
- package/dist/src/backends/rvf/NativeAccelerator.js +0 -630
- package/dist/src/backends/rvf/NativeAccelerator.js.map +0 -1
- package/dist/src/backends/rvf/RvfBackend.d.ts +0 -194
- package/dist/src/backends/rvf/RvfBackend.d.ts.map +0 -1
- package/dist/src/backends/rvf/RvfBackend.js +0 -607
- package/dist/src/backends/rvf/RvfBackend.js.map +0 -1
- package/dist/src/backends/rvf/RvfSolver.d.ts +0 -175
- package/dist/src/backends/rvf/RvfSolver.d.ts.map +0 -1
- package/dist/src/backends/rvf/RvfSolver.js +0 -176
- package/dist/src/backends/rvf/RvfSolver.js.map +0 -1
- package/dist/src/backends/rvf/SelfLearningRvfBackend.d.ts +0 -143
- package/dist/src/backends/rvf/SelfLearningRvfBackend.d.ts.map +0 -1
- package/dist/src/backends/rvf/SelfLearningRvfBackend.js +0 -569
- package/dist/src/backends/rvf/SelfLearningRvfBackend.js.map +0 -1
- package/dist/src/backends/rvf/SemanticQueryRouter.d.ts +0 -128
- package/dist/src/backends/rvf/SemanticQueryRouter.d.ts.map +0 -1
- package/dist/src/backends/rvf/SemanticQueryRouter.js +0 -415
- package/dist/src/backends/rvf/SemanticQueryRouter.js.map +0 -1
- package/dist/src/backends/rvf/SimdFallbacks.d.ts +0 -25
- package/dist/src/backends/rvf/SimdFallbacks.d.ts.map +0 -1
- package/dist/src/backends/rvf/SimdFallbacks.js +0 -287
- package/dist/src/backends/rvf/SimdFallbacks.js.map +0 -1
- package/dist/src/backends/rvf/SolverBandit.d.ts +0 -100
- package/dist/src/backends/rvf/SolverBandit.d.ts.map +0 -1
- package/dist/src/backends/rvf/SolverBandit.js +0 -216
- package/dist/src/backends/rvf/SolverBandit.js.map +0 -1
- package/dist/src/backends/rvf/SonaLearningBackend.d.ts +0 -157
- package/dist/src/backends/rvf/SonaLearningBackend.d.ts.map +0 -1
- package/dist/src/backends/rvf/SonaLearningBackend.js +0 -283
- package/dist/src/backends/rvf/SonaLearningBackend.js.map +0 -1
- package/dist/src/backends/rvf/SqlJsRvfBackend.d.ts +0 -77
- package/dist/src/backends/rvf/SqlJsRvfBackend.d.ts.map +0 -1
- package/dist/src/backends/rvf/SqlJsRvfBackend.js +0 -382
- package/dist/src/backends/rvf/SqlJsRvfBackend.js.map +0 -1
- package/dist/src/backends/rvf/WasmStoreBridge.d.ts +0 -27
- package/dist/src/backends/rvf/WasmStoreBridge.d.ts.map +0 -1
- package/dist/src/backends/rvf/WasmStoreBridge.js +0 -87
- package/dist/src/backends/rvf/WasmStoreBridge.js.map +0 -1
- package/dist/src/backends/rvf/validation.d.ts +0 -20
- package/dist/src/backends/rvf/validation.d.ts.map +0 -1
- package/dist/src/backends/rvf/validation.js +0 -78
- package/dist/src/backends/rvf/validation.js.map +0 -1
- package/dist/src/benchmark/BenchmarkSuite.d.ts +0 -318
- package/dist/src/benchmark/BenchmarkSuite.d.ts.map +0 -1
- package/dist/src/benchmark/BenchmarkSuite.js +0 -986
- package/dist/src/benchmark/BenchmarkSuite.js.map +0 -1
- package/dist/src/benchmark/index.d.ts +0 -29
- package/dist/src/benchmark/index.d.ts.map +0 -1
- package/dist/src/benchmark/index.js +0 -39
- package/dist/src/benchmark/index.js.map +0 -1
- package/dist/src/cli/commands/hyperbolic.d.ts +0 -11
- package/dist/src/cli/commands/hyperbolic.d.ts.map +0 -1
- package/dist/src/cli/commands/hyperbolic.js +0 -428
- package/dist/src/cli/commands/hyperbolic.js.map +0 -1
- package/dist/src/cli/commands/learn.d.ts +0 -11
- package/dist/src/cli/commands/learn.d.ts.map +0 -1
- package/dist/src/cli/commands/learn.js +0 -404
- package/dist/src/cli/commands/learn.js.map +0 -1
- package/dist/src/cli/commands/route.d.ts +0 -11
- package/dist/src/cli/commands/route.d.ts.map +0 -1
- package/dist/src/cli/commands/route.js +0 -414
- package/dist/src/cli/commands/route.js.map +0 -1
- package/dist/src/cli/commands/rvf.d.ts +0 -21
- package/dist/src/cli/commands/rvf.d.ts.map +0 -1
- package/dist/src/cli/commands/rvf.js +0 -448
- package/dist/src/cli/commands/rvf.js.map +0 -1
- package/dist/src/cli/tests/agentdb-cli.test.d.ts +0 -8
- package/dist/src/cli/tests/agentdb-cli.test.d.ts.map +0 -1
- package/dist/src/cli/tests/agentdb-cli.test.js +0 -50
- package/dist/src/cli/tests/agentdb-cli.test.js.map +0 -1
- package/dist/src/cli/tests/attention-cli.test.d.ts +0 -5
- package/dist/src/cli/tests/attention-cli.test.d.ts.map +0 -1
- package/dist/src/cli/tests/attention-cli.test.js +0 -257
- package/dist/src/cli/tests/attention-cli.test.js.map +0 -1
- package/dist/src/compatibility/DeprecationWarnings.d.ts +0 -54
- package/dist/src/compatibility/DeprecationWarnings.d.ts.map +0 -1
- package/dist/src/compatibility/DeprecationWarnings.js +0 -131
- package/dist/src/compatibility/DeprecationWarnings.js.map +0 -1
- package/dist/src/compatibility/MigrationUtilities.d.ts +0 -30
- package/dist/src/compatibility/MigrationUtilities.d.ts.map +0 -1
- package/dist/src/compatibility/MigrationUtilities.js +0 -184
- package/dist/src/compatibility/MigrationUtilities.js.map +0 -1
- package/dist/src/compatibility/V1toV2Adapter.d.ts +0 -76
- package/dist/src/compatibility/V1toV2Adapter.d.ts.map +0 -1
- package/dist/src/compatibility/V1toV2Adapter.js +0 -198
- package/dist/src/compatibility/V1toV2Adapter.js.map +0 -1
- package/dist/src/compatibility/VersionDetector.d.ts +0 -32
- package/dist/src/compatibility/VersionDetector.d.ts.map +0 -1
- package/dist/src/compatibility/VersionDetector.js +0 -144
- package/dist/src/compatibility/VersionDetector.js.map +0 -1
- package/dist/src/compatibility/index.d.ts +0 -11
- package/dist/src/compatibility/index.d.ts.map +0 -1
- package/dist/src/compatibility/index.js +0 -10
- package/dist/src/compatibility/index.js.map +0 -1
- package/dist/src/compatibility/types.d.ts +0 -103
- package/dist/src/compatibility/types.d.ts.map +0 -1
- package/dist/src/compatibility/types.js +0 -5
- package/dist/src/compatibility/types.js.map +0 -1
- package/dist/src/controllers/MemoryController.d.ts +0 -161
- package/dist/src/controllers/MemoryController.d.ts.map +0 -1
- package/dist/src/controllers/MemoryController.js +0 -290
- package/dist/src/controllers/MemoryController.js.map +0 -1
- package/dist/src/controllers/attention/CrossAttentionController.d.ts +0 -141
- package/dist/src/controllers/attention/CrossAttentionController.d.ts.map +0 -1
- package/dist/src/controllers/attention/CrossAttentionController.js +0 -325
- package/dist/src/controllers/attention/CrossAttentionController.js.map +0 -1
- package/dist/src/controllers/attention/MultiHeadAttentionController.d.ts +0 -137
- package/dist/src/controllers/attention/MultiHeadAttentionController.d.ts.map +0 -1
- package/dist/src/controllers/attention/MultiHeadAttentionController.js +0 -339
- package/dist/src/controllers/attention/MultiHeadAttentionController.js.map +0 -1
- package/dist/src/controllers/attention/SelfAttentionController.d.ts +0 -117
- package/dist/src/controllers/attention/SelfAttentionController.d.ts.map +0 -1
- package/dist/src/controllers/attention/SelfAttentionController.js +0 -205
- package/dist/src/controllers/attention/SelfAttentionController.js.map +0 -1
- package/dist/src/controllers/attention/index.d.ts +0 -15
- package/dist/src/controllers/attention/index.d.ts.map +0 -1
- package/dist/src/controllers/attention/index.js +0 -12
- package/dist/src/controllers/attention/index.js.map +0 -1
- package/dist/src/core/QueryCache.d.ts +0 -138
- package/dist/src/core/QueryCache.d.ts.map +0 -1
- package/dist/src/core/QueryCache.js +0 -313
- package/dist/src/core/QueryCache.js.map +0 -1
- package/dist/src/observability/index.d.ts +0 -8
- package/dist/src/observability/index.d.ts.map +0 -1
- package/dist/src/observability/index.js +0 -8
- package/dist/src/observability/index.js.map +0 -1
- package/dist/src/observability/integration.d.ts +0 -32
- package/dist/src/observability/integration.d.ts.map +0 -1
- package/dist/src/observability/integration.js +0 -157
- package/dist/src/observability/integration.js.map +0 -1
- package/dist/src/observability/telemetry.d.ts +0 -137
- package/dist/src/observability/telemetry.d.ts.map +0 -1
- package/dist/src/observability/telemetry.js +0 -420
- package/dist/src/observability/telemetry.js.map +0 -1
- package/dist/src/quantization/index.d.ts +0 -7
- package/dist/src/quantization/index.d.ts.map +0 -1
- package/dist/src/quantization/index.js +0 -15
- package/dist/src/quantization/index.js.map +0 -1
- package/dist/src/quantization/vector-quantization.d.ts +0 -388
- package/dist/src/quantization/vector-quantization.d.ts.map +0 -1
- package/dist/src/quantization/vector-quantization.js +0 -1136
- package/dist/src/quantization/vector-quantization.js.map +0 -1
- package/dist/src/search/HybridSearch.d.ts +0 -311
- package/dist/src/search/HybridSearch.d.ts.map +0 -1
- package/dist/src/search/HybridSearch.js +0 -712
- package/dist/src/search/HybridSearch.js.map +0 -1
- package/dist/src/search/index.d.ts +0 -12
- package/dist/src/search/index.d.ts.map +0 -1
- package/dist/src/search/index.js +0 -16
- package/dist/src/search/index.js.map +0 -1
- package/dist/src/services/AttentionService.d.ts +0 -303
- package/dist/src/services/AttentionService.d.ts.map +0 -1
- package/dist/src/services/AttentionService.js +0 -1167
- package/dist/src/services/AttentionService.js.map +0 -1
- package/dist/src/simd/index.d.ts +0 -9
- package/dist/src/simd/index.d.ts.map +0 -1
- package/dist/src/simd/index.js +0 -27
- package/dist/src/simd/index.js.map +0 -1
- package/dist/src/simd/simd-vector-ops.d.ts +0 -332
- package/dist/src/simd/simd-vector-ops.d.ts.map +0 -1
- package/dist/src/simd/simd-vector-ops.js +0 -947
- package/dist/src/simd/simd-vector-ops.js.map +0 -1
- package/dist/src/tests/attention-service.test.d.ts +0 -7
- package/dist/src/tests/attention-service.test.d.ts.map +0 -1
- package/dist/src/tests/attention-service.test.js +0 -401
- package/dist/src/tests/attention-service.test.js.map +0 -1
- package/dist/src/tests/integration/compatibility/backwards-compat.integration.test.d.ts +0 -7
- package/dist/src/tests/integration/compatibility/backwards-compat.integration.test.d.ts.map +0 -1
- package/dist/src/tests/integration/compatibility/backwards-compat.integration.test.js +0 -283
- package/dist/src/tests/integration/compatibility/backwards-compat.integration.test.js.map +0 -1
- package/dist/src/tests/query-cache.test.d.ts +0 -7
- package/dist/src/tests/query-cache.test.d.ts.map +0 -1
- package/dist/src/tests/query-cache.test.js +0 -343
- package/dist/src/tests/query-cache.test.js.map +0 -1
- package/dist/src/tests/ruvector-integration.test.d.ts +0 -14
- package/dist/src/tests/ruvector-integration.test.d.ts.map +0 -1
- package/dist/src/tests/ruvector-integration.test.js +0 -1156
- package/dist/src/tests/ruvector-integration.test.js.map +0 -1
- package/dist/src/tests/unit/auth/crypto.utils.test.d.ts +0 -6
- package/dist/src/tests/unit/auth/crypto.utils.test.d.ts.map +0 -1
- package/dist/src/tests/unit/auth/crypto.utils.test.js +0 -310
- package/dist/src/tests/unit/auth/crypto.utils.test.js.map +0 -1
- package/dist/src/tests/unit/compatibility/deprecation-warnings.test.d.ts +0 -5
- package/dist/src/tests/unit/compatibility/deprecation-warnings.test.d.ts.map +0 -1
- package/dist/src/tests/unit/compatibility/deprecation-warnings.test.js +0 -207
- package/dist/src/tests/unit/compatibility/deprecation-warnings.test.js.map +0 -1
- package/dist/src/tests/unit/compatibility/migration-utils.test.d.ts +0 -5
- package/dist/src/tests/unit/compatibility/migration-utils.test.d.ts.map +0 -1
- package/dist/src/tests/unit/compatibility/migration-utils.test.js +0 -264
- package/dist/src/tests/unit/compatibility/migration-utils.test.js.map +0 -1
- package/dist/src/tests/unit/compatibility/v1-adapter.test.d.ts +0 -7
- package/dist/src/tests/unit/compatibility/v1-adapter.test.d.ts.map +0 -1
- package/dist/src/tests/unit/compatibility/v1-adapter.test.js +0 -228
- package/dist/src/tests/unit/compatibility/v1-adapter.test.js.map +0 -1
- package/dist/src/tests/unit/compatibility/version-detector.test.d.ts +0 -10
- package/dist/src/tests/unit/compatibility/version-detector.test.d.ts.map +0 -1
- package/dist/src/tests/unit/compatibility/version-detector.test.js +0 -162
- package/dist/src/tests/unit/compatibility/version-detector.test.js.map +0 -1
- package/dist/src/tests/vector-quantization.test.d.ts +0 -5
- package/dist/src/tests/vector-quantization.test.d.ts.map +0 -1
- package/dist/src/tests/vector-quantization.test.js +0 -338
- package/dist/src/tests/vector-quantization.test.js.map +0 -1
- package/dist/src/tests/wasm-vector-search.test.d.ts +0 -7
- package/dist/src/tests/wasm-vector-search.test.d.ts.map +0 -1
- package/dist/src/tests/wasm-vector-search.test.js +0 -193
- package/dist/src/tests/wasm-vector-search.test.js.map +0 -1
- package/dist/src/types/database.types.d.ts +0 -275
- package/dist/src/types/database.types.d.ts.map +0 -1
- package/dist/src/types/database.types.js +0 -57
- package/dist/src/types/database.types.js.map +0 -1
- package/dist/src/utils/chalk-fallback.d.ts +0 -3
- package/dist/src/utils/chalk-fallback.d.ts.map +0 -1
- package/dist/src/utils/chalk-fallback.js +0 -20
- package/dist/src/utils/chalk-fallback.js.map +0 -1
- package/dist/src/utils/crypto.utils.d.ts +0 -122
- package/dist/src/utils/crypto.utils.d.ts.map +0 -1
- package/dist/src/utils/crypto.utils.js +0 -296
- package/dist/src/utils/crypto.utils.js.map +0 -1
- package/dist/src/utils/similarity.d.ts +0 -11
- package/dist/src/utils/similarity.d.ts.map +0 -1
- package/dist/src/utils/similarity.js +0 -25
- package/dist/src/utils/similarity.js.map +0 -1
- package/dist/src/wasm-loader.d.ts +0 -67
- package/dist/src/wasm-loader.d.ts.map +0 -1
- package/dist/src/wasm-loader.js +0 -78
- package/dist/src/wasm-loader.js.map +0 -1
- package/dist/src/wrappers/agentdb-fast.d.ts +0 -139
- package/dist/src/wrappers/agentdb-fast.d.ts.map +0 -1
- package/dist/src/wrappers/agentdb-fast.js +0 -316
- package/dist/src/wrappers/agentdb-fast.js.map +0 -1
- package/dist/src/wrappers/attention-fallbacks.d.ts +0 -351
- package/dist/src/wrappers/attention-fallbacks.d.ts.map +0 -1
- package/dist/src/wrappers/attention-fallbacks.js +0 -1487
- package/dist/src/wrappers/attention-fallbacks.js.map +0 -1
- package/dist/src/wrappers/embedding-service.d.ts +0 -117
- package/dist/src/wrappers/embedding-service.d.ts.map +0 -1
- package/dist/src/wrappers/embedding-service.js +0 -376
- package/dist/src/wrappers/embedding-service.js.map +0 -1
- package/dist/src/wrappers/gnn-wrapper.d.ts +0 -71
- package/dist/src/wrappers/gnn-wrapper.d.ts.map +0 -1
- package/dist/src/wrappers/gnn-wrapper.js +0 -240
- package/dist/src/wrappers/gnn-wrapper.js.map +0 -1
- package/dist/src/wrappers/index.d.ts +0 -48
- package/dist/src/wrappers/index.d.ts.map +0 -1
- package/dist/src/wrappers/index.js +0 -83
- package/dist/src/wrappers/index.js.map +0 -1
|
@@ -1,1156 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RuVector Integration Tests
|
|
3
|
-
*
|
|
4
|
-
* Comprehensive test suite for AgentDB's RuVector-powered features:
|
|
5
|
-
* - SIMD Vector Operations
|
|
6
|
-
* - Vector Quantization (8-bit, 4-bit, Product Quantization)
|
|
7
|
-
* - RuVectorBackend Enhancements
|
|
8
|
-
* - Enhanced Embedding Service
|
|
9
|
-
* - Attention Optimized Modules
|
|
10
|
-
*
|
|
11
|
-
* @module ruvector-integration.test
|
|
12
|
-
*/
|
|
13
|
-
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
14
|
-
// SIMD Vector Operations
|
|
15
|
-
import { cosineSimilaritySIMD, euclideanDistanceSIMD, batchCosineSimilarity, normalizeVector, detectSIMDSupport, SIMDVectorOps, } from '../simd/simd-vector-ops.js';
|
|
16
|
-
// Vector Quantization
|
|
17
|
-
import { quantize8bit, quantize4bit, dequantize8bit, dequantize4bit, calculateQuantizationError, getQuantizationStats, ProductQuantizer, createScalar8BitStore, createScalar4BitStore, createProductQuantizedStore, } from '../quantization/vector-quantization.js';
|
|
18
|
-
// Attention Modules
|
|
19
|
-
import { scaledDotProductAttention, scaledDotProductAttentionOptimized, batchSequenceAttention, MultiHeadAttention, MultiHeadAttentionOptimized, FlashAttention, FlashAttentionOptimized, LinearAttention, HyperbolicAttention, createAttention, createAttentionOptimized, toFloat32Array, flatten2D, getBufferPool, benchmarkAttention, } from '../wrappers/attention-fallbacks.js';
|
|
20
|
-
// RuVector Backend
|
|
21
|
-
import { RuVectorBackend, Semaphore, BufferPool } from '../backends/ruvector/RuVectorBackend.js';
|
|
22
|
-
// Enhanced Embedding Service
|
|
23
|
-
import { EnhancedEmbeddingService } from '../controllers/EnhancedEmbeddingService.js';
|
|
24
|
-
// WASM Vector Search
|
|
25
|
-
import { WASMVectorSearch } from '../controllers/WASMVectorSearch.js';
|
|
26
|
-
// ============================================================================
|
|
27
|
-
// Test Utilities
|
|
28
|
-
// ============================================================================
|
|
29
|
-
/**
|
|
30
|
-
* Generate a random Float32Array vector
|
|
31
|
-
*/
|
|
32
|
-
function randomVector(dimension) {
|
|
33
|
-
const vec = new Float32Array(dimension);
|
|
34
|
-
for (let i = 0; i < dimension; i++) {
|
|
35
|
-
vec[i] = Math.random() * 2 - 1;
|
|
36
|
-
}
|
|
37
|
-
return vec;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Generate a normalized random vector
|
|
41
|
-
*/
|
|
42
|
-
function normalizedRandomVector(dimension) {
|
|
43
|
-
const vec = randomVector(dimension);
|
|
44
|
-
return normalizeVector(vec);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Compare two Float32Arrays for approximate equality
|
|
48
|
-
*/
|
|
49
|
-
function vectorsApproxEqual(a, b, tolerance = 1e-5) {
|
|
50
|
-
if (a.length !== b.length)
|
|
51
|
-
return false;
|
|
52
|
-
for (let i = 0; i < a.length; i++) {
|
|
53
|
-
if (Math.abs(a[i] - b[i]) > tolerance)
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Reference cosine similarity implementation for validation
|
|
60
|
-
*/
|
|
61
|
-
function referenceCosine(a, b) {
|
|
62
|
-
let dot = 0, normA = 0, normB = 0;
|
|
63
|
-
for (let i = 0; i < a.length; i++) {
|
|
64
|
-
dot += a[i] * b[i];
|
|
65
|
-
normA += a[i] * a[i];
|
|
66
|
-
normB += b[i] * b[i];
|
|
67
|
-
}
|
|
68
|
-
const denom = Math.sqrt(normA) * Math.sqrt(normB);
|
|
69
|
-
return denom === 0 ? 0 : dot / denom;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Reference Euclidean distance implementation
|
|
73
|
-
*/
|
|
74
|
-
function referenceEuclidean(a, b) {
|
|
75
|
-
let sum = 0;
|
|
76
|
-
for (let i = 0; i < a.length; i++) {
|
|
77
|
-
const diff = a[i] - b[i];
|
|
78
|
-
sum += diff * diff;
|
|
79
|
-
}
|
|
80
|
-
return Math.sqrt(sum);
|
|
81
|
-
}
|
|
82
|
-
// ============================================================================
|
|
83
|
-
// 1. SIMD Vector Operations Tests
|
|
84
|
-
// ============================================================================
|
|
85
|
-
describe('SIMD Vector Operations', () => {
|
|
86
|
-
describe('cosineSimilaritySIMD', () => {
|
|
87
|
-
it('should return 1.0 for identical vectors', () => {
|
|
88
|
-
const v = normalizedRandomVector(384);
|
|
89
|
-
const similarity = cosineSimilaritySIMD(v, v);
|
|
90
|
-
expect(similarity).toBeCloseTo(1.0, 5);
|
|
91
|
-
});
|
|
92
|
-
it('should return -1.0 for opposite vectors', () => {
|
|
93
|
-
const v1 = new Float32Array([1, 0, 0]);
|
|
94
|
-
const v2 = new Float32Array([-1, 0, 0]);
|
|
95
|
-
const similarity = cosineSimilaritySIMD(v1, v2);
|
|
96
|
-
expect(similarity).toBeCloseTo(-1.0, 5);
|
|
97
|
-
});
|
|
98
|
-
it('should return 0.0 for orthogonal vectors', () => {
|
|
99
|
-
const v1 = new Float32Array([1, 0, 0]);
|
|
100
|
-
const v2 = new Float32Array([0, 1, 0]);
|
|
101
|
-
const similarity = cosineSimilaritySIMD(v1, v2);
|
|
102
|
-
expect(similarity).toBeCloseTo(0.0, 5);
|
|
103
|
-
});
|
|
104
|
-
it('should handle zero vectors', () => {
|
|
105
|
-
const zero = new Float32Array([0, 0, 0]);
|
|
106
|
-
const v = new Float32Array([1, 2, 3]);
|
|
107
|
-
const similarity = cosineSimilaritySIMD(zero, v);
|
|
108
|
-
expect(similarity).toBe(0);
|
|
109
|
-
});
|
|
110
|
-
it('should handle empty vectors', () => {
|
|
111
|
-
const empty = new Float32Array(0);
|
|
112
|
-
const similarity = cosineSimilaritySIMD(empty, empty);
|
|
113
|
-
expect(similarity).toBe(0);
|
|
114
|
-
});
|
|
115
|
-
it('should throw error for mismatched dimensions', () => {
|
|
116
|
-
const v1 = new Float32Array([1, 2, 3]);
|
|
117
|
-
const v2 = new Float32Array([1, 2]);
|
|
118
|
-
expect(() => cosineSimilaritySIMD(v1, v2)).toThrow();
|
|
119
|
-
});
|
|
120
|
-
it('should match reference implementation for random vectors', () => {
|
|
121
|
-
for (let i = 0; i < 10; i++) {
|
|
122
|
-
const v1 = randomVector(384);
|
|
123
|
-
const v2 = randomVector(384);
|
|
124
|
-
const simd = cosineSimilaritySIMD(v1, v2);
|
|
125
|
-
const ref = referenceCosine(v1, v2);
|
|
126
|
-
expect(simd).toBeCloseTo(ref, 5);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
it('should handle vectors not divisible by 8', () => {
|
|
130
|
-
const v1 = randomVector(13);
|
|
131
|
-
const v2 = randomVector(13);
|
|
132
|
-
const simd = cosineSimilaritySIMD(v1, v2);
|
|
133
|
-
const ref = referenceCosine(v1, v2);
|
|
134
|
-
expect(simd).toBeCloseTo(ref, 5);
|
|
135
|
-
});
|
|
136
|
-
it('should be bounded between -1 and 1', () => {
|
|
137
|
-
for (let i = 0; i < 100; i++) {
|
|
138
|
-
const v1 = randomVector(384);
|
|
139
|
-
const v2 = randomVector(384);
|
|
140
|
-
const similarity = cosineSimilaritySIMD(v1, v2);
|
|
141
|
-
expect(similarity).toBeGreaterThanOrEqual(-1);
|
|
142
|
-
expect(similarity).toBeLessThanOrEqual(1);
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
describe('euclideanDistanceSIMD', () => {
|
|
147
|
-
it('should return 0 for identical vectors', () => {
|
|
148
|
-
const v = randomVector(384);
|
|
149
|
-
const distance = euclideanDistanceSIMD(v, v);
|
|
150
|
-
expect(distance).toBeCloseTo(0, 5);
|
|
151
|
-
});
|
|
152
|
-
it('should compute correct distance for unit vectors', () => {
|
|
153
|
-
const v1 = new Float32Array([1, 0, 0]);
|
|
154
|
-
const v2 = new Float32Array([0, 1, 0]);
|
|
155
|
-
const distance = euclideanDistanceSIMD(v1, v2);
|
|
156
|
-
expect(distance).toBeCloseTo(Math.sqrt(2), 5);
|
|
157
|
-
});
|
|
158
|
-
it('should match reference implementation', () => {
|
|
159
|
-
for (let i = 0; i < 10; i++) {
|
|
160
|
-
const v1 = randomVector(384);
|
|
161
|
-
const v2 = randomVector(384);
|
|
162
|
-
const simd = euclideanDistanceSIMD(v1, v2);
|
|
163
|
-
const ref = referenceEuclidean(v1, v2);
|
|
164
|
-
expect(simd).toBeCloseTo(ref, 5);
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
it('should handle empty vectors', () => {
|
|
168
|
-
const empty = new Float32Array(0);
|
|
169
|
-
const distance = euclideanDistanceSIMD(empty, empty);
|
|
170
|
-
expect(distance).toBe(0);
|
|
171
|
-
});
|
|
172
|
-
it('should always be non-negative', () => {
|
|
173
|
-
for (let i = 0; i < 100; i++) {
|
|
174
|
-
const v1 = randomVector(384);
|
|
175
|
-
const v2 = randomVector(384);
|
|
176
|
-
const distance = euclideanDistanceSIMD(v1, v2);
|
|
177
|
-
expect(distance).toBeGreaterThanOrEqual(0);
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
describe('batchCosineSimilarity', () => {
|
|
182
|
-
it('should process batch correctly', () => {
|
|
183
|
-
const query = normalizedRandomVector(64);
|
|
184
|
-
const vectors = Array.from({ length: 100 }, () => normalizedRandomVector(64));
|
|
185
|
-
const results = batchCosineSimilarity(query, vectors);
|
|
186
|
-
expect(results).toHaveLength(100);
|
|
187
|
-
expect(results[0].similarity).toBeGreaterThanOrEqual(results[results.length - 1].similarity);
|
|
188
|
-
});
|
|
189
|
-
it('should return top-k results when specified', () => {
|
|
190
|
-
const query = normalizedRandomVector(64);
|
|
191
|
-
const vectors = Array.from({ length: 100 }, () => normalizedRandomVector(64));
|
|
192
|
-
const results = batchCosineSimilarity(query, vectors, { topK: 10 });
|
|
193
|
-
expect(results).toHaveLength(10);
|
|
194
|
-
});
|
|
195
|
-
it('should filter by threshold', () => {
|
|
196
|
-
const query = new Float32Array([1, 0, 0]);
|
|
197
|
-
const vectors = [
|
|
198
|
-
new Float32Array([1, 0, 0]), // similarity = 1.0
|
|
199
|
-
new Float32Array([0.9, 0.1, 0]), // similarity ~ 0.99
|
|
200
|
-
new Float32Array([0, 1, 0]), // similarity = 0.0
|
|
201
|
-
new Float32Array([-1, 0, 0]), // similarity = -1.0
|
|
202
|
-
];
|
|
203
|
-
const results = batchCosineSimilarity(query, vectors, { threshold: 0.5 });
|
|
204
|
-
expect(results.length).toBe(2);
|
|
205
|
-
results.forEach(r => {
|
|
206
|
-
expect(r.similarity).toBeGreaterThanOrEqual(0.5);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
it('should preserve index information', () => {
|
|
210
|
-
const query = new Float32Array([1, 0, 0]);
|
|
211
|
-
const vectors = [
|
|
212
|
-
new Float32Array([0, 1, 0]), // index 0
|
|
213
|
-
new Float32Array([1, 0, 0]), // index 1, most similar
|
|
214
|
-
new Float32Array([0, 0, 1]), // index 2
|
|
215
|
-
];
|
|
216
|
-
const results = batchCosineSimilarity(query, vectors, { topK: 1 });
|
|
217
|
-
expect(results[0].index).toBe(1);
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
describe('SIMDVectorOps class', () => {
|
|
221
|
-
let ops;
|
|
222
|
-
beforeEach(() => {
|
|
223
|
-
ops = new SIMDVectorOps({
|
|
224
|
-
bufferPoolSize: 16,
|
|
225
|
-
defaultDimension: 384,
|
|
226
|
-
enableLogging: false,
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
afterEach(() => {
|
|
230
|
-
ops.clearBufferPool();
|
|
231
|
-
});
|
|
232
|
-
describe('buffer pool acquire/release', () => {
|
|
233
|
-
it('should acquire buffer of specified size', () => {
|
|
234
|
-
const buffer = ops.acquireBuffer(256);
|
|
235
|
-
expect(buffer).toBeInstanceOf(Float32Array);
|
|
236
|
-
expect(buffer.length).toBe(256);
|
|
237
|
-
});
|
|
238
|
-
it('should reuse released buffers', () => {
|
|
239
|
-
const buffer1 = ops.acquireBuffer(128);
|
|
240
|
-
ops.releaseBuffer(buffer1);
|
|
241
|
-
const buffer2 = ops.acquireBuffer(128);
|
|
242
|
-
// Buffer should be reused (same or similar object)
|
|
243
|
-
expect(buffer2.length).toBe(128);
|
|
244
|
-
});
|
|
245
|
-
it('should track statistics', () => {
|
|
246
|
-
ops.cosineSimilarity(randomVector(64), randomVector(64));
|
|
247
|
-
ops.euclideanDistance(randomVector(64), randomVector(64));
|
|
248
|
-
const stats = ops.getStats();
|
|
249
|
-
expect(stats.operationsCount).toBeGreaterThanOrEqual(2);
|
|
250
|
-
expect(stats.vectorsProcessed).toBeGreaterThanOrEqual(4);
|
|
251
|
-
});
|
|
252
|
-
it('should reset statistics', () => {
|
|
253
|
-
ops.cosineSimilarity(randomVector(64), randomVector(64));
|
|
254
|
-
ops.resetStats();
|
|
255
|
-
const stats = ops.getStats();
|
|
256
|
-
expect(stats.operationsCount).toBe(0);
|
|
257
|
-
expect(stats.vectorsProcessed).toBe(0);
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
it('should report SIMD detection status', () => {
|
|
261
|
-
const stats = ops.getStats();
|
|
262
|
-
expect(typeof stats.simdEnabled).toBe('boolean');
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
describe('SIMD detection', () => {
|
|
266
|
-
it('should return boolean for SIMD support', () => {
|
|
267
|
-
const supported = detectSIMDSupport();
|
|
268
|
-
expect(typeof supported).toBe('boolean');
|
|
269
|
-
});
|
|
270
|
-
it('should cache detection result', () => {
|
|
271
|
-
const result1 = detectSIMDSupport();
|
|
272
|
-
const result2 = detectSIMDSupport();
|
|
273
|
-
expect(result1).toBe(result2);
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
// ============================================================================
|
|
278
|
-
// 2. Vector Quantization Tests
|
|
279
|
-
// ============================================================================
|
|
280
|
-
describe('Vector Quantization', () => {
|
|
281
|
-
describe('8-bit quantization', () => {
|
|
282
|
-
it('should quantize and dequantize with minimal error', () => {
|
|
283
|
-
const original = new Float32Array([0.1, 0.5, 0.9, -0.3, 0.0]);
|
|
284
|
-
const quantized = quantize8bit(original);
|
|
285
|
-
expect(quantized.type).toBe('8bit');
|
|
286
|
-
expect(quantized.data.length).toBe(original.length);
|
|
287
|
-
expect(quantized.dimension).toBe(original.length);
|
|
288
|
-
const reconstructed = dequantize8bit(quantized.data, quantized.min, quantized.max);
|
|
289
|
-
expect(reconstructed.length).toBe(original.length);
|
|
290
|
-
const error = calculateQuantizationError(original, reconstructed);
|
|
291
|
-
expect(error.maxError).toBeLessThan(0.01);
|
|
292
|
-
});
|
|
293
|
-
it('should achieve approximately 4x compression', () => {
|
|
294
|
-
const vector = randomVector(384);
|
|
295
|
-
const stats = getQuantizationStats(vector, '8bit');
|
|
296
|
-
expect(stats.compressionRatio).toBeCloseTo(4, 0.5);
|
|
297
|
-
});
|
|
298
|
-
it('should handle uniform vectors', () => {
|
|
299
|
-
const vector = new Float32Array([0.5, 0.5, 0.5, 0.5]);
|
|
300
|
-
const quantized = quantize8bit(vector);
|
|
301
|
-
const reconstructed = dequantize8bit(quantized.data, quantized.min, quantized.max);
|
|
302
|
-
for (let i = 0; i < vector.length; i++) {
|
|
303
|
-
expect(reconstructed[i]).toBeCloseTo(0.5, 5);
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
it('should handle empty vectors', () => {
|
|
307
|
-
const empty = new Float32Array(0);
|
|
308
|
-
const quantized = quantize8bit(empty);
|
|
309
|
-
expect(quantized.data.length).toBe(0);
|
|
310
|
-
const reconstructed = dequantize8bit(quantized.data, 0, 0);
|
|
311
|
-
expect(reconstructed.length).toBe(0);
|
|
312
|
-
});
|
|
313
|
-
it('should preserve relative ordering of values', () => {
|
|
314
|
-
const vector = new Float32Array([0.1, 0.3, 0.5, 0.7, 0.9]);
|
|
315
|
-
const quantized = quantize8bit(vector);
|
|
316
|
-
const reconstructed = dequantize8bit(quantized.data, quantized.min, quantized.max);
|
|
317
|
-
for (let i = 1; i < reconstructed.length; i++) {
|
|
318
|
-
expect(reconstructed[i]).toBeGreaterThan(reconstructed[i - 1]);
|
|
319
|
-
}
|
|
320
|
-
});
|
|
321
|
-
});
|
|
322
|
-
describe('4-bit quantization', () => {
|
|
323
|
-
it('should quantize and dequantize with acceptable error', () => {
|
|
324
|
-
const original = new Float32Array([0.1, 0.5, 0.9, -0.3, 0.0, 0.7]);
|
|
325
|
-
const quantized = quantize4bit(original);
|
|
326
|
-
expect(quantized.type).toBe('4bit');
|
|
327
|
-
expect(quantized.data.length).toBe(Math.ceil(original.length / 2));
|
|
328
|
-
expect(quantized.dimension).toBe(original.length);
|
|
329
|
-
const reconstructed = dequantize4bit(quantized.data, quantized.min, quantized.max, quantized.dimension);
|
|
330
|
-
expect(reconstructed.length).toBe(original.length);
|
|
331
|
-
const error = calculateQuantizationError(original, reconstructed);
|
|
332
|
-
expect(error.maxError).toBeLessThan(0.15);
|
|
333
|
-
});
|
|
334
|
-
it('should achieve approximately 8x compression', () => {
|
|
335
|
-
const vector = randomVector(384);
|
|
336
|
-
const stats = getQuantizationStats(vector, '4bit');
|
|
337
|
-
expect(stats.compressionRatio).toBeCloseTo(8, 1);
|
|
338
|
-
});
|
|
339
|
-
it('should handle odd-length vectors', () => {
|
|
340
|
-
const vector = new Float32Array([0.1, 0.5, 0.9]);
|
|
341
|
-
const quantized = quantize4bit(vector);
|
|
342
|
-
expect(quantized.data.length).toBe(2);
|
|
343
|
-
const reconstructed = dequantize4bit(quantized.data, quantized.min, quantized.max, quantized.dimension);
|
|
344
|
-
expect(reconstructed.length).toBe(3);
|
|
345
|
-
});
|
|
346
|
-
});
|
|
347
|
-
describe('ProductQuantizer', () => {
|
|
348
|
-
const dimension = 64;
|
|
349
|
-
const numSubspaces = 8;
|
|
350
|
-
const numCentroids = 16;
|
|
351
|
-
let pq;
|
|
352
|
-
let trainingVectors;
|
|
353
|
-
beforeEach(async () => {
|
|
354
|
-
trainingVectors = Array.from({ length: 100 }, () => randomVector(dimension));
|
|
355
|
-
pq = new ProductQuantizer({
|
|
356
|
-
dimension,
|
|
357
|
-
numSubspaces,
|
|
358
|
-
numCentroids,
|
|
359
|
-
maxIterations: 10,
|
|
360
|
-
seed: 42,
|
|
361
|
-
});
|
|
362
|
-
await pq.train(trainingVectors);
|
|
363
|
-
});
|
|
364
|
-
it('should train successfully', () => {
|
|
365
|
-
expect(pq.isTrained()).toBe(true);
|
|
366
|
-
});
|
|
367
|
-
it('should encode and decode vectors', () => {
|
|
368
|
-
const vector = trainingVectors[0];
|
|
369
|
-
const encoded = pq.encode(vector);
|
|
370
|
-
expect(encoded.codes.length).toBe(numSubspaces);
|
|
371
|
-
expect(encoded.norm).toBeGreaterThan(0);
|
|
372
|
-
const decoded = pq.decode(encoded);
|
|
373
|
-
expect(decoded.length).toBe(dimension);
|
|
374
|
-
});
|
|
375
|
-
it('should compute asymmetric distance', () => {
|
|
376
|
-
const query = trainingVectors[0];
|
|
377
|
-
const encoded = pq.encode(trainingVectors[1]);
|
|
378
|
-
const distance = pq.asymmetricDistance(query, encoded);
|
|
379
|
-
expect(distance).toBeGreaterThanOrEqual(0);
|
|
380
|
-
});
|
|
381
|
-
it('should compute distance using precomputed tables', () => {
|
|
382
|
-
const query = trainingVectors[0];
|
|
383
|
-
const encoded = pq.encode(trainingVectors[1]);
|
|
384
|
-
const tables = pq.precomputeDistanceTables(query);
|
|
385
|
-
expect(tables.length).toBe(numSubspaces);
|
|
386
|
-
const tableDistance = pq.distanceFromTables(tables, encoded);
|
|
387
|
-
const directDistance = pq.asymmetricDistance(query, encoded);
|
|
388
|
-
expect(tableDistance).toBeCloseTo(directDistance, 5);
|
|
389
|
-
});
|
|
390
|
-
it('should export and import codebooks', () => {
|
|
391
|
-
const exported = pq.exportCodebooks();
|
|
392
|
-
expect(typeof exported).toBe('string');
|
|
393
|
-
const pq2 = new ProductQuantizer({
|
|
394
|
-
dimension,
|
|
395
|
-
numSubspaces,
|
|
396
|
-
numCentroids,
|
|
397
|
-
});
|
|
398
|
-
pq2.importCodebooks(exported);
|
|
399
|
-
expect(pq2.isTrained()).toBe(true);
|
|
400
|
-
const vector = trainingVectors[0];
|
|
401
|
-
const encoded1 = pq.encode(vector);
|
|
402
|
-
const encoded2 = pq2.encode(vector);
|
|
403
|
-
expect(Array.from(encoded1.codes)).toEqual(Array.from(encoded2.codes));
|
|
404
|
-
});
|
|
405
|
-
it('should report correct stats', () => {
|
|
406
|
-
const stats = pq.getStats();
|
|
407
|
-
expect(stats.trained).toBe(true);
|
|
408
|
-
expect(stats.dimension).toBe(dimension);
|
|
409
|
-
expect(stats.numSubspaces).toBe(numSubspaces);
|
|
410
|
-
expect(stats.subspaceDim).toBe(dimension / numSubspaces);
|
|
411
|
-
expect(stats.numCentroids).toBe(numCentroids);
|
|
412
|
-
expect(stats.compressionRatio).toBeGreaterThan(1);
|
|
413
|
-
expect(stats.codebookSizeBytes).toBeGreaterThan(0);
|
|
414
|
-
});
|
|
415
|
-
it('should throw on invalid dimension', () => {
|
|
416
|
-
expect(() => {
|
|
417
|
-
new ProductQuantizer({
|
|
418
|
-
dimension: 65,
|
|
419
|
-
numSubspaces: 8,
|
|
420
|
-
numCentroids: 256,
|
|
421
|
-
});
|
|
422
|
-
}).toThrow();
|
|
423
|
-
});
|
|
424
|
-
it('should throw on too many centroids', () => {
|
|
425
|
-
expect(() => {
|
|
426
|
-
new ProductQuantizer({
|
|
427
|
-
dimension: 64,
|
|
428
|
-
numSubspaces: 8,
|
|
429
|
-
numCentroids: 257,
|
|
430
|
-
});
|
|
431
|
-
}).toThrow();
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
describe('QuantizedVectorStore', () => {
|
|
435
|
-
const dimension = 64;
|
|
436
|
-
describe('Scalar 8-bit store', () => {
|
|
437
|
-
let store;
|
|
438
|
-
beforeEach(() => {
|
|
439
|
-
store = createScalar8BitStore(dimension);
|
|
440
|
-
});
|
|
441
|
-
it('should insert and search vectors', () => {
|
|
442
|
-
const v1 = normalizedRandomVector(dimension);
|
|
443
|
-
const v2 = normalizedRandomVector(dimension);
|
|
444
|
-
const v3 = normalizedRandomVector(dimension);
|
|
445
|
-
store.insert('v1', v1, { label: 'first' });
|
|
446
|
-
store.insert('v2', v2, { label: 'second' });
|
|
447
|
-
store.insert('v3', v3, { label: 'third' });
|
|
448
|
-
const results = store.search(v1, 3);
|
|
449
|
-
expect(results.length).toBe(3);
|
|
450
|
-
expect(results[0].id).toBe('v1');
|
|
451
|
-
expect(results[0].similarity).toBeGreaterThan(0.9);
|
|
452
|
-
expect(results[0].metadata?.label).toBe('first');
|
|
453
|
-
});
|
|
454
|
-
it('should remove vectors', () => {
|
|
455
|
-
store.insert('v1', randomVector(dimension));
|
|
456
|
-
store.insert('v2', randomVector(dimension));
|
|
457
|
-
expect(store.remove('v1')).toBe(true);
|
|
458
|
-
expect(store.remove('v1')).toBe(false);
|
|
459
|
-
const stats = store.getStats();
|
|
460
|
-
expect(stats.count).toBe(1);
|
|
461
|
-
});
|
|
462
|
-
it('should retrieve dequantized vectors', () => {
|
|
463
|
-
const original = randomVector(dimension);
|
|
464
|
-
store.insert('v1', original);
|
|
465
|
-
const retrieved = store.getVector('v1');
|
|
466
|
-
expect(retrieved).not.toBeNull();
|
|
467
|
-
expect(retrieved.length).toBe(dimension);
|
|
468
|
-
const error = calculateQuantizationError(original, retrieved);
|
|
469
|
-
expect(error.meanError).toBeLessThan(0.05);
|
|
470
|
-
});
|
|
471
|
-
it('should export and import store', () => {
|
|
472
|
-
store.insert('v1', randomVector(dimension), { tag: 'a' });
|
|
473
|
-
store.insert('v2', randomVector(dimension), { tag: 'b' });
|
|
474
|
-
const exported = store.export();
|
|
475
|
-
const store2 = createScalar8BitStore(dimension);
|
|
476
|
-
store2.import(exported);
|
|
477
|
-
const stats = store2.getStats();
|
|
478
|
-
expect(stats.count).toBe(2);
|
|
479
|
-
const v1 = store2.getVector('v1');
|
|
480
|
-
expect(v1).not.toBeNull();
|
|
481
|
-
});
|
|
482
|
-
it('should batch insert vectors', () => {
|
|
483
|
-
const items = Array.from({ length: 50 }, (_, i) => ({
|
|
484
|
-
id: `v${i}`,
|
|
485
|
-
vector: randomVector(dimension),
|
|
486
|
-
metadata: { index: i },
|
|
487
|
-
}));
|
|
488
|
-
store.insertBatch(items);
|
|
489
|
-
const stats = store.getStats();
|
|
490
|
-
expect(stats.count).toBe(50);
|
|
491
|
-
});
|
|
492
|
-
it('should report memory usage', () => {
|
|
493
|
-
for (let i = 0; i < 100; i++) {
|
|
494
|
-
store.insert(`v${i}`, randomVector(dimension));
|
|
495
|
-
}
|
|
496
|
-
const stats = store.getStats();
|
|
497
|
-
expect(stats.memoryUsageBytes).toBeGreaterThan(0);
|
|
498
|
-
expect(stats.memoryUsageBytes).toBeLessThan(dimension * 4 * 100);
|
|
499
|
-
});
|
|
500
|
-
});
|
|
501
|
-
describe('Scalar 4-bit store', () => {
|
|
502
|
-
it('should achieve higher compression than 8-bit', () => {
|
|
503
|
-
const store4bit = createScalar4BitStore(dimension);
|
|
504
|
-
const store8bit = createScalar8BitStore(dimension);
|
|
505
|
-
for (let i = 0; i < 100; i++) {
|
|
506
|
-
const vec = randomVector(dimension);
|
|
507
|
-
store4bit.insert(`v${i}`, vec);
|
|
508
|
-
store8bit.insert(`v${i}`, vec);
|
|
509
|
-
}
|
|
510
|
-
const stats4bit = store4bit.getStats();
|
|
511
|
-
const stats8bit = store8bit.getStats();
|
|
512
|
-
expect(stats4bit.compressionRatio).toBeGreaterThan(stats8bit.compressionRatio);
|
|
513
|
-
});
|
|
514
|
-
it('should still find similar vectors', () => {
|
|
515
|
-
const store = createScalar4BitStore(dimension);
|
|
516
|
-
const baseVector = normalizedRandomVector(dimension);
|
|
517
|
-
const similarVector = new Float32Array(baseVector);
|
|
518
|
-
for (let i = 0; i < dimension; i++) {
|
|
519
|
-
similarVector[i] += (Math.random() - 0.5) * 0.1;
|
|
520
|
-
}
|
|
521
|
-
store.insert('base', baseVector);
|
|
522
|
-
store.insert('similar', normalizeVector(similarVector));
|
|
523
|
-
store.insert('random', normalizedRandomVector(dimension));
|
|
524
|
-
const results = store.search(baseVector, 2);
|
|
525
|
-
expect(results.length).toBe(2);
|
|
526
|
-
expect(results[0].id).toBe('base');
|
|
527
|
-
expect(results[1].id).toBe('similar');
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
describe('Product Quantized store', () => {
|
|
531
|
-
it('should require training before insertion', () => {
|
|
532
|
-
const store = createProductQuantizedStore(dimension, 8, 16);
|
|
533
|
-
expect(store.isReady()).toBe(false);
|
|
534
|
-
expect(() => {
|
|
535
|
-
store.insert('v1', randomVector(dimension));
|
|
536
|
-
}).toThrow();
|
|
537
|
-
});
|
|
538
|
-
it('should work after training', async () => {
|
|
539
|
-
const store = createProductQuantizedStore(dimension, 8, 16);
|
|
540
|
-
const trainingData = Array.from({ length: 50 }, () => normalizedRandomVector(dimension));
|
|
541
|
-
await store.train(trainingData);
|
|
542
|
-
expect(store.isReady()).toBe(true);
|
|
543
|
-
store.insert('v1', trainingData[0], { index: 0 });
|
|
544
|
-
store.insert('v2', trainingData[1], { index: 1 });
|
|
545
|
-
const results = store.search(trainingData[0], 2);
|
|
546
|
-
expect(results.length).toBe(2);
|
|
547
|
-
expect(results[0].id).toBe('v1');
|
|
548
|
-
});
|
|
549
|
-
it('should achieve high compression', async () => {
|
|
550
|
-
const store = createProductQuantizedStore(dimension, 8, 16);
|
|
551
|
-
const trainingData = Array.from({ length: 50 }, () => randomVector(dimension));
|
|
552
|
-
await store.train(trainingData);
|
|
553
|
-
for (let i = 0; i < 50; i++) {
|
|
554
|
-
store.insert(`v${i}`, trainingData[i]);
|
|
555
|
-
}
|
|
556
|
-
const stats = store.getStats();
|
|
557
|
-
expect(stats.compressionRatio).toBeGreaterThan(4);
|
|
558
|
-
});
|
|
559
|
-
});
|
|
560
|
-
});
|
|
561
|
-
describe('Quantization accuracy measurement', () => {
|
|
562
|
-
it('should track mean and max error', () => {
|
|
563
|
-
const original = randomVector(384);
|
|
564
|
-
const quantized = quantize8bit(original);
|
|
565
|
-
const reconstructed = dequantize8bit(quantized.data, quantized.min, quantized.max);
|
|
566
|
-
const error = calculateQuantizationError(original, reconstructed);
|
|
567
|
-
expect(error.meanError).toBeGreaterThanOrEqual(0);
|
|
568
|
-
expect(error.maxError).toBeGreaterThanOrEqual(error.meanError);
|
|
569
|
-
expect(error.mse).toBeGreaterThanOrEqual(0);
|
|
570
|
-
});
|
|
571
|
-
it('should throw for mismatched lengths', () => {
|
|
572
|
-
const v1 = new Float32Array([1, 2, 3]);
|
|
573
|
-
const v2 = new Float32Array([1, 2]);
|
|
574
|
-
expect(() => calculateQuantizationError(v1, v2)).toThrow();
|
|
575
|
-
});
|
|
576
|
-
});
|
|
577
|
-
});
|
|
578
|
-
// ============================================================================
|
|
579
|
-
// 3. RuVectorBackend Enhancement Tests
|
|
580
|
-
// ============================================================================
|
|
581
|
-
describe('RuVectorBackend Enhancements', () => {
|
|
582
|
-
describe('Semaphore', () => {
|
|
583
|
-
it('should limit concurrent operations', async () => {
|
|
584
|
-
const semaphore = new Semaphore(2);
|
|
585
|
-
let concurrent = 0;
|
|
586
|
-
let maxConcurrent = 0;
|
|
587
|
-
const tasks = Array.from({ length: 10 }, async () => {
|
|
588
|
-
await semaphore.acquire();
|
|
589
|
-
concurrent++;
|
|
590
|
-
maxConcurrent = Math.max(maxConcurrent, concurrent);
|
|
591
|
-
await new Promise(resolve => setTimeout(resolve, 10));
|
|
592
|
-
concurrent--;
|
|
593
|
-
semaphore.release();
|
|
594
|
-
});
|
|
595
|
-
await Promise.all(tasks);
|
|
596
|
-
expect(maxConcurrent).toBeLessThanOrEqual(2);
|
|
597
|
-
});
|
|
598
|
-
it('should track available permits', () => {
|
|
599
|
-
const semaphore = new Semaphore(3);
|
|
600
|
-
expect(semaphore.available).toBe(3);
|
|
601
|
-
semaphore.acquire();
|
|
602
|
-
expect(semaphore.available).toBe(2);
|
|
603
|
-
semaphore.release();
|
|
604
|
-
expect(semaphore.available).toBe(3);
|
|
605
|
-
});
|
|
606
|
-
});
|
|
607
|
-
describe('BufferPool', () => {
|
|
608
|
-
let pool;
|
|
609
|
-
beforeEach(() => {
|
|
610
|
-
pool = new BufferPool(10);
|
|
611
|
-
});
|
|
612
|
-
afterEach(() => {
|
|
613
|
-
pool.clear();
|
|
614
|
-
});
|
|
615
|
-
it('should acquire new buffers', () => {
|
|
616
|
-
const buffer = pool.acquire(256);
|
|
617
|
-
expect(buffer).toBeInstanceOf(Float32Array);
|
|
618
|
-
expect(buffer.length).toBe(256);
|
|
619
|
-
});
|
|
620
|
-
it('should reuse released buffers', () => {
|
|
621
|
-
const buffer1 = pool.acquire(128);
|
|
622
|
-
buffer1[0] = 42;
|
|
623
|
-
pool.release(buffer1);
|
|
624
|
-
const buffer2 = pool.acquire(128);
|
|
625
|
-
expect(buffer2[0]).toBe(0); // Buffer should be cleared
|
|
626
|
-
});
|
|
627
|
-
it('should maintain separate pools for different sizes', () => {
|
|
628
|
-
const buf128 = pool.acquire(128);
|
|
629
|
-
const buf256 = pool.acquire(256);
|
|
630
|
-
pool.release(buf128);
|
|
631
|
-
pool.release(buf256);
|
|
632
|
-
const stats = pool.getStats();
|
|
633
|
-
expect(stats.totalBuffers).toBe(2);
|
|
634
|
-
});
|
|
635
|
-
it('should report statistics', () => {
|
|
636
|
-
pool.acquire(64);
|
|
637
|
-
pool.acquire(64);
|
|
638
|
-
const buf = pool.acquire(128);
|
|
639
|
-
pool.release(buf);
|
|
640
|
-
const stats = pool.getStats();
|
|
641
|
-
expect(stats.totalBuffers).toBeGreaterThanOrEqual(1);
|
|
642
|
-
expect(stats.totalMemory).toBeGreaterThanOrEqual(128 * 4);
|
|
643
|
-
});
|
|
644
|
-
});
|
|
645
|
-
describe('Adaptive parameters', () => {
|
|
646
|
-
it('should return small dataset params for < 1000 vectors', () => {
|
|
647
|
-
const params = RuVectorBackend.getRecommendedParams(500);
|
|
648
|
-
expect(params.M).toBe(8);
|
|
649
|
-
expect(params.efConstruction).toBe(100);
|
|
650
|
-
expect(params.efSearch).toBe(50);
|
|
651
|
-
});
|
|
652
|
-
it('should return medium dataset params for 1000-100000 vectors', () => {
|
|
653
|
-
const params = RuVectorBackend.getRecommendedParams(50000);
|
|
654
|
-
expect(params.M).toBe(16);
|
|
655
|
-
expect(params.efConstruction).toBe(200);
|
|
656
|
-
expect(params.efSearch).toBe(100);
|
|
657
|
-
});
|
|
658
|
-
it('should return large dataset params for > 100000 vectors', () => {
|
|
659
|
-
const params = RuVectorBackend.getRecommendedParams(500000);
|
|
660
|
-
expect(params.M).toBe(32);
|
|
661
|
-
expect(params.efConstruction).toBe(400);
|
|
662
|
-
expect(params.efSearch).toBe(200);
|
|
663
|
-
});
|
|
664
|
-
});
|
|
665
|
-
});
|
|
666
|
-
// ============================================================================
|
|
667
|
-
// 4. Enhanced Embedding Service Tests
|
|
668
|
-
// ============================================================================
|
|
669
|
-
describe('EnhancedEmbeddingService', () => {
|
|
670
|
-
let service;
|
|
671
|
-
beforeEach(async () => {
|
|
672
|
-
service = new EnhancedEmbeddingService({
|
|
673
|
-
model: 'mock-model',
|
|
674
|
-
dimension: 384,
|
|
675
|
-
provider: 'local',
|
|
676
|
-
enableWASM: true,
|
|
677
|
-
enableBatchProcessing: true,
|
|
678
|
-
batchSize: 50,
|
|
679
|
-
});
|
|
680
|
-
await service.initialize();
|
|
681
|
-
});
|
|
682
|
-
describe('Batch embedding', () => {
|
|
683
|
-
it('should embed batch of texts', async () => {
|
|
684
|
-
const texts = ['hello', 'world', 'test', 'embedding', 'service'];
|
|
685
|
-
const embeddings = await service.embedBatch(texts);
|
|
686
|
-
expect(embeddings).toHaveLength(5);
|
|
687
|
-
embeddings.forEach(emb => {
|
|
688
|
-
expect(emb).toBeInstanceOf(Float32Array);
|
|
689
|
-
expect(emb.length).toBe(384);
|
|
690
|
-
});
|
|
691
|
-
});
|
|
692
|
-
it('should handle large batches', async () => {
|
|
693
|
-
const texts = Array.from({ length: 200 }, (_, i) => `text ${i}`);
|
|
694
|
-
const embeddings = await service.embedBatch(texts);
|
|
695
|
-
expect(embeddings).toHaveLength(200);
|
|
696
|
-
});
|
|
697
|
-
it('should deduplicate identical texts', async () => {
|
|
698
|
-
const texts = ['same', 'same', 'same', 'different'];
|
|
699
|
-
const embeddings = await service.embedBatch(texts);
|
|
700
|
-
expect(embeddings).toHaveLength(4);
|
|
701
|
-
expect(vectorsApproxEqual(embeddings[0], embeddings[1])).toBe(true);
|
|
702
|
-
expect(vectorsApproxEqual(embeddings[0], embeddings[2])).toBe(true);
|
|
703
|
-
});
|
|
704
|
-
});
|
|
705
|
-
describe('Similarity calculation', () => {
|
|
706
|
-
it('should calculate text similarity', async () => {
|
|
707
|
-
const similarity = await service.similarity('hello world', 'hello world');
|
|
708
|
-
expect(similarity).toBeCloseTo(1.0, 5);
|
|
709
|
-
});
|
|
710
|
-
it('should find most similar texts', async () => {
|
|
711
|
-
const corpus = [
|
|
712
|
-
'machine learning',
|
|
713
|
-
'artificial intelligence',
|
|
714
|
-
'deep learning',
|
|
715
|
-
'cooking recipes',
|
|
716
|
-
'neural networks',
|
|
717
|
-
];
|
|
718
|
-
const results = await service.findMostSimilar('AI and ML', corpus, 3);
|
|
719
|
-
expect(results).toHaveLength(3);
|
|
720
|
-
expect(results[0]).toHaveProperty('text');
|
|
721
|
-
expect(results[0]).toHaveProperty('similarity');
|
|
722
|
-
expect(results[0]).toHaveProperty('index');
|
|
723
|
-
results.forEach(result => {
|
|
724
|
-
expect(result.similarity).toBeGreaterThanOrEqual(-1);
|
|
725
|
-
expect(result.similarity).toBeLessThanOrEqual(1);
|
|
726
|
-
expect(corpus).toContain(result.text);
|
|
727
|
-
});
|
|
728
|
-
});
|
|
729
|
-
});
|
|
730
|
-
describe('Statistics', () => {
|
|
731
|
-
it('should provide service statistics', () => {
|
|
732
|
-
const stats = service.getStats();
|
|
733
|
-
expect(stats).toHaveProperty('cacheSize');
|
|
734
|
-
expect(stats).toHaveProperty('wasmEnabled');
|
|
735
|
-
expect(stats).toHaveProperty('simdEnabled');
|
|
736
|
-
expect(typeof stats.cacheSize).toBe('number');
|
|
737
|
-
});
|
|
738
|
-
});
|
|
739
|
-
describe('LRU cache behavior', () => {
|
|
740
|
-
it('should cache embeddings', async () => {
|
|
741
|
-
await service.embed('cached text');
|
|
742
|
-
await service.embed('cached text');
|
|
743
|
-
const stats = service.getStats();
|
|
744
|
-
expect(stats.cacheSize).toBeGreaterThanOrEqual(1);
|
|
745
|
-
});
|
|
746
|
-
});
|
|
747
|
-
});
|
|
748
|
-
// ============================================================================
|
|
749
|
-
// 5. Attention Optimized Tests
|
|
750
|
-
// ============================================================================
|
|
751
|
-
describe('Attention Optimized', () => {
|
|
752
|
-
describe('scaledDotProductAttention', () => {
|
|
753
|
-
it('should compute attention correctly', () => {
|
|
754
|
-
const query = [1, 0, 0, 0];
|
|
755
|
-
const key = [1, 0, 0, 0];
|
|
756
|
-
const value = [1, 2, 3, 4];
|
|
757
|
-
const { output, weights } = scaledDotProductAttention(query, key, value);
|
|
758
|
-
expect(output).toHaveLength(4);
|
|
759
|
-
expect(weights).toHaveLength(1);
|
|
760
|
-
});
|
|
761
|
-
it('should apply mask', () => {
|
|
762
|
-
const query = [1, 0, 0, 0];
|
|
763
|
-
const key = [1, 0, 0, 0];
|
|
764
|
-
const value = [1, 2, 3, 4];
|
|
765
|
-
const mask = [0];
|
|
766
|
-
const { weights } = scaledDotProductAttention(query, key, value, mask);
|
|
767
|
-
expect(weights[0]).toBe(0);
|
|
768
|
-
});
|
|
769
|
-
});
|
|
770
|
-
describe('scaledDotProductAttentionOptimized', () => {
|
|
771
|
-
it('should compute attention with TypedArrays', () => {
|
|
772
|
-
const query = new Float32Array([1, 0, 0, 0]);
|
|
773
|
-
const key = new Float32Array([1, 0, 0, 0]);
|
|
774
|
-
const value = new Float32Array([1, 2, 3, 4]);
|
|
775
|
-
const { output, weights } = scaledDotProductAttentionOptimized(query, key, value);
|
|
776
|
-
expect(output).toBeInstanceOf(Float32Array);
|
|
777
|
-
expect(output.length).toBe(4);
|
|
778
|
-
expect(weights).toBeInstanceOf(Float32Array);
|
|
779
|
-
});
|
|
780
|
-
it('should match original implementation', () => {
|
|
781
|
-
const query = new Float32Array([0.5, 0.3, 0.2, 0.1]);
|
|
782
|
-
const key = new Float32Array([0.4, 0.3, 0.2, 0.1]);
|
|
783
|
-
const value = new Float32Array([1, 2, 3, 4]);
|
|
784
|
-
const optimized = scaledDotProductAttentionOptimized(query, key, value);
|
|
785
|
-
const original = scaledDotProductAttention(Array.from(query), Array.from(key), Array.from(value));
|
|
786
|
-
for (let i = 0; i < value.length; i++) {
|
|
787
|
-
expect(optimized.output[i]).toBeCloseTo(original.output[i], 4);
|
|
788
|
-
}
|
|
789
|
-
});
|
|
790
|
-
});
|
|
791
|
-
describe('MultiHeadAttention vs MultiHeadAttentionOptimized', () => {
|
|
792
|
-
const config = { hiddenDim: 64, numHeads: 8 };
|
|
793
|
-
it('should produce outputs of same dimensions', () => {
|
|
794
|
-
const mha = new MultiHeadAttention(config);
|
|
795
|
-
const mhaOpt = new MultiHeadAttentionOptimized(config);
|
|
796
|
-
const query = Array.from({ length: 64 }, () => Math.random());
|
|
797
|
-
const key = Array.from({ length: 64 }, () => Math.random());
|
|
798
|
-
const value = Array.from({ length: 64 }, () => Math.random());
|
|
799
|
-
const queryF32 = new Float32Array(query);
|
|
800
|
-
const keyF32 = new Float32Array(key);
|
|
801
|
-
const valueF32 = new Float32Array(value);
|
|
802
|
-
const original = mha.forward(query, key, value);
|
|
803
|
-
const optimized = mhaOpt.forward(queryF32, keyF32, valueF32);
|
|
804
|
-
expect(original.output.length).toBe(optimized.output.length);
|
|
805
|
-
expect(original.attentionWeights.length).toBe(optimized.attentionWeights.length);
|
|
806
|
-
});
|
|
807
|
-
it('should support batch processing', () => {
|
|
808
|
-
const mhaOpt = new MultiHeadAttentionOptimized(config);
|
|
809
|
-
const batchSize = 4;
|
|
810
|
-
const queries = Array.from({ length: batchSize }, () => randomVector(64));
|
|
811
|
-
const keys = Array.from({ length: batchSize }, () => randomVector(64));
|
|
812
|
-
const values = Array.from({ length: batchSize }, () => randomVector(64));
|
|
813
|
-
const { outputs, attentionWeights } = mhaOpt.batchForward(queries, keys, values);
|
|
814
|
-
expect(outputs).toHaveLength(batchSize);
|
|
815
|
-
expect(attentionWeights).toHaveLength(batchSize);
|
|
816
|
-
});
|
|
817
|
-
it('should allow weight get/set', () => {
|
|
818
|
-
const mhaOpt = new MultiHeadAttentionOptimized(config);
|
|
819
|
-
const weights = mhaOpt.getWeights();
|
|
820
|
-
expect(weights.query).toBeInstanceOf(Float32Array);
|
|
821
|
-
expect(weights.key).toBeInstanceOf(Float32Array);
|
|
822
|
-
expect(weights.value).toBeInstanceOf(Float32Array);
|
|
823
|
-
expect(weights.output).toBeInstanceOf(Float32Array);
|
|
824
|
-
// Modify and set back
|
|
825
|
-
weights.query[0] = 999;
|
|
826
|
-
mhaOpt.setWeights(weights);
|
|
827
|
-
const retrieved = mhaOpt.getWeights();
|
|
828
|
-
expect(retrieved.query[0]).toBe(999);
|
|
829
|
-
});
|
|
830
|
-
});
|
|
831
|
-
describe('FlashAttention vs FlashAttentionOptimized', () => {
|
|
832
|
-
const config = { hiddenDim: 64 };
|
|
833
|
-
it('should compute attention over sequences', () => {
|
|
834
|
-
const flash = new FlashAttention(config);
|
|
835
|
-
const seqLen = 4;
|
|
836
|
-
const query = Array.from({ length: seqLen }, () => Array.from({ length: 64 }, () => Math.random()));
|
|
837
|
-
const key = Array.from({ length: seqLen }, () => Array.from({ length: 64 }, () => Math.random()));
|
|
838
|
-
const value = Array.from({ length: seqLen }, () => Array.from({ length: 64 }, () => Math.random()));
|
|
839
|
-
const { output, attentionScores } = flash.forward(query, key, value, 8);
|
|
840
|
-
expect(output).toHaveLength(seqLen);
|
|
841
|
-
expect(attentionScores).toHaveLength(seqLen);
|
|
842
|
-
});
|
|
843
|
-
it('should match dimensions in optimized version', () => {
|
|
844
|
-
const flashOpt = new FlashAttentionOptimized({
|
|
845
|
-
hiddenDim: 64,
|
|
846
|
-
blockSizeQ: 2,
|
|
847
|
-
blockSizeKV: 4,
|
|
848
|
-
});
|
|
849
|
-
const seqLen = 8;
|
|
850
|
-
const dim = 64;
|
|
851
|
-
const query = randomVector(seqLen * dim);
|
|
852
|
-
const key = randomVector(seqLen * dim);
|
|
853
|
-
const value = randomVector(seqLen * dim);
|
|
854
|
-
const { output, attentionScores } = flashOpt.forward(query, key, value, seqLen, dim, 8);
|
|
855
|
-
expect(output.length).toBe(seqLen * dim);
|
|
856
|
-
expect(attentionScores.length).toBe(seqLen * seqLen);
|
|
857
|
-
flashOpt.releaseBuffer(output);
|
|
858
|
-
flashOpt.releaseBuffer(attentionScores);
|
|
859
|
-
});
|
|
860
|
-
it('should support causal masking', () => {
|
|
861
|
-
const flashOpt = new FlashAttentionOptimized({
|
|
862
|
-
hiddenDim: 64,
|
|
863
|
-
causal: true,
|
|
864
|
-
});
|
|
865
|
-
const seqLen = 4;
|
|
866
|
-
const dim = 64;
|
|
867
|
-
const query = randomVector(seqLen * dim);
|
|
868
|
-
const key = randomVector(seqLen * dim);
|
|
869
|
-
const value = randomVector(seqLen * dim);
|
|
870
|
-
const { attentionScores } = flashOpt.forward(query, key, value, seqLen, dim, 8);
|
|
871
|
-
// The implementation stores raw scores (pre-softmax), so masked positions
|
|
872
|
-
// should have very large negative values (approximately -1e9)
|
|
873
|
-
// Check upper triangle has been masked (large negative values)
|
|
874
|
-
for (let i = 0; i < seqLen; i++) {
|
|
875
|
-
for (let j = i + 1; j < seqLen; j++) {
|
|
876
|
-
// Masked positions should be -1e9 (or very close to it)
|
|
877
|
-
expect(attentionScores[i * seqLen + j]).toBeLessThan(-1e8);
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
// Also verify lower triangle (including diagonal) is NOT masked
|
|
881
|
-
// These should be normal attention scores, not large negative values
|
|
882
|
-
for (let i = 0; i < seqLen; i++) {
|
|
883
|
-
for (let j = 0; j <= i; j++) {
|
|
884
|
-
expect(attentionScores[i * seqLen + j]).toBeGreaterThan(-100);
|
|
885
|
-
}
|
|
886
|
-
}
|
|
887
|
-
});
|
|
888
|
-
it('should support batch processing', () => {
|
|
889
|
-
const flashOpt = new FlashAttentionOptimized({ hiddenDim: 32 });
|
|
890
|
-
const batchSize = 3;
|
|
891
|
-
const seqLens = [4, 4, 4];
|
|
892
|
-
const dim = 32;
|
|
893
|
-
const queries = seqLens.map(len => randomVector(len * dim));
|
|
894
|
-
const keys = seqLens.map(len => randomVector(len * dim));
|
|
895
|
-
const values = seqLens.map(len => randomVector(len * dim));
|
|
896
|
-
const { outputs, attentionScores } = flashOpt.batchForward(queries, keys, values, seqLens, dim, 4);
|
|
897
|
-
expect(outputs).toHaveLength(batchSize);
|
|
898
|
-
expect(attentionScores).toHaveLength(batchSize);
|
|
899
|
-
});
|
|
900
|
-
});
|
|
901
|
-
describe('batchSequenceAttention', () => {
|
|
902
|
-
it('should process sequence attention', () => {
|
|
903
|
-
const seqLen = 4;
|
|
904
|
-
const dim = 8;
|
|
905
|
-
const queries = randomVector(seqLen * dim);
|
|
906
|
-
const keys = randomVector(seqLen * dim);
|
|
907
|
-
const values = randomVector(seqLen * dim);
|
|
908
|
-
const { output, weights } = batchSequenceAttention(queries, keys, values, seqLen, dim);
|
|
909
|
-
expect(output.length).toBe(seqLen * dim);
|
|
910
|
-
expect(weights.length).toBe(seqLen * seqLen);
|
|
911
|
-
});
|
|
912
|
-
it('should apply mask correctly', () => {
|
|
913
|
-
const seqLen = 2;
|
|
914
|
-
const dim = 4;
|
|
915
|
-
const queries = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0]);
|
|
916
|
-
const keys = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0]);
|
|
917
|
-
const values = new Float32Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
918
|
-
const mask = new Float32Array([1, 0, 1, 1]); // Block attention from pos 0 to pos 1
|
|
919
|
-
const { weights } = batchSequenceAttention(queries, keys, values, seqLen, dim, mask);
|
|
920
|
-
// Weight from position 0 to position 1 should be very small
|
|
921
|
-
expect(weights[1]).toBeLessThan(0.01);
|
|
922
|
-
});
|
|
923
|
-
});
|
|
924
|
-
describe('LinearAttention', () => {
|
|
925
|
-
it('should compute linear attention', () => {
|
|
926
|
-
const linear = new LinearAttention({ hiddenDim: 8 });
|
|
927
|
-
const query = [[1, 2, 3, 4, 5, 6, 7, 8]];
|
|
928
|
-
const key = [[1, 2, 3, 4, 5, 6, 7, 8]];
|
|
929
|
-
const value = [[1, 2, 3, 4, 5, 6, 7, 8]];
|
|
930
|
-
const { output } = linear.forward(query, key, value);
|
|
931
|
-
expect(output).toHaveLength(1);
|
|
932
|
-
expect(output[0]).toHaveLength(8);
|
|
933
|
-
});
|
|
934
|
-
});
|
|
935
|
-
describe('HyperbolicAttention', () => {
|
|
936
|
-
it('should compute hyperbolic attention', () => {
|
|
937
|
-
const hyper = new HyperbolicAttention({ hiddenDim: 4 });
|
|
938
|
-
const query = [0.1, 0.2, 0.3, 0.4];
|
|
939
|
-
const key = [0.15, 0.25, 0.35, 0.45];
|
|
940
|
-
const value = [1, 2, 3, 4];
|
|
941
|
-
const { output, distance } = hyper.forward(query, key, value);
|
|
942
|
-
expect(output).toHaveLength(4);
|
|
943
|
-
expect(distance).toBeGreaterThanOrEqual(0);
|
|
944
|
-
});
|
|
945
|
-
});
|
|
946
|
-
describe('Factory functions', () => {
|
|
947
|
-
it('should create attention modules', () => {
|
|
948
|
-
const config = { hiddenDim: 64 };
|
|
949
|
-
const mha = createAttention('multi-head', config);
|
|
950
|
-
expect(mha).toBeInstanceOf(MultiHeadAttention);
|
|
951
|
-
const flash = createAttention('flash', config);
|
|
952
|
-
expect(flash).toBeInstanceOf(FlashAttention);
|
|
953
|
-
const linear = createAttention('linear', config);
|
|
954
|
-
expect(linear).toBeInstanceOf(LinearAttention);
|
|
955
|
-
const hyper = createAttention('hyperbolic', config);
|
|
956
|
-
expect(hyper).toBeInstanceOf(HyperbolicAttention);
|
|
957
|
-
});
|
|
958
|
-
it('should create optimized attention modules', () => {
|
|
959
|
-
const config = { hiddenDim: 64 };
|
|
960
|
-
const mhaOpt = createAttentionOptimized('multi-head', config);
|
|
961
|
-
expect(mhaOpt).toBeInstanceOf(MultiHeadAttentionOptimized);
|
|
962
|
-
const flashOpt = createAttentionOptimized('flash', config);
|
|
963
|
-
expect(flashOpt).toBeInstanceOf(FlashAttentionOptimized);
|
|
964
|
-
});
|
|
965
|
-
});
|
|
966
|
-
describe('Buffer pool', () => {
|
|
967
|
-
it('should provide global buffer pool access', () => {
|
|
968
|
-
const pool = getBufferPool();
|
|
969
|
-
const buffer = pool.acquire(64);
|
|
970
|
-
expect(buffer).toBeInstanceOf(Float32Array);
|
|
971
|
-
expect(buffer.length).toBe(64);
|
|
972
|
-
pool.release(buffer);
|
|
973
|
-
});
|
|
974
|
-
});
|
|
975
|
-
describe('Utility functions', () => {
|
|
976
|
-
it('should convert arrays to Float32Array', () => {
|
|
977
|
-
const arr = [1, 2, 3, 4];
|
|
978
|
-
const f32 = toFloat32Array(arr);
|
|
979
|
-
expect(f32).toBeInstanceOf(Float32Array);
|
|
980
|
-
expect(Array.from(f32)).toEqual(arr);
|
|
981
|
-
});
|
|
982
|
-
it('should flatten 2D arrays', () => {
|
|
983
|
-
const arr2d = [[1, 2], [3, 4], [5, 6]];
|
|
984
|
-
const flat = flatten2D(arr2d);
|
|
985
|
-
expect(flat).toBeInstanceOf(Float32Array);
|
|
986
|
-
expect(Array.from(flat)).toEqual([1, 2, 3, 4, 5, 6]);
|
|
987
|
-
});
|
|
988
|
-
});
|
|
989
|
-
});
|
|
990
|
-
// ============================================================================
|
|
991
|
-
// 6. WASM Vector Search Tests
|
|
992
|
-
// ============================================================================
|
|
993
|
-
describe('WASMVectorSearch', () => {
|
|
994
|
-
let mockDb;
|
|
995
|
-
let wasmSearch;
|
|
996
|
-
beforeEach(() => {
|
|
997
|
-
mockDb = {
|
|
998
|
-
prepare: () => ({
|
|
999
|
-
all: () => [],
|
|
1000
|
-
get: () => null,
|
|
1001
|
-
run: () => ({ lastInsertRowid: 1, changes: 1 }),
|
|
1002
|
-
}),
|
|
1003
|
-
exec: () => { },
|
|
1004
|
-
};
|
|
1005
|
-
wasmSearch = new WASMVectorSearch(mockDb);
|
|
1006
|
-
});
|
|
1007
|
-
describe('Cosine Similarity', () => {
|
|
1008
|
-
it('should calculate correctly for identical vectors', () => {
|
|
1009
|
-
const v = new Float32Array([1, 0, 0]);
|
|
1010
|
-
const similarity = wasmSearch.cosineSimilarity(v, v);
|
|
1011
|
-
expect(similarity).toBeCloseTo(1.0, 5);
|
|
1012
|
-
});
|
|
1013
|
-
it('should handle orthogonal vectors', () => {
|
|
1014
|
-
const v1 = new Float32Array([1, 0, 0]);
|
|
1015
|
-
const v2 = new Float32Array([0, 1, 0]);
|
|
1016
|
-
const similarity = wasmSearch.cosineSimilarity(v1, v2);
|
|
1017
|
-
expect(similarity).toBeCloseTo(0.0, 5);
|
|
1018
|
-
});
|
|
1019
|
-
it('should throw on mismatched dimensions', () => {
|
|
1020
|
-
const v1 = new Float32Array([1, 0, 0]);
|
|
1021
|
-
const v2 = new Float32Array([1, 0]);
|
|
1022
|
-
expect(() => wasmSearch.cosineSimilarity(v1, v2)).toThrow();
|
|
1023
|
-
});
|
|
1024
|
-
});
|
|
1025
|
-
describe('Batch Operations', () => {
|
|
1026
|
-
it('should calculate batch similarities', () => {
|
|
1027
|
-
const query = new Float32Array([1, 0, 0]);
|
|
1028
|
-
const vectors = [
|
|
1029
|
-
new Float32Array([1, 0, 0]),
|
|
1030
|
-
new Float32Array([0, 1, 0]),
|
|
1031
|
-
new Float32Array([0, 0, 1]),
|
|
1032
|
-
];
|
|
1033
|
-
const similarities = wasmSearch.batchSimilarity(query, vectors);
|
|
1034
|
-
expect(similarities).toHaveLength(3);
|
|
1035
|
-
expect(similarities[0]).toBeCloseTo(1.0, 5);
|
|
1036
|
-
expect(similarities[1]).toBeCloseTo(0.0, 5);
|
|
1037
|
-
expect(similarities[2]).toBeCloseTo(0.0, 5);
|
|
1038
|
-
});
|
|
1039
|
-
it('should handle large batches', () => {
|
|
1040
|
-
const query = new Float32Array(384).fill(0.5);
|
|
1041
|
-
const vectors = [];
|
|
1042
|
-
for (let i = 0; i < 1000; i++) {
|
|
1043
|
-
vectors.push(new Float32Array(384).fill(Math.random()));
|
|
1044
|
-
}
|
|
1045
|
-
const startTime = performance.now();
|
|
1046
|
-
const similarities = wasmSearch.batchSimilarity(query, vectors);
|
|
1047
|
-
const duration = performance.now() - startTime;
|
|
1048
|
-
expect(similarities).toHaveLength(1000);
|
|
1049
|
-
expect(duration).toBeLessThan(1000);
|
|
1050
|
-
});
|
|
1051
|
-
});
|
|
1052
|
-
describe('Vector Index', () => {
|
|
1053
|
-
it('should build index for large datasets', () => {
|
|
1054
|
-
const vectors = [];
|
|
1055
|
-
const ids = [];
|
|
1056
|
-
for (let i = 0; i < 1500; i++) {
|
|
1057
|
-
vectors.push(new Float32Array(128).fill(Math.random()));
|
|
1058
|
-
ids.push(i);
|
|
1059
|
-
}
|
|
1060
|
-
wasmSearch.buildIndex(vectors, ids);
|
|
1061
|
-
const stats = wasmSearch.getStats();
|
|
1062
|
-
expect(stats.indexBuilt).toBe(true);
|
|
1063
|
-
expect(stats.indexSize).toBe(1500);
|
|
1064
|
-
});
|
|
1065
|
-
it('should skip index for small datasets', () => {
|
|
1066
|
-
const vectors = [new Float32Array([1, 0, 0])];
|
|
1067
|
-
const ids = [1];
|
|
1068
|
-
wasmSearch.buildIndex(vectors, ids);
|
|
1069
|
-
const stats = wasmSearch.getStats();
|
|
1070
|
-
expect(stats.indexBuilt).toBe(false);
|
|
1071
|
-
});
|
|
1072
|
-
it('should search index correctly', () => {
|
|
1073
|
-
const vectors = [
|
|
1074
|
-
new Float32Array([1, 0, 0]),
|
|
1075
|
-
new Float32Array([0, 1, 0]),
|
|
1076
|
-
new Float32Array([0, 0, 1]),
|
|
1077
|
-
new Float32Array([0.7, 0.7, 0]),
|
|
1078
|
-
];
|
|
1079
|
-
const ids = [1, 2, 3, 4];
|
|
1080
|
-
wasmSearch = new WASMVectorSearch(mockDb, { indexThreshold: 3 });
|
|
1081
|
-
wasmSearch.buildIndex(vectors, ids);
|
|
1082
|
-
const query = new Float32Array([1, 0, 0]);
|
|
1083
|
-
const results = wasmSearch.searchIndex(query, 2);
|
|
1084
|
-
expect(results).toHaveLength(2);
|
|
1085
|
-
expect(results[0].id).toBe(1);
|
|
1086
|
-
expect(results[0].similarity).toBeCloseTo(1.0, 5);
|
|
1087
|
-
});
|
|
1088
|
-
it('should clear index', () => {
|
|
1089
|
-
wasmSearch = new WASMVectorSearch(mockDb, { indexThreshold: 0 });
|
|
1090
|
-
wasmSearch.buildIndex([new Float32Array([1, 0, 0])], [1]);
|
|
1091
|
-
let stats = wasmSearch.getStats();
|
|
1092
|
-
expect(stats.indexBuilt).toBe(true);
|
|
1093
|
-
wasmSearch.clearIndex();
|
|
1094
|
-
stats = wasmSearch.getStats();
|
|
1095
|
-
expect(stats.indexBuilt).toBe(false);
|
|
1096
|
-
});
|
|
1097
|
-
});
|
|
1098
|
-
describe('Statistics', () => {
|
|
1099
|
-
it('should report correct stats', () => {
|
|
1100
|
-
const stats = wasmSearch.getStats();
|
|
1101
|
-
expect(stats).toHaveProperty('wasmAvailable');
|
|
1102
|
-
expect(stats).toHaveProperty('simdAvailable');
|
|
1103
|
-
expect(stats).toHaveProperty('indexBuilt');
|
|
1104
|
-
expect(stats).toHaveProperty('indexSize');
|
|
1105
|
-
expect(typeof stats.wasmAvailable).toBe('boolean');
|
|
1106
|
-
expect(typeof stats.simdAvailable).toBe('boolean');
|
|
1107
|
-
});
|
|
1108
|
-
});
|
|
1109
|
-
});
|
|
1110
|
-
// ============================================================================
|
|
1111
|
-
// Performance Tests
|
|
1112
|
-
// ============================================================================
|
|
1113
|
-
describe('Performance', () => {
|
|
1114
|
-
describe('SIMD operations performance', () => {
|
|
1115
|
-
it('should process 1000 similarity calculations efficiently', () => {
|
|
1116
|
-
const query = randomVector(384);
|
|
1117
|
-
const vectors = Array.from({ length: 1000 }, () => randomVector(384));
|
|
1118
|
-
const startTime = performance.now();
|
|
1119
|
-
vectors.forEach(v => cosineSimilaritySIMD(query, v));
|
|
1120
|
-
const duration = performance.now() - startTime;
|
|
1121
|
-
expect(duration).toBeLessThan(500);
|
|
1122
|
-
});
|
|
1123
|
-
it('should batch process efficiently', () => {
|
|
1124
|
-
const query = randomVector(384);
|
|
1125
|
-
const vectors = Array.from({ length: 10000 }, () => randomVector(384));
|
|
1126
|
-
const startTime = performance.now();
|
|
1127
|
-
batchCosineSimilarity(query, vectors, { topK: 100 });
|
|
1128
|
-
const duration = performance.now() - startTime;
|
|
1129
|
-
expect(duration).toBeLessThan(5000);
|
|
1130
|
-
});
|
|
1131
|
-
});
|
|
1132
|
-
describe('Quantization performance', () => {
|
|
1133
|
-
it('should quantize 1000 vectors efficiently', () => {
|
|
1134
|
-
const vectors = Array.from({ length: 1000 }, () => randomVector(384));
|
|
1135
|
-
const startTime = performance.now();
|
|
1136
|
-
vectors.forEach(v => quantize8bit(v));
|
|
1137
|
-
const duration = performance.now() - startTime;
|
|
1138
|
-
expect(duration).toBeLessThan(1000);
|
|
1139
|
-
});
|
|
1140
|
-
});
|
|
1141
|
-
describe('Attention performance', () => {
|
|
1142
|
-
it('should benchmark attention implementation', () => {
|
|
1143
|
-
const attention = new FlashAttentionOptimized({ hiddenDim: 64 });
|
|
1144
|
-
const result = benchmarkAttention(attention, {
|
|
1145
|
-
seqLen: 32,
|
|
1146
|
-
dim: 64,
|
|
1147
|
-
iterations: 10,
|
|
1148
|
-
numHeads: 8,
|
|
1149
|
-
});
|
|
1150
|
-
expect(result.avgTimeMs).toBeGreaterThan(0);
|
|
1151
|
-
expect(result.opsPerSecond).toBeGreaterThan(0);
|
|
1152
|
-
expect(result.memoryUsed).toBeGreaterThan(0);
|
|
1153
|
-
});
|
|
1154
|
-
});
|
|
1155
|
-
});
|
|
1156
|
-
//# sourceMappingURL=ruvector-integration.test.js.map
|