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,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Query Cache with LRU eviction for ultra-fast repeated queries
|
|
4
|
+
*
|
|
5
|
+
* Provides 50-100x speedup for repeated vector searches by caching results.
|
|
6
|
+
* Uses LRU (Least Recently Used) eviction strategy with TTL (Time To Live).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const cache = new QueryCache({ maxSize: 1000, ttl: 300000 }); // 5 min TTL
|
|
11
|
+
*
|
|
12
|
+
* // First query: miss, executes full search
|
|
13
|
+
* const results1 = cache.get(key) ?? performSearch();
|
|
14
|
+
* cache.set(key, results1);
|
|
15
|
+
*
|
|
16
|
+
* // Second query: hit, returns cached results (sub-millisecond)
|
|
17
|
+
* const results2 = cache.get(key); // 50-100x faster
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
var __assign = (this && this.__assign) || function () {
|
|
21
|
+
__assign = Object.assign || function(t) {
|
|
22
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
23
|
+
s = arguments[i];
|
|
24
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
25
|
+
t[p] = s[p];
|
|
26
|
+
}
|
|
27
|
+
return t;
|
|
28
|
+
};
|
|
29
|
+
return __assign.apply(this, arguments);
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.QueryCache = void 0;
|
|
33
|
+
var QueryCache = /** @class */ (function () {
|
|
34
|
+
function QueryCache(config) {
|
|
35
|
+
if (config === void 0) { config = {}; }
|
|
36
|
+
var _a, _b, _c;
|
|
37
|
+
this.cache = new Map();
|
|
38
|
+
// Statistics
|
|
39
|
+
this.stats = {
|
|
40
|
+
hits: 0,
|
|
41
|
+
misses: 0,
|
|
42
|
+
evictions: 0,
|
|
43
|
+
totalAccessTime: 0,
|
|
44
|
+
accessCount: 0
|
|
45
|
+
};
|
|
46
|
+
this.config = {
|
|
47
|
+
maxSize: (_a = config.maxSize) !== null && _a !== void 0 ? _a : 1000,
|
|
48
|
+
ttl: (_b = config.ttl) !== null && _b !== void 0 ? _b : 300000, // 5 minutes
|
|
49
|
+
enableStats: (_c = config.enableStats) !== null && _c !== void 0 ? _c : true
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Generate cache key from query parameters
|
|
54
|
+
*/
|
|
55
|
+
QueryCache.generateKey = function (embedding, k, metric, threshold) {
|
|
56
|
+
// Use first 8 dimensions for key (balance between uniqueness and performance)
|
|
57
|
+
var prefix = embedding.slice(0, 8).map(function (v) { return v.toFixed(4); }).join(',');
|
|
58
|
+
return "".concat(prefix, ":").concat(k, ":").concat(metric !== null && metric !== void 0 ? metric : 'cosine', ":").concat(threshold !== null && threshold !== void 0 ? threshold : 0);
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Get cached results if available and not expired
|
|
62
|
+
*/
|
|
63
|
+
QueryCache.prototype.get = function (key) {
|
|
64
|
+
var startTime = performance.now();
|
|
65
|
+
var entry = this.cache.get(key);
|
|
66
|
+
if (!entry) {
|
|
67
|
+
this.recordMiss(startTime);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
// Check expiry
|
|
71
|
+
var now = Date.now();
|
|
72
|
+
if (now > entry.expiry) {
|
|
73
|
+
this.cache.delete(key);
|
|
74
|
+
this.recordMiss(startTime);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
// Update access metadata
|
|
78
|
+
entry.lastAccessed = now;
|
|
79
|
+
entry.accessCount++;
|
|
80
|
+
this.recordHit(startTime);
|
|
81
|
+
return entry.results;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Store results in cache with LRU eviction
|
|
85
|
+
*/
|
|
86
|
+
QueryCache.prototype.set = function (key, results) {
|
|
87
|
+
// Evict if at capacity
|
|
88
|
+
if (this.cache.size >= this.config.maxSize) {
|
|
89
|
+
this.evictLRU();
|
|
90
|
+
}
|
|
91
|
+
var now = Date.now();
|
|
92
|
+
this.cache.set(key, {
|
|
93
|
+
results: results,
|
|
94
|
+
expiry: now + this.config.ttl,
|
|
95
|
+
lastAccessed: now,
|
|
96
|
+
accessCount: 1
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Evict least recently used entry
|
|
101
|
+
*/
|
|
102
|
+
QueryCache.prototype.evictLRU = function () {
|
|
103
|
+
var oldestKey = null;
|
|
104
|
+
var oldestTime = Infinity;
|
|
105
|
+
for (var _i = 0, _a = this.cache.entries(); _i < _a.length; _i++) {
|
|
106
|
+
var _b = _a[_i], key = _b[0], entry = _b[1];
|
|
107
|
+
if (entry.lastAccessed < oldestTime) {
|
|
108
|
+
oldestTime = entry.lastAccessed;
|
|
109
|
+
oldestKey = key;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (oldestKey) {
|
|
113
|
+
this.cache.delete(oldestKey);
|
|
114
|
+
if (this.config.enableStats) {
|
|
115
|
+
this.stats.evictions++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Clear all cached entries
|
|
121
|
+
*/
|
|
122
|
+
QueryCache.prototype.clear = function () {
|
|
123
|
+
this.cache.clear();
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Clear expired entries
|
|
127
|
+
*/
|
|
128
|
+
QueryCache.prototype.clearExpired = function () {
|
|
129
|
+
var _this = this;
|
|
130
|
+
var now = Date.now();
|
|
131
|
+
var toDelete = [];
|
|
132
|
+
for (var _i = 0, _a = this.cache.entries(); _i < _a.length; _i++) {
|
|
133
|
+
var _b = _a[_i], key = _b[0], entry = _b[1];
|
|
134
|
+
if (now > entry.expiry) {
|
|
135
|
+
toDelete.push(key);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
toDelete.forEach(function (key) { return _this.cache.delete(key); });
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Get cache statistics
|
|
142
|
+
*/
|
|
143
|
+
QueryCache.prototype.getStats = function () {
|
|
144
|
+
var total = this.stats.hits + this.stats.misses;
|
|
145
|
+
return {
|
|
146
|
+
hits: this.stats.hits,
|
|
147
|
+
misses: this.stats.misses,
|
|
148
|
+
hitRate: total > 0 ? this.stats.hits / total : 0,
|
|
149
|
+
size: this.cache.size,
|
|
150
|
+
evictions: this.stats.evictions,
|
|
151
|
+
avgAccessTime: this.stats.accessCount > 0
|
|
152
|
+
? this.stats.totalAccessTime / this.stats.accessCount
|
|
153
|
+
: 0
|
|
154
|
+
};
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* Reset statistics
|
|
158
|
+
*/
|
|
159
|
+
QueryCache.prototype.resetStats = function () {
|
|
160
|
+
this.stats = {
|
|
161
|
+
hits: 0,
|
|
162
|
+
misses: 0,
|
|
163
|
+
evictions: 0,
|
|
164
|
+
totalAccessTime: 0,
|
|
165
|
+
accessCount: 0
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
QueryCache.prototype.recordHit = function (startTime) {
|
|
169
|
+
if (this.config.enableStats) {
|
|
170
|
+
this.stats.hits++;
|
|
171
|
+
this.stats.totalAccessTime += performance.now() - startTime;
|
|
172
|
+
this.stats.accessCount++;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
QueryCache.prototype.recordMiss = function (startTime) {
|
|
176
|
+
if (this.config.enableStats) {
|
|
177
|
+
this.stats.misses++;
|
|
178
|
+
this.stats.totalAccessTime += performance.now() - startTime;
|
|
179
|
+
this.stats.accessCount++;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
Object.defineProperty(QueryCache.prototype, "size", {
|
|
183
|
+
/**
|
|
184
|
+
* Get current cache size
|
|
185
|
+
*/
|
|
186
|
+
get: function () {
|
|
187
|
+
return this.cache.size;
|
|
188
|
+
},
|
|
189
|
+
enumerable: false,
|
|
190
|
+
configurable: true
|
|
191
|
+
});
|
|
192
|
+
/**
|
|
193
|
+
* Check if cache has key
|
|
194
|
+
*/
|
|
195
|
+
QueryCache.prototype.has = function (key) {
|
|
196
|
+
var entry = this.cache.get(key);
|
|
197
|
+
if (!entry)
|
|
198
|
+
return false;
|
|
199
|
+
// Check expiry
|
|
200
|
+
if (Date.now() > entry.expiry) {
|
|
201
|
+
this.cache.delete(key);
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* Delete specific entry
|
|
208
|
+
*/
|
|
209
|
+
QueryCache.prototype.delete = function (key) {
|
|
210
|
+
return this.cache.delete(key);
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Get all cache keys
|
|
214
|
+
*/
|
|
215
|
+
QueryCache.prototype.keys = function () {
|
|
216
|
+
return Array.from(this.cache.keys());
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Get cache configuration
|
|
220
|
+
*/
|
|
221
|
+
QueryCache.prototype.getConfig = function () {
|
|
222
|
+
return __assign({}, this.config);
|
|
223
|
+
};
|
|
224
|
+
/**
|
|
225
|
+
* Update cache configuration
|
|
226
|
+
*/
|
|
227
|
+
QueryCache.prototype.updateConfig = function (config) {
|
|
228
|
+
if (config.maxSize !== undefined) {
|
|
229
|
+
this.config.maxSize = config.maxSize;
|
|
230
|
+
// Evict excess entries if new size is smaller
|
|
231
|
+
while (this.cache.size > this.config.maxSize) {
|
|
232
|
+
this.evictLRU();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (config.ttl !== undefined) {
|
|
236
|
+
this.config.ttl = config.ttl;
|
|
237
|
+
}
|
|
238
|
+
if (config.enableStats !== undefined) {
|
|
239
|
+
this.config.enableStats = config.enableStats;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
return QueryCache;
|
|
243
|
+
}());
|
|
244
|
+
exports.QueryCache = QueryCache;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Database CLI Commands
|
|
3
|
+
* Full-featured CLI commands for database operations
|
|
4
|
+
*/
|
|
5
|
+
import { Command } from 'commander';
|
|
6
|
+
/**
|
|
7
|
+
* Format options for import/export
|
|
8
|
+
*/
|
|
9
|
+
type FileFormat = 'json' | 'csv';
|
|
10
|
+
/**
|
|
11
|
+
* Import vectors from file
|
|
12
|
+
*/
|
|
13
|
+
export declare function importVectors(dbPath: string, filePath: string, options?: {
|
|
14
|
+
format?: FileFormat;
|
|
15
|
+
batchSize?: number;
|
|
16
|
+
verbose?: boolean;
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Export vectors to file
|
|
20
|
+
*/
|
|
21
|
+
export declare function exportVectors(dbPath: string, filePath: string, options?: {
|
|
22
|
+
format?: FileFormat;
|
|
23
|
+
limit?: number;
|
|
24
|
+
where?: string;
|
|
25
|
+
verbose?: boolean;
|
|
26
|
+
}): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Query database with vector
|
|
29
|
+
*/
|
|
30
|
+
export declare function queryVectors(dbPath: string, embeddingInput: string, options?: {
|
|
31
|
+
k?: number;
|
|
32
|
+
metric?: 'cosine' | 'euclidean' | 'dot';
|
|
33
|
+
threshold?: number;
|
|
34
|
+
format?: 'table' | 'json';
|
|
35
|
+
verbose?: boolean;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Show database statistics
|
|
39
|
+
*/
|
|
40
|
+
export declare function showStats(dbPath: string, options?: {
|
|
41
|
+
detailed?: boolean;
|
|
42
|
+
format?: 'table' | 'json';
|
|
43
|
+
}): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Setup database CLI commands
|
|
46
|
+
*/
|
|
47
|
+
export declare function setupDatabaseCommands(program: Command): void;
|
|
48
|
+
export {};
|