ruvector 0.1.53 → 0.1.55
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/bin/cli.js +21 -7
- package/bin/mcp-server.js +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +4 -1
- package/dist/core/intelligence-engine.d.ts +14 -4
- package/dist/core/intelligence-engine.d.ts.map +1 -1
- package/dist/core/intelligence-engine.js +67 -8
- package/dist/core/onnx/loader.js +348 -0
- package/dist/core/onnx/pkg/LICENSE +21 -0
- package/dist/core/onnx/pkg/README.md +295 -0
- package/dist/core/onnx-embedder.d.ts +81 -0
- package/dist/core/onnx-embedder.d.ts.map +1 -0
- package/dist/core/onnx-embedder.js +269 -0
- package/package.json +5 -2
- package/ruvector.db +0 -0
package/bin/cli.js
CHANGED
|
@@ -2121,11 +2121,12 @@ class Intelligence {
|
|
|
2121
2121
|
if (engineAvailable && IntelligenceEngine) {
|
|
2122
2122
|
try {
|
|
2123
2123
|
this.engine = new IntelligenceEngine({
|
|
2124
|
-
|
|
2124
|
+
// Let ONNX auto-select 384d if available, else 256d
|
|
2125
2125
|
maxMemories: 100000,
|
|
2126
2126
|
maxEpisodes: 50000,
|
|
2127
2127
|
enableSona: true,
|
|
2128
2128
|
enableAttention: true,
|
|
2129
|
+
enableOnnx: true, // Enable ONNX semantic embeddings
|
|
2129
2130
|
learningRate: this.alpha,
|
|
2130
2131
|
});
|
|
2131
2132
|
// Import existing data into engine
|
|
@@ -3045,17 +3046,30 @@ hooksCmd.command('suggest-context').description('Suggest relevant context').acti
|
|
|
3045
3046
|
console.log(`RuVector Intelligence: ${stats.total_patterns} learned patterns, ${stats.total_errors} error fixes available. Use 'ruvector hooks route' for agent suggestions.`);
|
|
3046
3047
|
});
|
|
3047
3048
|
|
|
3048
|
-
hooksCmd.command('remember').description('Store in memory').requiredOption('-t, --type <type>', 'Memory type').argument('<content...>', 'Content').action((content, opts) => {
|
|
3049
|
+
hooksCmd.command('remember').description('Store in memory').requiredOption('-t, --type <type>', 'Memory type').option('--silent', 'Suppress output').option('--semantic', 'Use ONNX semantic embeddings (slower, better quality)').argument('<content...>', 'Content').action(async (content, opts) => {
|
|
3049
3050
|
const intel = new Intelligence();
|
|
3050
|
-
|
|
3051
|
+
let id;
|
|
3052
|
+
if (opts.semantic) {
|
|
3053
|
+
// Use async ONNX embedding
|
|
3054
|
+
id = await intel.rememberAsync(opts.type, content.join(' '));
|
|
3055
|
+
} else {
|
|
3056
|
+
id = intel.remember(opts.type, content.join(' '));
|
|
3057
|
+
}
|
|
3051
3058
|
intel.save();
|
|
3052
|
-
|
|
3059
|
+
if (!opts.silent) {
|
|
3060
|
+
console.log(JSON.stringify({ success: true, id, semantic: !!opts.semantic }));
|
|
3061
|
+
}
|
|
3053
3062
|
});
|
|
3054
3063
|
|
|
3055
|
-
hooksCmd.command('recall').description('Search memory').argument('<query...>', 'Query').option('-k, --top-k <n>', 'Results', '5').action((query, opts) => {
|
|
3064
|
+
hooksCmd.command('recall').description('Search memory').argument('<query...>', 'Query').option('-k, --top-k <n>', 'Results', '5').option('--semantic', 'Use ONNX semantic search (slower, better quality)').action(async (query, opts) => {
|
|
3056
3065
|
const intel = new Intelligence();
|
|
3057
|
-
|
|
3058
|
-
|
|
3066
|
+
let results;
|
|
3067
|
+
if (opts.semantic) {
|
|
3068
|
+
results = await intel.recallAsync(query.join(' '), parseInt(opts.topK));
|
|
3069
|
+
} else {
|
|
3070
|
+
results = intel.recall(query.join(' '), parseInt(opts.topK));
|
|
3071
|
+
}
|
|
3072
|
+
console.log(JSON.stringify({ query: query.join(' '), semantic: !!opts.semantic, results: results.map(r => ({ type: r.memory_type, content: r.content.slice(0, 200), timestamp: r.timestamp })) }, null, 2));
|
|
3059
3073
|
});
|
|
3060
3074
|
|
|
3061
3075
|
hooksCmd.command('pre-compact').description('Pre-compact hook').option('--auto', 'Auto mode').action(() => {
|
package/bin/mcp-server.js
CHANGED
package/dist/core/index.d.ts
CHANGED
|
@@ -9,9 +9,11 @@ export * from './attention-fallbacks';
|
|
|
9
9
|
export * from './agentdb-fast';
|
|
10
10
|
export * from './sona-wrapper';
|
|
11
11
|
export * from './intelligence-engine';
|
|
12
|
+
export * from './onnx-embedder';
|
|
12
13
|
export { default as gnnWrapper } from './gnn-wrapper';
|
|
13
14
|
export { default as attentionFallbacks } from './attention-fallbacks';
|
|
14
15
|
export { default as agentdbFast } from './agentdb-fast';
|
|
15
16
|
export { default as Sona } from './sona-wrapper';
|
|
16
17
|
export { default as IntelligenceEngine } from './intelligence-engine';
|
|
18
|
+
export { default as OnnxEmbedder } from './onnx-embedder';
|
|
17
19
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -23,12 +23,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
23
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.IntelligenceEngine = exports.Sona = exports.agentdbFast = exports.attentionFallbacks = exports.gnnWrapper = void 0;
|
|
26
|
+
exports.OnnxEmbedder = exports.IntelligenceEngine = exports.Sona = exports.agentdbFast = exports.attentionFallbacks = exports.gnnWrapper = void 0;
|
|
27
27
|
__exportStar(require("./gnn-wrapper"), exports);
|
|
28
28
|
__exportStar(require("./attention-fallbacks"), exports);
|
|
29
29
|
__exportStar(require("./agentdb-fast"), exports);
|
|
30
30
|
__exportStar(require("./sona-wrapper"), exports);
|
|
31
31
|
__exportStar(require("./intelligence-engine"), exports);
|
|
32
|
+
__exportStar(require("./onnx-embedder"), exports);
|
|
32
33
|
// Re-export default objects for convenience
|
|
33
34
|
var gnn_wrapper_1 = require("./gnn-wrapper");
|
|
34
35
|
Object.defineProperty(exports, "gnnWrapper", { enumerable: true, get: function () { return __importDefault(gnn_wrapper_1).default; } });
|
|
@@ -40,3 +41,5 @@ var sona_wrapper_1 = require("./sona-wrapper");
|
|
|
40
41
|
Object.defineProperty(exports, "Sona", { enumerable: true, get: function () { return __importDefault(sona_wrapper_1).default; } });
|
|
41
42
|
var intelligence_engine_1 = require("./intelligence-engine");
|
|
42
43
|
Object.defineProperty(exports, "IntelligenceEngine", { enumerable: true, get: function () { return __importDefault(intelligence_engine_1).default; } });
|
|
44
|
+
var onnx_embedder_1 = require("./onnx-embedder");
|
|
45
|
+
Object.defineProperty(exports, "OnnxEmbedder", { enumerable: true, get: function () { return __importDefault(onnx_embedder_1).default; } });
|
|
@@ -47,9 +47,10 @@ export interface LearningStats {
|
|
|
47
47
|
errorPatterns: number;
|
|
48
48
|
coEditPatterns: number;
|
|
49
49
|
attentionEnabled: boolean;
|
|
50
|
+
onnxEnabled: boolean;
|
|
50
51
|
}
|
|
51
52
|
export interface IntelligenceConfig {
|
|
52
|
-
/** Embedding dimension for vectors (default: 256) */
|
|
53
|
+
/** Embedding dimension for vectors (default: 256, 384 for ONNX) */
|
|
53
54
|
embeddingDim?: number;
|
|
54
55
|
/** Maximum memories to store (default: 100000) */
|
|
55
56
|
maxMemories?: number;
|
|
@@ -59,6 +60,8 @@ export interface IntelligenceConfig {
|
|
|
59
60
|
enableSona?: boolean;
|
|
60
61
|
/** Enable attention mechanisms (default: true if available) */
|
|
61
62
|
enableAttention?: boolean;
|
|
63
|
+
/** Enable ONNX semantic embeddings (default: false, opt-in for quality) */
|
|
64
|
+
enableOnnx?: boolean;
|
|
62
65
|
/** SONA configuration */
|
|
63
66
|
sonaConfig?: Partial<SonaConfig>;
|
|
64
67
|
/** Storage path for persistence */
|
|
@@ -75,6 +78,8 @@ export declare class IntelligenceEngine {
|
|
|
75
78
|
private agentDb;
|
|
76
79
|
private sona;
|
|
77
80
|
private attention;
|
|
81
|
+
private onnxEmbedder;
|
|
82
|
+
private onnxReady;
|
|
78
83
|
private memories;
|
|
79
84
|
private routingPatterns;
|
|
80
85
|
private errorPatterns;
|
|
@@ -84,11 +89,16 @@ export declare class IntelligenceEngine {
|
|
|
84
89
|
private sessionStart;
|
|
85
90
|
private learningEnabled;
|
|
86
91
|
constructor(config?: IntelligenceConfig);
|
|
92
|
+
private initOnnx;
|
|
87
93
|
private initVectorDb;
|
|
88
94
|
/**
|
|
89
|
-
* Generate embedding using attention
|
|
95
|
+
* Generate embedding using ONNX, attention, or hash (in order of preference)
|
|
90
96
|
*/
|
|
91
97
|
embed(text: string): number[];
|
|
98
|
+
/**
|
|
99
|
+
* Async embedding with ONNX support (recommended for semantic quality)
|
|
100
|
+
*/
|
|
101
|
+
embedAsync(text: string): Promise<number[]>;
|
|
92
102
|
/**
|
|
93
103
|
* Attention-based embedding using Flash or Multi-head attention
|
|
94
104
|
*/
|
|
@@ -101,11 +111,11 @@ export declare class IntelligenceEngine {
|
|
|
101
111
|
private tokenEmbed;
|
|
102
112
|
private meanPool;
|
|
103
113
|
/**
|
|
104
|
-
* Store content in vector memory
|
|
114
|
+
* Store content in vector memory (uses ONNX if available)
|
|
105
115
|
*/
|
|
106
116
|
remember(content: string, type?: string): Promise<MemoryEntry>;
|
|
107
117
|
/**
|
|
108
|
-
* Semantic search of memories
|
|
118
|
+
* Semantic search of memories (uses ONNX if available)
|
|
109
119
|
*/
|
|
110
120
|
recall(query: string, topK?: number): Promise<MemoryEntry[]>;
|
|
111
121
|
private cosineSimilarity;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intelligence-engine.d.ts","sourceRoot":"","sources":["../../src/core/intelligence-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAoC,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACvF,OAAO,EAAc,UAAU,EAAE,cAAc,EAA8B,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"intelligence-engine.d.ts","sourceRoot":"","sources":["../../src/core/intelligence-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAoC,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACvF,OAAO,EAAc,UAAU,EAAE,cAAc,EAA8B,MAAM,gBAAgB,CAAC;AAOpG,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EA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H,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IA6B1C;;OAEG;IACH,IAAI,IAAI,MAAM,GAAG,IAAI;IAWrB;;OAEG;IACH,UAAU,IAAI,MAAM,GAAG,IAAI;IAe3B;;OAEG;IACH,QAAQ,IAAI,aAAa;IAkDzB;;OAEG;IACH,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IA8B7B;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,KAAK,GAAE,OAAe,GAAG,IAAI;IAoE/D;;OAEG;IACH,KAAK,IAAI,IAAI;IAab,8BAA8B;IAC9B,IAAI,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAMrD;IAED,mCAAmC;IACnC,IAAI,cAAc,IAAI,MAAM,EAAE,EAAE,CAW/B;IAED,4BAA4B;IAC5B,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAErC;CACF;AAMD;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,kBAAkB,CAExF;AAED;;GAEG;AACH,wBAAgB,2BAA2B,IAAI,kBAAkB,CAchE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,kBAAkB,CAQ5D;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -18,6 +18,7 @@ exports.createHighPerformanceEngine = createHighPerformanceEngine;
|
|
|
18
18
|
exports.createLightweightEngine = createLightweightEngine;
|
|
19
19
|
const agentdb_fast_1 = require("./agentdb-fast");
|
|
20
20
|
const sona_wrapper_1 = require("./sona-wrapper");
|
|
21
|
+
const onnx_embedder_1 = require("./onnx-embedder");
|
|
21
22
|
// ============================================================================
|
|
22
23
|
// Lazy Loading
|
|
23
24
|
// ============================================================================
|
|
@@ -72,6 +73,8 @@ class IntelligenceEngine {
|
|
|
72
73
|
this.vectorDb = null;
|
|
73
74
|
this.sona = null;
|
|
74
75
|
this.attention = null;
|
|
76
|
+
this.onnxEmbedder = null;
|
|
77
|
+
this.onnxReady = false;
|
|
75
78
|
// In-memory data structures
|
|
76
79
|
this.memories = new Map();
|
|
77
80
|
this.routingPatterns = new Map(); // state -> action -> value
|
|
@@ -82,18 +85,28 @@ class IntelligenceEngine {
|
|
|
82
85
|
this.currentTrajectoryId = null;
|
|
83
86
|
this.sessionStart = Date.now();
|
|
84
87
|
this.learningEnabled = true;
|
|
88
|
+
// If ONNX is enabled, use 384 dimensions (MiniLM default)
|
|
89
|
+
const useOnnx = !!(config.enableOnnx && (0, onnx_embedder_1.isOnnxAvailable)());
|
|
90
|
+
const embeddingDim = useOnnx ? 384 : (config.embeddingDim ?? 256);
|
|
85
91
|
this.config = {
|
|
86
|
-
embeddingDim
|
|
92
|
+
embeddingDim,
|
|
87
93
|
maxMemories: config.maxMemories ?? 100000,
|
|
88
94
|
maxEpisodes: config.maxEpisodes ?? 50000,
|
|
89
95
|
enableSona: config.enableSona ?? true,
|
|
90
96
|
enableAttention: config.enableAttention ?? true,
|
|
97
|
+
enableOnnx: useOnnx,
|
|
91
98
|
sonaConfig: config.sonaConfig ?? {},
|
|
92
99
|
storagePath: config.storagePath ?? '',
|
|
93
100
|
learningRate: config.learningRate ?? 0.1,
|
|
94
101
|
};
|
|
95
102
|
// Initialize FastAgentDB for episode storage
|
|
96
103
|
this.agentDb = new agentdb_fast_1.FastAgentDB(this.config.embeddingDim, this.config.maxEpisodes);
|
|
104
|
+
// Initialize ONNX embedder if enabled
|
|
105
|
+
if (this.config.enableOnnx) {
|
|
106
|
+
this.onnxEmbedder = new onnx_embedder_1.OnnxEmbedder();
|
|
107
|
+
// Initialize async (don't block constructor)
|
|
108
|
+
this.initOnnx();
|
|
109
|
+
}
|
|
97
110
|
// Initialize SONA if enabled and available
|
|
98
111
|
if (this.config.enableSona && (0, sona_wrapper_1.isSonaAvailable)()) {
|
|
99
112
|
try {
|
|
@@ -111,13 +124,25 @@ class IntelligenceEngine {
|
|
|
111
124
|
console.warn('SONA initialization failed, using fallback learning');
|
|
112
125
|
}
|
|
113
126
|
}
|
|
114
|
-
// Initialize attention if enabled
|
|
115
|
-
if (this.config.enableAttention) {
|
|
127
|
+
// Initialize attention if enabled (fallback if ONNX not available)
|
|
128
|
+
if (this.config.enableAttention && !this.config.enableOnnx) {
|
|
116
129
|
this.attention = getAttention();
|
|
117
130
|
}
|
|
118
131
|
// Initialize VectorDB for memory
|
|
119
132
|
this.initVectorDb();
|
|
120
133
|
}
|
|
134
|
+
async initOnnx() {
|
|
135
|
+
if (!this.onnxEmbedder)
|
|
136
|
+
return;
|
|
137
|
+
try {
|
|
138
|
+
await this.onnxEmbedder.init();
|
|
139
|
+
this.onnxReady = true;
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
console.warn('ONNX initialization failed, using fallback embeddings');
|
|
143
|
+
this.onnxReady = false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
121
146
|
async initVectorDb() {
|
|
122
147
|
try {
|
|
123
148
|
const VDB = getVectorDB();
|
|
@@ -134,10 +159,21 @@ class IntelligenceEngine {
|
|
|
134
159
|
// Embedding Generation
|
|
135
160
|
// =========================================================================
|
|
136
161
|
/**
|
|
137
|
-
* Generate embedding using attention
|
|
162
|
+
* Generate embedding using ONNX, attention, or hash (in order of preference)
|
|
138
163
|
*/
|
|
139
164
|
embed(text) {
|
|
140
165
|
const dim = this.config.embeddingDim;
|
|
166
|
+
// Try ONNX semantic embeddings first (best quality)
|
|
167
|
+
if (this.onnxReady && this.onnxEmbedder) {
|
|
168
|
+
try {
|
|
169
|
+
// Note: This is sync wrapper for async ONNX
|
|
170
|
+
// For full async, use embedAsync
|
|
171
|
+
return this.hashEmbed(text, dim); // Fallback for sync context
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
// Fall through
|
|
175
|
+
}
|
|
176
|
+
}
|
|
141
177
|
// Try to use attention-based embedding
|
|
142
178
|
if (this.attention?.DotProductAttention) {
|
|
143
179
|
try {
|
|
@@ -150,6 +186,26 @@ class IntelligenceEngine {
|
|
|
150
186
|
// Improved positional hash embedding
|
|
151
187
|
return this.hashEmbed(text, dim);
|
|
152
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Async embedding with ONNX support (recommended for semantic quality)
|
|
191
|
+
*/
|
|
192
|
+
async embedAsync(text) {
|
|
193
|
+
// Try ONNX first (best semantic quality)
|
|
194
|
+
if (this.onnxEmbedder) {
|
|
195
|
+
try {
|
|
196
|
+
if (!this.onnxReady) {
|
|
197
|
+
await this.onnxEmbedder.init();
|
|
198
|
+
this.onnxReady = true;
|
|
199
|
+
}
|
|
200
|
+
return await this.onnxEmbedder.embed(text);
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
// Fall through to sync methods
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
// Fall back to sync embedding
|
|
207
|
+
return this.embed(text);
|
|
208
|
+
}
|
|
153
209
|
/**
|
|
154
210
|
* Attention-based embedding using Flash or Multi-head attention
|
|
155
211
|
*/
|
|
@@ -256,11 +312,12 @@ class IntelligenceEngine {
|
|
|
256
312
|
// Memory Operations
|
|
257
313
|
// =========================================================================
|
|
258
314
|
/**
|
|
259
|
-
* Store content in vector memory
|
|
315
|
+
* Store content in vector memory (uses ONNX if available)
|
|
260
316
|
*/
|
|
261
317
|
async remember(content, type = 'general') {
|
|
262
318
|
const id = `mem-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
263
|
-
|
|
319
|
+
// Use async ONNX embeddings if available for better semantic quality
|
|
320
|
+
const embedding = await this.embedAsync(content);
|
|
264
321
|
const entry = {
|
|
265
322
|
id,
|
|
266
323
|
content,
|
|
@@ -286,10 +343,11 @@ class IntelligenceEngine {
|
|
|
286
343
|
return entry;
|
|
287
344
|
}
|
|
288
345
|
/**
|
|
289
|
-
* Semantic search of memories
|
|
346
|
+
* Semantic search of memories (uses ONNX if available)
|
|
290
347
|
*/
|
|
291
348
|
async recall(query, topK = 5) {
|
|
292
|
-
|
|
349
|
+
// Use async ONNX embeddings if available for better semantic quality
|
|
350
|
+
const queryEmbed = await this.embedAsync(query);
|
|
293
351
|
// Try VectorDB search first (HNSW - 150x faster)
|
|
294
352
|
if (this.vectorDb) {
|
|
295
353
|
try {
|
|
@@ -671,6 +729,7 @@ class IntelligenceEngine {
|
|
|
671
729
|
errorPatterns: this.errorPatterns.size,
|
|
672
730
|
coEditPatterns: this.coEditPatterns.size,
|
|
673
731
|
attentionEnabled: this.attention !== null,
|
|
732
|
+
onnxEnabled: this.onnxReady,
|
|
674
733
|
};
|
|
675
734
|
}
|
|
676
735
|
// =========================================================================
|