agentdb 1.0.11 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +196 -838
- package/dist/benchmarks/comprehensive-benchmark.js +664 -0
- package/dist/benchmarks/frontier-benchmark.js +419 -0
- package/dist/benchmarks/reflexion-benchmark.js +370 -0
- package/dist/cli/agentdb-cli.d.ts +117 -0
- package/dist/cli/agentdb-cli.d.ts.map +1 -0
- package/dist/cli/agentdb-cli.js +718 -0
- package/dist/cli/agentdb-cli.js.map +1 -0
- package/dist/controllers/CausalMemoryGraph.d.ts +125 -0
- package/dist/controllers/CausalMemoryGraph.d.ts.map +1 -0
- package/dist/controllers/CausalMemoryGraph.js +323 -0
- package/dist/controllers/CausalMemoryGraph.js.map +1 -0
- package/dist/controllers/CausalRecall.d.ts +111 -0
- package/dist/controllers/CausalRecall.d.ts.map +1 -0
- package/dist/controllers/CausalRecall.js +282 -0
- package/dist/controllers/CausalRecall.js.map +1 -0
- package/dist/controllers/EmbeddingService.d.ts +37 -0
- package/dist/controllers/EmbeddingService.d.ts.map +1 -0
- package/dist/controllers/EmbeddingService.js +119 -0
- package/dist/controllers/EmbeddingService.js.map +1 -0
- package/dist/controllers/ExplainableRecall.d.ts +138 -0
- package/dist/controllers/ExplainableRecall.d.ts.map +1 -0
- package/dist/controllers/ExplainableRecall.js +388 -0
- package/dist/controllers/ExplainableRecall.js.map +1 -0
- package/dist/controllers/NightlyLearner.d.ts +113 -0
- package/dist/controllers/NightlyLearner.d.ts.map +1 -0
- package/dist/controllers/NightlyLearner.js +383 -0
- package/dist/controllers/NightlyLearner.js.map +1 -0
- package/dist/controllers/ReflexionMemory.d.ts +84 -0
- package/dist/controllers/ReflexionMemory.d.ts.map +1 -0
- package/dist/controllers/ReflexionMemory.js +240 -0
- package/dist/controllers/ReflexionMemory.js.map +1 -0
- package/dist/controllers/SkillLibrary.d.ts +96 -0
- package/dist/controllers/SkillLibrary.d.ts.map +1 -0
- package/dist/controllers/SkillLibrary.js +277 -0
- package/dist/controllers/SkillLibrary.js.map +1 -0
- package/dist/controllers/frontier-index.d.ts +14 -0
- package/dist/controllers/frontier-index.d.ts.map +1 -0
- package/dist/controllers/frontier-index.js +10 -0
- package/dist/controllers/frontier-index.js.map +1 -0
- package/dist/controllers/index.d.ts +12 -0
- package/dist/controllers/index.d.ts.map +1 -0
- package/dist/controllers/index.js +9 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/optimizations/BatchOperations.d.ts +61 -0
- package/dist/optimizations/BatchOperations.d.ts.map +1 -0
- package/dist/optimizations/BatchOperations.js +199 -0
- package/dist/optimizations/BatchOperations.js.map +1 -0
- package/dist/optimizations/QueryOptimizer.d.ts +82 -0
- package/dist/optimizations/QueryOptimizer.d.ts.map +1 -0
- package/dist/optimizations/QueryOptimizer.js +226 -0
- package/dist/optimizations/QueryOptimizer.js.map +1 -0
- package/dist/optimizations/index.d.ts +10 -0
- package/dist/optimizations/index.d.ts.map +1 -0
- package/dist/optimizations/index.js +8 -0
- package/dist/optimizations/index.js.map +1 -0
- package/dist/schemas/frontier-schema.sql +341 -0
- package/dist/schemas/schema.sql +382 -0
- package/dist/tests/frontier-features.test.js +665 -0
- package/package.json +54 -117
- package/src/cli/agentdb-cli.ts +861 -0
- package/src/cli/examples.sh +83 -0
- package/src/controllers/CausalMemoryGraph.ts +504 -0
- package/src/controllers/CausalRecall.ts +395 -0
- package/src/controllers/EmbeddingService.ts +141 -0
- package/src/controllers/ExplainableRecall.ts +577 -0
- package/src/controllers/NightlyLearner.ts +475 -0
- package/src/controllers/ReflexionMemory.ts +349 -0
- package/src/controllers/SkillLibrary.ts +391 -0
- package/src/controllers/frontier-index.ts +35 -0
- package/src/controllers/index.ts +13 -0
- package/src/optimizations/BatchOperations.ts +292 -0
- package/src/optimizations/QueryOptimizer.ts +294 -0
- package/src/optimizations/index.ts +11 -0
- package/src/schemas/frontier-schema.sql +341 -0
- package/src/schemas/schema.sql +382 -0
- package/CHANGELOG.md +0 -166
- package/LICENSE +0 -38
- package/LICENSE-APACHE +0 -190
- package/LICENSE-MIT +0 -21
- package/bin/agentdb.js +0 -733
- package/bin/benchmark.js +0 -162
- package/bin/plugin-cli-wrapper.mjs +0 -21
- package/dist/agentdb.js +0 -5352
- package/dist/agentdb.js.map +0 -7
- package/dist/agentdb.min.js +0 -143
- package/dist/agentdb.min.js.map +0 -7
- package/dist/cache/query-cache.d.ts +0 -105
- package/dist/cache/query-cache.d.ts.map +0 -1
- package/dist/cache/query-cache.js +0 -224
- package/dist/cache/query-cache.js.map +0 -1
- package/dist/cache/query-cache.mjs +0 -219
- package/dist/cli/cache/query-cache.d.ts +0 -104
- package/dist/cli/cache/query-cache.js +0 -244
- package/dist/cli/cli/db-commands.d.ts +0 -48
- package/dist/cli/cli/db-commands.js +0 -613
- package/dist/cli/commands.d.ts +0 -7
- package/dist/cli/commands.d.ts.map +0 -1
- package/dist/cli/commands.js +0 -113
- package/dist/cli/commands.js.map +0 -1
- package/dist/cli/commands.mjs +0 -104
- package/dist/cli/core/backend-interface.d.ts +0 -70
- package/dist/cli/core/backend-interface.js +0 -15
- package/dist/cli/core/native-backend.d.ts +0 -140
- package/dist/cli/core/native-backend.js +0 -432
- package/dist/cli/core/vector-db.d.ts +0 -126
- package/dist/cli/core/vector-db.js +0 -338
- package/dist/cli/core/wasm-backend.d.ts +0 -95
- package/dist/cli/core/wasm-backend.js +0 -418
- package/dist/cli/db-commands.d.ts +0 -49
- package/dist/cli/db-commands.d.ts.map +0 -1
- package/dist/cli/db-commands.js +0 -533
- package/dist/cli/db-commands.js.map +0 -1
- package/dist/cli/db-commands.mjs +0 -522
- package/dist/cli/generator.d.ts +0 -11
- package/dist/cli/generator.d.ts.map +0 -1
- package/dist/cli/generator.js +0 -567
- package/dist/cli/generator.js.map +0 -1
- package/dist/cli/generator.mjs +0 -527
- package/dist/cli/help.d.ts +0 -18
- package/dist/cli/help.d.ts.map +0 -1
- package/dist/cli/help.js +0 -676
- package/dist/cli/help.js.map +0 -1
- package/dist/cli/help.mjs +0 -667
- package/dist/cli/index/hnsw.d.ts +0 -164
- package/dist/cli/index/hnsw.js +0 -558
- package/dist/cli/plugin-cli.d.ts +0 -7
- package/dist/cli/plugin-cli.d.ts.map +0 -1
- package/dist/cli/plugin-cli.js +0 -295
- package/dist/cli/plugin-cli.js.map +0 -1
- package/dist/cli/plugin-cli.mjs +0 -289
- package/dist/cli/quantization/product-quantization.d.ts +0 -108
- package/dist/cli/quantization/product-quantization.js +0 -350
- package/dist/cli/query/query-builder.d.ts +0 -322
- package/dist/cli/query/query-builder.js +0 -600
- package/dist/cli/templates.d.ts +0 -14
- package/dist/cli/templates.d.ts.map +0 -1
- package/dist/cli/templates.js +0 -182
- package/dist/cli/templates.js.map +0 -1
- package/dist/cli/templates.mjs +0 -176
- package/dist/cli/types/index.d.ts +0 -116
- package/dist/cli/types/index.js +0 -5
- package/dist/cli/types.d.ts +0 -91
- package/dist/cli/types.d.ts.map +0 -1
- package/dist/cli/types.js +0 -6
- package/dist/cli/types.js.map +0 -1
- package/dist/cli/types.mjs +0 -4
- package/dist/cli/wizard/index.d.ts +0 -6
- package/dist/cli/wizard/index.d.ts.map +0 -1
- package/dist/cli/wizard/index.js +0 -138
- package/dist/cli/wizard/index.js.map +0 -1
- package/dist/cli/wizard/index.mjs +0 -131
- package/dist/cli/wizard/prompts.d.ts +0 -11
- package/dist/cli/wizard/prompts.d.ts.map +0 -1
- package/dist/cli/wizard/prompts.js +0 -482
- package/dist/cli/wizard/prompts.js.map +0 -1
- package/dist/cli/wizard/prompts.mjs +0 -470
- package/dist/cli/wizard/validator.d.ts +0 -13
- package/dist/cli/wizard/validator.d.ts.map +0 -1
- package/dist/cli/wizard/validator.js +0 -234
- package/dist/cli/wizard/validator.js.map +0 -1
- package/dist/cli/wizard/validator.mjs +0 -224
- package/dist/core/backend-interface.d.ts +0 -71
- package/dist/core/backend-interface.d.ts.map +0 -1
- package/dist/core/backend-interface.js +0 -16
- package/dist/core/backend-interface.js.map +0 -1
- package/dist/core/backend-interface.mjs +0 -12
- package/dist/core/native-backend.d.ts +0 -141
- package/dist/core/native-backend.d.ts.map +0 -1
- package/dist/core/native-backend.js +0 -457
- package/dist/core/native-backend.js.map +0 -1
- package/dist/core/native-backend.mjs +0 -449
- package/dist/core/vector-db.d.ts +0 -127
- package/dist/core/vector-db.d.ts.map +0 -1
- package/dist/core/vector-db.js +0 -270
- package/dist/core/vector-db.js.map +0 -1
- package/dist/core/vector-db.mjs +0 -265
- package/dist/core/wasm-backend.d.ts +0 -96
- package/dist/core/wasm-backend.d.ts.map +0 -1
- package/dist/core/wasm-backend.js +0 -393
- package/dist/core/wasm-backend.js.map +0 -1
- package/dist/core/wasm-backend.mjs +0 -385
- package/dist/index/hnsw-optimized.d.ts +0 -75
- package/dist/index/hnsw-optimized.d.ts.map +0 -1
- package/dist/index/hnsw-optimized.js +0 -412
- package/dist/index/hnsw-optimized.js.map +0 -1
- package/dist/index/hnsw-optimized.mjs +0 -407
- package/dist/index/hnsw.d.ts +0 -165
- package/dist/index/hnsw.d.ts.map +0 -1
- package/dist/index/hnsw.js +0 -521
- package/dist/index/hnsw.js.map +0 -1
- package/dist/index/hnsw.mjs +0 -516
- package/dist/index.browser.d.ts +0 -47
- package/dist/index.browser.d.ts.map +0 -1
- package/dist/index.browser.js +0 -72
- package/dist/index.browser.js.map +0 -1
- package/dist/index.browser.mjs +0 -54
- package/dist/index.d.ts +0 -59
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -84
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -65
- package/dist/mcp/learning/core/experience-buffer.d.ts +0 -61
- package/dist/mcp/learning/core/experience-buffer.d.ts.map +0 -1
- package/dist/mcp/learning/core/experience-buffer.js +0 -175
- package/dist/mcp/learning/core/experience-buffer.js.map +0 -1
- package/dist/mcp/learning/core/experience-buffer.mjs +0 -170
- package/dist/mcp/learning/core/experience-recorder.d.ts +0 -40
- package/dist/mcp/learning/core/experience-recorder.d.ts.map +0 -1
- package/dist/mcp/learning/core/experience-recorder.js +0 -200
- package/dist/mcp/learning/core/experience-recorder.js.map +0 -1
- package/dist/mcp/learning/core/experience-recorder.mjs +0 -195
- package/dist/mcp/learning/core/learning-manager.d.ts +0 -66
- package/dist/mcp/learning/core/learning-manager.d.ts.map +0 -1
- package/dist/mcp/learning/core/learning-manager.js +0 -252
- package/dist/mcp/learning/core/learning-manager.js.map +0 -1
- package/dist/mcp/learning/core/learning-manager.mjs +0 -247
- package/dist/mcp/learning/core/policy-optimizer.d.ts +0 -53
- package/dist/mcp/learning/core/policy-optimizer.d.ts.map +0 -1
- package/dist/mcp/learning/core/policy-optimizer.js +0 -251
- package/dist/mcp/learning/core/policy-optimizer.js.map +0 -1
- package/dist/mcp/learning/core/policy-optimizer.mjs +0 -246
- package/dist/mcp/learning/core/reward-estimator.d.ts +0 -44
- package/dist/mcp/learning/core/reward-estimator.d.ts.map +0 -1
- package/dist/mcp/learning/core/reward-estimator.js +0 -158
- package/dist/mcp/learning/core/reward-estimator.js.map +0 -1
- package/dist/mcp/learning/core/reward-estimator.mjs +0 -153
- package/dist/mcp/learning/core/session-manager.d.ts +0 -63
- package/dist/mcp/learning/core/session-manager.d.ts.map +0 -1
- package/dist/mcp/learning/core/session-manager.js +0 -202
- package/dist/mcp/learning/core/session-manager.js.map +0 -1
- package/dist/mcp/learning/core/session-manager.mjs +0 -197
- package/dist/mcp/learning/index.d.ts +0 -19
- package/dist/mcp/learning/index.d.ts.map +0 -1
- package/dist/mcp/learning/index.js +0 -30
- package/dist/mcp/learning/index.js.map +0 -1
- package/dist/mcp/learning/index.mjs +0 -19
- package/dist/mcp/learning/tools/mcp-learning-tools.d.ts +0 -369
- package/dist/mcp/learning/tools/mcp-learning-tools.d.ts.map +0 -1
- package/dist/mcp/learning/tools/mcp-learning-tools.js +0 -361
- package/dist/mcp/learning/tools/mcp-learning-tools.js.map +0 -1
- package/dist/mcp/learning/tools/mcp-learning-tools.mjs +0 -356
- package/dist/mcp/learning/types/index.d.ts +0 -138
- package/dist/mcp/learning/types/index.d.ts.map +0 -1
- package/dist/mcp/learning/types/index.js +0 -6
- package/dist/mcp/learning/types/index.js.map +0 -1
- package/dist/mcp/learning/types/index.mjs +0 -4
- package/dist/mcp-server.d.ts +0 -29
- package/dist/mcp-server.d.ts.map +0 -1
- package/dist/mcp-server.js +0 -862
- package/dist/mcp-server.js.map +0 -1
- package/dist/mcp-server.mjs +0 -857
- package/dist/plugins/base-plugin.d.ts +0 -114
- package/dist/plugins/base-plugin.d.ts.map +0 -1
- package/dist/plugins/base-plugin.js +0 -313
- package/dist/plugins/base-plugin.js.map +0 -1
- package/dist/plugins/base-plugin.mjs +0 -275
- package/dist/plugins/implementations/active-learning.d.ts +0 -135
- package/dist/plugins/implementations/active-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/active-learning.js +0 -372
- package/dist/plugins/implementations/active-learning.js.map +0 -1
- package/dist/plugins/implementations/active-learning.mjs +0 -367
- package/dist/plugins/implementations/actor-critic.d.ts +0 -64
- package/dist/plugins/implementations/actor-critic.d.ts.map +0 -1
- package/dist/plugins/implementations/actor-critic.js +0 -363
- package/dist/plugins/implementations/actor-critic.js.map +0 -1
- package/dist/plugins/implementations/actor-critic.mjs +0 -358
- package/dist/plugins/implementations/adversarial-training.d.ts +0 -133
- package/dist/plugins/implementations/adversarial-training.d.ts.map +0 -1
- package/dist/plugins/implementations/adversarial-training.js +0 -409
- package/dist/plugins/implementations/adversarial-training.js.map +0 -1
- package/dist/plugins/implementations/adversarial-training.mjs +0 -404
- package/dist/plugins/implementations/curriculum-learning.d.ts +0 -132
- package/dist/plugins/implementations/curriculum-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/curriculum-learning.js +0 -354
- package/dist/plugins/implementations/curriculum-learning.js.map +0 -1
- package/dist/plugins/implementations/curriculum-learning.mjs +0 -349
- package/dist/plugins/implementations/decision-transformer.d.ts +0 -77
- package/dist/plugins/implementations/decision-transformer.d.ts.map +0 -1
- package/dist/plugins/implementations/decision-transformer.js +0 -422
- package/dist/plugins/implementations/decision-transformer.js.map +0 -1
- package/dist/plugins/implementations/decision-transformer.mjs +0 -417
- package/dist/plugins/implementations/federated-learning.d.ts +0 -126
- package/dist/plugins/implementations/federated-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/federated-learning.js +0 -436
- package/dist/plugins/implementations/federated-learning.js.map +0 -1
- package/dist/plugins/implementations/federated-learning.mjs +0 -431
- package/dist/plugins/implementations/index.d.ts +0 -30
- package/dist/plugins/implementations/index.d.ts.map +0 -1
- package/dist/plugins/implementations/index.js +0 -45
- package/dist/plugins/implementations/index.js.map +0 -1
- package/dist/plugins/implementations/index.mjs +0 -31
- package/dist/plugins/implementations/multi-task-learning.d.ts +0 -115
- package/dist/plugins/implementations/multi-task-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/multi-task-learning.js +0 -369
- package/dist/plugins/implementations/multi-task-learning.js.map +0 -1
- package/dist/plugins/implementations/multi-task-learning.mjs +0 -364
- package/dist/plugins/implementations/neural-architecture-search.d.ts +0 -148
- package/dist/plugins/implementations/neural-architecture-search.d.ts.map +0 -1
- package/dist/plugins/implementations/neural-architecture-search.js +0 -379
- package/dist/plugins/implementations/neural-architecture-search.js.map +0 -1
- package/dist/plugins/implementations/neural-architecture-search.mjs +0 -374
- package/dist/plugins/implementations/q-learning.d.ts +0 -98
- package/dist/plugins/implementations/q-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/q-learning.js +0 -435
- package/dist/plugins/implementations/q-learning.js.map +0 -1
- package/dist/plugins/implementations/q-learning.mjs +0 -430
- package/dist/plugins/implementations/sarsa.d.ts +0 -103
- package/dist/plugins/implementations/sarsa.d.ts.map +0 -1
- package/dist/plugins/implementations/sarsa.js +0 -347
- package/dist/plugins/implementations/sarsa.js.map +0 -1
- package/dist/plugins/implementations/sarsa.mjs +0 -342
- package/dist/plugins/index.d.ts +0 -107
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -179
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/index.mjs +0 -168
- package/dist/plugins/interface.d.ts +0 -439
- package/dist/plugins/interface.d.ts.map +0 -1
- package/dist/plugins/interface.js +0 -12
- package/dist/plugins/interface.js.map +0 -1
- package/dist/plugins/interface.mjs +0 -10
- package/dist/plugins/learning-plugin.interface.d.ts +0 -257
- package/dist/plugins/learning-plugin.interface.d.ts.map +0 -1
- package/dist/plugins/learning-plugin.interface.js +0 -7
- package/dist/plugins/learning-plugin.interface.js.map +0 -1
- package/dist/plugins/learning-plugin.interface.mjs +0 -5
- package/dist/plugins/plugin-exports.d.ts +0 -71
- package/dist/plugins/plugin-exports.d.ts.map +0 -1
- package/dist/plugins/plugin-exports.js +0 -78
- package/dist/plugins/plugin-exports.js.map +0 -1
- package/dist/plugins/plugin-exports.mjs +0 -69
- package/dist/plugins/registry.d.ts +0 -206
- package/dist/plugins/registry.d.ts.map +0 -1
- package/dist/plugins/registry.js +0 -365
- package/dist/plugins/registry.js.map +0 -1
- package/dist/plugins/registry.mjs +0 -356
- package/dist/plugins/validator.d.ts +0 -63
- package/dist/plugins/validator.d.ts.map +0 -1
- package/dist/plugins/validator.js +0 -464
- package/dist/plugins/validator.js.map +0 -1
- package/dist/plugins/validator.mjs +0 -458
- package/dist/presets.d.ts +0 -65
- package/dist/presets.d.ts.map +0 -1
- package/dist/presets.js +0 -145
- package/dist/presets.js.map +0 -1
- package/dist/presets.mjs +0 -140
- package/dist/quantization/binary-quantization.d.ts +0 -104
- package/dist/quantization/binary-quantization.d.ts.map +0 -1
- package/dist/quantization/binary-quantization.js +0 -246
- package/dist/quantization/binary-quantization.js.map +0 -1
- package/dist/quantization/binary-quantization.mjs +0 -240
- package/dist/quantization/optimized-pq.d.ts +0 -138
- package/dist/quantization/optimized-pq.d.ts.map +0 -1
- package/dist/quantization/optimized-pq.js +0 -320
- package/dist/quantization/optimized-pq.js.map +0 -1
- package/dist/quantization/optimized-pq.mjs +0 -313
- package/dist/quantization/product-quantization.d.ts +0 -109
- package/dist/quantization/product-quantization.d.ts.map +0 -1
- package/dist/quantization/product-quantization.js +0 -287
- package/dist/quantization/product-quantization.js.map +0 -1
- package/dist/quantization/product-quantization.mjs +0 -282
- package/dist/quantization/scalar-quantization.d.ts +0 -100
- package/dist/quantization/scalar-quantization.d.ts.map +0 -1
- package/dist/quantization/scalar-quantization.js +0 -324
- package/dist/quantization/scalar-quantization.js.map +0 -1
- package/dist/quantization/scalar-quantization.mjs +0 -319
- package/dist/query/index.d.ts +0 -6
- package/dist/query/index.d.ts.map +0 -1
- package/dist/query/index.js +0 -9
- package/dist/query/index.js.map +0 -1
- package/dist/query/index.mjs +0 -4
- package/dist/query/query-builder.d.ts +0 -323
- package/dist/query/query-builder.d.ts.map +0 -1
- package/dist/query/query-builder.js +0 -524
- package/dist/query/query-builder.js.map +0 -1
- package/dist/query/query-builder.mjs +0 -519
- package/dist/reasoning/context-synthesizer.d.ts +0 -57
- package/dist/reasoning/context-synthesizer.d.ts.map +0 -1
- package/dist/reasoning/context-synthesizer.js +0 -224
- package/dist/reasoning/context-synthesizer.js.map +0 -1
- package/dist/reasoning/context-synthesizer.mjs +0 -219
- package/dist/reasoning/experience-curator.d.ts +0 -66
- package/dist/reasoning/experience-curator.d.ts.map +0 -1
- package/dist/reasoning/experience-curator.js +0 -288
- package/dist/reasoning/experience-curator.js.map +0 -1
- package/dist/reasoning/experience-curator.mjs +0 -283
- package/dist/reasoning/memory-optimizer.d.ts +0 -69
- package/dist/reasoning/memory-optimizer.d.ts.map +0 -1
- package/dist/reasoning/memory-optimizer.js +0 -331
- package/dist/reasoning/memory-optimizer.js.map +0 -1
- package/dist/reasoning/memory-optimizer.mjs +0 -326
- package/dist/reasoning/pattern-matcher.d.ts +0 -59
- package/dist/reasoning/pattern-matcher.d.ts.map +0 -1
- package/dist/reasoning/pattern-matcher.js +0 -229
- package/dist/reasoning/pattern-matcher.js.map +0 -1
- package/dist/reasoning/pattern-matcher.mjs +0 -224
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts +0 -118
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts.map +0 -1
- package/dist/reasoningbank/adapter/agentdb-adapter.js +0 -477
- package/dist/reasoningbank/adapter/agentdb-adapter.js.map +0 -1
- package/dist/reasoningbank/adapter/types.d.ts +0 -113
- package/dist/reasoningbank/adapter/types.d.ts.map +0 -1
- package/dist/reasoningbank/adapter/types.js +0 -9
- package/dist/reasoningbank/adapter/types.js.map +0 -1
- package/dist/reasoningbank/cli/commands.d.ts +0 -16
- package/dist/reasoningbank/cli/commands.d.ts.map +0 -1
- package/dist/reasoningbank/cli/commands.js +0 -272
- package/dist/reasoningbank/cli/commands.js.map +0 -1
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts +0 -319
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts.map +0 -1
- package/dist/reasoningbank/mcp/agentdb-tools.js +0 -301
- package/dist/reasoningbank/mcp/agentdb-tools.js.map +0 -1
- package/dist/reasoningbank/migration/migrate.d.ts +0 -25
- package/dist/reasoningbank/migration/migrate.d.ts.map +0 -1
- package/dist/reasoningbank/migration/migrate.js +0 -178
- package/dist/reasoningbank/migration/migrate.js.map +0 -1
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts +0 -37
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/context-synthesizer.js +0 -114
- package/dist/reasoningbank/reasoning/context-synthesizer.js.map +0 -1
- package/dist/reasoningbank/reasoning/experience-curator.d.ts +0 -39
- package/dist/reasoningbank/reasoning/experience-curator.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/experience-curator.js +0 -98
- package/dist/reasoningbank/reasoning/experience-curator.js.map +0 -1
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts +0 -44
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/memory-optimizer.js +0 -184
- package/dist/reasoningbank/reasoning/memory-optimizer.js.map +0 -1
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts +0 -40
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/pattern-matcher.js +0 -87
- package/dist/reasoningbank/reasoning/pattern-matcher.js.map +0 -1
- package/dist/reasoningbank/sync/quic-sync.d.ts +0 -77
- package/dist/reasoningbank/sync/quic-sync.d.ts.map +0 -1
- package/dist/reasoningbank/sync/quic-sync.js +0 -165
- package/dist/reasoningbank/sync/quic-sync.js.map +0 -1
- package/dist/sync/conflict.d.ts +0 -78
- package/dist/sync/conflict.d.ts.map +0 -1
- package/dist/sync/conflict.js +0 -202
- package/dist/sync/conflict.js.map +0 -1
- package/dist/sync/conflict.mjs +0 -196
- package/dist/sync/coordinator.d.ts +0 -111
- package/dist/sync/coordinator.d.ts.map +0 -1
- package/dist/sync/coordinator.js +0 -256
- package/dist/sync/coordinator.js.map +0 -1
- package/dist/sync/coordinator.mjs +0 -250
- package/dist/sync/delta.d.ts +0 -81
- package/dist/sync/delta.d.ts.map +0 -1
- package/dist/sync/delta.js +0 -245
- package/dist/sync/delta.js.map +0 -1
- package/dist/sync/delta.mjs +0 -238
- package/dist/sync/index.d.ts +0 -11
- package/dist/sync/index.d.ts.map +0 -1
- package/dist/sync/index.js +0 -22
- package/dist/sync/index.js.map +0 -1
- package/dist/sync/index.mjs +0 -9
- package/dist/sync/quic-sync.d.ts +0 -81
- package/dist/sync/quic-sync.d.ts.map +0 -1
- package/dist/sync/quic-sync.js +0 -329
- package/dist/sync/quic-sync.js.map +0 -1
- package/dist/sync/quic-sync.mjs +0 -323
- package/dist/sync/types.d.ts +0 -168
- package/dist/sync/types.d.ts.map +0 -1
- package/dist/sync/types.js +0 -8
- package/dist/sync/types.js.map +0 -1
- package/dist/sync/types.mjs +0 -6
- package/dist/types/index.d.ts +0 -117
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -4
- package/dist/wasm/sql-wasm-debug.js +0 -6989
- package/dist/wasm/sql-wasm-debug.wasm +0 -0
- package/dist/wasm/sql-wasm.js +0 -188
- package/dist/wasm/sql-wasm.wasm +0 -0
- package/dist/wasm-loader.d.ts +0 -32
- package/dist/wasm-loader.d.ts.map +0 -1
- package/dist/wasm-loader.js +0 -78
- package/dist/wasm-loader.js.map +0 -1
- package/dist/wasm-loader.mjs +0 -67
- package/examples/adaptive-learning.ts +0 -284
- package/examples/browser/README.md +0 -732
- package/examples/browser/adaptive-recommendations/index.html +0 -427
- package/examples/browser/collaborative-filtering/index.html +0 -310
- package/examples/browser/continual-learning/index.html +0 -736
- package/examples/browser/experience-replay/index.html +0 -616
- package/examples/browser/index.html +0 -369
- package/examples/browser/meta-learning/index.html +0 -789
- package/examples/browser/neuro-symbolic/index.html +0 -692
- package/examples/browser/pattern-learning/index.html +0 -620
- package/examples/browser/quantum-inspired/index.html +0 -728
- package/examples/browser/rag/index.html +0 -624
- package/examples/browser/swarm-intelligence/index.html +0 -811
- package/examples/browser-basic.html +0 -170
- package/examples/browser-wasm-real.html +0 -231
- package/examples/hnsw-example.ts +0 -148
- package/examples/mcp-learning-example.ts +0 -220
- package/examples/node-basic.js +0 -70
- package/examples/quic-sync-example.ts +0 -310
- package/examples/quick-start.js +0 -68
- package/examples/test-v1.0.7-cdn.html +0 -190
- package/examples/wasm-example.ts +0 -222
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Product Quantization (PQ) for 4-32x vector compression
|
|
3
|
-
*
|
|
4
|
-
* Reduces storage requirements while maintaining 95%+ search accuracy.
|
|
5
|
-
* Splits vectors into subvectors and quantizes each independently.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```typescript
|
|
9
|
-
* const pq = new ProductQuantizer({ dimensions: 768, subvectors: 8, bits: 8 });
|
|
10
|
-
* await pq.train(trainingVectors); // Train codebooks
|
|
11
|
-
*
|
|
12
|
-
* // Compress vectors (768 floats → 8 bytes = 96x reduction)
|
|
13
|
-
* const codes = pq.encode(vector);
|
|
14
|
-
*
|
|
15
|
-
* // Decompress for similarity search
|
|
16
|
-
* const approximation = pq.decode(codes);
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export interface ProductQuantizerConfig {
|
|
20
|
-
/** Vector dimensions (e.g., 768 for many embeddings) */
|
|
21
|
-
dimensions: number;
|
|
22
|
-
/** Number of subvectors (typically 4-16) */
|
|
23
|
-
subvectors: number;
|
|
24
|
-
/** Bits per subvector (typically 8 = 256 centroids) */
|
|
25
|
-
bits: number;
|
|
26
|
-
/** K-means iterations for training (default: 20) */
|
|
27
|
-
kmeansIterations?: number;
|
|
28
|
-
/** Enable compression statistics (default: true) */
|
|
29
|
-
enableStats?: boolean;
|
|
30
|
-
}
|
|
31
|
-
export interface CompressionStats {
|
|
32
|
-
originalSize: number;
|
|
33
|
-
compressedSize: number;
|
|
34
|
-
compressionRatio: number;
|
|
35
|
-
encodeCount: number;
|
|
36
|
-
decodeCount: number;
|
|
37
|
-
avgEncodeTime: number;
|
|
38
|
-
avgDecodeTime: number;
|
|
39
|
-
}
|
|
40
|
-
interface Codebook {
|
|
41
|
-
centroids: number[][];
|
|
42
|
-
}
|
|
43
|
-
export declare class ProductQuantizer {
|
|
44
|
-
private config;
|
|
45
|
-
private codebooks;
|
|
46
|
-
private subvectorDim;
|
|
47
|
-
private trained;
|
|
48
|
-
private stats;
|
|
49
|
-
constructor(config: ProductQuantizerConfig);
|
|
50
|
-
/**
|
|
51
|
-
* Train codebooks using k-means clustering on training vectors
|
|
52
|
-
*/
|
|
53
|
-
train(trainingVectors: number[][]): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* Extract subvectors for a specific segment
|
|
56
|
-
*/
|
|
57
|
-
private extractSubvectors;
|
|
58
|
-
/**
|
|
59
|
-
* Train k-means clustering to create centroids
|
|
60
|
-
*/
|
|
61
|
-
private trainKMeans;
|
|
62
|
-
/**
|
|
63
|
-
* Encode vector into quantized codes
|
|
64
|
-
*/
|
|
65
|
-
encode(vector: number[]): Uint8Array;
|
|
66
|
-
/**
|
|
67
|
-
* Decode quantized codes back to approximate vector
|
|
68
|
-
*/
|
|
69
|
-
decode(codes: Uint8Array): number[];
|
|
70
|
-
/**
|
|
71
|
-
* Compute asymmetric distance for faster search
|
|
72
|
-
* Compare query vector directly with quantized database vectors
|
|
73
|
-
*/
|
|
74
|
-
asymmetricDistance(query: number[], codes: Uint8Array): number;
|
|
75
|
-
/**
|
|
76
|
-
* Euclidean distance between two vectors
|
|
77
|
-
*/
|
|
78
|
-
private euclideanDistance;
|
|
79
|
-
/**
|
|
80
|
-
* Squared Euclidean distance (faster, no sqrt)
|
|
81
|
-
*/
|
|
82
|
-
private euclideanDistanceSquared;
|
|
83
|
-
/**
|
|
84
|
-
* Get compression statistics
|
|
85
|
-
*/
|
|
86
|
-
getStats(): CompressionStats;
|
|
87
|
-
/**
|
|
88
|
-
* Reset statistics
|
|
89
|
-
*/
|
|
90
|
-
resetStats(): void;
|
|
91
|
-
/**
|
|
92
|
-
* Check if quantizer is trained
|
|
93
|
-
*/
|
|
94
|
-
isTrained(): boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Export codebooks for persistence
|
|
97
|
-
*/
|
|
98
|
-
exportCodebooks(): Codebook[];
|
|
99
|
-
/**
|
|
100
|
-
* Import codebooks from persistence
|
|
101
|
-
*/
|
|
102
|
-
importCodebooks(codebooks: Codebook[]): void;
|
|
103
|
-
/**
|
|
104
|
-
* Get configuration
|
|
105
|
-
*/
|
|
106
|
-
getConfig(): Required<ProductQuantizerConfig>;
|
|
107
|
-
}
|
|
108
|
-
export {};
|
|
@@ -1,350 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Product Quantization (PQ) for 4-32x vector compression
|
|
4
|
-
*
|
|
5
|
-
* Reduces storage requirements while maintaining 95%+ search accuracy.
|
|
6
|
-
* Splits vectors into subvectors and quantizes each independently.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* const pq = new ProductQuantizer({ dimensions: 768, subvectors: 8, bits: 8 });
|
|
11
|
-
* await pq.train(trainingVectors); // Train codebooks
|
|
12
|
-
*
|
|
13
|
-
* // Compress vectors (768 floats → 8 bytes = 96x reduction)
|
|
14
|
-
* const codes = pq.encode(vector);
|
|
15
|
-
*
|
|
16
|
-
* // Decompress for similarity search
|
|
17
|
-
* const approximation = pq.decode(codes);
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
var __assign = (this && this.__assign) || function () {
|
|
21
|
-
__assign = Object.assign || function(t) {
|
|
22
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
23
|
-
s = arguments[i];
|
|
24
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
25
|
-
t[p] = s[p];
|
|
26
|
-
}
|
|
27
|
-
return t;
|
|
28
|
-
};
|
|
29
|
-
return __assign.apply(this, arguments);
|
|
30
|
-
};
|
|
31
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
32
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
33
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
34
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
35
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
36
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
37
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
41
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
42
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
43
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
44
|
-
function step(op) {
|
|
45
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
46
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
47
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
48
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
49
|
-
switch (op[0]) {
|
|
50
|
-
case 0: case 1: t = op; break;
|
|
51
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
52
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
53
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
54
|
-
default:
|
|
55
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
56
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
57
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
58
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
59
|
-
if (t[2]) _.ops.pop();
|
|
60
|
-
_.trys.pop(); continue;
|
|
61
|
-
}
|
|
62
|
-
op = body.call(thisArg, _);
|
|
63
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
64
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
68
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
69
|
-
if (ar || !(i in from)) {
|
|
70
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
71
|
-
ar[i] = from[i];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
75
|
-
};
|
|
76
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
77
|
-
exports.ProductQuantizer = void 0;
|
|
78
|
-
var ProductQuantizer = /** @class */ (function () {
|
|
79
|
-
function ProductQuantizer(config) {
|
|
80
|
-
var _a, _b;
|
|
81
|
-
this.codebooks = [];
|
|
82
|
-
this.trained = false;
|
|
83
|
-
// Statistics
|
|
84
|
-
this.stats = {
|
|
85
|
-
encodeCount: 0,
|
|
86
|
-
decodeCount: 0,
|
|
87
|
-
totalEncodeTime: 0,
|
|
88
|
-
totalDecodeTime: 0
|
|
89
|
-
};
|
|
90
|
-
this.config = {
|
|
91
|
-
dimensions: config.dimensions,
|
|
92
|
-
subvectors: config.subvectors,
|
|
93
|
-
bits: config.bits,
|
|
94
|
-
kmeansIterations: (_a = config.kmeansIterations) !== null && _a !== void 0 ? _a : 20,
|
|
95
|
-
enableStats: (_b = config.enableStats) !== null && _b !== void 0 ? _b : true
|
|
96
|
-
};
|
|
97
|
-
if (config.dimensions % config.subvectors !== 0) {
|
|
98
|
-
throw new Error("Dimensions (".concat(config.dimensions, ") must be divisible by subvectors (").concat(config.subvectors, ")"));
|
|
99
|
-
}
|
|
100
|
-
this.subvectorDim = config.dimensions / config.subvectors;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Train codebooks using k-means clustering on training vectors
|
|
104
|
-
*/
|
|
105
|
-
ProductQuantizer.prototype.train = function (trainingVectors) {
|
|
106
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
107
|
-
var numCentroids, m, subvectors, centroids;
|
|
108
|
-
return __generator(this, function (_a) {
|
|
109
|
-
if (trainingVectors.length === 0) {
|
|
110
|
-
throw new Error('Training vectors cannot be empty');
|
|
111
|
-
}
|
|
112
|
-
numCentroids = Math.pow(2, this.config.bits);
|
|
113
|
-
this.codebooks = [];
|
|
114
|
-
// Train one codebook per subvector
|
|
115
|
-
for (m = 0; m < this.config.subvectors; m++) {
|
|
116
|
-
subvectors = this.extractSubvectors(trainingVectors, m);
|
|
117
|
-
centroids = this.trainKMeans(subvectors, numCentroids);
|
|
118
|
-
this.codebooks.push({ centroids: centroids });
|
|
119
|
-
}
|
|
120
|
-
this.trained = true;
|
|
121
|
-
return [2 /*return*/];
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Extract subvectors for a specific segment
|
|
127
|
-
*/
|
|
128
|
-
ProductQuantizer.prototype.extractSubvectors = function (vectors, segmentIndex) {
|
|
129
|
-
var start = segmentIndex * this.subvectorDim;
|
|
130
|
-
var end = start + this.subvectorDim;
|
|
131
|
-
return vectors.map(function (v) { return v.slice(start, end); });
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Train k-means clustering to create centroids
|
|
135
|
-
*/
|
|
136
|
-
ProductQuantizer.prototype.trainKMeans = function (vectors, k) {
|
|
137
|
-
var n = vectors.length;
|
|
138
|
-
var d = vectors[0].length;
|
|
139
|
-
// Initialize centroids randomly
|
|
140
|
-
var centroids = [];
|
|
141
|
-
var indices = new Set();
|
|
142
|
-
while (centroids.length < Math.min(k, n)) {
|
|
143
|
-
var idx = Math.floor(Math.random() * n);
|
|
144
|
-
if (!indices.has(idx)) {
|
|
145
|
-
centroids.push(__spreadArray([], vectors[idx], true));
|
|
146
|
-
indices.add(idx);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
// K-means iterations
|
|
150
|
-
for (var iter = 0; iter < this.config.kmeansIterations; iter++) {
|
|
151
|
-
// Assignment step
|
|
152
|
-
var assignments = new Array(n).fill(0);
|
|
153
|
-
for (var i = 0; i < n; i++) {
|
|
154
|
-
var minDist = Infinity;
|
|
155
|
-
var bestCluster = 0;
|
|
156
|
-
for (var c = 0; c < centroids.length; c++) {
|
|
157
|
-
var dist = this.euclideanDistance(vectors[i], centroids[c]);
|
|
158
|
-
if (dist < minDist) {
|
|
159
|
-
minDist = dist;
|
|
160
|
-
bestCluster = c;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
assignments[i] = bestCluster;
|
|
164
|
-
}
|
|
165
|
-
// Update step
|
|
166
|
-
var clusterSums = Array(centroids.length)
|
|
167
|
-
.fill(0)
|
|
168
|
-
.map(function () { return Array(d).fill(0); });
|
|
169
|
-
var clusterCounts = Array(centroids.length).fill(0);
|
|
170
|
-
for (var i = 0; i < n; i++) {
|
|
171
|
-
var cluster = assignments[i];
|
|
172
|
-
clusterCounts[cluster]++;
|
|
173
|
-
for (var j = 0; j < d; j++) {
|
|
174
|
-
clusterSums[cluster][j] += vectors[i][j];
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
// Update centroids
|
|
178
|
-
for (var c = 0; c < centroids.length; c++) {
|
|
179
|
-
if (clusterCounts[c] > 0) {
|
|
180
|
-
for (var j = 0; j < d; j++) {
|
|
181
|
-
centroids[c][j] = clusterSums[c][j] / clusterCounts[c];
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
// Fill remaining centroids if k > n
|
|
187
|
-
while (centroids.length < k) {
|
|
188
|
-
centroids.push(Array(d).fill(0));
|
|
189
|
-
}
|
|
190
|
-
return centroids;
|
|
191
|
-
};
|
|
192
|
-
/**
|
|
193
|
-
* Encode vector into quantized codes
|
|
194
|
-
*/
|
|
195
|
-
ProductQuantizer.prototype.encode = function (vector) {
|
|
196
|
-
if (!this.trained) {
|
|
197
|
-
throw new Error('Quantizer must be trained before encoding');
|
|
198
|
-
}
|
|
199
|
-
if (vector.length !== this.config.dimensions) {
|
|
200
|
-
throw new Error("Vector dimension (".concat(vector.length, ") does not match config (").concat(this.config.dimensions, ")"));
|
|
201
|
-
}
|
|
202
|
-
var startTime = performance.now();
|
|
203
|
-
var codes = new Uint8Array(this.config.subvectors);
|
|
204
|
-
for (var m = 0; m < this.config.subvectors; m++) {
|
|
205
|
-
var start = m * this.subvectorDim;
|
|
206
|
-
var end = start + this.subvectorDim;
|
|
207
|
-
var subvector = vector.slice(start, end);
|
|
208
|
-
// Find nearest centroid
|
|
209
|
-
var minDist = Infinity;
|
|
210
|
-
var bestCode = 0;
|
|
211
|
-
for (var c = 0; c < this.codebooks[m].centroids.length; c++) {
|
|
212
|
-
var dist = this.euclideanDistance(subvector, this.codebooks[m].centroids[c]);
|
|
213
|
-
if (dist < minDist) {
|
|
214
|
-
minDist = dist;
|
|
215
|
-
bestCode = c;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
codes[m] = bestCode;
|
|
219
|
-
}
|
|
220
|
-
if (this.config.enableStats) {
|
|
221
|
-
this.stats.encodeCount++;
|
|
222
|
-
this.stats.totalEncodeTime += performance.now() - startTime;
|
|
223
|
-
}
|
|
224
|
-
return codes;
|
|
225
|
-
};
|
|
226
|
-
/**
|
|
227
|
-
* Decode quantized codes back to approximate vector
|
|
228
|
-
*/
|
|
229
|
-
ProductQuantizer.prototype.decode = function (codes) {
|
|
230
|
-
if (!this.trained) {
|
|
231
|
-
throw new Error('Quantizer must be trained before decoding');
|
|
232
|
-
}
|
|
233
|
-
if (codes.length !== this.config.subvectors) {
|
|
234
|
-
throw new Error("Code length (".concat(codes.length, ") does not match subvectors (").concat(this.config.subvectors, ")"));
|
|
235
|
-
}
|
|
236
|
-
var startTime = performance.now();
|
|
237
|
-
var vector = [];
|
|
238
|
-
for (var m = 0; m < this.config.subvectors; m++) {
|
|
239
|
-
var code = codes[m];
|
|
240
|
-
var centroid = this.codebooks[m].centroids[code];
|
|
241
|
-
vector.push.apply(vector, centroid);
|
|
242
|
-
}
|
|
243
|
-
if (this.config.enableStats) {
|
|
244
|
-
this.stats.decodeCount++;
|
|
245
|
-
this.stats.totalDecodeTime += performance.now() - startTime;
|
|
246
|
-
}
|
|
247
|
-
return vector;
|
|
248
|
-
};
|
|
249
|
-
/**
|
|
250
|
-
* Compute asymmetric distance for faster search
|
|
251
|
-
* Compare query vector directly with quantized database vectors
|
|
252
|
-
*/
|
|
253
|
-
ProductQuantizer.prototype.asymmetricDistance = function (query, codes) {
|
|
254
|
-
if (!this.trained) {
|
|
255
|
-
throw new Error('Quantizer must be trained before computing distances');
|
|
256
|
-
}
|
|
257
|
-
var distance = 0;
|
|
258
|
-
for (var m = 0; m < this.config.subvectors; m++) {
|
|
259
|
-
var start = m * this.subvectorDim;
|
|
260
|
-
var end = start + this.subvectorDim;
|
|
261
|
-
var querySubvector = query.slice(start, end);
|
|
262
|
-
var code = codes[m];
|
|
263
|
-
var centroid = this.codebooks[m].centroids[code];
|
|
264
|
-
distance += this.euclideanDistanceSquared(querySubvector, centroid);
|
|
265
|
-
}
|
|
266
|
-
return Math.sqrt(distance);
|
|
267
|
-
};
|
|
268
|
-
/**
|
|
269
|
-
* Euclidean distance between two vectors
|
|
270
|
-
*/
|
|
271
|
-
ProductQuantizer.prototype.euclideanDistance = function (a, b) {
|
|
272
|
-
return Math.sqrt(this.euclideanDistanceSquared(a, b));
|
|
273
|
-
};
|
|
274
|
-
/**
|
|
275
|
-
* Squared Euclidean distance (faster, no sqrt)
|
|
276
|
-
*/
|
|
277
|
-
ProductQuantizer.prototype.euclideanDistanceSquared = function (a, b) {
|
|
278
|
-
var sum = 0;
|
|
279
|
-
for (var i = 0; i < a.length; i++) {
|
|
280
|
-
var diff = a[i] - b[i];
|
|
281
|
-
sum += diff * diff;
|
|
282
|
-
}
|
|
283
|
-
return sum;
|
|
284
|
-
};
|
|
285
|
-
/**
|
|
286
|
-
* Get compression statistics
|
|
287
|
-
*/
|
|
288
|
-
ProductQuantizer.prototype.getStats = function () {
|
|
289
|
-
var originalSize = this.config.dimensions * 4; // 4 bytes per float32
|
|
290
|
-
var compressedSize = this.config.subvectors; // 1 byte per subvector
|
|
291
|
-
return {
|
|
292
|
-
originalSize: originalSize,
|
|
293
|
-
compressedSize: compressedSize,
|
|
294
|
-
compressionRatio: originalSize / compressedSize,
|
|
295
|
-
encodeCount: this.stats.encodeCount,
|
|
296
|
-
decodeCount: this.stats.decodeCount,
|
|
297
|
-
avgEncodeTime: this.stats.encodeCount > 0
|
|
298
|
-
? this.stats.totalEncodeTime / this.stats.encodeCount
|
|
299
|
-
: 0,
|
|
300
|
-
avgDecodeTime: this.stats.decodeCount > 0
|
|
301
|
-
? this.stats.totalDecodeTime / this.stats.decodeCount
|
|
302
|
-
: 0
|
|
303
|
-
};
|
|
304
|
-
};
|
|
305
|
-
/**
|
|
306
|
-
* Reset statistics
|
|
307
|
-
*/
|
|
308
|
-
ProductQuantizer.prototype.resetStats = function () {
|
|
309
|
-
this.stats = {
|
|
310
|
-
encodeCount: 0,
|
|
311
|
-
decodeCount: 0,
|
|
312
|
-
totalEncodeTime: 0,
|
|
313
|
-
totalDecodeTime: 0
|
|
314
|
-
};
|
|
315
|
-
};
|
|
316
|
-
/**
|
|
317
|
-
* Check if quantizer is trained
|
|
318
|
-
*/
|
|
319
|
-
ProductQuantizer.prototype.isTrained = function () {
|
|
320
|
-
return this.trained;
|
|
321
|
-
};
|
|
322
|
-
/**
|
|
323
|
-
* Export codebooks for persistence
|
|
324
|
-
*/
|
|
325
|
-
ProductQuantizer.prototype.exportCodebooks = function () {
|
|
326
|
-
return this.codebooks.map(function (cb) { return ({
|
|
327
|
-
centroids: cb.centroids.map(function (c) { return __spreadArray([], c, true); })
|
|
328
|
-
}); });
|
|
329
|
-
};
|
|
330
|
-
/**
|
|
331
|
-
* Import codebooks from persistence
|
|
332
|
-
*/
|
|
333
|
-
ProductQuantizer.prototype.importCodebooks = function (codebooks) {
|
|
334
|
-
if (codebooks.length !== this.config.subvectors) {
|
|
335
|
-
throw new Error("Codebook count (".concat(codebooks.length, ") does not match subvectors (").concat(this.config.subvectors, ")"));
|
|
336
|
-
}
|
|
337
|
-
this.codebooks = codebooks.map(function (cb) { return ({
|
|
338
|
-
centroids: cb.centroids.map(function (c) { return __spreadArray([], c, true); })
|
|
339
|
-
}); });
|
|
340
|
-
this.trained = true;
|
|
341
|
-
};
|
|
342
|
-
/**
|
|
343
|
-
* Get configuration
|
|
344
|
-
*/
|
|
345
|
-
ProductQuantizer.prototype.getConfig = function () {
|
|
346
|
-
return __assign({}, this.config);
|
|
347
|
-
};
|
|
348
|
-
return ProductQuantizer;
|
|
349
|
-
}());
|
|
350
|
-
exports.ProductQuantizer = ProductQuantizer;
|