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,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for learning plugins providing common functionality
|
|
3
|
+
*/
|
|
4
|
+
import { SQLiteVectorDB } from '../core/vector-db.mjs';
|
|
5
|
+
/**
|
|
6
|
+
* Abstract base class that provides common functionality for all learning plugins
|
|
7
|
+
*/
|
|
8
|
+
export class BasePlugin {
|
|
9
|
+
constructor() {
|
|
10
|
+
/** Whether plugin is initialized */
|
|
11
|
+
this.initialized = false;
|
|
12
|
+
/** Experience counter */
|
|
13
|
+
this.experienceCount = 0;
|
|
14
|
+
/** Episode counter */
|
|
15
|
+
this.episodeCount = 0;
|
|
16
|
+
/** Success counter */
|
|
17
|
+
this.successCount = 0;
|
|
18
|
+
/** Total reward accumulated */
|
|
19
|
+
this.totalReward = 0;
|
|
20
|
+
/** Total duration accumulated */
|
|
21
|
+
this.totalDuration = 0;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Initialize the plugin with configuration
|
|
25
|
+
*/
|
|
26
|
+
async initialize(config) {
|
|
27
|
+
this.config = config;
|
|
28
|
+
// Initialize vector database
|
|
29
|
+
const dbConfig = {
|
|
30
|
+
path: config.storage.path,
|
|
31
|
+
memoryMode: false,
|
|
32
|
+
queryCache: {
|
|
33
|
+
enabled: true,
|
|
34
|
+
maxSize: 1000,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
// Add quantization if properly configured
|
|
38
|
+
if (config.storage.quantization?.enabled) {
|
|
39
|
+
dbConfig.quantization = {
|
|
40
|
+
enabled: true,
|
|
41
|
+
dimensions: config.algorithm.stateDim || 768,
|
|
42
|
+
subvectors: 8,
|
|
43
|
+
bits: config.storage.quantization.bits || 8,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
this.vectorDB = new SQLiteVectorDB(dbConfig);
|
|
47
|
+
// If using WASM backend, initialize async
|
|
48
|
+
if (this.vectorDB.getBackendType() === 'wasm') {
|
|
49
|
+
await this.vectorDB.initializeAsync();
|
|
50
|
+
}
|
|
51
|
+
this.initialized = true;
|
|
52
|
+
// Call custom initialization
|
|
53
|
+
await this.onInitialize();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Destroy the plugin and cleanup resources
|
|
57
|
+
*/
|
|
58
|
+
async destroy() {
|
|
59
|
+
if (this.vectorDB) {
|
|
60
|
+
this.vectorDB.close();
|
|
61
|
+
}
|
|
62
|
+
this.initialized = false;
|
|
63
|
+
// Call custom cleanup
|
|
64
|
+
await this.onDestroy();
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Store a single experience
|
|
68
|
+
*/
|
|
69
|
+
async storeExperience(experience) {
|
|
70
|
+
this.checkInitialized();
|
|
71
|
+
// Generate ID if not provided
|
|
72
|
+
if (!experience.id) {
|
|
73
|
+
experience.id = this.generateId();
|
|
74
|
+
}
|
|
75
|
+
// Store in vector database
|
|
76
|
+
this.vectorDB.insert({
|
|
77
|
+
id: experience.id,
|
|
78
|
+
embedding: experience.state,
|
|
79
|
+
metadata: {
|
|
80
|
+
action: experience.action,
|
|
81
|
+
reward: experience.reward,
|
|
82
|
+
nextState: experience.nextState,
|
|
83
|
+
done: experience.done,
|
|
84
|
+
episodeId: experience.episodeId,
|
|
85
|
+
stepIndex: experience.stepIndex,
|
|
86
|
+
...experience.metadata,
|
|
87
|
+
timestamp: experience.timestamp || Date.now(),
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
// Update counters
|
|
91
|
+
this.experienceCount++;
|
|
92
|
+
this.totalReward += experience.reward;
|
|
93
|
+
if (experience.metadata?.duration) {
|
|
94
|
+
this.totalDuration += experience.metadata.duration;
|
|
95
|
+
}
|
|
96
|
+
if (experience.metadata?.success) {
|
|
97
|
+
this.successCount++;
|
|
98
|
+
}
|
|
99
|
+
// Track unique episodes
|
|
100
|
+
if (experience.done && experience.episodeId) {
|
|
101
|
+
this.episodeCount++;
|
|
102
|
+
}
|
|
103
|
+
// Call custom hook
|
|
104
|
+
await this.onStoreExperience(experience);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Store a batch of experiences
|
|
108
|
+
*/
|
|
109
|
+
async storeBatch(experiences) {
|
|
110
|
+
this.checkInitialized();
|
|
111
|
+
for (const experience of experiences) {
|
|
112
|
+
await this.storeExperience(experience);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Retrieve similar experiences from storage
|
|
117
|
+
*/
|
|
118
|
+
async retrieveSimilar(state, k) {
|
|
119
|
+
this.checkInitialized();
|
|
120
|
+
const results = this.vectorDB.search(state, k, 'cosine');
|
|
121
|
+
return results.map(r => ({
|
|
122
|
+
id: r.id,
|
|
123
|
+
score: r.score,
|
|
124
|
+
embedding: r.embedding,
|
|
125
|
+
metadata: {
|
|
126
|
+
id: r.id,
|
|
127
|
+
state: r.embedding,
|
|
128
|
+
action: r.metadata.action,
|
|
129
|
+
reward: r.metadata.reward,
|
|
130
|
+
nextState: r.metadata.nextState,
|
|
131
|
+
done: r.metadata.done,
|
|
132
|
+
episodeId: r.metadata.episodeId,
|
|
133
|
+
stepIndex: r.metadata.stepIndex,
|
|
134
|
+
metadata: r.metadata,
|
|
135
|
+
timestamp: r.metadata.timestamp,
|
|
136
|
+
},
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get current plugin metrics
|
|
141
|
+
*/
|
|
142
|
+
async getMetrics() {
|
|
143
|
+
return {
|
|
144
|
+
totalExperiences: this.experienceCount,
|
|
145
|
+
totalEpisodes: this.episodeCount,
|
|
146
|
+
successRate: this.experienceCount > 0 ? this.successCount / this.experienceCount : 0,
|
|
147
|
+
avgReward: this.experienceCount > 0 ? this.totalReward / this.experienceCount : 0,
|
|
148
|
+
avgDuration: this.experienceCount > 0 ? this.totalDuration / this.experienceCount : 0,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Get plugin configuration
|
|
153
|
+
*/
|
|
154
|
+
getConfig() {
|
|
155
|
+
return this.config;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Save plugin state to disk
|
|
159
|
+
*/
|
|
160
|
+
async save(path) {
|
|
161
|
+
this.checkInitialized();
|
|
162
|
+
// Export database if WASM
|
|
163
|
+
if (this.vectorDB.getBackendType() === 'wasm') {
|
|
164
|
+
const data = this.vectorDB.export();
|
|
165
|
+
if (data) {
|
|
166
|
+
const fs = await import('fs/promises');
|
|
167
|
+
await fs.writeFile(path, data);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Call custom save
|
|
171
|
+
await this.onSave(path);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Load plugin state from disk
|
|
175
|
+
*/
|
|
176
|
+
async load(path) {
|
|
177
|
+
this.checkInitialized();
|
|
178
|
+
// Import database if WASM
|
|
179
|
+
if (this.vectorDB.getBackendType() === 'wasm') {
|
|
180
|
+
const fs = await import('fs/promises');
|
|
181
|
+
const data = await fs.readFile(path);
|
|
182
|
+
await this.vectorDB.importAsync(new Uint8Array(data));
|
|
183
|
+
}
|
|
184
|
+
// Call custom load
|
|
185
|
+
await this.onLoad(path);
|
|
186
|
+
}
|
|
187
|
+
// Lifecycle hooks (can be overridden by subclasses)
|
|
188
|
+
/**
|
|
189
|
+
* Called after initialize() completes
|
|
190
|
+
*/
|
|
191
|
+
async onInitialize() {
|
|
192
|
+
// Override in subclass if needed
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Called before destroy() completes
|
|
196
|
+
*/
|
|
197
|
+
async onDestroy() {
|
|
198
|
+
// Override in subclass if needed
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Called after each experience is stored
|
|
202
|
+
*/
|
|
203
|
+
async onStoreExperience(experience) {
|
|
204
|
+
// Override in subclass if needed
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Called during save()
|
|
208
|
+
*/
|
|
209
|
+
async onSave(path) {
|
|
210
|
+
// Override in subclass if needed
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Called during load()
|
|
214
|
+
*/
|
|
215
|
+
async onLoad(path) {
|
|
216
|
+
// Override in subclass if needed
|
|
217
|
+
}
|
|
218
|
+
// Utility methods
|
|
219
|
+
/**
|
|
220
|
+
* Check if plugin is initialized
|
|
221
|
+
*/
|
|
222
|
+
checkInitialized() {
|
|
223
|
+
if (!this.initialized) {
|
|
224
|
+
throw new Error(`Plugin ${this.name} not initialized. Call initialize() first.`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Generate unique ID
|
|
229
|
+
*/
|
|
230
|
+
generateId() {
|
|
231
|
+
return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Compute discounted returns for an episode
|
|
235
|
+
*/
|
|
236
|
+
computeReturns(rewards, gamma) {
|
|
237
|
+
const returns = new Array(rewards.length);
|
|
238
|
+
let futureReturn = 0;
|
|
239
|
+
for (let i = rewards.length - 1; i >= 0; i--) {
|
|
240
|
+
futureReturn = rewards[i] + gamma * futureReturn;
|
|
241
|
+
returns[i] = futureReturn;
|
|
242
|
+
}
|
|
243
|
+
return returns;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Compute custom reward based on configuration
|
|
247
|
+
*/
|
|
248
|
+
computeReward(experience) {
|
|
249
|
+
if (!this.config.reward) {
|
|
250
|
+
return experience.reward;
|
|
251
|
+
}
|
|
252
|
+
const { type } = this.config.reward;
|
|
253
|
+
const metadata = experience.metadata || {};
|
|
254
|
+
switch (type) {
|
|
255
|
+
case 'success_based':
|
|
256
|
+
return metadata.success ? 1.0 : -1.0;
|
|
257
|
+
case 'time_aware': {
|
|
258
|
+
const baseReward = metadata.success ? 1.0 : -1.0;
|
|
259
|
+
const timePenalty = -0.1 * ((metadata.duration || 0) / 1000);
|
|
260
|
+
return baseReward + timePenalty;
|
|
261
|
+
}
|
|
262
|
+
case 'token_aware': {
|
|
263
|
+
const baseReward = metadata.success ? 1.0 : -1.0;
|
|
264
|
+
const tokenPenalty = -0.01 * ((metadata.tokensUsed || 0) / 100);
|
|
265
|
+
return baseReward + tokenPenalty;
|
|
266
|
+
}
|
|
267
|
+
case 'custom':
|
|
268
|
+
// Custom reward function would be evaluated here
|
|
269
|
+
// For now, return the base reward
|
|
270
|
+
return experience.reward;
|
|
271
|
+
default:
|
|
272
|
+
return experience.reward;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Active Learning Plugin
|
|
3
|
+
*
|
|
4
|
+
* Implements query-based learning where the agent actively selects
|
|
5
|
+
* the most informative samples to learn from, maximizing data efficiency.
|
|
6
|
+
*
|
|
7
|
+
* Key features:
|
|
8
|
+
* - Uncertainty sampling
|
|
9
|
+
* - Query-by-committee
|
|
10
|
+
* - Expected model change
|
|
11
|
+
* - Diversity-based sampling
|
|
12
|
+
* - Budget-aware querying
|
|
13
|
+
*/
|
|
14
|
+
import { BasePlugin } from '../base-plugin';
|
|
15
|
+
import { Action, Experience, TrainOptions, TrainingMetrics, Vector } from '../learning-plugin.interface';
|
|
16
|
+
/**
|
|
17
|
+
* Sample with query information
|
|
18
|
+
*/
|
|
19
|
+
interface QuerySample {
|
|
20
|
+
state: Vector;
|
|
21
|
+
uncertainty: number;
|
|
22
|
+
queryValue: number;
|
|
23
|
+
metadata?: Record<string, any>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Active Learning Plugin Implementation
|
|
27
|
+
*/
|
|
28
|
+
export declare class ActiveLearningPlugin extends BasePlugin {
|
|
29
|
+
name: string;
|
|
30
|
+
version: string;
|
|
31
|
+
private experiences;
|
|
32
|
+
private queryStrategy;
|
|
33
|
+
private labelingBudget;
|
|
34
|
+
private queriedSamples;
|
|
35
|
+
private unlabeledPool;
|
|
36
|
+
private committee;
|
|
37
|
+
private committeeSize;
|
|
38
|
+
private diversityThreshold;
|
|
39
|
+
constructor(config?: Partial<any>);
|
|
40
|
+
/**
|
|
41
|
+
* Override to skip initialization check for in-memory operation
|
|
42
|
+
*/
|
|
43
|
+
protected checkInitialized(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Override selectAction to provide base implementation
|
|
46
|
+
*/
|
|
47
|
+
selectAction(state: any, context?: any): Promise<Action>;
|
|
48
|
+
/**
|
|
49
|
+
* Override to store experiences in-memory without vectorDB
|
|
50
|
+
*/
|
|
51
|
+
storeExperience(experience: Experience): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Override to retrieve from local experiences
|
|
54
|
+
*/
|
|
55
|
+
retrieveSimilar(state: number[], k: number): Promise<import('../..').SearchResult<Experience>[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Initialize committee for query-by-committee
|
|
58
|
+
*/
|
|
59
|
+
private initializeCommittee;
|
|
60
|
+
/**
|
|
61
|
+
* Add unlabeled sample to pool
|
|
62
|
+
*/
|
|
63
|
+
addUnlabeledSample(state: Vector, metadata?: Record<string, any>): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Calculate uncertainty for a sample
|
|
66
|
+
*/
|
|
67
|
+
private calculateUncertainty;
|
|
68
|
+
/**
|
|
69
|
+
* Uncertainty sampling: Select samples with highest prediction uncertainty
|
|
70
|
+
*/
|
|
71
|
+
private uncertaintySampling;
|
|
72
|
+
/**
|
|
73
|
+
* Margin sampling: Select samples where top two predictions are close
|
|
74
|
+
*/
|
|
75
|
+
private marginSampling;
|
|
76
|
+
/**
|
|
77
|
+
* Entropy sampling: Select samples with highest prediction entropy
|
|
78
|
+
*/
|
|
79
|
+
private entropySampling;
|
|
80
|
+
/**
|
|
81
|
+
* Query-by-committee: Select samples where committee disagrees most
|
|
82
|
+
*/
|
|
83
|
+
private queryByCommittee;
|
|
84
|
+
/**
|
|
85
|
+
* Expected model change: Select samples that would change model most
|
|
86
|
+
*/
|
|
87
|
+
private expectedModelChange;
|
|
88
|
+
/**
|
|
89
|
+
* Diversity sampling: Select diverse batch of samples
|
|
90
|
+
*/
|
|
91
|
+
private diversitySampling;
|
|
92
|
+
/**
|
|
93
|
+
* Get top K predictions for a state
|
|
94
|
+
*/
|
|
95
|
+
private getTopPredictions;
|
|
96
|
+
/**
|
|
97
|
+
* Predict using specific weights
|
|
98
|
+
*/
|
|
99
|
+
private predictWithWeights;
|
|
100
|
+
/**
|
|
101
|
+
* Hash state for tracking
|
|
102
|
+
*/
|
|
103
|
+
private hashState;
|
|
104
|
+
/**
|
|
105
|
+
* Euclidean distance between states
|
|
106
|
+
*/
|
|
107
|
+
private euclideanDistance;
|
|
108
|
+
/**
|
|
109
|
+
* Select next batch of samples to query (label)
|
|
110
|
+
*/
|
|
111
|
+
selectQueryBatch(batchSize: number): Promise<QuerySample[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Train with active learning
|
|
114
|
+
*/
|
|
115
|
+
train(options?: TrainOptions): Promise<TrainingMetrics>;
|
|
116
|
+
/**
|
|
117
|
+
* Update committee members
|
|
118
|
+
*/
|
|
119
|
+
private updateCommittee;
|
|
120
|
+
/**
|
|
121
|
+
* Get active learning statistics
|
|
122
|
+
*/
|
|
123
|
+
getStats(): {
|
|
124
|
+
queriedCount: number;
|
|
125
|
+
remainingBudget: number;
|
|
126
|
+
unlabeledCount: number;
|
|
127
|
+
averageUncertainty: number;
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Reset querying state
|
|
131
|
+
*/
|
|
132
|
+
resetQuery(): void;
|
|
133
|
+
}
|
|
134
|
+
export {};
|
|
135
|
+
//# sourceMappingURL=active-learning.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"active-learning.d.ts","sourceRoot":"","sources":["../../../src/plugins/implementations/active-learning.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,MAAM,EAEN,UAAU,EACV,YAAY,EACZ,eAAe,EACf,MAAM,EACP,MAAM,8BAA8B,CAAC;AAatC;;GAEG;AACH,UAAU,WAAW;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAChC;AAWD;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,UAAU;IAClD,IAAI,SAAqB;IACzB,OAAO,SAAW;IAElB,OAAO,CAAC,WAAW,CAAoB;IACvC,OAAO,CAAC,aAAa,CAAgC;IACrD,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,cAAc,CAA0B;IAChD,OAAO,CAAC,aAAa,CAAqB;IAG1C,OAAO,CAAC,SAAS,CAAyB;IAC1C,OAAO,CAAC,aAAa,CAAa;IAGlC,OAAO,CAAC,kBAAkB,CAAe;gBAE7B,MAAM,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC;IAiBjC;;OAEG;IACH,SAAS,CAAC,gBAAgB,IAAI,IAAI;IAIlC;;OAEG;IACG,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAS9D;;OAEG;IACG,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5D;;OAEG;IACG,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,OAAO,EAAE,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;IAStG;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;OAEG;IACG,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAStF;;OAEG;YACW,oBAAoB;IAmBlC;;OAEG;YACW,mBAAmB;IAQjC;;OAEG;YACW,cAAc;IAa5B;;OAEG;YACW,eAAe;IAiB7B;;OAEG;YACW,gBAAgB;IAiB9B;;OAEG;YACW,mBAAmB;IAcjC;;OAEG;YACW,iBAAiB;IAsB/B;;OAEG;YACW,iBAAiB;IAW/B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;OAEG;IACH,OAAO,CAAC,SAAS;IAIjB;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAUzB;;OAEG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAmCjE;;OAEG;IACG,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC;IAwD7D;;OAEG;YACW,eAAe;IAyB7B;;OAEG;IACH,QAAQ,IAAI;QACV,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,EAAE,MAAM,CAAC;QACxB,cAAc,EAAE,MAAM,CAAC;QACvB,kBAAkB,EAAE,MAAM,CAAC;KAC5B;IAaD;;OAEG;IACH,UAAU,IAAI,IAAI;CAInB"}
|