ruvector 0.1.56 → 0.1.58
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 +7 -8
- package/bin/mcp-server.js +1 -1
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm.d.ts +1 -54
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm.js +5 -694
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.js +1 -0
- package/dist/core/onnx/pkg/ruvector_onnx_embeddings_wasm_bg.wasm +0 -0
- package/dist/core/onnx-embedder.d.ts.map +1 -1
- package/dist/core/onnx-embedder.js +7 -3
- package/package.json +1 -1
- package/ruvector.db +0 -0
- package/dist/core/onnx/pkg/README.md +0 -295
- package/dist/core/onnx/pkg/ruvector.db +0 -0
package/bin/cli.js
CHANGED
|
@@ -2314,14 +2314,13 @@ class Intelligence {
|
|
|
2314
2314
|
if (this.engine) {
|
|
2315
2315
|
try {
|
|
2316
2316
|
const results = await this.engine.recall(query, topK);
|
|
2317
|
+
// Return same format as sync recall() - direct memory objects
|
|
2317
2318
|
return results.map(r => ({
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
timestamp: r.created
|
|
2324
|
-
}
|
|
2319
|
+
id: r.id,
|
|
2320
|
+
content: r.content || '',
|
|
2321
|
+
memory_type: r.type || 'general',
|
|
2322
|
+
timestamp: r.created || new Date().toISOString(),
|
|
2323
|
+
score: r.score || 0
|
|
2325
2324
|
}));
|
|
2326
2325
|
} catch {}
|
|
2327
2326
|
}
|
|
@@ -3069,7 +3068,7 @@ hooksCmd.command('recall').description('Search memory').argument('<query...>', '
|
|
|
3069
3068
|
} else {
|
|
3070
3069
|
results = intel.recall(query.join(' '), parseInt(opts.topK));
|
|
3071
3070
|
}
|
|
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));
|
|
3071
|
+
console.log(JSON.stringify({ query: query.join(' '), semantic: !!opts.semantic, results: results.map(r => ({ type: r.memory_type || 'unknown', content: (r.content || '').slice(0, 200), timestamp: r.timestamp || '', score: r.score })) }, null, 2));
|
|
3073
3072
|
});
|
|
3074
3073
|
|
|
3075
3074
|
hooksCmd.command('pre-compact').description('Pre-compact hook').option('--auto', 'Auto mode').action(() => {
|
package/bin/mcp-server.js
CHANGED
|
@@ -102,6 +102,7 @@ export function normalizeL2(embedding: Float32Array): Float32Array;
|
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Check if SIMD is available (for performance info)
|
|
105
|
+
* Returns true if compiled with WASM SIMD128 support
|
|
105
106
|
*/
|
|
106
107
|
export function simd_available(): boolean;
|
|
107
108
|
|
|
@@ -109,57 +110,3 @@ export function simd_available(): boolean;
|
|
|
109
110
|
* Get the library version
|
|
110
111
|
*/
|
|
111
112
|
export function version(): string;
|
|
112
|
-
|
|
113
|
-
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
114
|
-
|
|
115
|
-
export interface InitOutput {
|
|
116
|
-
readonly memory: WebAssembly.Memory;
|
|
117
|
-
readonly __wbg_wasmembedder_free: (a: number, b: number) => void;
|
|
118
|
-
readonly __wbg_wasmembedderconfig_free: (a: number, b: number) => void;
|
|
119
|
-
readonly cosineSimilarity: (a: number, b: number, c: number, d: number) => number;
|
|
120
|
-
readonly normalizeL2: (a: number, b: number) => [number, number];
|
|
121
|
-
readonly wasmembedder_dimension: (a: number) => number;
|
|
122
|
-
readonly wasmembedder_embedBatch: (a: number, b: number, c: number) => [number, number, number, number];
|
|
123
|
-
readonly wasmembedder_embedOne: (a: number, b: number, c: number) => [number, number, number, number];
|
|
124
|
-
readonly wasmembedder_maxLength: (a: number) => number;
|
|
125
|
-
readonly wasmembedder_new: (a: number, b: number, c: number, d: number) => [number, number, number];
|
|
126
|
-
readonly wasmembedder_similarity: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
127
|
-
readonly wasmembedder_withConfig: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
128
|
-
readonly wasmembedderconfig_new: () => number;
|
|
129
|
-
readonly wasmembedderconfig_setMaxLength: (a: number, b: number) => number;
|
|
130
|
-
readonly wasmembedderconfig_setNormalize: (a: number, b: number) => number;
|
|
131
|
-
readonly wasmembedderconfig_setPooling: (a: number, b: number) => number;
|
|
132
|
-
readonly init: () => void;
|
|
133
|
-
readonly simd_available: () => number;
|
|
134
|
-
readonly version: () => [number, number];
|
|
135
|
-
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
136
|
-
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
137
|
-
readonly __wbindgen_exn_store: (a: number) => void;
|
|
138
|
-
readonly __externref_table_alloc: () => number;
|
|
139
|
-
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
140
|
-
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
141
|
-
readonly __externref_table_dealloc: (a: number) => void;
|
|
142
|
-
readonly __wbindgen_start: () => void;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Instantiates the given `module`, which can either be bytes or
|
|
149
|
-
* a precompiled `WebAssembly.Module`.
|
|
150
|
-
*
|
|
151
|
-
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
152
|
-
*
|
|
153
|
-
* @returns {InitOutput}
|
|
154
|
-
*/
|
|
155
|
-
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
159
|
-
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
160
|
-
*
|
|
161
|
-
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
162
|
-
*
|
|
163
|
-
* @returns {Promise<InitOutput>}
|
|
164
|
-
*/
|
|
165
|
-
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -1,694 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
return idx;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function _assertClass(instance, klass) {
|
|
10
|
-
if (!(instance instanceof klass)) {
|
|
11
|
-
throw new Error(`expected instance of ${klass.name}`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function getArrayF32FromWasm0(ptr, len) {
|
|
16
|
-
ptr = ptr >>> 0;
|
|
17
|
-
return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getArrayU8FromWasm0(ptr, len) {
|
|
21
|
-
ptr = ptr >>> 0;
|
|
22
|
-
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let cachedDataViewMemory0 = null;
|
|
26
|
-
function getDataViewMemory0() {
|
|
27
|
-
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
28
|
-
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
29
|
-
}
|
|
30
|
-
return cachedDataViewMemory0;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let cachedFloat32ArrayMemory0 = null;
|
|
34
|
-
function getFloat32ArrayMemory0() {
|
|
35
|
-
if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
|
|
36
|
-
cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
|
|
37
|
-
}
|
|
38
|
-
return cachedFloat32ArrayMemory0;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function getStringFromWasm0(ptr, len) {
|
|
42
|
-
ptr = ptr >>> 0;
|
|
43
|
-
return decodeText(ptr, len);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let cachedUint8ArrayMemory0 = null;
|
|
47
|
-
function getUint8ArrayMemory0() {
|
|
48
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
49
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
50
|
-
}
|
|
51
|
-
return cachedUint8ArrayMemory0;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function handleError(f, args) {
|
|
55
|
-
try {
|
|
56
|
-
return f.apply(this, args);
|
|
57
|
-
} catch (e) {
|
|
58
|
-
const idx = addToExternrefTable0(e);
|
|
59
|
-
wasm.__wbindgen_exn_store(idx);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function isLikeNone(x) {
|
|
64
|
-
return x === undefined || x === null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function passArray8ToWasm0(arg, malloc) {
|
|
68
|
-
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
69
|
-
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
70
|
-
WASM_VECTOR_LEN = arg.length;
|
|
71
|
-
return ptr;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function passArrayF32ToWasm0(arg, malloc) {
|
|
75
|
-
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
76
|
-
getFloat32ArrayMemory0().set(arg, ptr / 4);
|
|
77
|
-
WASM_VECTOR_LEN = arg.length;
|
|
78
|
-
return ptr;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function passArrayJsValueToWasm0(array, malloc) {
|
|
82
|
-
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
83
|
-
for (let i = 0; i < array.length; i++) {
|
|
84
|
-
const add = addToExternrefTable0(array[i]);
|
|
85
|
-
getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
|
|
86
|
-
}
|
|
87
|
-
WASM_VECTOR_LEN = array.length;
|
|
88
|
-
return ptr;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
92
|
-
if (realloc === undefined) {
|
|
93
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
94
|
-
const ptr = malloc(buf.length, 1) >>> 0;
|
|
95
|
-
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
96
|
-
WASM_VECTOR_LEN = buf.length;
|
|
97
|
-
return ptr;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
let len = arg.length;
|
|
101
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
102
|
-
|
|
103
|
-
const mem = getUint8ArrayMemory0();
|
|
104
|
-
|
|
105
|
-
let offset = 0;
|
|
106
|
-
|
|
107
|
-
for (; offset < len; offset++) {
|
|
108
|
-
const code = arg.charCodeAt(offset);
|
|
109
|
-
if (code > 0x7F) break;
|
|
110
|
-
mem[ptr + offset] = code;
|
|
111
|
-
}
|
|
112
|
-
if (offset !== len) {
|
|
113
|
-
if (offset !== 0) {
|
|
114
|
-
arg = arg.slice(offset);
|
|
115
|
-
}
|
|
116
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
117
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
118
|
-
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
119
|
-
|
|
120
|
-
offset += ret.written;
|
|
121
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
WASM_VECTOR_LEN = offset;
|
|
125
|
-
return ptr;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function takeFromExternrefTable0(idx) {
|
|
129
|
-
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
130
|
-
wasm.__externref_table_dealloc(idx);
|
|
131
|
-
return value;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
135
|
-
cachedTextDecoder.decode();
|
|
136
|
-
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
137
|
-
let numBytesDecoded = 0;
|
|
138
|
-
function decodeText(ptr, len) {
|
|
139
|
-
numBytesDecoded += len;
|
|
140
|
-
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
141
|
-
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
142
|
-
cachedTextDecoder.decode();
|
|
143
|
-
numBytesDecoded = len;
|
|
144
|
-
}
|
|
145
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const cachedTextEncoder = new TextEncoder();
|
|
149
|
-
|
|
150
|
-
if (!('encodeInto' in cachedTextEncoder)) {
|
|
151
|
-
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
152
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
153
|
-
view.set(buf);
|
|
154
|
-
return {
|
|
155
|
-
read: arg.length,
|
|
156
|
-
written: buf.length
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
let WASM_VECTOR_LEN = 0;
|
|
162
|
-
|
|
163
|
-
const WasmEmbedderFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
164
|
-
? { register: () => {}, unregister: () => {} }
|
|
165
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_wasmembedder_free(ptr >>> 0, 1));
|
|
166
|
-
|
|
167
|
-
const WasmEmbedderConfigFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
168
|
-
? { register: () => {}, unregister: () => {} }
|
|
169
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_wasmembedderconfig_free(ptr >>> 0, 1));
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Strategy for pooling token embeddings into a single sentence embedding
|
|
173
|
-
* @enum {0 | 1 | 2 | 3 | 4}
|
|
174
|
-
*/
|
|
175
|
-
export const PoolingStrategy = Object.freeze({
|
|
176
|
-
/**
|
|
177
|
-
* Average all token embeddings (most common)
|
|
178
|
-
*/
|
|
179
|
-
Mean: 0, "0": "Mean",
|
|
180
|
-
/**
|
|
181
|
-
* Use only the [CLS] token embedding
|
|
182
|
-
*/
|
|
183
|
-
Cls: 1, "1": "Cls",
|
|
184
|
-
/**
|
|
185
|
-
* Take the maximum value across all tokens for each dimension
|
|
186
|
-
*/
|
|
187
|
-
Max: 2, "2": "Max",
|
|
188
|
-
/**
|
|
189
|
-
* Mean pooling normalized by sqrt of sequence length
|
|
190
|
-
*/
|
|
191
|
-
MeanSqrtLen: 3, "3": "MeanSqrtLen",
|
|
192
|
-
/**
|
|
193
|
-
* Use the last token embedding (for decoder models)
|
|
194
|
-
*/
|
|
195
|
-
LastToken: 4, "4": "LastToken",
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* WASM-compatible embedder using Tract for inference
|
|
200
|
-
*/
|
|
201
|
-
export class WasmEmbedder {
|
|
202
|
-
static __wrap(ptr) {
|
|
203
|
-
ptr = ptr >>> 0;
|
|
204
|
-
const obj = Object.create(WasmEmbedder.prototype);
|
|
205
|
-
obj.__wbg_ptr = ptr;
|
|
206
|
-
WasmEmbedderFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
207
|
-
return obj;
|
|
208
|
-
}
|
|
209
|
-
__destroy_into_raw() {
|
|
210
|
-
const ptr = this.__wbg_ptr;
|
|
211
|
-
this.__wbg_ptr = 0;
|
|
212
|
-
WasmEmbedderFinalization.unregister(this);
|
|
213
|
-
return ptr;
|
|
214
|
-
}
|
|
215
|
-
free() {
|
|
216
|
-
const ptr = this.__destroy_into_raw();
|
|
217
|
-
wasm.__wbg_wasmembedder_free(ptr, 0);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Get maximum sequence length
|
|
221
|
-
* @returns {number}
|
|
222
|
-
*/
|
|
223
|
-
maxLength() {
|
|
224
|
-
const ret = wasm.wasmembedder_maxLength(this.__wbg_ptr);
|
|
225
|
-
return ret >>> 0;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Compute similarity between two texts
|
|
229
|
-
* @param {string} text1
|
|
230
|
-
* @param {string} text2
|
|
231
|
-
* @returns {number}
|
|
232
|
-
*/
|
|
233
|
-
similarity(text1, text2) {
|
|
234
|
-
const ptr0 = passStringToWasm0(text1, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
235
|
-
const len0 = WASM_VECTOR_LEN;
|
|
236
|
-
const ptr1 = passStringToWasm0(text2, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
237
|
-
const len1 = WASM_VECTOR_LEN;
|
|
238
|
-
const ret = wasm.wasmembedder_similarity(this.__wbg_ptr, ptr0, len0, ptr1, len1);
|
|
239
|
-
if (ret[2]) {
|
|
240
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
241
|
-
}
|
|
242
|
-
return ret[0];
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Generate embeddings for multiple texts
|
|
246
|
-
* @param {string[]} texts
|
|
247
|
-
* @returns {Float32Array}
|
|
248
|
-
*/
|
|
249
|
-
embedBatch(texts) {
|
|
250
|
-
const ptr0 = passArrayJsValueToWasm0(texts, wasm.__wbindgen_malloc);
|
|
251
|
-
const len0 = WASM_VECTOR_LEN;
|
|
252
|
-
const ret = wasm.wasmembedder_embedBatch(this.__wbg_ptr, ptr0, len0);
|
|
253
|
-
if (ret[3]) {
|
|
254
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
255
|
-
}
|
|
256
|
-
var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
|
257
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
258
|
-
return v2;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Create embedder with custom configuration
|
|
262
|
-
* @param {Uint8Array} model_bytes
|
|
263
|
-
* @param {string} tokenizer_json
|
|
264
|
-
* @param {WasmEmbedderConfig} config
|
|
265
|
-
* @returns {WasmEmbedder}
|
|
266
|
-
*/
|
|
267
|
-
static withConfig(model_bytes, tokenizer_json, config) {
|
|
268
|
-
const ptr0 = passArray8ToWasm0(model_bytes, wasm.__wbindgen_malloc);
|
|
269
|
-
const len0 = WASM_VECTOR_LEN;
|
|
270
|
-
const ptr1 = passStringToWasm0(tokenizer_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
271
|
-
const len1 = WASM_VECTOR_LEN;
|
|
272
|
-
_assertClass(config, WasmEmbedderConfig);
|
|
273
|
-
var ptr2 = config.__destroy_into_raw();
|
|
274
|
-
const ret = wasm.wasmembedder_withConfig(ptr0, len0, ptr1, len1, ptr2);
|
|
275
|
-
if (ret[2]) {
|
|
276
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
277
|
-
}
|
|
278
|
-
return WasmEmbedder.__wrap(ret[0]);
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Create a new embedder from model and tokenizer bytes
|
|
282
|
-
*
|
|
283
|
-
* # Arguments
|
|
284
|
-
* * `model_bytes` - ONNX model file bytes
|
|
285
|
-
* * `tokenizer_json` - Tokenizer JSON configuration
|
|
286
|
-
* @param {Uint8Array} model_bytes
|
|
287
|
-
* @param {string} tokenizer_json
|
|
288
|
-
*/
|
|
289
|
-
constructor(model_bytes, tokenizer_json) {
|
|
290
|
-
const ptr0 = passArray8ToWasm0(model_bytes, wasm.__wbindgen_malloc);
|
|
291
|
-
const len0 = WASM_VECTOR_LEN;
|
|
292
|
-
const ptr1 = passStringToWasm0(tokenizer_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
293
|
-
const len1 = WASM_VECTOR_LEN;
|
|
294
|
-
const ret = wasm.wasmembedder_new(ptr0, len0, ptr1, len1);
|
|
295
|
-
if (ret[2]) {
|
|
296
|
-
throw takeFromExternrefTable0(ret[1]);
|
|
297
|
-
}
|
|
298
|
-
this.__wbg_ptr = ret[0] >>> 0;
|
|
299
|
-
WasmEmbedderFinalization.register(this, this.__wbg_ptr, this);
|
|
300
|
-
return this;
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Get the embedding dimension
|
|
304
|
-
* @returns {number}
|
|
305
|
-
*/
|
|
306
|
-
dimension() {
|
|
307
|
-
const ret = wasm.wasmembedder_dimension(this.__wbg_ptr);
|
|
308
|
-
return ret >>> 0;
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Generate embedding for a single text
|
|
312
|
-
* @param {string} text
|
|
313
|
-
* @returns {Float32Array}
|
|
314
|
-
*/
|
|
315
|
-
embedOne(text) {
|
|
316
|
-
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
317
|
-
const len0 = WASM_VECTOR_LEN;
|
|
318
|
-
const ret = wasm.wasmembedder_embedOne(this.__wbg_ptr, ptr0, len0);
|
|
319
|
-
if (ret[3]) {
|
|
320
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
321
|
-
}
|
|
322
|
-
var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
|
323
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
324
|
-
return v2;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
if (Symbol.dispose) WasmEmbedder.prototype[Symbol.dispose] = WasmEmbedder.prototype.free;
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Configuration for the WASM embedder
|
|
331
|
-
*/
|
|
332
|
-
export class WasmEmbedderConfig {
|
|
333
|
-
static __wrap(ptr) {
|
|
334
|
-
ptr = ptr >>> 0;
|
|
335
|
-
const obj = Object.create(WasmEmbedderConfig.prototype);
|
|
336
|
-
obj.__wbg_ptr = ptr;
|
|
337
|
-
WasmEmbedderConfigFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
338
|
-
return obj;
|
|
339
|
-
}
|
|
340
|
-
__destroy_into_raw() {
|
|
341
|
-
const ptr = this.__wbg_ptr;
|
|
342
|
-
this.__wbg_ptr = 0;
|
|
343
|
-
WasmEmbedderConfigFinalization.unregister(this);
|
|
344
|
-
return ptr;
|
|
345
|
-
}
|
|
346
|
-
free() {
|
|
347
|
-
const ptr = this.__destroy_into_raw();
|
|
348
|
-
wasm.__wbg_wasmembedderconfig_free(ptr, 0);
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Set pooling strategy (0=Mean, 1=Cls, 2=Max, 3=MeanSqrtLen, 4=LastToken)
|
|
352
|
-
* @param {number} pooling
|
|
353
|
-
* @returns {WasmEmbedderConfig}
|
|
354
|
-
*/
|
|
355
|
-
setPooling(pooling) {
|
|
356
|
-
const ptr = this.__destroy_into_raw();
|
|
357
|
-
const ret = wasm.wasmembedderconfig_setPooling(ptr, pooling);
|
|
358
|
-
return WasmEmbedderConfig.__wrap(ret);
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Set whether to normalize embeddings
|
|
362
|
-
* @param {boolean} normalize
|
|
363
|
-
* @returns {WasmEmbedderConfig}
|
|
364
|
-
*/
|
|
365
|
-
setNormalize(normalize) {
|
|
366
|
-
const ptr = this.__destroy_into_raw();
|
|
367
|
-
const ret = wasm.wasmembedderconfig_setNormalize(ptr, normalize);
|
|
368
|
-
return WasmEmbedderConfig.__wrap(ret);
|
|
369
|
-
}
|
|
370
|
-
/**
|
|
371
|
-
* Set maximum sequence length
|
|
372
|
-
* @param {number} max_length
|
|
373
|
-
* @returns {WasmEmbedderConfig}
|
|
374
|
-
*/
|
|
375
|
-
setMaxLength(max_length) {
|
|
376
|
-
const ptr = this.__destroy_into_raw();
|
|
377
|
-
const ret = wasm.wasmembedderconfig_setMaxLength(ptr, max_length);
|
|
378
|
-
return WasmEmbedderConfig.__wrap(ret);
|
|
379
|
-
}
|
|
380
|
-
/**
|
|
381
|
-
* Create a new configuration
|
|
382
|
-
*/
|
|
383
|
-
constructor() {
|
|
384
|
-
const ret = wasm.wasmembedderconfig_new();
|
|
385
|
-
this.__wbg_ptr = ret >>> 0;
|
|
386
|
-
WasmEmbedderConfigFinalization.register(this, this.__wbg_ptr, this);
|
|
387
|
-
return this;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
if (Symbol.dispose) WasmEmbedderConfig.prototype[Symbol.dispose] = WasmEmbedderConfig.prototype.free;
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Compute cosine similarity between two embedding vectors (JS-friendly)
|
|
394
|
-
* @param {Float32Array} a
|
|
395
|
-
* @param {Float32Array} b
|
|
396
|
-
* @returns {number}
|
|
397
|
-
*/
|
|
398
|
-
export function cosineSimilarity(a, b) {
|
|
399
|
-
const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_malloc);
|
|
400
|
-
const len0 = WASM_VECTOR_LEN;
|
|
401
|
-
const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_malloc);
|
|
402
|
-
const len1 = WASM_VECTOR_LEN;
|
|
403
|
-
const ret = wasm.cosineSimilarity(ptr0, len0, ptr1, len1);
|
|
404
|
-
return ret;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Initialize panic hook for better error messages in WASM
|
|
409
|
-
*/
|
|
410
|
-
export function init() {
|
|
411
|
-
wasm.init();
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
/**
|
|
415
|
-
* L2 normalize an embedding vector (JS-friendly)
|
|
416
|
-
* @param {Float32Array} embedding
|
|
417
|
-
* @returns {Float32Array}
|
|
418
|
-
*/
|
|
419
|
-
export function normalizeL2(embedding) {
|
|
420
|
-
const ptr0 = passArrayF32ToWasm0(embedding, wasm.__wbindgen_malloc);
|
|
421
|
-
const len0 = WASM_VECTOR_LEN;
|
|
422
|
-
const ret = wasm.normalizeL2(ptr0, len0);
|
|
423
|
-
var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
|
424
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
425
|
-
return v2;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* Check if SIMD is available (for performance info)
|
|
430
|
-
* @returns {boolean}
|
|
431
|
-
*/
|
|
432
|
-
export function simd_available() {
|
|
433
|
-
const ret = wasm.simd_available();
|
|
434
|
-
return ret !== 0;
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* Get the library version
|
|
439
|
-
* @returns {string}
|
|
440
|
-
*/
|
|
441
|
-
export function version() {
|
|
442
|
-
let deferred1_0;
|
|
443
|
-
let deferred1_1;
|
|
444
|
-
try {
|
|
445
|
-
const ret = wasm.version();
|
|
446
|
-
deferred1_0 = ret[0];
|
|
447
|
-
deferred1_1 = ret[1];
|
|
448
|
-
return getStringFromWasm0(ret[0], ret[1]);
|
|
449
|
-
} finally {
|
|
450
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
451
|
-
}
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
|
|
455
|
-
|
|
456
|
-
async function __wbg_load(module, imports) {
|
|
457
|
-
if (typeof Response === 'function' && module instanceof Response) {
|
|
458
|
-
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
459
|
-
try {
|
|
460
|
-
return await WebAssembly.instantiateStreaming(module, imports);
|
|
461
|
-
} catch (e) {
|
|
462
|
-
const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
|
|
463
|
-
|
|
464
|
-
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
465
|
-
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
466
|
-
|
|
467
|
-
} else {
|
|
468
|
-
throw e;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
const bytes = await module.arrayBuffer();
|
|
474
|
-
return await WebAssembly.instantiate(bytes, imports);
|
|
475
|
-
} else {
|
|
476
|
-
const instance = await WebAssembly.instantiate(module, imports);
|
|
477
|
-
|
|
478
|
-
if (instance instanceof WebAssembly.Instance) {
|
|
479
|
-
return { instance, module };
|
|
480
|
-
} else {
|
|
481
|
-
return instance;
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
function __wbg_get_imports() {
|
|
487
|
-
const imports = {};
|
|
488
|
-
imports.wbg = {};
|
|
489
|
-
imports.wbg.__wbg___wbindgen_is_function_8d400b8b1af978cd = function(arg0) {
|
|
490
|
-
const ret = typeof(arg0) === 'function';
|
|
491
|
-
return ret;
|
|
492
|
-
};
|
|
493
|
-
imports.wbg.__wbg___wbindgen_is_object_ce774f3490692386 = function(arg0) {
|
|
494
|
-
const val = arg0;
|
|
495
|
-
const ret = typeof(val) === 'object' && val !== null;
|
|
496
|
-
return ret;
|
|
497
|
-
};
|
|
498
|
-
imports.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030 = function(arg0) {
|
|
499
|
-
const ret = typeof(arg0) === 'string';
|
|
500
|
-
return ret;
|
|
501
|
-
};
|
|
502
|
-
imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
|
|
503
|
-
const ret = arg0 === undefined;
|
|
504
|
-
return ret;
|
|
505
|
-
};
|
|
506
|
-
imports.wbg.__wbg___wbindgen_string_get_a2a31e16edf96e42 = function(arg0, arg1) {
|
|
507
|
-
const obj = arg1;
|
|
508
|
-
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
509
|
-
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
510
|
-
var len1 = WASM_VECTOR_LEN;
|
|
511
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
512
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
513
|
-
};
|
|
514
|
-
imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
|
|
515
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
516
|
-
};
|
|
517
|
-
imports.wbg.__wbg_call_3020136f7a2d6e44 = function() { return handleError(function (arg0, arg1, arg2) {
|
|
518
|
-
const ret = arg0.call(arg1, arg2);
|
|
519
|
-
return ret;
|
|
520
|
-
}, arguments) };
|
|
521
|
-
imports.wbg.__wbg_call_abb4ff46ce38be40 = function() { return handleError(function (arg0, arg1) {
|
|
522
|
-
const ret = arg0.call(arg1);
|
|
523
|
-
return ret;
|
|
524
|
-
}, arguments) };
|
|
525
|
-
imports.wbg.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
|
|
526
|
-
const ret = arg0.crypto;
|
|
527
|
-
return ret;
|
|
528
|
-
};
|
|
529
|
-
imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
|
|
530
|
-
let deferred0_0;
|
|
531
|
-
let deferred0_1;
|
|
532
|
-
try {
|
|
533
|
-
deferred0_0 = arg0;
|
|
534
|
-
deferred0_1 = arg1;
|
|
535
|
-
console.error(getStringFromWasm0(arg0, arg1));
|
|
536
|
-
} finally {
|
|
537
|
-
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
538
|
-
}
|
|
539
|
-
};
|
|
540
|
-
imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
|
|
541
|
-
arg0.getRandomValues(arg1);
|
|
542
|
-
}, arguments) };
|
|
543
|
-
imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
|
|
544
|
-
const ret = arg0.length;
|
|
545
|
-
return ret;
|
|
546
|
-
};
|
|
547
|
-
imports.wbg.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
|
|
548
|
-
const ret = arg0.msCrypto;
|
|
549
|
-
return ret;
|
|
550
|
-
};
|
|
551
|
-
imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
|
|
552
|
-
const ret = new Error();
|
|
553
|
-
return ret;
|
|
554
|
-
};
|
|
555
|
-
imports.wbg.__wbg_new_no_args_cb138f77cf6151ee = function(arg0, arg1) {
|
|
556
|
-
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
557
|
-
return ret;
|
|
558
|
-
};
|
|
559
|
-
imports.wbg.__wbg_new_with_length_aa5eaf41d35235e5 = function(arg0) {
|
|
560
|
-
const ret = new Uint8Array(arg0 >>> 0);
|
|
561
|
-
return ret;
|
|
562
|
-
};
|
|
563
|
-
imports.wbg.__wbg_node_905d3e251edff8a2 = function(arg0) {
|
|
564
|
-
const ret = arg0.node;
|
|
565
|
-
return ret;
|
|
566
|
-
};
|
|
567
|
-
imports.wbg.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
|
|
568
|
-
const ret = arg0.process;
|
|
569
|
-
return ret;
|
|
570
|
-
};
|
|
571
|
-
imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) {
|
|
572
|
-
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
573
|
-
};
|
|
574
|
-
imports.wbg.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) {
|
|
575
|
-
arg0.randomFillSync(arg1);
|
|
576
|
-
}, arguments) };
|
|
577
|
-
imports.wbg.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () {
|
|
578
|
-
const ret = module.require;
|
|
579
|
-
return ret;
|
|
580
|
-
}, arguments) };
|
|
581
|
-
imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
|
|
582
|
-
const ret = arg1.stack;
|
|
583
|
-
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
584
|
-
const len1 = WASM_VECTOR_LEN;
|
|
585
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
586
|
-
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
587
|
-
};
|
|
588
|
-
imports.wbg.__wbg_static_accessor_GLOBAL_769e6b65d6557335 = function() {
|
|
589
|
-
const ret = typeof global === 'undefined' ? null : global;
|
|
590
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
591
|
-
};
|
|
592
|
-
imports.wbg.__wbg_static_accessor_GLOBAL_THIS_60cf02db4de8e1c1 = function() {
|
|
593
|
-
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
594
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
595
|
-
};
|
|
596
|
-
imports.wbg.__wbg_static_accessor_SELF_08f5a74c69739274 = function() {
|
|
597
|
-
const ret = typeof self === 'undefined' ? null : self;
|
|
598
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
599
|
-
};
|
|
600
|
-
imports.wbg.__wbg_static_accessor_WINDOW_a8924b26aa92d024 = function() {
|
|
601
|
-
const ret = typeof window === 'undefined' ? null : window;
|
|
602
|
-
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
603
|
-
};
|
|
604
|
-
imports.wbg.__wbg_subarray_845f2f5bce7d061a = function(arg0, arg1, arg2) {
|
|
605
|
-
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
606
|
-
return ret;
|
|
607
|
-
};
|
|
608
|
-
imports.wbg.__wbg_versions_c01dfd4722a88165 = function(arg0) {
|
|
609
|
-
const ret = arg0.versions;
|
|
610
|
-
return ret;
|
|
611
|
-
};
|
|
612
|
-
imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
|
|
613
|
-
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
614
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
615
|
-
return ret;
|
|
616
|
-
};
|
|
617
|
-
imports.wbg.__wbindgen_cast_cb9088102bce6b30 = function(arg0, arg1) {
|
|
618
|
-
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
619
|
-
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
620
|
-
return ret;
|
|
621
|
-
};
|
|
622
|
-
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
623
|
-
const table = wasm.__wbindgen_externrefs;
|
|
624
|
-
const offset = table.grow(4);
|
|
625
|
-
table.set(0, undefined);
|
|
626
|
-
table.set(offset + 0, undefined);
|
|
627
|
-
table.set(offset + 1, null);
|
|
628
|
-
table.set(offset + 2, true);
|
|
629
|
-
table.set(offset + 3, false);
|
|
630
|
-
};
|
|
631
|
-
|
|
632
|
-
return imports;
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
function __wbg_finalize_init(instance, module) {
|
|
636
|
-
wasm = instance.exports;
|
|
637
|
-
__wbg_init.__wbindgen_wasm_module = module;
|
|
638
|
-
cachedDataViewMemory0 = null;
|
|
639
|
-
cachedFloat32ArrayMemory0 = null;
|
|
640
|
-
cachedUint8ArrayMemory0 = null;
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
wasm.__wbindgen_start();
|
|
644
|
-
return wasm;
|
|
645
|
-
}
|
|
646
|
-
|
|
647
|
-
function initSync(module) {
|
|
648
|
-
if (wasm !== undefined) return wasm;
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
if (typeof module !== 'undefined') {
|
|
652
|
-
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
653
|
-
({module} = module)
|
|
654
|
-
} else {
|
|
655
|
-
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
|
|
659
|
-
const imports = __wbg_get_imports();
|
|
660
|
-
if (!(module instanceof WebAssembly.Module)) {
|
|
661
|
-
module = new WebAssembly.Module(module);
|
|
662
|
-
}
|
|
663
|
-
const instance = new WebAssembly.Instance(module, imports);
|
|
664
|
-
return __wbg_finalize_init(instance, module);
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
async function __wbg_init(module_or_path) {
|
|
668
|
-
if (wasm !== undefined) return wasm;
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
if (typeof module_or_path !== 'undefined') {
|
|
672
|
-
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
673
|
-
({module_or_path} = module_or_path)
|
|
674
|
-
} else {
|
|
675
|
-
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
676
|
-
}
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
if (typeof module_or_path === 'undefined') {
|
|
680
|
-
module_or_path = new URL('ruvector_onnx_embeddings_wasm_bg.wasm', import.meta.url);
|
|
681
|
-
}
|
|
682
|
-
const imports = __wbg_get_imports();
|
|
683
|
-
|
|
684
|
-
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
685
|
-
module_or_path = fetch(module_or_path);
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
689
|
-
|
|
690
|
-
return __wbg_finalize_init(instance, module);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
export { initSync };
|
|
694
|
-
export default __wbg_init;
|
|
1
|
+
import * as wasm from "./ruvector_onnx_embeddings_wasm_bg.wasm";
|
|
2
|
+
export * from "./ruvector_onnx_embeddings_wasm_bg.js";
|
|
3
|
+
import { __wbg_set_wasm } from "./ruvector_onnx_embeddings_wasm_bg.js";
|
|
4
|
+
__wbg_set_wasm(wasm);
|
|
5
|
+
wasm.__wbindgen_start();
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onnx-embedder.d.ts","sourceRoot":"","sources":["../../src/core/onnx-embedder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;
|
|
1
|
+
{"version":3,"file":"onnx-embedder.d.ts","sourceRoot":"","sources":["../../src/core/onnx-embedder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAWH,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAYD;;GAEG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAOzC;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,MAAM,GAAE,kBAAuB,GAAG,OAAO,CAAC,OAAO,CAAC,CAkExF;AAED;;GAEG;AACH,wBAAsB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAiBlE;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC,CAyB5E;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAaxF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAiBjE;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,MAAM,CAErC;AAED;;GAEG;AACH,wBAAgB,OAAO,IAAI,OAAO,CAEjC;AAED;;GAEG;AACH,wBAAgB,QAAQ,IAAI;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAM/E;AAGD,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAqB;gBAEvB,MAAM,GAAE,kBAAuB;IAIrC,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAIxB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAKtC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IAKhD,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK/D,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,IAAI,KAAK,IAAI,OAAO,CAEnB;CACF;AAED,eAAe,YAAY,CAAC"}
|
|
@@ -59,6 +59,7 @@ exports.isReady = isReady;
|
|
|
59
59
|
exports.getStats = getStats;
|
|
60
60
|
const path = __importStar(require("path"));
|
|
61
61
|
const fs = __importStar(require("fs"));
|
|
62
|
+
const url_1 = require("url");
|
|
62
63
|
// Force native dynamic import (avoids TypeScript transpiling to require)
|
|
63
64
|
// eslint-disable-next-line @typescript-eslint/no-implied-eval
|
|
64
65
|
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
@@ -102,8 +103,11 @@ async function initOnnxEmbedder(config = {}) {
|
|
|
102
103
|
if (!fs.existsSync(pkgPath)) {
|
|
103
104
|
throw new Error('ONNX WASM files not bundled. The onnx/ directory is missing.');
|
|
104
105
|
}
|
|
105
|
-
//
|
|
106
|
-
|
|
106
|
+
// Convert paths to file:// URLs for cross-platform ESM compatibility (Windows fix)
|
|
107
|
+
const pkgUrl = (0, url_1.pathToFileURL)(pkgPath).href;
|
|
108
|
+
const loaderUrl = (0, url_1.pathToFileURL)(loaderPath).href;
|
|
109
|
+
// Dynamic import of bundled modules using file:// URLs
|
|
110
|
+
wasmModule = await dynamicImport(pkgUrl);
|
|
107
111
|
// Initialize WASM module (loads the .wasm file)
|
|
108
112
|
const wasmPath = path.join(__dirname, 'onnx', 'pkg', 'ruvector_onnx_embeddings_wasm_bg.wasm');
|
|
109
113
|
if (wasmModule.default && typeof wasmModule.default === 'function') {
|
|
@@ -111,7 +115,7 @@ async function initOnnxEmbedder(config = {}) {
|
|
|
111
115
|
const wasmBytes = fs.readFileSync(wasmPath);
|
|
112
116
|
await wasmModule.default(wasmBytes);
|
|
113
117
|
}
|
|
114
|
-
const loaderModule = await dynamicImport(
|
|
118
|
+
const loaderModule = await dynamicImport(loaderUrl);
|
|
115
119
|
const { ModelLoader } = loaderModule;
|
|
116
120
|
// Create model loader with caching
|
|
117
121
|
const modelLoader = new ModelLoader({
|
package/package.json
CHANGED
package/ruvector.db
CHANGED
|
Binary file
|
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
# RuVector ONNX Embeddings WASM
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/ruvector-onnx-embeddings-wasm)
|
|
4
|
-
[](https://crates.io/crates/ruvector-onnx-embeddings-wasm)
|
|
5
|
-
[](https://opensource.org/licenses/MIT)
|
|
6
|
-
[](https://webassembly.org/)
|
|
7
|
-
|
|
8
|
-
> **Portable embedding generation that runs anywhere WebAssembly runs**
|
|
9
|
-
|
|
10
|
-
Generate text embeddings directly in browsers, Cloudflare Workers, Deno, and any WASM runtime. Built with [Tract](https://github.com/sonos/tract) for pure Rust ONNX inference.
|
|
11
|
-
|
|
12
|
-
## Features
|
|
13
|
-
|
|
14
|
-
| Feature | Description |
|
|
15
|
-
|---------|-------------|
|
|
16
|
-
| 🌐 **Browser Support** | Generate embeddings client-side, no server needed |
|
|
17
|
-
| ⚡ **Edge Computing** | Deploy to Cloudflare Workers, Vercel Edge, Deno Deploy |
|
|
18
|
-
| 📦 **Zero Dependencies** | Single WASM binary, no native modules |
|
|
19
|
-
| 🤗 **HuggingFace Models** | Pre-configured URLs for popular models |
|
|
20
|
-
| 🔄 **Auto Caching** | Browser Cache API for instant reloads |
|
|
21
|
-
| 🎯 **Same API** | Compatible with native `ruvector-onnx-embeddings` |
|
|
22
|
-
|
|
23
|
-
## Quick Start
|
|
24
|
-
|
|
25
|
-
### Browser (ES Modules)
|
|
26
|
-
|
|
27
|
-
```html
|
|
28
|
-
<script type="module">
|
|
29
|
-
import init, { WasmEmbedder } from 'https://unpkg.com/ruvector-onnx-embeddings-wasm/ruvector_onnx_embeddings_wasm.js';
|
|
30
|
-
import { createEmbedder } from 'https://unpkg.com/ruvector-onnx-embeddings-wasm/loader.js';
|
|
31
|
-
|
|
32
|
-
// Initialize WASM
|
|
33
|
-
await init();
|
|
34
|
-
|
|
35
|
-
// Create embedder (downloads model automatically)
|
|
36
|
-
const embedder = await createEmbedder('all-MiniLM-L6-v2');
|
|
37
|
-
|
|
38
|
-
// Generate embeddings
|
|
39
|
-
const embedding = embedder.embedOne("Hello, world!");
|
|
40
|
-
console.log("Dimension:", embedding.length); // 384
|
|
41
|
-
|
|
42
|
-
// Compute similarity
|
|
43
|
-
const sim = embedder.similarity("I love Rust", "Rust is great");
|
|
44
|
-
console.log("Similarity:", sim.toFixed(4)); // ~0.85
|
|
45
|
-
</script>
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Node.js
|
|
49
|
-
|
|
50
|
-
```bash
|
|
51
|
-
npm install ruvector-onnx-embeddings-wasm
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
```javascript
|
|
55
|
-
import { createEmbedder, similarity, embed } from 'ruvector-onnx-embeddings-wasm/loader.js';
|
|
56
|
-
|
|
57
|
-
// One-liner similarity
|
|
58
|
-
const score = await similarity("I love dogs", "I adore puppies");
|
|
59
|
-
console.log(score); // ~0.85
|
|
60
|
-
|
|
61
|
-
// One-liner embedding
|
|
62
|
-
const embedding = await embed("Hello world");
|
|
63
|
-
console.log(embedding.length); // 384
|
|
64
|
-
|
|
65
|
-
// Full control
|
|
66
|
-
const embedder = await createEmbedder('bge-small-en-v1.5');
|
|
67
|
-
const emb1 = embedder.embedOne("First text");
|
|
68
|
-
const emb2 = embedder.embedOne("Second text");
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Cloudflare Workers
|
|
72
|
-
|
|
73
|
-
```javascript
|
|
74
|
-
import { WasmEmbedder, WasmEmbedderConfig } from 'ruvector-onnx-embeddings-wasm';
|
|
75
|
-
|
|
76
|
-
export default {
|
|
77
|
-
async fetch(request, env) {
|
|
78
|
-
// Load model from R2 or KV
|
|
79
|
-
const modelBytes = await env.MODELS.get('model.onnx', 'arrayBuffer');
|
|
80
|
-
const tokenizerJson = await env.MODELS.get('tokenizer.json', 'text');
|
|
81
|
-
|
|
82
|
-
const embedder = new WasmEmbedder(
|
|
83
|
-
new Uint8Array(modelBytes),
|
|
84
|
-
tokenizerJson
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
const { text } = await request.json();
|
|
88
|
-
const embedding = embedder.embedOne(text);
|
|
89
|
-
|
|
90
|
-
return Response.json({
|
|
91
|
-
embedding: Array.from(embedding),
|
|
92
|
-
dimension: embedding.length
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Available Models
|
|
99
|
-
|
|
100
|
-
| Model | Dimension | Size | Speed | Quality | Best For |
|
|
101
|
-
|-------|-----------|------|-------|---------|----------|
|
|
102
|
-
| **all-MiniLM-L6-v2** ⭐ | 384 | 23MB | ⚡⚡⚡ | ⭐⭐⭐ | Default, fast |
|
|
103
|
-
| **all-MiniLM-L12-v2** | 384 | 33MB | ⚡⚡ | ⭐⭐⭐⭐ | Better quality |
|
|
104
|
-
| **bge-small-en-v1.5** | 384 | 33MB | ⚡⚡⚡ | ⭐⭐⭐⭐ | State-of-the-art |
|
|
105
|
-
| **bge-base-en-v1.5** | 768 | 110MB | ⚡ | ⭐⭐⭐⭐⭐ | Best quality |
|
|
106
|
-
| **e5-small-v2** | 384 | 33MB | ⚡⚡⚡ | ⭐⭐⭐⭐ | Search/retrieval |
|
|
107
|
-
| **gte-small** | 384 | 33MB | ⚡⚡⚡ | ⭐⭐⭐⭐ | Multilingual |
|
|
108
|
-
|
|
109
|
-
## API Reference
|
|
110
|
-
|
|
111
|
-
### ModelLoader
|
|
112
|
-
|
|
113
|
-
```javascript
|
|
114
|
-
import { ModelLoader, MODELS, DEFAULT_MODEL } from './loader.js';
|
|
115
|
-
|
|
116
|
-
// List available models
|
|
117
|
-
console.log(ModelLoader.listModels());
|
|
118
|
-
|
|
119
|
-
// Load with progress
|
|
120
|
-
const loader = new ModelLoader({
|
|
121
|
-
cache: true,
|
|
122
|
-
onProgress: ({ percent }) => console.log(`${percent}%`)
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
const { modelBytes, tokenizerJson, config } = await loader.loadModel('all-MiniLM-L6-v2');
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### WasmEmbedder
|
|
129
|
-
|
|
130
|
-
```typescript
|
|
131
|
-
class WasmEmbedder {
|
|
132
|
-
constructor(modelBytes: Uint8Array, tokenizerJson: string);
|
|
133
|
-
|
|
134
|
-
static withConfig(
|
|
135
|
-
modelBytes: Uint8Array,
|
|
136
|
-
tokenizerJson: string,
|
|
137
|
-
config: WasmEmbedderConfig
|
|
138
|
-
): WasmEmbedder;
|
|
139
|
-
|
|
140
|
-
embedOne(text: string): Float32Array;
|
|
141
|
-
embedBatch(texts: string[]): Float32Array;
|
|
142
|
-
similarity(text1: string, text2: string): number;
|
|
143
|
-
|
|
144
|
-
dimension(): number;
|
|
145
|
-
maxLength(): number;
|
|
146
|
-
}
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### WasmEmbedderConfig
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
class WasmEmbedderConfig {
|
|
153
|
-
constructor();
|
|
154
|
-
setMaxLength(length: number): WasmEmbedderConfig;
|
|
155
|
-
setNormalize(normalize: boolean): WasmEmbedderConfig;
|
|
156
|
-
setPooling(strategy: number): WasmEmbedderConfig;
|
|
157
|
-
// 0=Mean, 1=Cls, 2=Max, 3=MeanSqrtLen, 4=LastToken
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Utility Functions
|
|
162
|
-
|
|
163
|
-
```typescript
|
|
164
|
-
function cosineSimilarity(a: Float32Array, b: Float32Array): number;
|
|
165
|
-
function normalizeL2(embedding: Float32Array): Float32Array;
|
|
166
|
-
function version(): string;
|
|
167
|
-
function simd_available(): boolean;
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
## Pooling Strategies
|
|
171
|
-
|
|
172
|
-
| Value | Strategy | Description |
|
|
173
|
-
|-------|----------|-------------|
|
|
174
|
-
| 0 | **Mean** | Average all tokens (default, recommended) |
|
|
175
|
-
| 1 | **Cls** | Use [CLS] token only (BERT-style) |
|
|
176
|
-
| 2 | **Max** | Max pooling across tokens |
|
|
177
|
-
| 3 | **MeanSqrtLen** | Mean normalized by sqrt(length) |
|
|
178
|
-
| 4 | **LastToken** | Last token (decoder models) |
|
|
179
|
-
|
|
180
|
-
## Performance
|
|
181
|
-
|
|
182
|
-
| Environment | Throughput | Latency |
|
|
183
|
-
|-------------|------------|---------|
|
|
184
|
-
| Chrome (M1 Mac) | ~50 texts/sec | ~20ms |
|
|
185
|
-
| Firefox (M1 Mac) | ~45 texts/sec | ~22ms |
|
|
186
|
-
| Node.js 20 | ~80 texts/sec | ~12ms |
|
|
187
|
-
| Cloudflare Workers | ~30 texts/sec | ~33ms |
|
|
188
|
-
| Deno | ~75 texts/sec | ~13ms |
|
|
189
|
-
|
|
190
|
-
*Tested with all-MiniLM-L6-v2, 128 token inputs*
|
|
191
|
-
|
|
192
|
-
## Comparison: Native vs WASM
|
|
193
|
-
|
|
194
|
-
| Aspect | Native (`ort`) | WASM (`tract`) |
|
|
195
|
-
|--------|----------------|----------------|
|
|
196
|
-
| Speed | ⚡⚡⚡ Native | ⚡⚡ ~2-3x slower |
|
|
197
|
-
| Browser | ❌ | ✅ |
|
|
198
|
-
| Edge Workers | ❌ | ✅ |
|
|
199
|
-
| GPU | CUDA, TensorRT | ❌ |
|
|
200
|
-
| Bundle Size | ~50MB | ~8MB |
|
|
201
|
-
| Portability | Platform-specific | Universal |
|
|
202
|
-
|
|
203
|
-
**Use native** for: servers, high throughput, GPU acceleration
|
|
204
|
-
**Use WASM** for: browsers, edge, portability
|
|
205
|
-
|
|
206
|
-
## Building from Source
|
|
207
|
-
|
|
208
|
-
```bash
|
|
209
|
-
# Install wasm-pack
|
|
210
|
-
cargo install wasm-pack
|
|
211
|
-
|
|
212
|
-
# Build for web
|
|
213
|
-
wasm-pack build --target web
|
|
214
|
-
|
|
215
|
-
# Build for Node.js
|
|
216
|
-
wasm-pack build --target nodejs
|
|
217
|
-
|
|
218
|
-
# Build for bundlers (webpack, vite)
|
|
219
|
-
wasm-pack build --target bundler
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
## Use Cases
|
|
223
|
-
|
|
224
|
-
### Semantic Search
|
|
225
|
-
|
|
226
|
-
```javascript
|
|
227
|
-
const embedder = await createEmbedder();
|
|
228
|
-
|
|
229
|
-
// Index documents
|
|
230
|
-
const docs = ["Rust is fast", "Python is easy", "JavaScript runs everywhere"];
|
|
231
|
-
const embeddings = docs.map(d => embedder.embedOne(d));
|
|
232
|
-
|
|
233
|
-
// Search
|
|
234
|
-
const query = embedder.embedOne("Which language is performant?");
|
|
235
|
-
const scores = embeddings.map((e, i) => ({
|
|
236
|
-
doc: docs[i],
|
|
237
|
-
score: cosineSimilarity(query, e)
|
|
238
|
-
}));
|
|
239
|
-
scores.sort((a, b) => b.score - a.score);
|
|
240
|
-
console.log(scores[0]); // { doc: "Rust is fast", score: 0.82 }
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
### Text Clustering
|
|
244
|
-
|
|
245
|
-
```javascript
|
|
246
|
-
const texts = [
|
|
247
|
-
"Machine learning is amazing",
|
|
248
|
-
"Deep learning uses neural networks",
|
|
249
|
-
"I love pizza",
|
|
250
|
-
"Italian food is delicious"
|
|
251
|
-
];
|
|
252
|
-
|
|
253
|
-
const embeddings = texts.map(t => embedder.embedOne(t));
|
|
254
|
-
// Use k-means or hierarchical clustering on embeddings
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
### RAG (Retrieval-Augmented Generation)
|
|
258
|
-
|
|
259
|
-
```javascript
|
|
260
|
-
// Build knowledge base
|
|
261
|
-
const knowledge = [
|
|
262
|
-
"RuVector is a vector database",
|
|
263
|
-
"Embeddings capture semantic meaning",
|
|
264
|
-
// ... more docs
|
|
265
|
-
];
|
|
266
|
-
const knowledgeEmbeddings = knowledge.map(k => embedder.embedOne(k));
|
|
267
|
-
|
|
268
|
-
// Retrieve relevant context for LLM
|
|
269
|
-
function getContext(query, topK = 3) {
|
|
270
|
-
const queryEmb = embedder.embedOne(query);
|
|
271
|
-
const scores = knowledgeEmbeddings.map((e, i) => ({
|
|
272
|
-
text: knowledge[i],
|
|
273
|
-
score: cosineSimilarity(queryEmb, e)
|
|
274
|
-
}));
|
|
275
|
-
return scores.sort((a, b) => b.score - a.score).slice(0, topK);
|
|
276
|
-
}
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
## Related Packages
|
|
280
|
-
|
|
281
|
-
| Package | Runtime | Use Case |
|
|
282
|
-
|---------|---------|----------|
|
|
283
|
-
| [ruvector-onnx-embeddings](https://crates.io/crates/ruvector-onnx-embeddings) | Native | High-performance servers |
|
|
284
|
-
| **ruvector-onnx-embeddings-wasm** | WASM | Browsers, edge, portable |
|
|
285
|
-
|
|
286
|
-
## License
|
|
287
|
-
|
|
288
|
-
MIT License - See [LICENSE](../../LICENSE) for details.
|
|
289
|
-
|
|
290
|
-
---
|
|
291
|
-
|
|
292
|
-
<p align="center">
|
|
293
|
-
<b>Part of the RuVector ecosystem</b><br>
|
|
294
|
-
High-performance vector operations in Rust
|
|
295
|
-
</p>
|
|
Binary file
|