@brainwires/idbvec 0.1.0 → 0.2.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.
@@ -0,0 +1,687 @@
1
+ /**
2
+ * Main VectorDB class - exposed to JavaScript
3
+ */
4
+ export class VectorDB {
5
+ static __wrap(ptr) {
6
+ ptr = ptr >>> 0;
7
+ const obj = Object.create(VectorDB.prototype);
8
+ obj.__wbg_ptr = ptr;
9
+ VectorDBFinalization.register(obj, obj.__wbg_ptr, obj);
10
+ return obj;
11
+ }
12
+ __destroy_into_raw() {
13
+ const ptr = this.__wbg_ptr;
14
+ this.__wbg_ptr = 0;
15
+ VectorDBFinalization.unregister(this);
16
+ return ptr;
17
+ }
18
+ free() {
19
+ const ptr = this.__destroy_into_raw();
20
+ wasm.__wbg_vectordb_free(ptr, 0);
21
+ }
22
+ /**
23
+ * Delete a vector by ID
24
+ * @param {string} id
25
+ * @returns {boolean}
26
+ */
27
+ delete(id) {
28
+ const ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29
+ const len0 = WASM_VECTOR_LEN;
30
+ const ret = wasm.vectordb_delete(this.__wbg_ptr, ptr0, len0);
31
+ return ret !== 0;
32
+ }
33
+ /**
34
+ * Delete multiple vectors by ID, returns number of deletions
35
+ * @param {string[]} ids
36
+ * @returns {number}
37
+ */
38
+ delete_batch(ids) {
39
+ const ptr0 = passArrayJsValueToWasm0(ids, wasm.__wbindgen_malloc);
40
+ const len0 = WASM_VECTOR_LEN;
41
+ const ret = wasm.vectordb_delete_batch(this.__wbg_ptr, ptr0, len0);
42
+ return ret >>> 0;
43
+ }
44
+ /**
45
+ * Deserialize and restore database from JSON
46
+ * @param {string} json
47
+ * @returns {VectorDB}
48
+ */
49
+ static deserialize(json) {
50
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
51
+ const len0 = WASM_VECTOR_LEN;
52
+ const ret = wasm.vectordb_deserialize(ptr0, len0);
53
+ if (ret[2]) {
54
+ throw takeFromExternrefTable0(ret[1]);
55
+ }
56
+ return VectorDB.__wrap(ret[0]);
57
+ }
58
+ /**
59
+ * Get a vector and its metadata by ID
60
+ * @param {string} id
61
+ * @returns {any}
62
+ */
63
+ get(id) {
64
+ const ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
65
+ const len0 = WASM_VECTOR_LEN;
66
+ const ret = wasm.vectordb_get(this.__wbg_ptr, ptr0, len0);
67
+ if (ret[2]) {
68
+ throw takeFromExternrefTable0(ret[1]);
69
+ }
70
+ return takeFromExternrefTable0(ret[0]);
71
+ }
72
+ /**
73
+ * Check if a vector exists by ID
74
+ * @param {string} id
75
+ * @returns {boolean}
76
+ */
77
+ has(id) {
78
+ const ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
79
+ const len0 = WASM_VECTOR_LEN;
80
+ const ret = wasm.vectordb_has(this.__wbg_ptr, ptr0, len0);
81
+ return ret !== 0;
82
+ }
83
+ /**
84
+ * Insert a vector into the database
85
+ * @param {string} id
86
+ * @param {Float32Array} vector
87
+ * @param {any} metadata
88
+ */
89
+ insert(id, vector, metadata) {
90
+ const ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
91
+ const len0 = WASM_VECTOR_LEN;
92
+ const ptr1 = passArrayF32ToWasm0(vector, wasm.__wbindgen_malloc);
93
+ const len1 = WASM_VECTOR_LEN;
94
+ const ret = wasm.vectordb_insert(this.__wbg_ptr, ptr0, len0, ptr1, len1, metadata);
95
+ if (ret[1]) {
96
+ throw takeFromExternrefTable0(ret[0]);
97
+ }
98
+ }
99
+ /**
100
+ * List all vector IDs
101
+ * @returns {any}
102
+ */
103
+ list_ids() {
104
+ const ret = wasm.vectordb_list_ids(this.__wbg_ptr);
105
+ if (ret[2]) {
106
+ throw takeFromExternrefTable0(ret[1]);
107
+ }
108
+ return takeFromExternrefTable0(ret[0]);
109
+ }
110
+ /**
111
+ * Create a new VectorDB instance
112
+ * @param {number} dimensions
113
+ * @param {number} m
114
+ * @param {number} ef_construction
115
+ * @param {string | null} [metric]
116
+ */
117
+ constructor(dimensions, m, ef_construction, metric) {
118
+ var ptr0 = isLikeNone(metric) ? 0 : passStringToWasm0(metric, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
119
+ var len0 = WASM_VECTOR_LEN;
120
+ const ret = wasm.vectordb_new(dimensions, m, ef_construction, ptr0, len0);
121
+ this.__wbg_ptr = ret >>> 0;
122
+ VectorDBFinalization.register(this, this.__wbg_ptr, this);
123
+ return this;
124
+ }
125
+ /**
126
+ * Search for nearest neighbors
127
+ * @param {Float32Array} query
128
+ * @param {number} k
129
+ * @param {number} ef
130
+ * @returns {any}
131
+ */
132
+ search(query, k, ef) {
133
+ const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_malloc);
134
+ const len0 = WASM_VECTOR_LEN;
135
+ const ret = wasm.vectordb_search(this.__wbg_ptr, ptr0, len0, k, ef);
136
+ if (ret[2]) {
137
+ throw takeFromExternrefTable0(ret[1]);
138
+ }
139
+ return takeFromExternrefTable0(ret[0]);
140
+ }
141
+ /**
142
+ * Serialize the entire database to JSON
143
+ * @returns {string}
144
+ */
145
+ serialize() {
146
+ let deferred2_0;
147
+ let deferred2_1;
148
+ try {
149
+ const ret = wasm.vectordb_serialize(this.__wbg_ptr);
150
+ var ptr1 = ret[0];
151
+ var len1 = ret[1];
152
+ if (ret[3]) {
153
+ ptr1 = 0; len1 = 0;
154
+ throw takeFromExternrefTable0(ret[2]);
155
+ }
156
+ deferred2_0 = ptr1;
157
+ deferred2_1 = len1;
158
+ return getStringFromWasm0(ptr1, len1);
159
+ } finally {
160
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
161
+ }
162
+ }
163
+ /**
164
+ * Get total number of vectors
165
+ * @returns {number}
166
+ */
167
+ size() {
168
+ const ret = wasm.vectordb_size(this.__wbg_ptr);
169
+ return ret >>> 0;
170
+ }
171
+ }
172
+ if (Symbol.dispose) VectorDB.prototype[Symbol.dispose] = VectorDB.prototype.free;
173
+
174
+ /**
175
+ * Standalone distance functions exposed to JS
176
+ * @param {Float32Array} a
177
+ * @param {Float32Array} b
178
+ * @returns {number}
179
+ */
180
+ export function cosine_similarity(a, b) {
181
+ const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_malloc);
182
+ const len0 = WASM_VECTOR_LEN;
183
+ const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_malloc);
184
+ const len1 = WASM_VECTOR_LEN;
185
+ const ret = wasm.cosine_similarity(ptr0, len0, ptr1, len1);
186
+ if (ret[2]) {
187
+ throw takeFromExternrefTable0(ret[1]);
188
+ }
189
+ return ret[0];
190
+ }
191
+
192
+ /**
193
+ * @param {Float32Array} a
194
+ * @param {Float32Array} b
195
+ * @returns {number}
196
+ */
197
+ export function dot_product(a, b) {
198
+ const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_malloc);
199
+ const len0 = WASM_VECTOR_LEN;
200
+ const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_malloc);
201
+ const len1 = WASM_VECTOR_LEN;
202
+ const ret = wasm.dot_product(ptr0, len0, ptr1, len1);
203
+ if (ret[2]) {
204
+ throw takeFromExternrefTable0(ret[1]);
205
+ }
206
+ return ret[0];
207
+ }
208
+
209
+ /**
210
+ * @param {Float32Array} a
211
+ * @param {Float32Array} b
212
+ * @returns {number}
213
+ */
214
+ export function euclidean_distance(a, b) {
215
+ const ptr0 = passArrayF32ToWasm0(a, wasm.__wbindgen_malloc);
216
+ const len0 = WASM_VECTOR_LEN;
217
+ const ptr1 = passArrayF32ToWasm0(b, wasm.__wbindgen_malloc);
218
+ const len1 = WASM_VECTOR_LEN;
219
+ const ret = wasm.euclidean_distance(ptr0, len0, ptr1, len1);
220
+ if (ret[2]) {
221
+ throw takeFromExternrefTable0(ret[1]);
222
+ }
223
+ return ret[0];
224
+ }
225
+ export function __wbg_Error_8c4e43fe74559d73(arg0, arg1) {
226
+ const ret = Error(getStringFromWasm0(arg0, arg1));
227
+ return ret;
228
+ }
229
+ export function __wbg___wbindgen_boolean_get_bbbb1c18aa2f5e25(arg0) {
230
+ const v = arg0;
231
+ const ret = typeof(v) === 'boolean' ? v : undefined;
232
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
233
+ }
234
+ export function __wbg___wbindgen_debug_string_0bc8482c6e3508ae(arg0, arg1) {
235
+ const ret = debugString(arg1);
236
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
237
+ const len1 = WASM_VECTOR_LEN;
238
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
239
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
240
+ }
241
+ export function __wbg___wbindgen_is_function_0095a73b8b156f76(arg0) {
242
+ const ret = typeof(arg0) === 'function';
243
+ return ret;
244
+ }
245
+ export function __wbg___wbindgen_is_null_ac34f5003991759a(arg0) {
246
+ const ret = arg0 === null;
247
+ return ret;
248
+ }
249
+ export function __wbg___wbindgen_is_object_5ae8e5880f2c1fbd(arg0) {
250
+ const val = arg0;
251
+ const ret = typeof(val) === 'object' && val !== null;
252
+ return ret;
253
+ }
254
+ export function __wbg___wbindgen_is_string_cd444516edc5b180(arg0) {
255
+ const ret = typeof(arg0) === 'string';
256
+ return ret;
257
+ }
258
+ export function __wbg___wbindgen_is_undefined_9e4d92534c42d778(arg0) {
259
+ const ret = arg0 === undefined;
260
+ return ret;
261
+ }
262
+ export function __wbg___wbindgen_jsval_loose_eq_9dd77d8cd6671811(arg0, arg1) {
263
+ const ret = arg0 == arg1;
264
+ return ret;
265
+ }
266
+ export function __wbg___wbindgen_number_get_8ff4255516ccad3e(arg0, arg1) {
267
+ const obj = arg1;
268
+ const ret = typeof(obj) === 'number' ? obj : undefined;
269
+ getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
270
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
271
+ }
272
+ export function __wbg___wbindgen_string_get_72fb696202c56729(arg0, arg1) {
273
+ const obj = arg1;
274
+ const ret = typeof(obj) === 'string' ? obj : undefined;
275
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
276
+ var len1 = WASM_VECTOR_LEN;
277
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
278
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
279
+ }
280
+ export function __wbg___wbindgen_throw_be289d5034ed271b(arg0, arg1) {
281
+ throw new Error(getStringFromWasm0(arg0, arg1));
282
+ }
283
+ export function __wbg_call_389efe28435a9388() { return handleError(function (arg0, arg1) {
284
+ const ret = arg0.call(arg1);
285
+ return ret;
286
+ }, arguments); }
287
+ export function __wbg_call_4708e0c13bdc8e95() { return handleError(function (arg0, arg1, arg2) {
288
+ const ret = arg0.call(arg1, arg2);
289
+ return ret;
290
+ }, arguments); }
291
+ export function __wbg_crypto_86f2631e91b51511(arg0) {
292
+ const ret = arg0.crypto;
293
+ return ret;
294
+ }
295
+ export function __wbg_done_57b39ecd9addfe81(arg0) {
296
+ const ret = arg0.done;
297
+ return ret;
298
+ }
299
+ export function __wbg_entries_58c7934c745daac7(arg0) {
300
+ const ret = Object.entries(arg0);
301
+ return ret;
302
+ }
303
+ export function __wbg_getRandomValues_b3f15fcbfabb0f8b() { return handleError(function (arg0, arg1) {
304
+ arg0.getRandomValues(arg1);
305
+ }, arguments); }
306
+ export function __wbg_get_9b94d73e6221f75c(arg0, arg1) {
307
+ const ret = arg0[arg1 >>> 0];
308
+ return ret;
309
+ }
310
+ export function __wbg_get_b3ed3ad4be2bc8ac() { return handleError(function (arg0, arg1) {
311
+ const ret = Reflect.get(arg0, arg1);
312
+ return ret;
313
+ }, arguments); }
314
+ export function __wbg_instanceof_ArrayBuffer_c367199e2fa2aa04(arg0) {
315
+ let result;
316
+ try {
317
+ result = arg0 instanceof ArrayBuffer;
318
+ } catch (_) {
319
+ result = false;
320
+ }
321
+ const ret = result;
322
+ return ret;
323
+ }
324
+ export function __wbg_instanceof_Uint8Array_9b9075935c74707c(arg0) {
325
+ let result;
326
+ try {
327
+ result = arg0 instanceof Uint8Array;
328
+ } catch (_) {
329
+ result = false;
330
+ }
331
+ const ret = result;
332
+ return ret;
333
+ }
334
+ export function __wbg_iterator_6ff6560ca1568e55() {
335
+ const ret = Symbol.iterator;
336
+ return ret;
337
+ }
338
+ export function __wbg_length_32ed9a279acd054c(arg0) {
339
+ const ret = arg0.length;
340
+ return ret;
341
+ }
342
+ export function __wbg_length_35a7bace40f36eac(arg0) {
343
+ const ret = arg0.length;
344
+ return ret;
345
+ }
346
+ export function __wbg_length_9a7876c9728a0979(arg0) {
347
+ const ret = arg0.length;
348
+ return ret;
349
+ }
350
+ export function __wbg_msCrypto_d562bbe83e0d4b91(arg0) {
351
+ const ret = arg0.msCrypto;
352
+ return ret;
353
+ }
354
+ export function __wbg_new_361308b2356cecd0() {
355
+ const ret = new Object();
356
+ return ret;
357
+ }
358
+ export function __wbg_new_3eb36ae241fe6f44() {
359
+ const ret = new Array();
360
+ return ret;
361
+ }
362
+ export function __wbg_new_dd2b680c8bf6ae29(arg0) {
363
+ const ret = new Uint8Array(arg0);
364
+ return ret;
365
+ }
366
+ export function __wbg_new_no_args_1c7c842f08d00ebb(arg0, arg1) {
367
+ const ret = new Function(getStringFromWasm0(arg0, arg1));
368
+ return ret;
369
+ }
370
+ export function __wbg_new_with_length_63f2683cc2521026(arg0) {
371
+ const ret = new Float32Array(arg0 >>> 0);
372
+ return ret;
373
+ }
374
+ export function __wbg_new_with_length_a2c39cbe88fd8ff1(arg0) {
375
+ const ret = new Uint8Array(arg0 >>> 0);
376
+ return ret;
377
+ }
378
+ export function __wbg_next_3482f54c49e8af19() { return handleError(function (arg0) {
379
+ const ret = arg0.next();
380
+ return ret;
381
+ }, arguments); }
382
+ export function __wbg_next_418f80d8f5303233(arg0) {
383
+ const ret = arg0.next;
384
+ return ret;
385
+ }
386
+ export function __wbg_node_e1f24f89a7336c2e(arg0) {
387
+ const ret = arg0.node;
388
+ return ret;
389
+ }
390
+ export function __wbg_process_3975fd6c72f520aa(arg0) {
391
+ const ret = arg0.process;
392
+ return ret;
393
+ }
394
+ export function __wbg_prototypesetcall_bdcdcc5842e4d77d(arg0, arg1, arg2) {
395
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
396
+ }
397
+ export function __wbg_push_8ffdcb2063340ba5(arg0, arg1) {
398
+ const ret = arg0.push(arg1);
399
+ return ret;
400
+ }
401
+ export function __wbg_randomFillSync_f8c153b79f285817() { return handleError(function (arg0, arg1) {
402
+ arg0.randomFillSync(arg1);
403
+ }, arguments); }
404
+ export function __wbg_require_b74f47fc2d022fd6() { return handleError(function () {
405
+ const ret = module.require;
406
+ return ret;
407
+ }, arguments); }
408
+ export function __wbg_set_6cb8631f80447a67() { return handleError(function (arg0, arg1, arg2) {
409
+ const ret = Reflect.set(arg0, arg1, arg2);
410
+ return ret;
411
+ }, arguments); }
412
+ export function __wbg_set_f8edeec46569cc70(arg0, arg1, arg2) {
413
+ arg0.set(getArrayF32FromWasm0(arg1, arg2));
414
+ }
415
+ export function __wbg_static_accessor_GLOBAL_12837167ad935116() {
416
+ const ret = typeof global === 'undefined' ? null : global;
417
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
418
+ }
419
+ export function __wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f() {
420
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
421
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
422
+ }
423
+ export function __wbg_static_accessor_SELF_a621d3dfbb60d0ce() {
424
+ const ret = typeof self === 'undefined' ? null : self;
425
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
426
+ }
427
+ export function __wbg_static_accessor_WINDOW_f8727f0cf888e0bd() {
428
+ const ret = typeof window === 'undefined' ? null : window;
429
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
430
+ }
431
+ export function __wbg_subarray_a96e1fef17ed23cb(arg0, arg1, arg2) {
432
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
433
+ return ret;
434
+ }
435
+ export function __wbg_value_0546255b415e96c1(arg0) {
436
+ const ret = arg0.value;
437
+ return ret;
438
+ }
439
+ export function __wbg_versions_4e31226f5e8dc909(arg0) {
440
+ const ret = arg0.versions;
441
+ return ret;
442
+ }
443
+ export function __wbindgen_cast_0000000000000001(arg0) {
444
+ // Cast intrinsic for `F64 -> Externref`.
445
+ const ret = arg0;
446
+ return ret;
447
+ }
448
+ export function __wbindgen_cast_0000000000000002(arg0, arg1) {
449
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
450
+ const ret = getArrayU8FromWasm0(arg0, arg1);
451
+ return ret;
452
+ }
453
+ export function __wbindgen_cast_0000000000000003(arg0, arg1) {
454
+ // Cast intrinsic for `Ref(String) -> Externref`.
455
+ const ret = getStringFromWasm0(arg0, arg1);
456
+ return ret;
457
+ }
458
+ export function __wbindgen_init_externref_table() {
459
+ const table = wasm.__wbindgen_externrefs;
460
+ const offset = table.grow(4);
461
+ table.set(0, undefined);
462
+ table.set(offset + 0, undefined);
463
+ table.set(offset + 1, null);
464
+ table.set(offset + 2, true);
465
+ table.set(offset + 3, false);
466
+ }
467
+ const VectorDBFinalization = (typeof FinalizationRegistry === 'undefined')
468
+ ? { register: () => {}, unregister: () => {} }
469
+ : new FinalizationRegistry(ptr => wasm.__wbg_vectordb_free(ptr >>> 0, 1));
470
+
471
+ function addToExternrefTable0(obj) {
472
+ const idx = wasm.__externref_table_alloc();
473
+ wasm.__wbindgen_externrefs.set(idx, obj);
474
+ return idx;
475
+ }
476
+
477
+ function debugString(val) {
478
+ // primitive types
479
+ const type = typeof val;
480
+ if (type == 'number' || type == 'boolean' || val == null) {
481
+ return `${val}`;
482
+ }
483
+ if (type == 'string') {
484
+ return `"${val}"`;
485
+ }
486
+ if (type == 'symbol') {
487
+ const description = val.description;
488
+ if (description == null) {
489
+ return 'Symbol';
490
+ } else {
491
+ return `Symbol(${description})`;
492
+ }
493
+ }
494
+ if (type == 'function') {
495
+ const name = val.name;
496
+ if (typeof name == 'string' && name.length > 0) {
497
+ return `Function(${name})`;
498
+ } else {
499
+ return 'Function';
500
+ }
501
+ }
502
+ // objects
503
+ if (Array.isArray(val)) {
504
+ const length = val.length;
505
+ let debug = '[';
506
+ if (length > 0) {
507
+ debug += debugString(val[0]);
508
+ }
509
+ for(let i = 1; i < length; i++) {
510
+ debug += ', ' + debugString(val[i]);
511
+ }
512
+ debug += ']';
513
+ return debug;
514
+ }
515
+ // Test for built-in
516
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
517
+ let className;
518
+ if (builtInMatches && builtInMatches.length > 1) {
519
+ className = builtInMatches[1];
520
+ } else {
521
+ // Failed to match the standard '[object ClassName]'
522
+ return toString.call(val);
523
+ }
524
+ if (className == 'Object') {
525
+ // we're a user defined class or Object
526
+ // JSON.stringify avoids problems with cycles, and is generally much
527
+ // easier than looping through ownProperties of `val`.
528
+ try {
529
+ return 'Object(' + JSON.stringify(val) + ')';
530
+ } catch (_) {
531
+ return 'Object';
532
+ }
533
+ }
534
+ // errors
535
+ if (val instanceof Error) {
536
+ return `${val.name}: ${val.message}\n${val.stack}`;
537
+ }
538
+ // TODO we could test for more things here, like `Set`s and `Map`s.
539
+ return className;
540
+ }
541
+
542
+ function getArrayF32FromWasm0(ptr, len) {
543
+ ptr = ptr >>> 0;
544
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
545
+ }
546
+
547
+ function getArrayU8FromWasm0(ptr, len) {
548
+ ptr = ptr >>> 0;
549
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
550
+ }
551
+
552
+ let cachedDataViewMemory0 = null;
553
+ function getDataViewMemory0() {
554
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
555
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
556
+ }
557
+ return cachedDataViewMemory0;
558
+ }
559
+
560
+ let cachedFloat32ArrayMemory0 = null;
561
+ function getFloat32ArrayMemory0() {
562
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
563
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
564
+ }
565
+ return cachedFloat32ArrayMemory0;
566
+ }
567
+
568
+ function getStringFromWasm0(ptr, len) {
569
+ ptr = ptr >>> 0;
570
+ return decodeText(ptr, len);
571
+ }
572
+
573
+ let cachedUint8ArrayMemory0 = null;
574
+ function getUint8ArrayMemory0() {
575
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
576
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
577
+ }
578
+ return cachedUint8ArrayMemory0;
579
+ }
580
+
581
+ function handleError(f, args) {
582
+ try {
583
+ return f.apply(this, args);
584
+ } catch (e) {
585
+ const idx = addToExternrefTable0(e);
586
+ wasm.__wbindgen_exn_store(idx);
587
+ }
588
+ }
589
+
590
+ function isLikeNone(x) {
591
+ return x === undefined || x === null;
592
+ }
593
+
594
+ function passArrayF32ToWasm0(arg, malloc) {
595
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
596
+ getFloat32ArrayMemory0().set(arg, ptr / 4);
597
+ WASM_VECTOR_LEN = arg.length;
598
+ return ptr;
599
+ }
600
+
601
+ function passArrayJsValueToWasm0(array, malloc) {
602
+ const ptr = malloc(array.length * 4, 4) >>> 0;
603
+ for (let i = 0; i < array.length; i++) {
604
+ const add = addToExternrefTable0(array[i]);
605
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
606
+ }
607
+ WASM_VECTOR_LEN = array.length;
608
+ return ptr;
609
+ }
610
+
611
+ function passStringToWasm0(arg, malloc, realloc) {
612
+ if (realloc === undefined) {
613
+ const buf = cachedTextEncoder.encode(arg);
614
+ const ptr = malloc(buf.length, 1) >>> 0;
615
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
616
+ WASM_VECTOR_LEN = buf.length;
617
+ return ptr;
618
+ }
619
+
620
+ let len = arg.length;
621
+ let ptr = malloc(len, 1) >>> 0;
622
+
623
+ const mem = getUint8ArrayMemory0();
624
+
625
+ let offset = 0;
626
+
627
+ for (; offset < len; offset++) {
628
+ const code = arg.charCodeAt(offset);
629
+ if (code > 0x7F) break;
630
+ mem[ptr + offset] = code;
631
+ }
632
+ if (offset !== len) {
633
+ if (offset !== 0) {
634
+ arg = arg.slice(offset);
635
+ }
636
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
637
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
638
+ const ret = cachedTextEncoder.encodeInto(arg, view);
639
+
640
+ offset += ret.written;
641
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
642
+ }
643
+
644
+ WASM_VECTOR_LEN = offset;
645
+ return ptr;
646
+ }
647
+
648
+ function takeFromExternrefTable0(idx) {
649
+ const value = wasm.__wbindgen_externrefs.get(idx);
650
+ wasm.__externref_table_dealloc(idx);
651
+ return value;
652
+ }
653
+
654
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
655
+ cachedTextDecoder.decode();
656
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
657
+ let numBytesDecoded = 0;
658
+ function decodeText(ptr, len) {
659
+ numBytesDecoded += len;
660
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
661
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
662
+ cachedTextDecoder.decode();
663
+ numBytesDecoded = len;
664
+ }
665
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
666
+ }
667
+
668
+ const cachedTextEncoder = new TextEncoder();
669
+
670
+ if (!('encodeInto' in cachedTextEncoder)) {
671
+ cachedTextEncoder.encodeInto = function (arg, view) {
672
+ const buf = cachedTextEncoder.encode(arg);
673
+ view.set(buf);
674
+ return {
675
+ read: arg.length,
676
+ written: buf.length
677
+ };
678
+ };
679
+ }
680
+
681
+ let WASM_VECTOR_LEN = 0;
682
+
683
+
684
+ let wasm;
685
+ export function __wbg_set_wasm(val) {
686
+ wasm = val;
687
+ }
Binary file
@@ -0,0 +1,26 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_vectordb_free: (a: number, b: number) => void;
5
+ export const cosine_similarity: (a: number, b: number, c: number, d: number) => [number, number, number];
6
+ export const dot_product: (a: number, b: number, c: number, d: number) => [number, number, number];
7
+ export const euclidean_distance: (a: number, b: number, c: number, d: number) => [number, number, number];
8
+ export const vectordb_delete: (a: number, b: number, c: number) => number;
9
+ export const vectordb_delete_batch: (a: number, b: number, c: number) => number;
10
+ export const vectordb_deserialize: (a: number, b: number) => [number, number, number];
11
+ export const vectordb_get: (a: number, b: number, c: number) => [number, number, number];
12
+ export const vectordb_has: (a: number, b: number, c: number) => number;
13
+ export const vectordb_insert: (a: number, b: number, c: number, d: number, e: number, f: any) => [number, number];
14
+ export const vectordb_list_ids: (a: number) => [number, number, number];
15
+ export const vectordb_new: (a: number, b: number, c: number, d: number, e: number) => number;
16
+ export const vectordb_search: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
17
+ export const vectordb_serialize: (a: number) => [number, number, number, number];
18
+ export const vectordb_size: (a: number) => number;
19
+ export const __wbindgen_malloc: (a: number, b: number) => number;
20
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
21
+ export const __wbindgen_exn_store: (a: number) => void;
22
+ export const __externref_table_alloc: () => number;
23
+ export const __wbindgen_externrefs: WebAssembly.Table;
24
+ export const __externref_table_dealloc: (a: number) => void;
25
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
26
+ export const __wbindgen_start: () => void;