agentdb 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +38 -0
- package/LICENSE-APACHE +190 -0
- package/LICENSE-MIT +21 -0
- package/README.md +953 -0
- package/bin/agentdb.js +485 -0
- package/bin/plugin-cli-wrapper.mjs +21 -0
- package/dist/cache/query-cache.d.ts +105 -0
- package/dist/cache/query-cache.d.ts.map +1 -0
- package/dist/cache/query-cache.js +224 -0
- package/dist/cache/query-cache.js.map +1 -0
- package/dist/cache/query-cache.mjs +219 -0
- package/dist/cli/cache/query-cache.d.ts +104 -0
- package/dist/cli/cache/query-cache.js +244 -0
- package/dist/cli/cli/db-commands.d.ts +48 -0
- package/dist/cli/cli/db-commands.js +613 -0
- package/dist/cli/commands.d.ts +7 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +113 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/commands.mjs +104 -0
- package/dist/cli/core/backend-interface.d.ts +70 -0
- package/dist/cli/core/backend-interface.js +15 -0
- package/dist/cli/core/native-backend.d.ts +140 -0
- package/dist/cli/core/native-backend.js +432 -0
- package/dist/cli/core/vector-db.d.ts +126 -0
- package/dist/cli/core/vector-db.js +338 -0
- package/dist/cli/core/wasm-backend.d.ts +95 -0
- package/dist/cli/core/wasm-backend.js +418 -0
- package/dist/cli/db-commands.d.ts +49 -0
- package/dist/cli/db-commands.d.ts.map +1 -0
- package/dist/cli/db-commands.js +533 -0
- package/dist/cli/db-commands.js.map +1 -0
- package/dist/cli/db-commands.mjs +522 -0
- package/dist/cli/generator.d.ts +11 -0
- package/dist/cli/generator.d.ts.map +1 -0
- package/dist/cli/generator.js +567 -0
- package/dist/cli/generator.js.map +1 -0
- package/dist/cli/generator.mjs +527 -0
- package/dist/cli/help.d.ts +18 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +676 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/help.mjs +667 -0
- package/dist/cli/index/hnsw.d.ts +164 -0
- package/dist/cli/index/hnsw.js +558 -0
- package/dist/cli/plugin-cli.d.ts +7 -0
- package/dist/cli/plugin-cli.d.ts.map +1 -0
- package/dist/cli/plugin-cli.js +295 -0
- package/dist/cli/plugin-cli.js.map +1 -0
- package/dist/cli/plugin-cli.mjs +289 -0
- package/dist/cli/quantization/product-quantization.d.ts +108 -0
- package/dist/cli/quantization/product-quantization.js +350 -0
- package/dist/cli/query/query-builder.d.ts +322 -0
- package/dist/cli/query/query-builder.js +600 -0
- package/dist/cli/templates.d.ts +14 -0
- package/dist/cli/templates.d.ts.map +1 -0
- package/dist/cli/templates.js +182 -0
- package/dist/cli/templates.js.map +1 -0
- package/dist/cli/templates.mjs +176 -0
- package/dist/cli/types/index.d.ts +116 -0
- package/dist/cli/types/index.js +5 -0
- package/dist/cli/types.d.ts +91 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +6 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/types.mjs +4 -0
- package/dist/cli/wizard/index.d.ts +6 -0
- package/dist/cli/wizard/index.d.ts.map +1 -0
- package/dist/cli/wizard/index.js +138 -0
- package/dist/cli/wizard/index.js.map +1 -0
- package/dist/cli/wizard/index.mjs +131 -0
- package/dist/cli/wizard/prompts.d.ts +11 -0
- package/dist/cli/wizard/prompts.d.ts.map +1 -0
- package/dist/cli/wizard/prompts.js +482 -0
- package/dist/cli/wizard/prompts.js.map +1 -0
- package/dist/cli/wizard/prompts.mjs +470 -0
- package/dist/cli/wizard/validator.d.ts +13 -0
- package/dist/cli/wizard/validator.d.ts.map +1 -0
- package/dist/cli/wizard/validator.js +234 -0
- package/dist/cli/wizard/validator.js.map +1 -0
- package/dist/cli/wizard/validator.mjs +224 -0
- package/dist/core/backend-interface.d.ts +71 -0
- package/dist/core/backend-interface.d.ts.map +1 -0
- package/dist/core/backend-interface.js +16 -0
- package/dist/core/backend-interface.js.map +1 -0
- package/dist/core/backend-interface.mjs +12 -0
- package/dist/core/native-backend.d.ts +141 -0
- package/dist/core/native-backend.d.ts.map +1 -0
- package/dist/core/native-backend.js +457 -0
- package/dist/core/native-backend.js.map +1 -0
- package/dist/core/native-backend.mjs +449 -0
- package/dist/core/vector-db.d.ts +127 -0
- package/dist/core/vector-db.d.ts.map +1 -0
- package/dist/core/vector-db.js +266 -0
- package/dist/core/vector-db.js.map +1 -0
- package/dist/core/vector-db.mjs +261 -0
- package/dist/core/wasm-backend.d.ts +96 -0
- package/dist/core/wasm-backend.d.ts.map +1 -0
- package/dist/core/wasm-backend.js +393 -0
- package/dist/core/wasm-backend.js.map +1 -0
- package/dist/core/wasm-backend.mjs +385 -0
- package/dist/index/hnsw-optimized.d.ts +75 -0
- package/dist/index/hnsw-optimized.d.ts.map +1 -0
- package/dist/index/hnsw-optimized.js +412 -0
- package/dist/index/hnsw-optimized.js.map +1 -0
- package/dist/index/hnsw-optimized.mjs +407 -0
- package/dist/index/hnsw.d.ts +165 -0
- package/dist/index/hnsw.d.ts.map +1 -0
- package/dist/index/hnsw.js +521 -0
- package/dist/index/hnsw.js.map +1 -0
- package/dist/index/hnsw.mjs +516 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +63 -0
- package/dist/mcp-server.d.ts +27 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +789 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp-server.mjs +784 -0
- package/dist/plugins/base-plugin.d.ts +114 -0
- package/dist/plugins/base-plugin.d.ts.map +1 -0
- package/dist/plugins/base-plugin.js +313 -0
- package/dist/plugins/base-plugin.js.map +1 -0
- package/dist/plugins/base-plugin.mjs +275 -0
- package/dist/plugins/implementations/active-learning.d.ts +135 -0
- package/dist/plugins/implementations/active-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/active-learning.js +372 -0
- package/dist/plugins/implementations/active-learning.js.map +1 -0
- package/dist/plugins/implementations/active-learning.mjs +367 -0
- package/dist/plugins/implementations/actor-critic.d.ts +64 -0
- package/dist/plugins/implementations/actor-critic.d.ts.map +1 -0
- package/dist/plugins/implementations/actor-critic.js +363 -0
- package/dist/plugins/implementations/actor-critic.js.map +1 -0
- package/dist/plugins/implementations/actor-critic.mjs +358 -0
- package/dist/plugins/implementations/adversarial-training.d.ts +133 -0
- package/dist/plugins/implementations/adversarial-training.d.ts.map +1 -0
- package/dist/plugins/implementations/adversarial-training.js +409 -0
- package/dist/plugins/implementations/adversarial-training.js.map +1 -0
- package/dist/plugins/implementations/adversarial-training.mjs +404 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts +132 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.js +354 -0
- package/dist/plugins/implementations/curriculum-learning.js.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.mjs +349 -0
- package/dist/plugins/implementations/decision-transformer.d.ts +77 -0
- package/dist/plugins/implementations/decision-transformer.d.ts.map +1 -0
- package/dist/plugins/implementations/decision-transformer.js +422 -0
- package/dist/plugins/implementations/decision-transformer.js.map +1 -0
- package/dist/plugins/implementations/decision-transformer.mjs +417 -0
- package/dist/plugins/implementations/federated-learning.d.ts +126 -0
- package/dist/plugins/implementations/federated-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/federated-learning.js +436 -0
- package/dist/plugins/implementations/federated-learning.js.map +1 -0
- package/dist/plugins/implementations/federated-learning.mjs +431 -0
- package/dist/plugins/implementations/index.d.ts +30 -0
- package/dist/plugins/implementations/index.d.ts.map +1 -0
- package/dist/plugins/implementations/index.js +45 -0
- package/dist/plugins/implementations/index.js.map +1 -0
- package/dist/plugins/implementations/index.mjs +31 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts +115 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.js +369 -0
- package/dist/plugins/implementations/multi-task-learning.js.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.mjs +364 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts +148 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.js +379 -0
- package/dist/plugins/implementations/neural-architecture-search.js.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.mjs +374 -0
- package/dist/plugins/implementations/q-learning.d.ts +98 -0
- package/dist/plugins/implementations/q-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/q-learning.js +435 -0
- package/dist/plugins/implementations/q-learning.js.map +1 -0
- package/dist/plugins/implementations/q-learning.mjs +430 -0
- package/dist/plugins/implementations/sarsa.d.ts +103 -0
- package/dist/plugins/implementations/sarsa.d.ts.map +1 -0
- package/dist/plugins/implementations/sarsa.js +347 -0
- package/dist/plugins/implementations/sarsa.js.map +1 -0
- package/dist/plugins/implementations/sarsa.mjs +342 -0
- package/dist/plugins/index.d.ts +107 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +179 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/index.mjs +168 -0
- package/dist/plugins/interface.d.ts +439 -0
- package/dist/plugins/interface.d.ts.map +1 -0
- package/dist/plugins/interface.js +12 -0
- package/dist/plugins/interface.js.map +1 -0
- package/dist/plugins/interface.mjs +10 -0
- package/dist/plugins/learning-plugin.interface.d.ts +257 -0
- package/dist/plugins/learning-plugin.interface.d.ts.map +1 -0
- package/dist/plugins/learning-plugin.interface.js +7 -0
- package/dist/plugins/learning-plugin.interface.js.map +1 -0
- package/dist/plugins/learning-plugin.interface.mjs +5 -0
- package/dist/plugins/plugin-exports.d.ts +71 -0
- package/dist/plugins/plugin-exports.d.ts.map +1 -0
- package/dist/plugins/plugin-exports.js +78 -0
- package/dist/plugins/plugin-exports.js.map +1 -0
- package/dist/plugins/plugin-exports.mjs +69 -0
- package/dist/plugins/registry.d.ts +206 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +365 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/registry.mjs +356 -0
- package/dist/plugins/validator.d.ts +63 -0
- package/dist/plugins/validator.d.ts.map +1 -0
- package/dist/plugins/validator.js +464 -0
- package/dist/plugins/validator.js.map +1 -0
- package/dist/plugins/validator.mjs +458 -0
- package/dist/quantization/binary-quantization.d.ts +104 -0
- package/dist/quantization/binary-quantization.d.ts.map +1 -0
- package/dist/quantization/binary-quantization.js +246 -0
- package/dist/quantization/binary-quantization.js.map +1 -0
- package/dist/quantization/binary-quantization.mjs +240 -0
- package/dist/quantization/optimized-pq.d.ts +138 -0
- package/dist/quantization/optimized-pq.d.ts.map +1 -0
- package/dist/quantization/optimized-pq.js +320 -0
- package/dist/quantization/optimized-pq.js.map +1 -0
- package/dist/quantization/optimized-pq.mjs +313 -0
- package/dist/quantization/product-quantization.d.ts +109 -0
- package/dist/quantization/product-quantization.d.ts.map +1 -0
- package/dist/quantization/product-quantization.js +287 -0
- package/dist/quantization/product-quantization.js.map +1 -0
- package/dist/quantization/product-quantization.mjs +282 -0
- package/dist/quantization/scalar-quantization.d.ts +100 -0
- package/dist/quantization/scalar-quantization.d.ts.map +1 -0
- package/dist/quantization/scalar-quantization.js +324 -0
- package/dist/quantization/scalar-quantization.js.map +1 -0
- package/dist/quantization/scalar-quantization.mjs +319 -0
- package/dist/query/index.d.ts +6 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +9 -0
- package/dist/query/index.js.map +1 -0
- package/dist/query/index.mjs +4 -0
- package/dist/query/query-builder.d.ts +323 -0
- package/dist/query/query-builder.d.ts.map +1 -0
- package/dist/query/query-builder.js +524 -0
- package/dist/query/query-builder.js.map +1 -0
- package/dist/query/query-builder.mjs +519 -0
- package/dist/reasoning/context-synthesizer.d.ts +57 -0
- package/dist/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoning/context-synthesizer.js +224 -0
- package/dist/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoning/context-synthesizer.mjs +219 -0
- package/dist/reasoning/experience-curator.d.ts +66 -0
- package/dist/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoning/experience-curator.js +288 -0
- package/dist/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoning/experience-curator.mjs +283 -0
- package/dist/reasoning/memory-optimizer.d.ts +69 -0
- package/dist/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoning/memory-optimizer.js +331 -0
- package/dist/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoning/memory-optimizer.mjs +326 -0
- package/dist/reasoning/pattern-matcher.d.ts +59 -0
- package/dist/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoning/pattern-matcher.js +229 -0
- package/dist/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoning/pattern-matcher.mjs +224 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts +118 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js +477 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js.map +1 -0
- package/dist/reasoningbank/adapter/types.d.ts +113 -0
- package/dist/reasoningbank/adapter/types.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/types.js +9 -0
- package/dist/reasoningbank/adapter/types.js.map +1 -0
- package/dist/reasoningbank/cli/commands.d.ts +16 -0
- package/dist/reasoningbank/cli/commands.d.ts.map +1 -0
- package/dist/reasoningbank/cli/commands.js +272 -0
- package/dist/reasoningbank/cli/commands.js.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts +319 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js +301 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js.map +1 -0
- package/dist/reasoningbank/migration/migrate.d.ts +25 -0
- package/dist/reasoningbank/migration/migrate.d.ts.map +1 -0
- package/dist/reasoningbank/migration/migrate.js +178 -0
- package/dist/reasoningbank/migration/migrate.js.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts +37 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js +114 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts +39 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.js +98 -0
- package/dist/reasoningbank/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts +44 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js +184 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts +40 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js +87 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts +77 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.js +165 -0
- package/dist/reasoningbank/sync/quic-sync.js.map +1 -0
- package/dist/sync/conflict.d.ts +78 -0
- package/dist/sync/conflict.d.ts.map +1 -0
- package/dist/sync/conflict.js +202 -0
- package/dist/sync/conflict.js.map +1 -0
- package/dist/sync/conflict.mjs +196 -0
- package/dist/sync/coordinator.d.ts +111 -0
- package/dist/sync/coordinator.d.ts.map +1 -0
- package/dist/sync/coordinator.js +256 -0
- package/dist/sync/coordinator.js.map +1 -0
- package/dist/sync/coordinator.mjs +250 -0
- package/dist/sync/delta.d.ts +81 -0
- package/dist/sync/delta.d.ts.map +1 -0
- package/dist/sync/delta.js +245 -0
- package/dist/sync/delta.js.map +1 -0
- package/dist/sync/delta.mjs +238 -0
- package/dist/sync/index.d.ts +11 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +22 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/index.mjs +9 -0
- package/dist/sync/quic-sync.d.ts +81 -0
- package/dist/sync/quic-sync.d.ts.map +1 -0
- package/dist/sync/quic-sync.js +329 -0
- package/dist/sync/quic-sync.js.map +1 -0
- package/dist/sync/quic-sync.mjs +323 -0
- package/dist/sync/types.d.ts +168 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +8 -0
- package/dist/sync/types.js.map +1 -0
- package/dist/sync/types.mjs +6 -0
- package/dist/types/index.d.ts +117 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +4 -0
- package/dist/wasm-loader.d.ts +32 -0
- package/dist/wasm-loader.d.ts.map +1 -0
- package/dist/wasm-loader.js +75 -0
- package/dist/wasm-loader.js.map +1 -0
- package/dist/wasm-loader.mjs +64 -0
- package/examples/adaptive-learning.ts +284 -0
- package/examples/browser/README.md +732 -0
- package/examples/browser/adaptive-recommendations/index.html +427 -0
- package/examples/browser/collaborative-filtering/index.html +310 -0
- package/examples/browser/continual-learning/index.html +736 -0
- package/examples/browser/experience-replay/index.html +616 -0
- package/examples/browser/index.html +369 -0
- package/examples/browser/meta-learning/index.html +789 -0
- package/examples/browser/neuro-symbolic/index.html +692 -0
- package/examples/browser/pattern-learning/index.html +620 -0
- package/examples/browser/quantum-inspired/index.html +728 -0
- package/examples/browser/rag/index.html +624 -0
- package/examples/browser/swarm-intelligence/index.html +811 -0
- package/examples/browser-basic.html +170 -0
- package/examples/hnsw-example.ts +148 -0
- package/examples/node-basic.js +70 -0
- package/examples/quic-sync-example.ts +310 -0
- package/examples/quick-start.js +68 -0
- package/examples/wasm-example.ts +222 -0
- package/package.json +118 -0
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native backend implementation using better-sqlite3
|
|
3
|
+
* High-performance backend for Node.js environments
|
|
4
|
+
*/
|
|
5
|
+
import Database from 'better-sqlite3';
|
|
6
|
+
import { HNSWIndex, DEFAULT_HNSW_CONFIG } from '../index/hnsw.mjs';
|
|
7
|
+
/**
|
|
8
|
+
* Native backend using better-sqlite3
|
|
9
|
+
* Optimized for Node.js with native SQLite bindings
|
|
10
|
+
* Features HNSW index for high-performance approximate nearest neighbor search
|
|
11
|
+
*/
|
|
12
|
+
export class NativeBackend {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.db = null;
|
|
15
|
+
this.insertStmt = null;
|
|
16
|
+
this.initialized = false;
|
|
17
|
+
this.hnswIndex = null;
|
|
18
|
+
this.hnswConfig = DEFAULT_HNSW_CONFIG;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Initialize the native backend
|
|
22
|
+
*/
|
|
23
|
+
initialize(config = {}) {
|
|
24
|
+
if (this.initialized) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const { path = ':memory:', memoryMode = true, cacheSize = 100 * 1024, // 100MB in KB
|
|
28
|
+
walMode = true, mmapSize = 256 * 1024 * 1024, // 256MB
|
|
29
|
+
hnsw = {} } = config;
|
|
30
|
+
// Create database instance
|
|
31
|
+
this.db = new Database(memoryMode ? ':memory:' : path);
|
|
32
|
+
// Initialize schema and prepare statements
|
|
33
|
+
this.initializeSchema(cacheSize, walMode, mmapSize);
|
|
34
|
+
this.registerCustomFunctions();
|
|
35
|
+
this.prepareStatements();
|
|
36
|
+
// Initialize HNSW index
|
|
37
|
+
this.hnswConfig = { ...DEFAULT_HNSW_CONFIG, ...hnsw };
|
|
38
|
+
if (this.hnswConfig.enabled) {
|
|
39
|
+
this.hnswIndex = new HNSWIndex(this.db, this.hnswConfig);
|
|
40
|
+
}
|
|
41
|
+
this.initialized = true;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Initialize database schema
|
|
45
|
+
*/
|
|
46
|
+
initializeSchema(cacheSize, walMode, mmapSize) {
|
|
47
|
+
if (!this.db)
|
|
48
|
+
throw new Error('Database not initialized');
|
|
49
|
+
// Optimize SQLite for vector operations
|
|
50
|
+
this.db.pragma('journal_mode = ' + (walMode ? 'WAL' : 'MEMORY'));
|
|
51
|
+
this.db.pragma('synchronous = NORMAL');
|
|
52
|
+
this.db.pragma(`cache_size = -${cacheSize}`);
|
|
53
|
+
this.db.pragma('temp_store = MEMORY');
|
|
54
|
+
this.db.pragma(`mmap_size = ${mmapSize}`);
|
|
55
|
+
this.db.pragma('page_size = 4096');
|
|
56
|
+
// Create vectors table with optimized schema
|
|
57
|
+
this.db.exec(`
|
|
58
|
+
CREATE TABLE IF NOT EXISTS vectors (
|
|
59
|
+
id TEXT PRIMARY KEY,
|
|
60
|
+
embedding BLOB NOT NULL,
|
|
61
|
+
norm REAL NOT NULL,
|
|
62
|
+
metadata TEXT,
|
|
63
|
+
timestamp INTEGER NOT NULL
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
CREATE INDEX IF NOT EXISTS idx_vectors_norm ON vectors(norm);
|
|
67
|
+
CREATE INDEX IF NOT EXISTS idx_vectors_timestamp ON vectors(timestamp);
|
|
68
|
+
`);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Register custom SQL functions for similarity calculations
|
|
72
|
+
*/
|
|
73
|
+
registerCustomFunctions() {
|
|
74
|
+
if (!this.db)
|
|
75
|
+
throw new Error('Database not initialized');
|
|
76
|
+
// Cosine similarity
|
|
77
|
+
this.db.function('cosine_similarity', { deterministic: true }, (a, b, normA, normB) => {
|
|
78
|
+
const arrA = new Float32Array(a.buffer, a.byteOffset, a.byteLength / 4);
|
|
79
|
+
const arrB = new Float32Array(b.buffer, b.byteOffset, b.byteLength / 4);
|
|
80
|
+
let dotProduct = 0;
|
|
81
|
+
for (let i = 0; i < arrA.length; i++) {
|
|
82
|
+
dotProduct += arrA[i] * arrB[i];
|
|
83
|
+
}
|
|
84
|
+
return dotProduct / (normA * normB);
|
|
85
|
+
});
|
|
86
|
+
// Euclidean distance
|
|
87
|
+
this.db.function('euclidean_distance', { deterministic: true }, (a, b) => {
|
|
88
|
+
const arrA = new Float32Array(a.buffer, a.byteOffset, a.byteLength / 4);
|
|
89
|
+
const arrB = new Float32Array(b.buffer, b.byteOffset, b.byteLength / 4);
|
|
90
|
+
let sum = 0;
|
|
91
|
+
for (let i = 0; i < arrA.length; i++) {
|
|
92
|
+
const diff = arrA[i] - arrB[i];
|
|
93
|
+
sum += diff * diff;
|
|
94
|
+
}
|
|
95
|
+
return Math.sqrt(sum);
|
|
96
|
+
});
|
|
97
|
+
// Dot product
|
|
98
|
+
this.db.function('dot_product', { deterministic: true }, (a, b) => {
|
|
99
|
+
const arrA = new Float32Array(a.buffer, a.byteOffset, a.byteLength / 4);
|
|
100
|
+
const arrB = new Float32Array(b.buffer, b.byteOffset, b.byteLength / 4);
|
|
101
|
+
let dotProduct = 0;
|
|
102
|
+
for (let i = 0; i < arrA.length; i++) {
|
|
103
|
+
dotProduct += arrA[i] * arrB[i];
|
|
104
|
+
}
|
|
105
|
+
return dotProduct;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Prepare frequently used statements
|
|
110
|
+
*/
|
|
111
|
+
prepareStatements() {
|
|
112
|
+
if (!this.db)
|
|
113
|
+
throw new Error('Database not initialized');
|
|
114
|
+
this.insertStmt = this.db.prepare(`
|
|
115
|
+
INSERT OR REPLACE INTO vectors (id, embedding, norm, metadata, timestamp)
|
|
116
|
+
VALUES (?, ?, ?, ?, ?)
|
|
117
|
+
`);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Calculate L2 norm of a vector
|
|
121
|
+
*/
|
|
122
|
+
calculateNorm(embedding) {
|
|
123
|
+
let sum = 0;
|
|
124
|
+
for (const val of embedding) {
|
|
125
|
+
sum += val * val;
|
|
126
|
+
}
|
|
127
|
+
return Math.sqrt(sum);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Serialize embedding to binary format
|
|
131
|
+
*/
|
|
132
|
+
serializeEmbedding(embedding) {
|
|
133
|
+
const buffer = Buffer.allocUnsafe(embedding.length * 4);
|
|
134
|
+
const view = new Float32Array(buffer.buffer, buffer.byteOffset, embedding.length);
|
|
135
|
+
view.set(embedding);
|
|
136
|
+
return buffer;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Deserialize embedding from binary format
|
|
140
|
+
*/
|
|
141
|
+
deserializeEmbedding(buffer) {
|
|
142
|
+
const view = new Float32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4);
|
|
143
|
+
return Array.from(view);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Generate unique ID
|
|
147
|
+
*/
|
|
148
|
+
generateId() {
|
|
149
|
+
return `vec_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Insert a single vector
|
|
153
|
+
*/
|
|
154
|
+
insert(vector) {
|
|
155
|
+
if (!this.db || !this.insertStmt)
|
|
156
|
+
throw new Error('Database not initialized');
|
|
157
|
+
const id = vector.id || this.generateId();
|
|
158
|
+
const norm = this.calculateNorm(vector.embedding);
|
|
159
|
+
const embedding = this.serializeEmbedding(vector.embedding);
|
|
160
|
+
const metadata = vector.metadata ? JSON.stringify(vector.metadata) : null;
|
|
161
|
+
const timestamp = vector.timestamp || Date.now();
|
|
162
|
+
this.insertStmt.run(id, embedding, norm, metadata, timestamp);
|
|
163
|
+
// Update HNSW index if enabled
|
|
164
|
+
if (this.hnswIndex && this.shouldUseHNSW()) {
|
|
165
|
+
this.hnswIndex.insert(id, vector.embedding);
|
|
166
|
+
}
|
|
167
|
+
return id;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Insert multiple vectors in a transaction with optimized batch processing
|
|
171
|
+
* Performance improvements:
|
|
172
|
+
* - Single transaction for all inserts
|
|
173
|
+
* - Reused prepared statement
|
|
174
|
+
* - No wrapper function overhead
|
|
175
|
+
* - Chunked processing for large batches
|
|
176
|
+
* - Automatic HNSW index building after batch insert
|
|
177
|
+
*/
|
|
178
|
+
insertBatch(vectors) {
|
|
179
|
+
if (!this.db || !this.insertStmt)
|
|
180
|
+
throw new Error('Database not initialized');
|
|
181
|
+
const ids = [];
|
|
182
|
+
const CHUNK_SIZE = 5000; // Process in chunks to avoid memory spikes
|
|
183
|
+
// Helper function to process a chunk of vectors
|
|
184
|
+
const processChunk = (chunk) => {
|
|
185
|
+
const chunkIds = [];
|
|
186
|
+
const transaction = this.db.transaction((vecs) => {
|
|
187
|
+
// Reuse the prepared statement for all inserts
|
|
188
|
+
for (const vector of vecs) {
|
|
189
|
+
const id = vector.id || this.generateId();
|
|
190
|
+
const norm = this.calculateNorm(vector.embedding);
|
|
191
|
+
const embedding = this.serializeEmbedding(vector.embedding);
|
|
192
|
+
const metadata = vector.metadata ? JSON.stringify(vector.metadata) : null;
|
|
193
|
+
const timestamp = vector.timestamp || Date.now();
|
|
194
|
+
this.insertStmt.run(id, embedding, norm, metadata, timestamp);
|
|
195
|
+
chunkIds.push(id);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
transaction(chunk);
|
|
199
|
+
return chunkIds;
|
|
200
|
+
};
|
|
201
|
+
// Process vectors in chunks
|
|
202
|
+
if (vectors.length <= CHUNK_SIZE) {
|
|
203
|
+
// Small batch - process directly
|
|
204
|
+
ids.push(...processChunk(vectors));
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// Large batch - process in chunks to manage memory
|
|
208
|
+
for (let i = 0; i < vectors.length; i += CHUNK_SIZE) {
|
|
209
|
+
const chunk = vectors.slice(i, i + CHUNK_SIZE);
|
|
210
|
+
ids.push(...processChunk(chunk));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Build HNSW index if threshold reached and not already built
|
|
214
|
+
if (this.hnswIndex && this.shouldUseHNSW() && !this.hnswIndex.isReady()) {
|
|
215
|
+
console.log('Building HNSW index after batch insert...');
|
|
216
|
+
this.hnswIndex.build();
|
|
217
|
+
}
|
|
218
|
+
return ids;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Check if HNSW index should be used
|
|
222
|
+
*/
|
|
223
|
+
shouldUseHNSW() {
|
|
224
|
+
if (!this.hnswIndex || !this.hnswConfig.enabled) {
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
const stats = this.stats();
|
|
228
|
+
return stats.count >= this.hnswConfig.minVectorsForIndex;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Search for k-nearest neighbors
|
|
232
|
+
* Automatically uses HNSW index when available and beneficial
|
|
233
|
+
*/
|
|
234
|
+
search(queryEmbedding, k = 5, metric = 'cosine', threshold = 0.0) {
|
|
235
|
+
if (!this.db)
|
|
236
|
+
throw new Error('Database not initialized');
|
|
237
|
+
// Use HNSW index for euclidean distance if available
|
|
238
|
+
// Note: HNSW currently optimized for euclidean, can be extended for other metrics
|
|
239
|
+
if (this.hnswIndex && this.hnswIndex.isReady() && this.shouldUseHNSW() && metric === 'euclidean') {
|
|
240
|
+
return this.searchWithHNSW(queryEmbedding, k, threshold);
|
|
241
|
+
}
|
|
242
|
+
// Fall back to brute-force search
|
|
243
|
+
return this.bruteForceSearch(queryEmbedding, k, metric, threshold);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Search using HNSW index (fast approximate search)
|
|
247
|
+
*/
|
|
248
|
+
searchWithHNSW(queryEmbedding, k, threshold) {
|
|
249
|
+
if (!this.hnswIndex || !this.db) {
|
|
250
|
+
throw new Error('HNSW index not initialized');
|
|
251
|
+
}
|
|
252
|
+
const results = this.hnswIndex.search(queryEmbedding, k);
|
|
253
|
+
// Filter by threshold and get metadata from main table
|
|
254
|
+
return results
|
|
255
|
+
.filter(r => threshold === 0 || r.distance <= threshold)
|
|
256
|
+
.map(result => {
|
|
257
|
+
const stmt = this.db.prepare('SELECT metadata FROM vectors WHERE id = ?');
|
|
258
|
+
const row = stmt.get(result.vectorId);
|
|
259
|
+
return {
|
|
260
|
+
id: result.vectorId,
|
|
261
|
+
score: result.distance,
|
|
262
|
+
embedding: result.embedding,
|
|
263
|
+
metadata: row?.metadata ? JSON.parse(row.metadata) : undefined
|
|
264
|
+
};
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Brute-force search (accurate but slower)
|
|
269
|
+
*/
|
|
270
|
+
bruteForceSearch(queryEmbedding, k, metric, threshold) {
|
|
271
|
+
if (!this.db)
|
|
272
|
+
throw new Error('Database not initialized');
|
|
273
|
+
const queryBuffer = this.serializeEmbedding(queryEmbedding);
|
|
274
|
+
const queryNorm = this.calculateNorm(queryEmbedding);
|
|
275
|
+
let sql;
|
|
276
|
+
let params;
|
|
277
|
+
switch (metric) {
|
|
278
|
+
case 'cosine':
|
|
279
|
+
sql = `
|
|
280
|
+
SELECT
|
|
281
|
+
id,
|
|
282
|
+
embedding,
|
|
283
|
+
metadata,
|
|
284
|
+
cosine_similarity(embedding, ?, norm, ?) as score
|
|
285
|
+
FROM vectors
|
|
286
|
+
WHERE cosine_similarity(embedding, ?, norm, ?) >= ?
|
|
287
|
+
ORDER BY score DESC
|
|
288
|
+
LIMIT ?
|
|
289
|
+
`;
|
|
290
|
+
params = [queryBuffer, queryNorm, queryBuffer, queryNorm, threshold, k];
|
|
291
|
+
break;
|
|
292
|
+
case 'euclidean':
|
|
293
|
+
sql = `
|
|
294
|
+
SELECT
|
|
295
|
+
id,
|
|
296
|
+
embedding,
|
|
297
|
+
metadata,
|
|
298
|
+
euclidean_distance(embedding, ?) as score
|
|
299
|
+
FROM vectors
|
|
300
|
+
WHERE euclidean_distance(embedding, ?) <= ? OR ? = 0
|
|
301
|
+
ORDER BY score ASC
|
|
302
|
+
LIMIT ?
|
|
303
|
+
`;
|
|
304
|
+
params = [queryBuffer, queryBuffer, threshold, threshold, k];
|
|
305
|
+
break;
|
|
306
|
+
case 'dot':
|
|
307
|
+
sql = `
|
|
308
|
+
SELECT
|
|
309
|
+
id,
|
|
310
|
+
embedding,
|
|
311
|
+
metadata,
|
|
312
|
+
dot_product(embedding, ?) as score
|
|
313
|
+
FROM vectors
|
|
314
|
+
WHERE dot_product(embedding, ?) >= ?
|
|
315
|
+
ORDER BY score DESC
|
|
316
|
+
LIMIT ?
|
|
317
|
+
`;
|
|
318
|
+
params = [queryBuffer, queryBuffer, threshold, k];
|
|
319
|
+
break;
|
|
320
|
+
default:
|
|
321
|
+
throw new Error(`Unsupported similarity metric: ${metric}`);
|
|
322
|
+
}
|
|
323
|
+
const stmt = this.db.prepare(sql);
|
|
324
|
+
const rows = stmt.all(...params);
|
|
325
|
+
return rows.map(row => ({
|
|
326
|
+
id: row.id,
|
|
327
|
+
score: row.score,
|
|
328
|
+
embedding: this.deserializeEmbedding(row.embedding),
|
|
329
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : undefined
|
|
330
|
+
}));
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get vector by ID
|
|
334
|
+
*/
|
|
335
|
+
get(id) {
|
|
336
|
+
if (!this.db)
|
|
337
|
+
throw new Error('Database not initialized');
|
|
338
|
+
const stmt = this.db.prepare('SELECT * FROM vectors WHERE id = ?');
|
|
339
|
+
const row = stmt.get(id);
|
|
340
|
+
if (!row)
|
|
341
|
+
return null;
|
|
342
|
+
return {
|
|
343
|
+
id: row.id,
|
|
344
|
+
embedding: this.deserializeEmbedding(row.embedding),
|
|
345
|
+
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
|
346
|
+
norm: row.norm,
|
|
347
|
+
timestamp: row.timestamp
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Delete vector by ID
|
|
352
|
+
*/
|
|
353
|
+
delete(id) {
|
|
354
|
+
if (!this.db)
|
|
355
|
+
throw new Error('Database not initialized');
|
|
356
|
+
// Delete from HNSW index if enabled
|
|
357
|
+
if (this.hnswIndex && this.shouldUseHNSW()) {
|
|
358
|
+
this.hnswIndex.delete(id);
|
|
359
|
+
}
|
|
360
|
+
const stmt = this.db.prepare('DELETE FROM vectors WHERE id = ?');
|
|
361
|
+
const result = stmt.run(id);
|
|
362
|
+
return result.changes > 0;
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Get database statistics
|
|
366
|
+
*/
|
|
367
|
+
stats() {
|
|
368
|
+
if (!this.db)
|
|
369
|
+
throw new Error('Database not initialized');
|
|
370
|
+
const countStmt = this.db.prepare('SELECT COUNT(*) as count FROM vectors');
|
|
371
|
+
const sizeStmt = this.db.prepare('SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size()');
|
|
372
|
+
const count = countStmt.get().count;
|
|
373
|
+
const size = sizeStmt.get().size;
|
|
374
|
+
return { count, size };
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Close database connection
|
|
378
|
+
*/
|
|
379
|
+
close() {
|
|
380
|
+
if (this.db) {
|
|
381
|
+
this.db.close();
|
|
382
|
+
this.db = null;
|
|
383
|
+
}
|
|
384
|
+
this.insertStmt = null;
|
|
385
|
+
this.initialized = false;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* Get raw database instance (for advanced usage)
|
|
389
|
+
*/
|
|
390
|
+
getDatabase() {
|
|
391
|
+
return this.db;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Check if backend is initialized
|
|
395
|
+
*/
|
|
396
|
+
isInitialized() {
|
|
397
|
+
return this.initialized;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Build HNSW index manually
|
|
401
|
+
* Useful for pre-building index on existing data
|
|
402
|
+
*/
|
|
403
|
+
buildHNSWIndex() {
|
|
404
|
+
if (!this.hnswIndex) {
|
|
405
|
+
throw new Error('HNSW index not enabled');
|
|
406
|
+
}
|
|
407
|
+
if (!this.shouldUseHNSW()) {
|
|
408
|
+
const stats = this.stats();
|
|
409
|
+
console.warn(`Vector count (${stats.count}) below threshold (${this.hnswConfig.minVectorsForIndex}). Index build skipped.`);
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
this.hnswIndex.build();
|
|
413
|
+
}
|
|
414
|
+
/**
|
|
415
|
+
* Get HNSW index statistics
|
|
416
|
+
*/
|
|
417
|
+
getHNSWStats() {
|
|
418
|
+
if (!this.hnswIndex) {
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
const stats = this.hnswIndex.getStats();
|
|
422
|
+
return {
|
|
423
|
+
enabled: this.hnswConfig.enabled,
|
|
424
|
+
ready: this.hnswIndex.isReady(),
|
|
425
|
+
...stats
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Clear HNSW index
|
|
430
|
+
*/
|
|
431
|
+
clearHNSWIndex() {
|
|
432
|
+
if (this.hnswIndex) {
|
|
433
|
+
this.hnswIndex.clear();
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Update HNSW configuration and rebuild if needed
|
|
438
|
+
*/
|
|
439
|
+
updateHNSWConfig(config, rebuild = false) {
|
|
440
|
+
if (!this.hnswIndex) {
|
|
441
|
+
throw new Error('HNSW index not enabled');
|
|
442
|
+
}
|
|
443
|
+
this.hnswIndex.updateConfig(config);
|
|
444
|
+
this.hnswConfig = { ...this.hnswConfig, ...config };
|
|
445
|
+
if (rebuild) {
|
|
446
|
+
this.hnswIndex.build();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core SQLiteVector database implementation with backend abstraction
|
|
3
|
+
* Supports both native (better-sqlite3) and WASM (sql.js) backends
|
|
4
|
+
*/
|
|
5
|
+
import { Vector, SearchResult, SimilarityMetric, DatabaseConfig } from '../types';
|
|
6
|
+
import { VectorBackend, BackendType, ExtendedDatabaseConfig } from './backend-interface';
|
|
7
|
+
import { QueryCache } from '../cache/query-cache';
|
|
8
|
+
import { ProductQuantizer } from '../quantization/product-quantization';
|
|
9
|
+
import { VectorQueryBuilder } from '../query/query-builder';
|
|
10
|
+
export declare class SQLiteVectorDB {
|
|
11
|
+
private backend;
|
|
12
|
+
private backendType;
|
|
13
|
+
private queryCache?;
|
|
14
|
+
private quantizer?;
|
|
15
|
+
constructor(config?: ExtendedDatabaseConfig);
|
|
16
|
+
/**
|
|
17
|
+
* Detect appropriate backend based on environment and configuration
|
|
18
|
+
*/
|
|
19
|
+
private detectBackend;
|
|
20
|
+
/**
|
|
21
|
+
* Create backend instance
|
|
22
|
+
*/
|
|
23
|
+
private createBackend;
|
|
24
|
+
/**
|
|
25
|
+
* Async initialization for WASM backend
|
|
26
|
+
* Must be called after constructor if using WASM backend
|
|
27
|
+
*/
|
|
28
|
+
initializeAsync(config?: DatabaseConfig): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Get backend type
|
|
31
|
+
*/
|
|
32
|
+
getBackendType(): BackendType;
|
|
33
|
+
/**
|
|
34
|
+
* Check if backend is initialized
|
|
35
|
+
*/
|
|
36
|
+
isInitialized(): boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Insert a single vector
|
|
39
|
+
*/
|
|
40
|
+
insert(vector: Vector): string;
|
|
41
|
+
/**
|
|
42
|
+
* Insert multiple vectors in a transaction
|
|
43
|
+
*/
|
|
44
|
+
insertBatch(vectors: Vector[]): string[];
|
|
45
|
+
/**
|
|
46
|
+
* Search for k-nearest neighbors with optional caching
|
|
47
|
+
*/
|
|
48
|
+
search(queryEmbedding: number[], k?: number, metric?: SimilarityMetric, threshold?: number): SearchResult[];
|
|
49
|
+
/**
|
|
50
|
+
* Get vector by ID
|
|
51
|
+
*/
|
|
52
|
+
get(id: string): Vector | null;
|
|
53
|
+
/**
|
|
54
|
+
* Delete vector by ID
|
|
55
|
+
*/
|
|
56
|
+
delete(id: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Get database statistics
|
|
59
|
+
*/
|
|
60
|
+
stats(): {
|
|
61
|
+
count: number;
|
|
62
|
+
size: number;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Close database connection
|
|
66
|
+
*/
|
|
67
|
+
close(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Export database to binary format (WASM only)
|
|
70
|
+
*/
|
|
71
|
+
export(): Uint8Array | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Import database from binary format (WASM only)
|
|
74
|
+
*/
|
|
75
|
+
importAsync(data: Uint8Array): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Get raw backend instance (for advanced usage)
|
|
78
|
+
*/
|
|
79
|
+
getBackend(): VectorBackend;
|
|
80
|
+
/**
|
|
81
|
+
* Get raw database instance (for advanced usage with native backend)
|
|
82
|
+
* @deprecated Use getBackend() instead for cross-backend compatibility
|
|
83
|
+
*/
|
|
84
|
+
getDatabase(): any;
|
|
85
|
+
/**
|
|
86
|
+
* Get query cache instance
|
|
87
|
+
*/
|
|
88
|
+
getQueryCache(): QueryCache<SearchResult[]> | undefined;
|
|
89
|
+
/**
|
|
90
|
+
* Get query cache statistics
|
|
91
|
+
*/
|
|
92
|
+
getCacheStats(): import("../cache/query-cache").CacheStats | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Clear query cache
|
|
95
|
+
*/
|
|
96
|
+
clearCache(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Get quantizer instance
|
|
99
|
+
*/
|
|
100
|
+
getQuantizer(): ProductQuantizer | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Train quantizer with existing vectors
|
|
103
|
+
*/
|
|
104
|
+
trainQuantizer(): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Get compression statistics (if quantization enabled)
|
|
107
|
+
*/
|
|
108
|
+
getCompressionStats(): import("../quantization/product-quantization").CompressionStats | undefined;
|
|
109
|
+
/**
|
|
110
|
+
* Create a fluent query builder for complex queries
|
|
111
|
+
*
|
|
112
|
+
* @returns VectorQueryBuilder instance
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const results = await db.query()
|
|
117
|
+
* .similarTo(queryVector)
|
|
118
|
+
* .where('metadata.category', '=', 'tech')
|
|
119
|
+
* .whereBetween('metadata.year', 2020, 2024)
|
|
120
|
+
* .orderBySimilarity('desc')
|
|
121
|
+
* .limit(10)
|
|
122
|
+
* .execute();
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
query<T = any>(): VectorQueryBuilder<T>;
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=vector-db.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-db.d.ts","sourceRoot":"","sources":["../../src/core/vector-db.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAClF,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAGzF,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,UAAU,CAAC,CAA6B;IAChD,OAAO,CAAC,SAAS,CAAC,CAAmB;gBAEzB,MAAM,GAAE,sBAA2B;IAiC/C;;OAEG;IACH,OAAO,CAAC,aAAa;IAqBrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAWrB;;;OAGG;IACG,eAAe,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7D;;OAEG;IACH,cAAc,IAAI,WAAW;IAI7B;;OAEG;IACH,aAAa,IAAI,OAAO;IAOxB;;OAEG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAI9B;;OAEG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAIxC;;OAEG;IACH,MAAM,CACJ,cAAc,EAAE,MAAM,EAAE,EACxB,CAAC,GAAE,MAAU,EACb,MAAM,GAAE,gBAA2B,EACnC,SAAS,GAAE,MAAY,GACtB,YAAY,EAAE;IAmBjB;;OAEG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAI9B;;OAEG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI3B;;OAEG;IACH,KAAK,IAAI;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAIxC;;OAEG;IACH,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,MAAM,IAAI,UAAU,GAAG,SAAS;IAOhC;;OAEG;IACG,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAQlD;;OAEG;IACH,UAAU,IAAI,aAAa;IAI3B;;;OAGG;IACH,WAAW,IAAI,GAAG;IAOlB;;OAEG;IACH,aAAa,IAAI,UAAU,CAAC,YAAY,EAAE,CAAC,GAAG,SAAS;IAIvD;;OAEG;IACH,aAAa;IAIb;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;OAEG;IACH,YAAY,IAAI,gBAAgB,GAAG,SAAS;IAI5C;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAoBrC;;OAEG;IACH,mBAAmB;IAInB;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,CAAC,GAAG,GAAG,KAAK,kBAAkB,CAAC,CAAC,CAAC;CAGxC"}
|