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