ruvector 0.2.25 → 0.2.26
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 +121 -16
- package/bin/mcp-server.js +94 -22
- package/dist/core/intelligence-engine.d.ts +1 -1
- package/dist/core/intelligence-engine.d.ts.map +1 -1
- package/dist/core/intelligence-engine.js +10 -14
- package/dist/core/learning-engine.d.ts +2 -0
- package/dist/core/learning-engine.d.ts.map +1 -1
- package/dist/core/learning-engine.js +23 -3
- package/dist/core/onnx/loader.js +348 -0
- package/dist/core/onnx/pkg/LICENSE +21 -0
- package/dist/core/onnx/pkg/loader.js +348 -0
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm.d.ts +112 -0
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm.js +5 -0
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.js +638 -0
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.wasm +0 -0
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.wasm.d.ts +29 -0
- package/dist/core/onnx-embedder.d.ts.map +1 -1
- package/dist/core/onnx-embedder.js +16 -12
- package/dist/index.d.ts +54 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +102 -1
- package/package.json +4 -3
|
@@ -181,22 +181,26 @@ async function initOnnxEmbedder(config = {}) {
|
|
|
181
181
|
loadPromise = (async () => {
|
|
182
182
|
try {
|
|
183
183
|
// Paths to bundled ONNX files
|
|
184
|
-
const
|
|
184
|
+
const bgJsPath = path.join(__dirname, 'onnx', 'pkg', 'ruvector_onnx_embeddings_wasm_bg.js');
|
|
185
|
+
const wasmPath = path.join(__dirname, 'onnx', 'pkg', 'ruvector_onnx_embeddings_wasm_bg.wasm');
|
|
185
186
|
const loaderPath = path.join(__dirname, 'onnx', 'loader.js');
|
|
186
|
-
if (!fs.existsSync(
|
|
187
|
+
if (!fs.existsSync(bgJsPath) || !fs.existsSync(wasmPath)) {
|
|
187
188
|
throw new Error('ONNX WASM files not bundled. The onnx/ directory is missing.');
|
|
188
189
|
}
|
|
189
|
-
//
|
|
190
|
-
|
|
190
|
+
// Load the bg.js module directly (avoids the ESM `import * as wasm from "*.wasm"`
|
|
191
|
+
// in the main .js shim which requires --experimental-wasm-modules on Node 18-24).
|
|
192
|
+
const bgUrl = (0, url_1.pathToFileURL)(bgJsPath).href;
|
|
191
193
|
const loaderUrl = (0, url_1.pathToFileURL)(loaderPath).href;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
194
|
+
wasmModule = await dynamicImport(bgUrl);
|
|
195
|
+
// Instantiate the .wasm bytes via WebAssembly API (no --experimental-wasm-modules needed).
|
|
196
|
+
const wasmBytes = fs.readFileSync(wasmPath);
|
|
197
|
+
const wasmResult = await WebAssembly.instantiate(wasmBytes, { './ruvector_onnx_embeddings_wasm_bg.js': wasmModule });
|
|
198
|
+
const wasmExports = wasmResult.instance.exports;
|
|
199
|
+
if (typeof wasmModule.__wbg_set_wasm === 'function') {
|
|
200
|
+
wasmModule.__wbg_set_wasm(wasmExports);
|
|
201
|
+
}
|
|
202
|
+
if (typeof wasmExports.__wbindgen_start === 'function') {
|
|
203
|
+
wasmExports.__wbindgen_start();
|
|
200
204
|
}
|
|
201
205
|
const loaderModule = await dynamicImport(loaderUrl);
|
|
202
206
|
const { ModelLoader } = loaderModule;
|
package/dist/index.d.ts
CHANGED
|
@@ -102,5 +102,59 @@ declare class VectorDBWrapper {
|
|
|
102
102
|
export declare const VectorDb: typeof VectorDBWrapper;
|
|
103
103
|
export declare const VectorDB: typeof VectorDBWrapper;
|
|
104
104
|
export declare const NativeVectorDb: any;
|
|
105
|
+
/** High-level index class compatible with the test-suite API. */
|
|
106
|
+
export declare class VectorIndex {
|
|
107
|
+
private db;
|
|
108
|
+
private _dimension;
|
|
109
|
+
private _storagePath;
|
|
110
|
+
constructor(opts: {
|
|
111
|
+
dimension: number;
|
|
112
|
+
metric?: string;
|
|
113
|
+
indexType?: string;
|
|
114
|
+
});
|
|
115
|
+
insert(entry: {
|
|
116
|
+
id?: string;
|
|
117
|
+
values: number[];
|
|
118
|
+
}): Promise<string>;
|
|
119
|
+
insertBatch(entries: Array<{
|
|
120
|
+
id?: string;
|
|
121
|
+
values: number[];
|
|
122
|
+
}>, _opts?: {
|
|
123
|
+
batchSize?: number;
|
|
124
|
+
progressCallback?: (p: number) => void;
|
|
125
|
+
}): Promise<string[]>;
|
|
126
|
+
search(query: number[], opts: {
|
|
127
|
+
k: number;
|
|
128
|
+
}): Promise<Array<{
|
|
129
|
+
id: string;
|
|
130
|
+
score: number;
|
|
131
|
+
}>>;
|
|
132
|
+
get(id: string): Promise<{
|
|
133
|
+
id: string;
|
|
134
|
+
values: number[];
|
|
135
|
+
} | null>;
|
|
136
|
+
delete(id: string): Promise<boolean>;
|
|
137
|
+
stats(): Promise<{
|
|
138
|
+
vectorCount: number;
|
|
139
|
+
dimension: number;
|
|
140
|
+
}>;
|
|
141
|
+
clear(): Promise<void>;
|
|
142
|
+
optimize(): Promise<void>;
|
|
143
|
+
}
|
|
144
|
+
/** Get backend info (compat with old getBackendInfo() call). */
|
|
145
|
+
export declare function getBackendInfo(): {
|
|
146
|
+
type: 'native' | 'wasm';
|
|
147
|
+
version: string;
|
|
148
|
+
features: string[];
|
|
149
|
+
};
|
|
150
|
+
/** Check native availability (compat alias for isNative()). */
|
|
151
|
+
export declare function isNativeAvailable(): boolean;
|
|
152
|
+
/** Vector utility functions used by tests and downstream packages. */
|
|
153
|
+
export declare const Utils: {
|
|
154
|
+
cosineSimilarity(a: number[], b: number[]): number;
|
|
155
|
+
euclideanDistance(a: number[], b: number[]): number;
|
|
156
|
+
normalize(v: number[]): number[];
|
|
157
|
+
randomVector(dimension: number): number[];
|
|
158
|
+
};
|
|
105
159
|
export default implementation;
|
|
106
160
|
//# sourceMappingUR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3C;AAED,sEAAsE;AACtE,eAAO,MAAM,KAAK;wBACI,MAAM,EAAE,KAAK,MAAM,EAAE,GAAG,MAAM;yBAO7B,MAAM,EAAE,KAAK,MAAM,EAAE,GAAG,MAAM;iBAItC,MAAM,EAAE,GAAG,MAAM,EAAE;4BAKR,MAAM,GAAG,MAAM,EAAE;CAI1C,CAAC;AAGF,eAAe,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -25,12 +25,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
25
25
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.NativeVectorDb = exports.VectorDB = exports.VectorDb = void 0;
|
|
28
|
+
exports.Utils = exports.VectorIndex = exports.NativeVectorDb = exports.VectorDB = exports.VectorDb = void 0;
|
|
29
29
|
exports.getImplementationType = getImplementationType;
|
|
30
30
|
exports.isNative = isNative;
|
|
31
31
|
exports.isRvf = isRvf;
|
|
32
32
|
exports.isWasm = isWasm;
|
|
33
33
|
exports.getVersion = getVersion;
|
|
34
|
+
exports.getBackendInfo = getBackendInfo;
|
|
35
|
+
exports.isNativeAvailable = isNativeAvailable;
|
|
34
36
|
__exportStar(require("./types"), exports);
|
|
35
37
|
// Export core wrappers (safe interfaces with automatic type conversion)
|
|
36
38
|
__exportStar(require("./core"), exports);
|
|
@@ -254,5 +256,104 @@ exports.VectorDb = VectorDBWrapper;
|
|
|
254
256
|
exports.VectorDB = VectorDBWrapper;
|
|
255
257
|
// Also export the raw native implementation for advanced users
|
|
256
258
|
exports.NativeVectorDb = implementation.VectorDb;
|
|
259
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
260
|
+
// Backwards-compat surface used by tests and older integrations
|
|
261
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
262
|
+
/** High-level index class compatible with the test-suite API. */
|
|
263
|
+
class VectorIndex {
|
|
264
|
+
constructor(opts) {
|
|
265
|
+
if (opts.dimension <= 0) {
|
|
266
|
+
throw new Error(`Invalid dimensions: must be positive, got ${opts.dimension}`);
|
|
267
|
+
}
|
|
268
|
+
this._dimension = opts.dimension;
|
|
269
|
+
// Use a unique temp path per instance to avoid cross-instance dimension conflicts
|
|
270
|
+
this._storagePath = require('os').tmpdir() + `/ruvector-idx-${Date.now()}-${Math.random().toString(36).slice(2)}.db`;
|
|
271
|
+
this.db = new VectorDBWrapper({ dimensions: opts.dimension, distanceMetric: opts.metric, storagePath: this._storagePath });
|
|
272
|
+
}
|
|
273
|
+
async insert(entry) {
|
|
274
|
+
return this.db.insert({ id: entry.id, vector: new Float32Array(entry.values) });
|
|
275
|
+
}
|
|
276
|
+
async insertBatch(entries, _opts) {
|
|
277
|
+
const ids = [];
|
|
278
|
+
const batchSize = _opts?.batchSize ?? entries.length;
|
|
279
|
+
for (let i = 0; i < entries.length; i += batchSize) {
|
|
280
|
+
const slice = entries.slice(i, i + batchSize);
|
|
281
|
+
const batch = slice.map(e => ({ id: e.id, vector: new Float32Array(e.values) }));
|
|
282
|
+
const batchIds = await this.db.insertBatch(batch);
|
|
283
|
+
ids.push(...batchIds);
|
|
284
|
+
_opts?.progressCallback?.(Math.min((i + batchSize) / entries.length, 1));
|
|
285
|
+
}
|
|
286
|
+
return ids;
|
|
287
|
+
}
|
|
288
|
+
async search(query, opts) {
|
|
289
|
+
return this.db.search({ vector: new Float32Array(query), k: opts.k });
|
|
290
|
+
}
|
|
291
|
+
async get(id) {
|
|
292
|
+
const r = await this.db.get(id);
|
|
293
|
+
if (!r)
|
|
294
|
+
return null;
|
|
295
|
+
return { id: r.id ?? id, values: Array.from(r.vector) };
|
|
296
|
+
}
|
|
297
|
+
async delete(id) {
|
|
298
|
+
return this.db.delete(id);
|
|
299
|
+
}
|
|
300
|
+
async stats() {
|
|
301
|
+
const count = await this.db.len();
|
|
302
|
+
return { vectorCount: count, dimension: this._dimension };
|
|
303
|
+
}
|
|
304
|
+
async clear() {
|
|
305
|
+
// Create a fresh db at a new temp path to reset state
|
|
306
|
+
const newPath = require('os').tmpdir() + `/ruvector-idx-${Date.now()}-${Math.random().toString(36).slice(2)}.db`;
|
|
307
|
+
this._storagePath = newPath;
|
|
308
|
+
this.db = new VectorDBWrapper({ dimensions: this._dimension, storagePath: newPath });
|
|
309
|
+
}
|
|
310
|
+
async optimize() {
|
|
311
|
+
// No-op: native HNSW self-optimises on insert
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
exports.VectorIndex = VectorIndex;
|
|
315
|
+
/** Get backend info (compat with old getBackendInfo() call). */
|
|
316
|
+
function getBackendInfo() {
|
|
317
|
+
const type = implementationType === 'native' ? 'native' : 'wasm';
|
|
318
|
+
const { version } = getVersion();
|
|
319
|
+
const features = type === 'native'
|
|
320
|
+
? ['SIMD', 'Multi-threading', 'Rust-native']
|
|
321
|
+
: ['Browser-compatible', 'Cross-platform'];
|
|
322
|
+
return { type, version, features };
|
|
323
|
+
}
|
|
324
|
+
/** Check native availability (compat alias for isNative()). */
|
|
325
|
+
function isNativeAvailable() {
|
|
326
|
+
return implementationType === 'native';
|
|
327
|
+
}
|
|
328
|
+
/** Vector utility functions used by tests and downstream packages. */
|
|
329
|
+
exports.Utils = {
|
|
330
|
+
cosineSimilarity(a, b) {
|
|
331
|
+
if (a.length !== b.length)
|
|
332
|
+
throw new Error('Vectors must have same dimension');
|
|
333
|
+
let dot = 0, na = 0, nb = 0;
|
|
334
|
+
for (let i = 0; i < a.length; i++) {
|
|
335
|
+
dot += a[i] * b[i];
|
|
336
|
+
na += a[i] ** 2;
|
|
337
|
+
nb += b[i] ** 2;
|
|
338
|
+
}
|
|
339
|
+
const denom = Math.sqrt(na) * Math.sqrt(nb);
|
|
340
|
+
return denom === 0 ? 0 : dot / denom;
|
|
341
|
+
},
|
|
342
|
+
euclideanDistance(a, b) {
|
|
343
|
+
if (a.length !== b.length)
|
|
344
|
+
throw new Error('Vectors must have same dimension');
|
|
345
|
+
return Math.sqrt(a.reduce((sum, v, i) => sum + (v - b[i]) ** 2, 0));
|
|
346
|
+
},
|
|
347
|
+
normalize(v) {
|
|
348
|
+
const mag = Math.sqrt(v.reduce((s, x) => s + x * x, 0));
|
|
349
|
+
if (mag === 0)
|
|
350
|
+
return v.slice();
|
|
351
|
+
return v.map(x => x / mag);
|
|
352
|
+
},
|
|
353
|
+
randomVector(dimension) {
|
|
354
|
+
const v = Array.from({ length: dimension }, () => Math.random() * 2 - 1);
|
|
355
|
+
return exports.Utils.normalize(v);
|
|
356
|
+
},
|
|
357
|
+
};
|
|
257
358
|
// Export everything from the implementation
|
|
258
359
|
exports.default = implementation;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruvector",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.26",
|
|
4
4
|
"description": "Self-learning vector database for Node.js — hybrid search, Graph RAG, FlashAttention-3, HNSW, 50+ attention mechanisms",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -8,10 +8,11 @@
|
|
|
8
8
|
"ruvector": "./bin/cli.js"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "tsc && cp src/core/onnx/pkg
|
|
11
|
+
"build": "tsc && mkdir -p dist/core/onnx/pkg && cp -r src/core/onnx/pkg/. dist/core/onnx/pkg/",
|
|
12
12
|
"verify-dist": "node scripts/verify-dist.js",
|
|
13
|
+
"prepack": "npm run build && npm run verify-dist",
|
|
13
14
|
"prepublishOnly": "npm run build && npm run verify-dist",
|
|
14
|
-
"test": "node test/integration.js && node test/cli-commands.js"
|
|
15
|
+
"test": "node test/integration.js && node test/cli-commands.js && node test/sigterm-cleanup.js"
|
|
15
16
|
},
|
|
16
17
|
"keywords": [
|
|
17
18
|
"vector",
|