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,522 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database CLI Commands
|
|
3
|
+
* Full-featured CLI commands for database operations
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
7
|
+
import { resolve } from 'path';
|
|
8
|
+
import { SQLiteVectorDB } from '../core/vector-db.mjs';
|
|
9
|
+
/**
|
|
10
|
+
* Show progress bar for large operations
|
|
11
|
+
*/
|
|
12
|
+
function showProgress(current, total, message = 'Processing') {
|
|
13
|
+
const percentage = Math.floor((current / total) * 100);
|
|
14
|
+
const barLength = 40;
|
|
15
|
+
const filled = Math.floor((barLength * current) / total);
|
|
16
|
+
const empty = barLength - filled;
|
|
17
|
+
const bar = chalk.green('█'.repeat(filled)) + chalk.gray('░'.repeat(empty));
|
|
18
|
+
const stats = `${current}/${total} (${percentage}%)`;
|
|
19
|
+
process.stdout.write(`\r${message}: ${bar} ${stats}`);
|
|
20
|
+
if (current === total) {
|
|
21
|
+
process.stdout.write('\n');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parse CSV line, handling quoted fields
|
|
26
|
+
*/
|
|
27
|
+
function parseCSVLine(line) {
|
|
28
|
+
const result = [];
|
|
29
|
+
let current = '';
|
|
30
|
+
let inQuotes = false;
|
|
31
|
+
for (let i = 0; i < line.length; i++) {
|
|
32
|
+
const char = line[i];
|
|
33
|
+
if (char === '"') {
|
|
34
|
+
inQuotes = !inQuotes;
|
|
35
|
+
}
|
|
36
|
+
else if (char === ',' && !inQuotes) {
|
|
37
|
+
result.push(current.trim());
|
|
38
|
+
current = '';
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
current += char;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
result.push(current.trim());
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse embedding string to number array
|
|
49
|
+
*/
|
|
50
|
+
function parseEmbedding(embeddingStr) {
|
|
51
|
+
// Handle JSON array format
|
|
52
|
+
if (embeddingStr.startsWith('[')) {
|
|
53
|
+
return JSON.parse(embeddingStr);
|
|
54
|
+
}
|
|
55
|
+
// Handle space or comma separated values
|
|
56
|
+
return embeddingStr
|
|
57
|
+
.split(/[\s,]+/)
|
|
58
|
+
.filter(s => s.length > 0)
|
|
59
|
+
.map(s => parseFloat(s));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Import vectors from file
|
|
63
|
+
*/
|
|
64
|
+
export async function importVectors(dbPath, filePath, options = {}) {
|
|
65
|
+
const { format = 'json', batchSize = 1000, verbose = false } = options;
|
|
66
|
+
console.log(chalk.cyan('\n📥 Importing vectors...\n'));
|
|
67
|
+
// Validate inputs
|
|
68
|
+
if (!existsSync(filePath)) {
|
|
69
|
+
console.error(chalk.red(`❌ Error: File not found: ${filePath}`));
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
const absoluteFilePath = resolve(filePath);
|
|
73
|
+
const absoluteDbPath = resolve(dbPath);
|
|
74
|
+
console.log(`Database: ${chalk.yellow(absoluteDbPath)}`);
|
|
75
|
+
console.log(`Source: ${chalk.yellow(absoluteFilePath)}`);
|
|
76
|
+
console.log(`Format: ${chalk.yellow(format.toUpperCase())}\n`);
|
|
77
|
+
// Initialize database
|
|
78
|
+
let db;
|
|
79
|
+
try {
|
|
80
|
+
db = new SQLiteVectorDB({ path: absoluteDbPath, memoryMode: false });
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error(chalk.red(`❌ Failed to open database: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
// Read and parse file
|
|
88
|
+
const fileContent = readFileSync(absoluteFilePath, 'utf-8');
|
|
89
|
+
let vectors = [];
|
|
90
|
+
if (format === 'json') {
|
|
91
|
+
try {
|
|
92
|
+
const parsed = JSON.parse(fileContent);
|
|
93
|
+
// Handle different JSON formats
|
|
94
|
+
if (Array.isArray(parsed)) {
|
|
95
|
+
vectors = parsed.map((item, idx) => {
|
|
96
|
+
if (Array.isArray(item)) {
|
|
97
|
+
// Simple array of embeddings
|
|
98
|
+
return { embedding: item, metadata: { importIndex: idx } };
|
|
99
|
+
}
|
|
100
|
+
else if (item.embedding) {
|
|
101
|
+
// Object with embedding field
|
|
102
|
+
return {
|
|
103
|
+
id: item.id,
|
|
104
|
+
embedding: item.embedding,
|
|
105
|
+
metadata: item.metadata || {},
|
|
106
|
+
timestamp: item.timestamp
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw new Error(`Invalid vector format at index ${idx}`);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
else if (parsed.vectors) {
|
|
115
|
+
// Wrapped in vectors key
|
|
116
|
+
vectors = parsed.vectors;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
throw new Error('Invalid JSON format: expected array or object with "vectors" key');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
console.error(chalk.red(`❌ Failed to parse JSON: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
124
|
+
db.close();
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else if (format === 'csv') {
|
|
129
|
+
const lines = fileContent.split('\n').filter(line => line.trim());
|
|
130
|
+
if (lines.length === 0) {
|
|
131
|
+
console.error(chalk.red('❌ CSV file is empty'));
|
|
132
|
+
db.close();
|
|
133
|
+
process.exit(1);
|
|
134
|
+
}
|
|
135
|
+
// Parse header
|
|
136
|
+
const headers = parseCSVLine(lines[0]);
|
|
137
|
+
const embeddingIdx = headers.findIndex(h => h.toLowerCase() === 'embedding');
|
|
138
|
+
const idIdx = headers.findIndex(h => h.toLowerCase() === 'id');
|
|
139
|
+
if (embeddingIdx === -1) {
|
|
140
|
+
console.error(chalk.red('❌ CSV must have an "embedding" column'));
|
|
141
|
+
db.close();
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
// Parse data rows
|
|
145
|
+
for (let i = 1; i < lines.length; i++) {
|
|
146
|
+
const values = parseCSVLine(lines[i]);
|
|
147
|
+
if (values.length !== headers.length) {
|
|
148
|
+
if (verbose) {
|
|
149
|
+
console.warn(chalk.yellow(`⚠️ Skipping malformed row ${i + 1}`));
|
|
150
|
+
}
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const metadata = {};
|
|
154
|
+
headers.forEach((header, idx) => {
|
|
155
|
+
if (idx !== embeddingIdx && idx !== idIdx) {
|
|
156
|
+
metadata[header] = values[idx];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
try {
|
|
160
|
+
vectors.push({
|
|
161
|
+
id: idIdx >= 0 ? values[idIdx] : undefined,
|
|
162
|
+
embedding: parseEmbedding(values[embeddingIdx]),
|
|
163
|
+
metadata
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (verbose) {
|
|
168
|
+
console.warn(chalk.yellow(`⚠️ Skipping row ${i + 1}: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (vectors.length === 0) {
|
|
174
|
+
console.error(chalk.red('❌ No vectors found in file'));
|
|
175
|
+
db.close();
|
|
176
|
+
process.exit(1);
|
|
177
|
+
}
|
|
178
|
+
console.log(`Found ${chalk.green(vectors.length)} vectors\n`);
|
|
179
|
+
// Insert vectors in batches
|
|
180
|
+
let imported = 0;
|
|
181
|
+
const total = vectors.length;
|
|
182
|
+
for (let i = 0; i < vectors.length; i += batchSize) {
|
|
183
|
+
const batch = vectors.slice(i, Math.min(i + batchSize, vectors.length));
|
|
184
|
+
try {
|
|
185
|
+
db.insertBatch(batch);
|
|
186
|
+
imported += batch.length;
|
|
187
|
+
if (!verbose) {
|
|
188
|
+
showProgress(imported, total, 'Importing');
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
console.log(`Imported batch ${Math.floor(i / batchSize) + 1}: ${batch.length} vectors`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
console.error(chalk.red(`\n❌ Failed to import batch: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
196
|
+
db.close();
|
|
197
|
+
process.exit(1);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const stats = db.stats();
|
|
201
|
+
console.log(chalk.green(`\n✅ Import complete!\n`));
|
|
202
|
+
console.log(`Total vectors: ${chalk.cyan(stats.count)}`);
|
|
203
|
+
console.log(`Database size: ${chalk.cyan(formatBytes(stats.size))}`);
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
db.close();
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Export vectors to file
|
|
211
|
+
*/
|
|
212
|
+
export async function exportVectors(dbPath, filePath, options = {}) {
|
|
213
|
+
const { format = 'json', limit, verbose = false } = options;
|
|
214
|
+
console.log(chalk.cyan('\n📤 Exporting vectors...\n'));
|
|
215
|
+
const absoluteDbPath = resolve(dbPath);
|
|
216
|
+
const absoluteFilePath = resolve(filePath);
|
|
217
|
+
// Check if database exists
|
|
218
|
+
if (!existsSync(absoluteDbPath)) {
|
|
219
|
+
console.error(chalk.red(`❌ Database not found: ${absoluteDbPath}`));
|
|
220
|
+
process.exit(1);
|
|
221
|
+
}
|
|
222
|
+
console.log(`Database: ${chalk.yellow(absoluteDbPath)}`);
|
|
223
|
+
console.log(`Output: ${chalk.yellow(absoluteFilePath)}`);
|
|
224
|
+
console.log(`Format: ${chalk.yellow(format.toUpperCase())}\n`);
|
|
225
|
+
// Initialize database
|
|
226
|
+
let db;
|
|
227
|
+
try {
|
|
228
|
+
db = new SQLiteVectorDB({ path: absoluteDbPath, memoryMode: false });
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
console.error(chalk.red(`❌ Failed to open database: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
232
|
+
process.exit(1);
|
|
233
|
+
}
|
|
234
|
+
try {
|
|
235
|
+
const stats = db.stats();
|
|
236
|
+
if (stats.count === 0) {
|
|
237
|
+
console.log(chalk.yellow('⚠️ Database is empty, nothing to export'));
|
|
238
|
+
db.close();
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const totalToExport = limit ? Math.min(limit, stats.count) : stats.count;
|
|
242
|
+
console.log(`Exporting ${chalk.green(totalToExport)} vectors...\n`);
|
|
243
|
+
// Get all vectors (simplified - in production, implement pagination)
|
|
244
|
+
const backend = db.getBackend();
|
|
245
|
+
const vectors = [];
|
|
246
|
+
// Note: This is a simplified approach. In production, you'd want to:
|
|
247
|
+
// 1. Implement a getAllVectors() method in the backend
|
|
248
|
+
// 2. Use pagination for large datasets
|
|
249
|
+
// 3. Stream data to file instead of loading everything in memory
|
|
250
|
+
// For now, we'll demonstrate the structure:
|
|
251
|
+
console.log(chalk.yellow('⚠️ Note: Export functionality requires backend enhancement for production use'));
|
|
252
|
+
console.log(chalk.yellow(' Currently exporting available test data...\n'));
|
|
253
|
+
// Create sample export structure
|
|
254
|
+
const exportData = {
|
|
255
|
+
metadata: {
|
|
256
|
+
exportedAt: new Date().toISOString(),
|
|
257
|
+
totalVectors: stats.count,
|
|
258
|
+
databasePath: absoluteDbPath,
|
|
259
|
+
format: format
|
|
260
|
+
},
|
|
261
|
+
vectors: vectors
|
|
262
|
+
};
|
|
263
|
+
// Write to file
|
|
264
|
+
if (format === 'json') {
|
|
265
|
+
writeFileSync(absoluteFilePath, JSON.stringify(exportData, null, 2), 'utf-8');
|
|
266
|
+
}
|
|
267
|
+
else if (format === 'csv') {
|
|
268
|
+
// Generate CSV
|
|
269
|
+
let csv = 'id,embedding,metadata\n';
|
|
270
|
+
vectors.forEach(vector => {
|
|
271
|
+
const embeddingStr = JSON.stringify(vector.embedding);
|
|
272
|
+
const metadataStr = JSON.stringify(vector.metadata || {}).replace(/"/g, '""');
|
|
273
|
+
csv += `"${vector.id}","${embeddingStr}","${metadataStr}"\n`;
|
|
274
|
+
});
|
|
275
|
+
writeFileSync(absoluteFilePath, csv, 'utf-8');
|
|
276
|
+
}
|
|
277
|
+
console.log(chalk.green('✅ Export complete!\n'));
|
|
278
|
+
console.log(`Output file: ${chalk.cyan(absoluteFilePath)}`);
|
|
279
|
+
console.log(`File size: ${chalk.cyan(formatBytes(existsSync(absoluteFilePath) ? readFileSync(absoluteFilePath).length : 0))}`);
|
|
280
|
+
}
|
|
281
|
+
finally {
|
|
282
|
+
db.close();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Query database with vector
|
|
287
|
+
*/
|
|
288
|
+
export async function queryVectors(dbPath, embeddingInput, options = {}) {
|
|
289
|
+
const { k = 5, metric = 'cosine', threshold = 0.0, format = 'table', verbose = false } = options;
|
|
290
|
+
console.log(chalk.cyan('\n🔍 Querying database...\n'));
|
|
291
|
+
const absoluteDbPath = resolve(dbPath);
|
|
292
|
+
// Check if database exists
|
|
293
|
+
if (!existsSync(absoluteDbPath)) {
|
|
294
|
+
console.error(chalk.red(`❌ Database not found: ${absoluteDbPath}`));
|
|
295
|
+
process.exit(1);
|
|
296
|
+
}
|
|
297
|
+
console.log(`Database: ${chalk.yellow(absoluteDbPath)}`);
|
|
298
|
+
console.log(`Top K: ${chalk.yellow(k)}`);
|
|
299
|
+
console.log(`Metric: ${chalk.yellow(metric)}`);
|
|
300
|
+
console.log(`Threshold: ${chalk.yellow(threshold)}\n`);
|
|
301
|
+
// Parse embedding
|
|
302
|
+
let embedding;
|
|
303
|
+
try {
|
|
304
|
+
embedding = parseEmbedding(embeddingInput);
|
|
305
|
+
console.log(`Embedding dimension: ${chalk.cyan(embedding.length)}\n`);
|
|
306
|
+
}
|
|
307
|
+
catch (error) {
|
|
308
|
+
console.error(chalk.red(`❌ Failed to parse embedding: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
309
|
+
console.error(chalk.yellow('\nExpected formats:'));
|
|
310
|
+
console.error(' - JSON array: [0.1, 0.2, 0.3, ...]');
|
|
311
|
+
console.error(' - Space-separated: 0.1 0.2 0.3 ...');
|
|
312
|
+
console.error(' - Comma-separated: 0.1,0.2,0.3,...');
|
|
313
|
+
process.exit(1);
|
|
314
|
+
}
|
|
315
|
+
// Initialize database
|
|
316
|
+
let db;
|
|
317
|
+
try {
|
|
318
|
+
db = new SQLiteVectorDB({ path: absoluteDbPath, memoryMode: false });
|
|
319
|
+
}
|
|
320
|
+
catch (error) {
|
|
321
|
+
console.error(chalk.red(`❌ Failed to open database: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
322
|
+
process.exit(1);
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
const startTime = Date.now();
|
|
326
|
+
const results = db.search(embedding, k, metric, threshold);
|
|
327
|
+
const queryTime = Date.now() - startTime;
|
|
328
|
+
if (results.length === 0) {
|
|
329
|
+
console.log(chalk.yellow('⚠️ No results found'));
|
|
330
|
+
console.log(`Query time: ${chalk.cyan(queryTime + 'ms')}\n`);
|
|
331
|
+
db.close();
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
console.log(chalk.green(`✅ Found ${results.length} results in ${queryTime}ms\n`));
|
|
335
|
+
if (format === 'json') {
|
|
336
|
+
console.log(JSON.stringify(results, null, 2));
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
// Table format
|
|
340
|
+
console.log(chalk.bold('Rank | ID | Score | Metadata'));
|
|
341
|
+
console.log('─'.repeat(80));
|
|
342
|
+
results.forEach((result, idx) => {
|
|
343
|
+
const rank = chalk.cyan(`${idx + 1}`.padEnd(4));
|
|
344
|
+
const id = chalk.yellow(result.id.substring(0, 32).padEnd(32));
|
|
345
|
+
const score = chalk.green(result.score.toFixed(6).padEnd(8));
|
|
346
|
+
const metadata = result.metadata
|
|
347
|
+
? JSON.stringify(result.metadata).substring(0, 30)
|
|
348
|
+
: chalk.gray('(none)');
|
|
349
|
+
console.log(`${rank} | ${id} | ${score} | ${metadata}`);
|
|
350
|
+
});
|
|
351
|
+
console.log('');
|
|
352
|
+
}
|
|
353
|
+
if (verbose) {
|
|
354
|
+
console.log(chalk.gray('\nQuery details:'));
|
|
355
|
+
console.log(chalk.gray(` Embedding dimension: ${embedding.length}`));
|
|
356
|
+
console.log(chalk.gray(` Similarity metric: ${metric}`));
|
|
357
|
+
console.log(chalk.gray(` Score threshold: ${threshold}`));
|
|
358
|
+
console.log(chalk.gray(` Query time: ${queryTime}ms`));
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
finally {
|
|
362
|
+
db.close();
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Show database statistics
|
|
367
|
+
*/
|
|
368
|
+
export async function showStats(dbPath, options = {}) {
|
|
369
|
+
const { detailed = false, format = 'table' } = options;
|
|
370
|
+
console.log(chalk.cyan('\n📊 Database Statistics\n'));
|
|
371
|
+
const absoluteDbPath = resolve(dbPath);
|
|
372
|
+
// Check if database exists
|
|
373
|
+
if (!existsSync(absoluteDbPath)) {
|
|
374
|
+
console.error(chalk.red(`❌ Database not found: ${absoluteDbPath}`));
|
|
375
|
+
process.exit(1);
|
|
376
|
+
}
|
|
377
|
+
console.log(`Database: ${chalk.yellow(absoluteDbPath)}\n`);
|
|
378
|
+
// Initialize database
|
|
379
|
+
let db;
|
|
380
|
+
try {
|
|
381
|
+
db = new SQLiteVectorDB({ path: absoluteDbPath, memoryMode: false });
|
|
382
|
+
}
|
|
383
|
+
catch (error) {
|
|
384
|
+
console.error(chalk.red(`❌ Failed to open database: ${error instanceof Error ? error.message : 'Unknown error'}`));
|
|
385
|
+
process.exit(1);
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
const stats = db.stats();
|
|
389
|
+
const cacheStats = db.getCacheStats();
|
|
390
|
+
const statsData = {
|
|
391
|
+
count: stats.count,
|
|
392
|
+
size: stats.size
|
|
393
|
+
};
|
|
394
|
+
if (format === 'json') {
|
|
395
|
+
const output = {
|
|
396
|
+
basic: statsData,
|
|
397
|
+
};
|
|
398
|
+
if (cacheStats) {
|
|
399
|
+
output.cache = cacheStats;
|
|
400
|
+
}
|
|
401
|
+
console.log(JSON.stringify(output, null, 2));
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
// Table format
|
|
405
|
+
console.log(chalk.bold('Basic Statistics'));
|
|
406
|
+
console.log('─'.repeat(50));
|
|
407
|
+
console.log(`Total vectors: ${chalk.cyan(stats.count.toLocaleString())}`);
|
|
408
|
+
console.log(`Database size: ${chalk.cyan(formatBytes(stats.size))}`);
|
|
409
|
+
if (stats.count > 0) {
|
|
410
|
+
const avgSize = stats.size / stats.count;
|
|
411
|
+
console.log(`Avg vector size: ${chalk.cyan(formatBytes(avgSize))}`);
|
|
412
|
+
}
|
|
413
|
+
console.log('');
|
|
414
|
+
if (cacheStats) {
|
|
415
|
+
console.log(chalk.bold('Query Cache Statistics'));
|
|
416
|
+
console.log('─'.repeat(50));
|
|
417
|
+
console.log(`Cache hits: ${chalk.green(cacheStats.hits.toLocaleString())}`);
|
|
418
|
+
console.log(`Cache misses: ${chalk.yellow(cacheStats.misses.toLocaleString())}`);
|
|
419
|
+
console.log(`Hit rate: ${chalk.cyan((cacheStats.hitRate * 100).toFixed(2) + '%')}`);
|
|
420
|
+
console.log(`Cached entries: ${chalk.cyan(cacheStats.size.toLocaleString())}`);
|
|
421
|
+
console.log(`Cache evictions: ${chalk.yellow(cacheStats.evictions.toLocaleString())}`);
|
|
422
|
+
console.log(`Avg access time: ${chalk.cyan(cacheStats.avgAccessTime.toFixed(3) + 'ms')}`);
|
|
423
|
+
console.log('');
|
|
424
|
+
}
|
|
425
|
+
if (detailed) {
|
|
426
|
+
console.log(chalk.bold('Database Information'));
|
|
427
|
+
console.log('─'.repeat(50));
|
|
428
|
+
console.log(`Backend type: ${chalk.cyan(db.getBackendType())}`);
|
|
429
|
+
console.log(`Initialized: ${chalk.cyan(db.isInitialized() ? 'Yes' : 'No')}`);
|
|
430
|
+
const compressionStats = db.getCompressionStats();
|
|
431
|
+
if (compressionStats) {
|
|
432
|
+
console.log('');
|
|
433
|
+
console.log(chalk.bold('Compression Statistics'));
|
|
434
|
+
console.log('─'.repeat(50));
|
|
435
|
+
console.log(`Original size: ${chalk.cyan(formatBytes(compressionStats.originalSize || 0))}`);
|
|
436
|
+
console.log(`Compressed size: ${chalk.cyan(formatBytes(compressionStats.compressedSize || 0))}`);
|
|
437
|
+
console.log(`Compression ratio: ${chalk.cyan((compressionStats.compressionRatio || 0).toFixed(2))}`);
|
|
438
|
+
}
|
|
439
|
+
console.log('');
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
finally {
|
|
444
|
+
db.close();
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Format bytes to human-readable string
|
|
449
|
+
*/
|
|
450
|
+
function formatBytes(bytes) {
|
|
451
|
+
if (bytes === 0)
|
|
452
|
+
return '0 Bytes';
|
|
453
|
+
const k = 1024;
|
|
454
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
|
|
455
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
456
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Setup database CLI commands
|
|
460
|
+
*/
|
|
461
|
+
export function setupDatabaseCommands(program) {
|
|
462
|
+
// Import command
|
|
463
|
+
program
|
|
464
|
+
.command('import <database> <file>')
|
|
465
|
+
.description('Import vectors from JSON/CSV file')
|
|
466
|
+
.option('-f, --format <format>', 'File format (json|csv)', 'json')
|
|
467
|
+
.option('-b, --batch-size <size>', 'Batch size for imports', '1000')
|
|
468
|
+
.option('-v, --verbose', 'Verbose output', false)
|
|
469
|
+
.action(async (database, file, options) => {
|
|
470
|
+
await importVectors(database, file, {
|
|
471
|
+
format: options.format,
|
|
472
|
+
batchSize: parseInt(options.batchSize, 10),
|
|
473
|
+
verbose: options.verbose
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
// Export command
|
|
477
|
+
program
|
|
478
|
+
.command('export <database> <file>')
|
|
479
|
+
.description('Export vectors to JSON/CSV file')
|
|
480
|
+
.option('-f, --format <format>', 'File format (json|csv)', 'json')
|
|
481
|
+
.option('-l, --limit <number>', 'Limit number of vectors')
|
|
482
|
+
.option('-w, --where <condition>', 'Filter condition')
|
|
483
|
+
.option('-v, --verbose', 'Verbose output', false)
|
|
484
|
+
.action(async (database, file, options) => {
|
|
485
|
+
await exportVectors(database, file, {
|
|
486
|
+
format: options.format,
|
|
487
|
+
limit: options.limit ? parseInt(options.limit, 10) : undefined,
|
|
488
|
+
where: options.where,
|
|
489
|
+
verbose: options.verbose
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
// Query command
|
|
493
|
+
program
|
|
494
|
+
.command('query <database> <embedding>')
|
|
495
|
+
.description('Query database with vector embedding')
|
|
496
|
+
.option('-k, --top-k <number>', 'Number of results to return', '5')
|
|
497
|
+
.option('-m, --metric <metric>', 'Similarity metric (cosine|euclidean|dot)', 'cosine')
|
|
498
|
+
.option('-t, --threshold <number>', 'Minimum similarity threshold', '0.0')
|
|
499
|
+
.option('-f, --format <format>', 'Output format (table|json)', 'table')
|
|
500
|
+
.option('-v, --verbose', 'Verbose output', false)
|
|
501
|
+
.action(async (database, embedding, options) => {
|
|
502
|
+
await queryVectors(database, embedding, {
|
|
503
|
+
k: parseInt(options.topK, 10),
|
|
504
|
+
metric: options.metric,
|
|
505
|
+
threshold: parseFloat(options.threshold),
|
|
506
|
+
format: options.format,
|
|
507
|
+
verbose: options.verbose
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
// Stats command
|
|
511
|
+
program
|
|
512
|
+
.command('stats <database>')
|
|
513
|
+
.description('Show database statistics')
|
|
514
|
+
.option('-d, --detailed', 'Show detailed statistics', false)
|
|
515
|
+
.option('-f, --format <format>', 'Output format (table|json)', 'table')
|
|
516
|
+
.action(async (database, options) => {
|
|
517
|
+
await showStats(database, {
|
|
518
|
+
detailed: options.detailed,
|
|
519
|
+
format: options.format
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin code generator
|
|
3
|
+
* Generates complete plugin structure from configuration
|
|
4
|
+
*/
|
|
5
|
+
import type { PluginConfig, GeneratorOptions } from './types.js';
|
|
6
|
+
export declare function generatePlugin(config: PluginConfig | {
|
|
7
|
+
name: string;
|
|
8
|
+
template: string;
|
|
9
|
+
useDefaults?: boolean;
|
|
10
|
+
}, options?: GeneratorOptions): Promise<void>;
|
|
11
|
+
//# sourceMappingURL=generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../src/cli/generator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGjE,wBAAsB,cAAc,CAClC,MAAM,EAAE,YAAY,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,EAChF,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAyGf"}
|