@wiscale/velesdb-wasm 1.1.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/velesdb_wasm.js CHANGED
@@ -9,6 +9,12 @@ function addHeapObject(obj) {
9
9
  return idx;
10
10
  }
11
11
 
12
+ function _assertClass(instance, klass) {
13
+ if (!(instance instanceof klass)) {
14
+ throw new Error(`expected instance of ${klass.name}`);
15
+ }
16
+ }
17
+
12
18
  const CLOSURE_DTORS = (typeof FinalizationRegistry === 'undefined')
13
19
  ? { register: () => {}, unregister: () => {} }
14
20
  : new FinalizationRegistry(state => state.dtor(state.a, state.b));
@@ -84,11 +90,34 @@ function dropObject(idx) {
84
90
  heap_next = idx;
85
91
  }
86
92
 
93
+ function getArrayJsValueFromWasm0(ptr, len) {
94
+ ptr = ptr >>> 0;
95
+ const mem = getDataViewMemory0();
96
+ const result = [];
97
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
98
+ result.push(takeObject(mem.getUint32(i, true)));
99
+ }
100
+ return result;
101
+ }
102
+
103
+ function getArrayU64FromWasm0(ptr, len) {
104
+ ptr = ptr >>> 0;
105
+ return getBigUint64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
106
+ }
107
+
87
108
  function getArrayU8FromWasm0(ptr, len) {
88
109
  ptr = ptr >>> 0;
89
110
  return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
90
111
  }
91
112
 
113
+ let cachedBigUint64ArrayMemory0 = null;
114
+ function getBigUint64ArrayMemory0() {
115
+ if (cachedBigUint64ArrayMemory0 === null || cachedBigUint64ArrayMemory0.byteLength === 0) {
116
+ cachedBigUint64ArrayMemory0 = new BigUint64Array(wasm.memory.buffer);
117
+ }
118
+ return cachedBigUint64ArrayMemory0;
119
+ }
120
+
92
121
  let cachedDataViewMemory0 = null;
93
122
  function getDataViewMemory0() {
94
123
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
@@ -187,87 +216,756 @@ function passStringToWasm0(arg, malloc, realloc) {
187
216
  WASM_VECTOR_LEN = buf.length;
188
217
  return ptr;
189
218
  }
190
-
191
- let len = arg.length;
192
- let ptr = malloc(len, 1) >>> 0;
193
-
194
- const mem = getUint8ArrayMemory0();
195
-
196
- let offset = 0;
197
-
198
- for (; offset < len; offset++) {
199
- const code = arg.charCodeAt(offset);
200
- if (code > 0x7F) break;
201
- mem[ptr + offset] = code;
219
+
220
+ let len = arg.length;
221
+ let ptr = malloc(len, 1) >>> 0;
222
+
223
+ const mem = getUint8ArrayMemory0();
224
+
225
+ let offset = 0;
226
+
227
+ for (; offset < len; offset++) {
228
+ const code = arg.charCodeAt(offset);
229
+ if (code > 0x7F) break;
230
+ mem[ptr + offset] = code;
231
+ }
232
+ if (offset !== len) {
233
+ if (offset !== 0) {
234
+ arg = arg.slice(offset);
235
+ }
236
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
237
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
238
+ const ret = cachedTextEncoder.encodeInto(arg, view);
239
+
240
+ offset += ret.written;
241
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
242
+ }
243
+
244
+ WASM_VECTOR_LEN = offset;
245
+ return ptr;
246
+ }
247
+
248
+ function takeObject(idx) {
249
+ const ret = getObject(idx);
250
+ dropObject(idx);
251
+ return ret;
252
+ }
253
+
254
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
255
+ cachedTextDecoder.decode();
256
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
257
+ let numBytesDecoded = 0;
258
+ function decodeText(ptr, len) {
259
+ numBytesDecoded += len;
260
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
261
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
262
+ cachedTextDecoder.decode();
263
+ numBytesDecoded = len;
264
+ }
265
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
266
+ }
267
+
268
+ const cachedTextEncoder = new TextEncoder();
269
+
270
+ if (!('encodeInto' in cachedTextEncoder)) {
271
+ cachedTextEncoder.encodeInto = function (arg, view) {
272
+ const buf = cachedTextEncoder.encode(arg);
273
+ view.set(buf);
274
+ return {
275
+ read: arg.length,
276
+ written: buf.length
277
+ };
278
+ }
279
+ }
280
+
281
+ let WASM_VECTOR_LEN = 0;
282
+
283
+ function __wasm_bindgen_func_elem_198(arg0, arg1, arg2) {
284
+ wasm.__wasm_bindgen_func_elem_198(arg0, arg1, addHeapObject(arg2));
285
+ }
286
+
287
+ function __wasm_bindgen_func_elem_640(arg0, arg1, arg2) {
288
+ wasm.__wasm_bindgen_func_elem_640(arg0, arg1, addHeapObject(arg2));
289
+ }
290
+
291
+ function __wasm_bindgen_func_elem_689(arg0, arg1, arg2, arg3) {
292
+ wasm.__wasm_bindgen_func_elem_689(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
293
+ }
294
+
295
+ const __wbindgen_enum_IdbTransactionMode = ["readonly", "readwrite", "versionchange", "readwriteflush", "cleanup"];
296
+
297
+ const GraphEdgeFinalization = (typeof FinalizationRegistry === 'undefined')
298
+ ? { register: () => {}, unregister: () => {} }
299
+ : new FinalizationRegistry(ptr => wasm.__wbg_graphedge_free(ptr >>> 0, 1));
300
+
301
+ const GraphNodeFinalization = (typeof FinalizationRegistry === 'undefined')
302
+ ? { register: () => {}, unregister: () => {} }
303
+ : new FinalizationRegistry(ptr => wasm.__wbg_graphnode_free(ptr >>> 0, 1));
304
+
305
+ const GraphStoreFinalization = (typeof FinalizationRegistry === 'undefined')
306
+ ? { register: () => {}, unregister: () => {} }
307
+ : new FinalizationRegistry(ptr => wasm.__wbg_graphstore_free(ptr >>> 0, 1));
308
+
309
+ const VectorStoreFinalization = (typeof FinalizationRegistry === 'undefined')
310
+ ? { register: () => {}, unregister: () => {} }
311
+ : new FinalizationRegistry(ptr => wasm.__wbg_vectorstore_free(ptr >>> 0, 1));
312
+
313
+ /**
314
+ * A graph edge representing a relationship between nodes.
315
+ */
316
+ export class GraphEdge {
317
+ static __wrap(ptr) {
318
+ ptr = ptr >>> 0;
319
+ const obj = Object.create(GraphEdge.prototype);
320
+ obj.__wbg_ptr = ptr;
321
+ GraphEdgeFinalization.register(obj, obj.__wbg_ptr, obj);
322
+ return obj;
323
+ }
324
+ __destroy_into_raw() {
325
+ const ptr = this.__wbg_ptr;
326
+ this.__wbg_ptr = 0;
327
+ GraphEdgeFinalization.unregister(this);
328
+ return ptr;
329
+ }
330
+ free() {
331
+ const ptr = this.__destroy_into_raw();
332
+ wasm.__wbg_graphedge_free(ptr, 0);
333
+ }
334
+ /**
335
+ * Sets a numeric property on the edge.
336
+ * @param {string} key
337
+ * @param {number} value
338
+ */
339
+ set_number_property(key, value) {
340
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
341
+ const len0 = WASM_VECTOR_LEN;
342
+ wasm.graphedge_set_number_property(this.__wbg_ptr, ptr0, len0, value);
343
+ }
344
+ /**
345
+ * Sets a string property on the edge.
346
+ * @param {string} key
347
+ * @param {string} value
348
+ */
349
+ set_string_property(key, value) {
350
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
351
+ const len0 = WASM_VECTOR_LEN;
352
+ const ptr1 = passStringToWasm0(value, wasm.__wbindgen_export, wasm.__wbindgen_export2);
353
+ const len1 = WASM_VECTOR_LEN;
354
+ wasm.graphedge_set_string_property(this.__wbg_ptr, ptr0, len0, ptr1, len1);
355
+ }
356
+ /**
357
+ * Returns the edge ID.
358
+ * @returns {bigint}
359
+ */
360
+ get id() {
361
+ const ret = wasm.graphedge_id(this.__wbg_ptr);
362
+ return BigInt.asUintN(64, ret);
363
+ }
364
+ /**
365
+ * Creates a new graph edge.
366
+ *
367
+ * # Arguments
368
+ *
369
+ * * `id` - Unique identifier for the edge
370
+ * * `source` - Source node ID
371
+ * * `target` - Target node ID
372
+ * * `label` - Relationship type (e.g., "KNOWS", "WROTE")
373
+ * @param {bigint} id
374
+ * @param {bigint} source
375
+ * @param {bigint} target
376
+ * @param {string} label
377
+ */
378
+ constructor(id, source, target, label) {
379
+ try {
380
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
381
+ const ptr0 = passStringToWasm0(label, wasm.__wbindgen_export, wasm.__wbindgen_export2);
382
+ const len0 = WASM_VECTOR_LEN;
383
+ wasm.graphedge_new(retptr, id, source, target, ptr0, len0);
384
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
385
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
386
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
387
+ if (r2) {
388
+ throw takeObject(r1);
389
+ }
390
+ this.__wbg_ptr = r0 >>> 0;
391
+ GraphEdgeFinalization.register(this, this.__wbg_ptr, this);
392
+ return this;
393
+ } finally {
394
+ wasm.__wbindgen_add_to_stack_pointer(16);
395
+ }
396
+ }
397
+ /**
398
+ * Returns the edge label (relationship type).
399
+ * @returns {string}
400
+ */
401
+ get label() {
402
+ let deferred1_0;
403
+ let deferred1_1;
404
+ try {
405
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
406
+ wasm.graphedge_label(retptr, this.__wbg_ptr);
407
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
408
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
409
+ deferred1_0 = r0;
410
+ deferred1_1 = r1;
411
+ return getStringFromWasm0(r0, r1);
412
+ } finally {
413
+ wasm.__wbindgen_add_to_stack_pointer(16);
414
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
415
+ }
416
+ }
417
+ /**
418
+ * Returns the source node ID.
419
+ * @returns {bigint}
420
+ */
421
+ get source() {
422
+ const ret = wasm.graphedge_source(this.__wbg_ptr);
423
+ return BigInt.asUintN(64, ret);
424
+ }
425
+ /**
426
+ * Returns the target node ID.
427
+ * @returns {bigint}
428
+ */
429
+ get target() {
430
+ const ret = wasm.graphedge_target(this.__wbg_ptr);
431
+ return BigInt.asUintN(64, ret);
432
+ }
433
+ /**
434
+ * Converts to JSON for JavaScript interop.
435
+ * @returns {any}
436
+ */
437
+ to_json() {
438
+ try {
439
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
440
+ wasm.graphedge_to_json(retptr, this.__wbg_ptr);
441
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
442
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
443
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
444
+ if (r2) {
445
+ throw takeObject(r1);
446
+ }
447
+ return takeObject(r0);
448
+ } finally {
449
+ wasm.__wbindgen_add_to_stack_pointer(16);
450
+ }
451
+ }
452
+ }
453
+ if (Symbol.dispose) GraphEdge.prototype[Symbol.dispose] = GraphEdge.prototype.free;
454
+
455
+ /**
456
+ * A graph node for knowledge graph construction.
457
+ */
458
+ export class GraphNode {
459
+ static __wrap(ptr) {
460
+ ptr = ptr >>> 0;
461
+ const obj = Object.create(GraphNode.prototype);
462
+ obj.__wbg_ptr = ptr;
463
+ GraphNodeFinalization.register(obj, obj.__wbg_ptr, obj);
464
+ return obj;
465
+ }
466
+ __destroy_into_raw() {
467
+ const ptr = this.__wbg_ptr;
468
+ this.__wbg_ptr = 0;
469
+ GraphNodeFinalization.unregister(this);
470
+ return ptr;
471
+ }
472
+ free() {
473
+ const ptr = this.__destroy_into_raw();
474
+ wasm.__wbg_graphnode_free(ptr, 0);
475
+ }
476
+ /**
477
+ * Returns true if this node has a vector embedding.
478
+ * @returns {boolean}
479
+ */
480
+ has_vector() {
481
+ const ret = wasm.graphnode_has_vector(this.__wbg_ptr);
482
+ return ret !== 0;
483
+ }
484
+ /**
485
+ * Sets a vector embedding on the node.
486
+ * @param {Float32Array} vector
487
+ */
488
+ set_vector(vector) {
489
+ const ptr0 = passArrayF32ToWasm0(vector, wasm.__wbindgen_export);
490
+ const len0 = WASM_VECTOR_LEN;
491
+ wasm.graphnode_set_vector(this.__wbg_ptr, ptr0, len0);
492
+ }
493
+ /**
494
+ * Sets a boolean property on the node.
495
+ * @param {string} key
496
+ * @param {boolean} value
497
+ */
498
+ set_bool_property(key, value) {
499
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
500
+ const len0 = WASM_VECTOR_LEN;
501
+ wasm.graphnode_set_bool_property(this.__wbg_ptr, ptr0, len0, value);
502
+ }
503
+ /**
504
+ * Sets a numeric property on the node.
505
+ * @param {string} key
506
+ * @param {number} value
507
+ */
508
+ set_number_property(key, value) {
509
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
510
+ const len0 = WASM_VECTOR_LEN;
511
+ wasm.graphnode_set_number_property(this.__wbg_ptr, ptr0, len0, value);
512
+ }
513
+ /**
514
+ * Sets a string property on the node.
515
+ * @param {string} key
516
+ * @param {string} value
517
+ */
518
+ set_string_property(key, value) {
519
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_export, wasm.__wbindgen_export2);
520
+ const len0 = WASM_VECTOR_LEN;
521
+ const ptr1 = passStringToWasm0(value, wasm.__wbindgen_export, wasm.__wbindgen_export2);
522
+ const len1 = WASM_VECTOR_LEN;
523
+ wasm.graphnode_set_string_property(this.__wbg_ptr, ptr0, len0, ptr1, len1);
524
+ }
525
+ /**
526
+ * Returns the node ID.
527
+ * @returns {bigint}
528
+ */
529
+ get id() {
530
+ const ret = wasm.graphedge_id(this.__wbg_ptr);
531
+ return BigInt.asUintN(64, ret);
532
+ }
533
+ /**
534
+ * Creates a new graph node.
535
+ *
536
+ * # Arguments
537
+ *
538
+ * * `id` - Unique identifier for the node
539
+ * * `label` - Node type/label (e.g., "Person", "Document")
540
+ * @param {bigint} id
541
+ * @param {string} label
542
+ */
543
+ constructor(id, label) {
544
+ const ptr0 = passStringToWasm0(label, wasm.__wbindgen_export, wasm.__wbindgen_export2);
545
+ const len0 = WASM_VECTOR_LEN;
546
+ const ret = wasm.graphnode_new(id, ptr0, len0);
547
+ this.__wbg_ptr = ret >>> 0;
548
+ GraphNodeFinalization.register(this, this.__wbg_ptr, this);
549
+ return this;
550
+ }
551
+ /**
552
+ * Returns the node label.
553
+ * @returns {string}
554
+ */
555
+ get label() {
556
+ let deferred1_0;
557
+ let deferred1_1;
558
+ try {
559
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
560
+ wasm.graphnode_label(retptr, this.__wbg_ptr);
561
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
562
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
563
+ deferred1_0 = r0;
564
+ deferred1_1 = r1;
565
+ return getStringFromWasm0(r0, r1);
566
+ } finally {
567
+ wasm.__wbindgen_add_to_stack_pointer(16);
568
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
569
+ }
570
+ }
571
+ /**
572
+ * Converts to JSON for JavaScript interop.
573
+ * @returns {any}
574
+ */
575
+ to_json() {
576
+ try {
577
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
578
+ wasm.graphnode_to_json(retptr, this.__wbg_ptr);
579
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
580
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
581
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
582
+ if (r2) {
583
+ throw takeObject(r1);
584
+ }
585
+ return takeObject(r0);
586
+ } finally {
587
+ wasm.__wbindgen_add_to_stack_pointer(16);
588
+ }
589
+ }
590
+ }
591
+ if (Symbol.dispose) GraphNode.prototype[Symbol.dispose] = GraphNode.prototype.free;
592
+
593
+ /**
594
+ * In-memory graph store for browser-based knowledge graphs.
595
+ *
596
+ * Stores nodes and edges with bidirectional indexing for efficient traversal.
597
+ */
598
+ export class GraphStore {
599
+ __destroy_into_raw() {
600
+ const ptr = this.__wbg_ptr;
601
+ this.__wbg_ptr = 0;
602
+ GraphStoreFinalization.unregister(this);
603
+ return ptr;
604
+ }
605
+ free() {
606
+ const ptr = this.__destroy_into_raw();
607
+ wasm.__wbg_graphstore_free(ptr, 0);
608
+ }
609
+ /**
610
+ * Returns the number of edges.
611
+ * @returns {number}
612
+ */
613
+ get edge_count() {
614
+ const ret = wasm.graphstore_edge_count(this.__wbg_ptr);
615
+ return ret >>> 0;
616
+ }
617
+ /**
618
+ * Returns the number of nodes.
619
+ * @returns {number}
620
+ */
621
+ get node_count() {
622
+ const ret = wasm.graphstore_node_count(this.__wbg_ptr);
623
+ return ret >>> 0;
624
+ }
625
+ /**
626
+ * Gets the degree (number of outgoing edges) of a node.
627
+ * @param {bigint} node_id
628
+ * @returns {number}
629
+ */
630
+ out_degree(node_id) {
631
+ const ret = wasm.graphstore_out_degree(this.__wbg_ptr, node_id);
632
+ return ret >>> 0;
633
+ }
634
+ /**
635
+ * Removes an edge by ID.
636
+ * @param {bigint} edge_id
637
+ */
638
+ remove_edge(edge_id) {
639
+ wasm.graphstore_remove_edge(this.__wbg_ptr, edge_id);
640
+ }
641
+ /**
642
+ * Removes a node and all connected edges.
643
+ * @param {bigint} node_id
644
+ */
645
+ remove_node(node_id) {
646
+ wasm.graphstore_remove_node(this.__wbg_ptr, node_id);
647
+ }
648
+ /**
649
+ * Performs BFS traversal from a source node.
650
+ *
651
+ * # Arguments
652
+ *
653
+ * * `source_id` - Starting node ID
654
+ * * `max_depth` - Maximum traversal depth
655
+ * * `limit` - Maximum number of results
656
+ *
657
+ * # Returns
658
+ *
659
+ * Array of reachable node IDs with their depths.
660
+ * @param {bigint} source_id
661
+ * @param {number} max_depth
662
+ * @param {number} limit
663
+ * @returns {any}
664
+ */
665
+ bfs_traverse(source_id, max_depth, limit) {
666
+ try {
667
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
668
+ wasm.graphstore_bfs_traverse(retptr, this.__wbg_ptr, source_id, max_depth, limit);
669
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
670
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
671
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
672
+ if (r2) {
673
+ throw takeObject(r1);
674
+ }
675
+ return takeObject(r0);
676
+ } finally {
677
+ wasm.__wbindgen_add_to_stack_pointer(16);
678
+ }
679
+ }
680
+ /**
681
+ * Performs DFS traversal from a source node.
682
+ *
683
+ * # Arguments
684
+ *
685
+ * * `source_id` - Starting node ID
686
+ * * `max_depth` - Maximum traversal depth
687
+ * * `limit` - Maximum number of results
688
+ *
689
+ * # Returns
690
+ *
691
+ * Array of reachable node IDs with their depths (depth-first order).
692
+ * @param {bigint} source_id
693
+ * @param {number} max_depth
694
+ * @param {number} limit
695
+ * @returns {any}
696
+ */
697
+ dfs_traverse(source_id, max_depth, limit) {
698
+ try {
699
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
700
+ wasm.graphstore_dfs_traverse(retptr, this.__wbg_ptr, source_id, max_depth, limit);
701
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
702
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
703
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
704
+ if (r2) {
705
+ throw takeObject(r1);
706
+ }
707
+ return takeObject(r0);
708
+ } finally {
709
+ wasm.__wbindgen_add_to_stack_pointer(16);
710
+ }
711
+ }
712
+ /**
713
+ * Gets incoming edges to a node.
714
+ * @param {bigint} node_id
715
+ * @returns {GraphEdge[]}
716
+ */
717
+ get_incoming(node_id) {
718
+ try {
719
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
720
+ wasm.graphstore_get_incoming(retptr, this.__wbg_ptr, node_id);
721
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
722
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
723
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
724
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
725
+ return v1;
726
+ } finally {
727
+ wasm.__wbindgen_add_to_stack_pointer(16);
728
+ }
729
+ }
730
+ /**
731
+ * Gets outgoing edges from a node.
732
+ * @param {bigint} node_id
733
+ * @returns {GraphEdge[]}
734
+ */
735
+ get_outgoing(node_id) {
736
+ try {
737
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
738
+ wasm.graphstore_get_outgoing(retptr, this.__wbg_ptr, node_id);
739
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
740
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
741
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
742
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
743
+ return v1;
744
+ } finally {
745
+ wasm.__wbindgen_add_to_stack_pointer(16);
746
+ }
747
+ }
748
+ /**
749
+ * Gets neighbors reachable from a node (1-hop).
750
+ * @param {bigint} node_id
751
+ * @returns {BigUint64Array}
752
+ */
753
+ get_neighbors(node_id) {
754
+ try {
755
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
756
+ wasm.graphstore_get_neighbors(retptr, this.__wbg_ptr, node_id);
757
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
758
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
759
+ var v1 = getArrayU64FromWasm0(r0, r1).slice();
760
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
761
+ return v1;
762
+ } finally {
763
+ wasm.__wbindgen_add_to_stack_pointer(16);
764
+ }
765
+ }
766
+ /**
767
+ * Gets all edge IDs in the graph.
768
+ * @returns {BigUint64Array}
769
+ */
770
+ get_all_edge_ids() {
771
+ try {
772
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
773
+ wasm.graphstore_get_all_edge_ids(retptr, this.__wbg_ptr);
774
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
775
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
776
+ var v1 = getArrayU64FromWasm0(r0, r1).slice();
777
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
778
+ return v1;
779
+ } finally {
780
+ wasm.__wbindgen_add_to_stack_pointer(16);
781
+ }
782
+ }
783
+ /**
784
+ * Gets all node IDs in the graph.
785
+ * @returns {BigUint64Array}
786
+ */
787
+ get_all_node_ids() {
788
+ try {
789
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
790
+ wasm.graphstore_get_all_node_ids(retptr, this.__wbg_ptr);
791
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
792
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
793
+ var v1 = getArrayU64FromWasm0(r0, r1).slice();
794
+ wasm.__wbindgen_export4(r0, r1 * 8, 8);
795
+ return v1;
796
+ } finally {
797
+ wasm.__wbindgen_add_to_stack_pointer(16);
798
+ }
799
+ }
800
+ /**
801
+ * Gets all edges with a specific label.
802
+ *
803
+ * # Arguments
804
+ *
805
+ * * `label` - The relationship type to filter by
806
+ *
807
+ * # Returns
808
+ *
809
+ * Array of edges matching the label.
810
+ * @param {string} label
811
+ * @returns {GraphEdge[]}
812
+ */
813
+ get_edges_by_label(label) {
814
+ try {
815
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
816
+ const ptr0 = passStringToWasm0(label, wasm.__wbindgen_export, wasm.__wbindgen_export2);
817
+ const len0 = WASM_VECTOR_LEN;
818
+ wasm.graphstore_get_edges_by_label(retptr, this.__wbg_ptr, ptr0, len0);
819
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
820
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
821
+ var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
822
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
823
+ return v2;
824
+ } finally {
825
+ wasm.__wbindgen_add_to_stack_pointer(16);
826
+ }
827
+ }
828
+ /**
829
+ * Gets all nodes with a specific label.
830
+ *
831
+ * # Arguments
832
+ *
833
+ * * `label` - The label to filter by
834
+ *
835
+ * # Returns
836
+ *
837
+ * Array of nodes matching the label.
838
+ * @param {string} label
839
+ * @returns {GraphNode[]}
840
+ */
841
+ get_nodes_by_label(label) {
842
+ try {
843
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
844
+ const ptr0 = passStringToWasm0(label, wasm.__wbindgen_export, wasm.__wbindgen_export2);
845
+ const len0 = WASM_VECTOR_LEN;
846
+ wasm.graphstore_get_nodes_by_label(retptr, this.__wbg_ptr, ptr0, len0);
847
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
848
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
849
+ var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
850
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
851
+ return v2;
852
+ } finally {
853
+ wasm.__wbindgen_add_to_stack_pointer(16);
854
+ }
855
+ }
856
+ /**
857
+ * Gets outgoing edges filtered by label.
858
+ * @param {bigint} node_id
859
+ * @param {string} label
860
+ * @returns {GraphEdge[]}
861
+ */
862
+ get_outgoing_by_label(node_id, label) {
863
+ try {
864
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
865
+ const ptr0 = passStringToWasm0(label, wasm.__wbindgen_export, wasm.__wbindgen_export2);
866
+ const len0 = WASM_VECTOR_LEN;
867
+ wasm.graphstore_get_outgoing_by_label(retptr, this.__wbg_ptr, node_id, ptr0, len0);
868
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
869
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
870
+ var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
871
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
872
+ return v2;
873
+ } finally {
874
+ wasm.__wbindgen_add_to_stack_pointer(16);
875
+ }
876
+ }
877
+ /**
878
+ * Creates a new empty graph store.
879
+ */
880
+ constructor() {
881
+ const ret = wasm.graphstore_new();
882
+ this.__wbg_ptr = ret >>> 0;
883
+ GraphStoreFinalization.register(this, this.__wbg_ptr, this);
884
+ return this;
885
+ }
886
+ /**
887
+ * Clears all nodes and edges.
888
+ */
889
+ clear() {
890
+ wasm.graphstore_clear(this.__wbg_ptr);
202
891
  }
203
- if (offset !== len) {
204
- if (offset !== 0) {
205
- arg = arg.slice(offset);
892
+ /**
893
+ * Adds an edge to the graph.
894
+ *
895
+ * Returns an error if an edge with the same ID already exists.
896
+ * @param {GraphEdge} edge
897
+ */
898
+ add_edge(edge) {
899
+ try {
900
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
901
+ _assertClass(edge, GraphEdge);
902
+ var ptr0 = edge.__destroy_into_raw();
903
+ wasm.graphstore_add_edge(retptr, this.__wbg_ptr, ptr0);
904
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
905
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
906
+ if (r1) {
907
+ throw takeObject(r0);
908
+ }
909
+ } finally {
910
+ wasm.__wbindgen_add_to_stack_pointer(16);
206
911
  }
207
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
208
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
209
- const ret = cachedTextEncoder.encodeInto(arg, view);
210
-
211
- offset += ret.written;
212
- ptr = realloc(ptr, len, offset, 1) >>> 0;
213
912
  }
214
-
215
- WASM_VECTOR_LEN = offset;
216
- return ptr;
217
- }
218
-
219
- function takeObject(idx) {
220
- const ret = getObject(idx);
221
- dropObject(idx);
222
- return ret;
223
- }
224
-
225
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
226
- cachedTextDecoder.decode();
227
- const MAX_SAFARI_DECODE_BYTES = 2146435072;
228
- let numBytesDecoded = 0;
229
- function decodeText(ptr, len) {
230
- numBytesDecoded += len;
231
- if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
232
- cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
233
- cachedTextDecoder.decode();
234
- numBytesDecoded = len;
913
+ /**
914
+ * Adds a node to the graph.
915
+ * @param {GraphNode} node
916
+ */
917
+ add_node(node) {
918
+ _assertClass(node, GraphNode);
919
+ var ptr0 = node.__destroy_into_raw();
920
+ wasm.graphstore_add_node(this.__wbg_ptr, ptr0);
235
921
  }
236
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
237
- }
238
-
239
- const cachedTextEncoder = new TextEncoder();
240
-
241
- if (!('encodeInto' in cachedTextEncoder)) {
242
- cachedTextEncoder.encodeInto = function (arg, view) {
243
- const buf = cachedTextEncoder.encode(arg);
244
- view.set(buf);
245
- return {
246
- read: arg.length,
247
- written: buf.length
248
- };
922
+ /**
923
+ * Gets an edge by ID.
924
+ * @param {bigint} id
925
+ * @returns {GraphEdge | undefined}
926
+ */
927
+ get_edge(id) {
928
+ const ret = wasm.graphstore_get_edge(this.__wbg_ptr, id);
929
+ return ret === 0 ? undefined : GraphEdge.__wrap(ret);
930
+ }
931
+ /**
932
+ * Gets a node by ID.
933
+ * @param {bigint} id
934
+ * @returns {GraphNode | undefined}
935
+ */
936
+ get_node(id) {
937
+ const ret = wasm.graphstore_get_node(this.__wbg_ptr, id);
938
+ return ret === 0 ? undefined : GraphNode.__wrap(ret);
939
+ }
940
+ /**
941
+ * Checks if an edge exists.
942
+ * @param {bigint} id
943
+ * @returns {boolean}
944
+ */
945
+ has_edge(id) {
946
+ const ret = wasm.graphstore_has_edge(this.__wbg_ptr, id);
947
+ return ret !== 0;
948
+ }
949
+ /**
950
+ * Checks if a node exists.
951
+ * @param {bigint} id
952
+ * @returns {boolean}
953
+ */
954
+ has_node(id) {
955
+ const ret = wasm.graphstore_has_node(this.__wbg_ptr, id);
956
+ return ret !== 0;
957
+ }
958
+ /**
959
+ * Gets the in-degree (number of incoming edges) of a node.
960
+ * @param {bigint} node_id
961
+ * @returns {number}
962
+ */
963
+ in_degree(node_id) {
964
+ const ret = wasm.graphstore_in_degree(this.__wbg_ptr, node_id);
965
+ return ret >>> 0;
249
966
  }
250
967
  }
251
-
252
- let WASM_VECTOR_LEN = 0;
253
-
254
- function __wasm_bindgen_func_elem_148(arg0, arg1, arg2) {
255
- wasm.__wasm_bindgen_func_elem_148(arg0, arg1, addHeapObject(arg2));
256
- }
257
-
258
- function __wasm_bindgen_func_elem_528(arg0, arg1, arg2) {
259
- wasm.__wasm_bindgen_func_elem_528(arg0, arg1, addHeapObject(arg2));
260
- }
261
-
262
- function __wasm_bindgen_func_elem_577(arg0, arg1, arg2, arg3) {
263
- wasm.__wasm_bindgen_func_elem_577(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
264
- }
265
-
266
- const __wbindgen_enum_IdbTransactionMode = ["readonly", "readwrite", "versionchange", "readwriteflush", "cleanup"];
267
-
268
- const VectorStoreFinalization = (typeof FinalizationRegistry === 'undefined')
269
- ? { register: () => {}, unregister: () => {} }
270
- : new FinalizationRegistry(ptr => wasm.__wbg_vectorstore_free(ptr >>> 0, 1));
968
+ if (Symbol.dispose) GraphStore.prototype[Symbol.dispose] = GraphStore.prototype.free;
271
969
 
272
970
  /**
273
971
  * Storage mode for vector quantization.
@@ -322,20 +1020,7 @@ export class VectorStore {
322
1020
  wasm.__wbg_vectorstore_free(ptr, 0);
323
1021
  }
324
1022
  /**
325
- * Performs text search on payload fields.
326
- *
327
- * This is a simple substring-based search on payload text fields.
328
- * For full BM25 text search, use the REST API backend.
329
- *
330
- * # Arguments
331
- *
332
- * * `query` - Text query to search for
333
- * * `k` - Number of results
334
- * * `field` - Optional field name to search in (default: searches all string fields)
335
- *
336
- * # Returns
337
- *
338
- * Array of results with matching payloads.
1023
+ * Text search on payload fields (substring matching).
339
1024
  * @param {string} query
340
1025
  * @param {number} k
341
1026
  * @param {string | null} [field]
@@ -361,17 +1046,7 @@ export class VectorStore {
361
1046
  }
362
1047
  }
363
1048
  /**
364
- * Batch search for multiple vectors in parallel.
365
- *
366
- * # Arguments
367
- *
368
- * * `vectors` - Flat array of query vectors (concatenated)
369
- * * `num_vectors` - Number of vectors
370
- * * `k` - Results per query
371
- *
372
- * # Returns
373
- *
374
- * Array of arrays of (id, score) tuples.
1049
+ * Batch search for multiple vectors. Returns [[[id, score], ...], ...].
375
1050
  * @param {Float32Array} vectors
376
1051
  * @param {number} num_vectors
377
1052
  * @param {number} k
@@ -395,18 +1070,7 @@ export class VectorStore {
395
1070
  }
396
1071
  }
397
1072
  /**
398
- * Inserts multiple vectors in a single batch operation.
399
- *
400
- * This is significantly faster than calling `insert()` multiple times
401
- * because it pre-allocates memory and reduces per-call overhead.
402
- *
403
- * # Arguments
404
- *
405
- * * `batch` - JavaScript array of `[id, Float32Array]` pairs
406
- *
407
- * # Errors
408
- *
409
- * Returns an error if any vector dimension doesn't match store dimension.
1073
+ * Batch insert. Input: `[[id, Float32Array], ...]`.
410
1074
  * @param {any} batch
411
1075
  */
412
1076
  insert_batch(batch) {
@@ -451,20 +1115,7 @@ export class VectorStore {
451
1115
  }
452
1116
  }
453
1117
  /**
454
- * Performs hybrid search combining vector similarity and text search.
455
- *
456
- * Uses a simple weighted fusion of vector search and text search results.
457
- *
458
- * # Arguments
459
- *
460
- * * `query_vector` - Query vector for similarity search
461
- * * `text_query` - Text query for payload search
462
- * * `k` - Number of results to return
463
- * * `vector_weight` - Weight for vector results (0.0-1.0, default 0.5)
464
- *
465
- * # Returns
466
- *
467
- * Array of fused results with id, score, and payload.
1118
+ * Hybrid search (vector + text). `vector_weight` 0-1 (default 0.5).
468
1119
  * @param {Float32Array} query_vector
469
1120
  * @param {string} text_query
470
1121
  * @param {number} k
@@ -491,23 +1142,7 @@ export class VectorStore {
491
1142
  }
492
1143
  }
493
1144
  /**
494
- * Creates a new vector store with specified storage mode for memory optimization.
495
- *
496
- * # Arguments
497
- *
498
- * * `dimension` - Vector dimension
499
- * * `metric` - Distance metric
500
- * * `mode` - Storage mode: "full", "sq8", or "binary"
501
- *
502
- * # Storage Modes
503
- *
504
- * - `full`: Best recall, 4 bytes/dimension
505
- * - `sq8`: 4x compression, ~1% recall loss
506
- * - `binary`: 32x compression, ~5-10% recall loss
507
- *
508
- * # Errors
509
- *
510
- * Returns an error if the metric or storage mode is unknown.
1145
+ * Creates store with mode: full (4B/dim), sq8 (4x compression), binary (32x).
511
1146
  * @param {number} dimension
512
1147
  * @param {string} metric
513
1148
  * @param {string} mode
@@ -533,20 +1168,7 @@ export class VectorStore {
533
1168
  }
534
1169
  }
535
1170
  /**
536
- * Creates a new vector store with pre-allocated capacity.
537
- *
538
- * This is more efficient when you know the approximate number of vectors
539
- * you'll be inserting, as it avoids repeated memory allocations.
540
- *
541
- * # Arguments
542
- *
543
- * * `dimension` - Vector dimension
544
- * * `metric` - Distance metric: "cosine", "euclidean", or "dot"
545
- * * `capacity` - Number of vectors to pre-allocate space for
546
- *
547
- * # Errors
548
- *
549
- * Returns an error if the metric is not recognized.
1171
+ * Creates store with pre-allocated capacity.
550
1172
  * @param {number} dimension
551
1173
  * @param {string} metric
552
1174
  * @param {number} capacity
@@ -570,17 +1192,7 @@ export class VectorStore {
570
1192
  }
571
1193
  }
572
1194
  /**
573
- * Deletes the `IndexedDB` database.
574
- *
575
- * Use this to clear all persisted data.
576
- *
577
- * # Arguments
578
- *
579
- * * `db_name` - Name of the `IndexedDB` database to delete
580
- *
581
- * # Errors
582
- *
583
- * Returns an error if the deletion fails.
1195
+ * Deletes `IndexedDB` database.
584
1196
  * @param {string} db_name
585
1197
  * @returns {Promise<void>}
586
1198
  */
@@ -591,23 +1203,7 @@ export class VectorStore {
591
1203
  return takeObject(ret);
592
1204
  }
593
1205
  /**
594
- * Exports the vector store to a binary format.
595
- *
596
- * The binary format contains:
597
- * - Header: dimension (u32), metric (u8), count (u64)
598
- * - For each vector: id (u64), data (f32 array)
599
- *
600
- * Use this to persist data to `IndexedDB` or `localStorage`.
601
- *
602
- * # Errors
603
- *
604
- * This function currently does not return errors but uses `Result`
605
- * for future extensibility.
606
- *
607
- * # Performance
608
- *
609
- * Perf: Pre-allocates exact buffer size to avoid reallocations.
610
- * Throughput: ~1600 MB/s on 10k vectors (768D)
1206
+ * Exports to binary format for IndexedDB/localStorage.
611
1207
  * @returns {Uint8Array}
612
1208
  */
613
1209
  export_to_bytes() {
@@ -637,17 +1233,7 @@ export class VectorStore {
637
1233
  return ret !== 0;
638
1234
  }
639
1235
  /**
640
- * Imports a vector store from binary format.
641
- *
642
- * Use this to restore data from `IndexedDB` or `localStorage`.
643
- *
644
- * # Errors
645
- *
646
- * Returns an error if:
647
- * - The data is too short or corrupted
648
- * - The magic number is invalid
649
- * - The version is unsupported
650
- * - The metric byte is invalid
1236
+ * Imports from binary format.
651
1237
  * @param {Uint8Array} bytes
652
1238
  * @returns {VectorStore}
653
1239
  */
@@ -670,8 +1256,6 @@ export class VectorStore {
670
1256
  }
671
1257
  /**
672
1258
  * Creates a metadata-only store (no vectors, only payloads).
673
- *
674
- * Useful for storing auxiliary data without vector embeddings.
675
1259
  * @returns {VectorStore}
676
1260
  */
677
1261
  static new_metadata_only() {
@@ -679,22 +1263,34 @@ export class VectorStore {
679
1263
  return VectorStore.__wrap(ret);
680
1264
  }
681
1265
  /**
682
- * Performs multi-query search with result fusion.
683
- *
684
- * Executes searches for multiple query vectors and fuses results
685
- * using the specified strategy.
686
- *
687
- * # Arguments
688
- *
689
- * * `vectors` - Array of query vectors (as flat array with dimension stride)
690
- * * `num_vectors` - Number of vectors in the array
691
- * * `k` - Number of results to return
692
- * * `strategy` - Fusion strategy: "average", "maximum", "rrf"
693
- * * `rrf_k` - RRF k parameter (only used when strategy = "rrf", default 60)
694
- *
695
- * # Returns
696
- *
697
- * Array of fused results with id and score.
1266
+ * Similarity search with threshold. Operators: >, >=, <, <=, =, !=.
1267
+ * @param {Float32Array} query
1268
+ * @param {number} threshold
1269
+ * @param {string} operator
1270
+ * @param {number} k
1271
+ * @returns {any}
1272
+ */
1273
+ similarity_search(query, threshold, operator, k) {
1274
+ try {
1275
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1276
+ const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
1277
+ const len0 = WASM_VECTOR_LEN;
1278
+ const ptr1 = passStringToWasm0(operator, wasm.__wbindgen_export, wasm.__wbindgen_export2);
1279
+ const len1 = WASM_VECTOR_LEN;
1280
+ wasm.vectorstore_similarity_search(retptr, this.__wbg_ptr, ptr0, len0, threshold, ptr1, len1, k);
1281
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1282
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1283
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
1284
+ if (r2) {
1285
+ throw takeObject(r1);
1286
+ }
1287
+ return takeObject(r0);
1288
+ } finally {
1289
+ wasm.__wbindgen_add_to_stack_pointer(16);
1290
+ }
1291
+ }
1292
+ /**
1293
+ * Multi-query search with fusion. Strategies: average, maximum, rrf.
698
1294
  * @param {Float32Array} vectors
699
1295
  * @param {number} num_vectors
700
1296
  * @param {number} k
@@ -722,17 +1318,7 @@ export class VectorStore {
722
1318
  }
723
1319
  }
724
1320
  /**
725
- * Searches with metadata filtering.
726
- *
727
- * # Arguments
728
- *
729
- * * `query` - Query vector
730
- * * `k` - Number of results
731
- * * `filter` - JSON filter object (e.g., `{"condition": {"type": "eq", "field": "category", "value": "tech"}}`)
732
- *
733
- * # Returns
734
- *
735
- * Array of `[id, score, payload]` tuples sorted by relevance.
1321
+ * Searches with metadata filtering. Returns [{id, score, payload}].
736
1322
  * @param {Float32Array} query
737
1323
  * @param {number} k
738
1324
  * @param {any} filter
@@ -756,17 +1342,7 @@ export class VectorStore {
756
1342
  }
757
1343
  }
758
1344
  /**
759
- * Inserts a vector with the given ID and optional JSON payload.
760
- *
761
- * # Arguments
762
- *
763
- * * `id` - Unique identifier for the vector
764
- * * `vector` - `Float32Array` of the vector data
765
- * * `payload` - Optional JSON payload (metadata)
766
- *
767
- * # Errors
768
- *
769
- * Returns an error if vector dimension doesn't match store dimension.
1345
+ * Inserts a vector with ID and optional JSON payload.
770
1346
  * @param {bigint} id
771
1347
  * @param {Float32Array} vector
772
1348
  * @param {any} payload
@@ -787,15 +1363,7 @@ export class VectorStore {
787
1363
  }
788
1364
  }
789
1365
  /**
790
- * Gets a vector by ID.
791
- *
792
- * # Arguments
793
- *
794
- * * `id` - The vector ID to retrieve
795
- *
796
- * # Returns
797
- *
798
- * An object with `id`, `vector`, and `payload` fields, or null if not found.
1366
+ * Gets a vector by ID. Returns {id, vector, payload} or null.
799
1367
  * @param {bigint} id
800
1368
  * @returns {any}
801
1369
  */
@@ -823,16 +1391,7 @@ export class VectorStore {
823
1391
  return ret >>> 0;
824
1392
  }
825
1393
  /**
826
- * Creates a new vector store with the specified dimension and distance metric.
827
- *
828
- * # Arguments
829
- *
830
- * * `dimension` - Vector dimension (e.g., 768 for BERT, 1536 for GPT)
831
- * * `metric` - Distance metric: "cosine", "euclidean", or "dot"
832
- *
833
- * # Errors
834
- *
835
- * Returns an error if the metric is not recognized.
1394
+ * Creates a new vector store. Metrics: cosine, euclidean, dot, hamming, jaccard.
836
1395
  * @param {number} dimension
837
1396
  * @param {string} metric
838
1397
  */
@@ -856,24 +1415,7 @@ export class VectorStore {
856
1415
  }
857
1416
  }
858
1417
  /**
859
- * Loads a vector store from `IndexedDB`.
860
- *
861
- * This method restores all vectors from the browser's `IndexedDB`.
862
- *
863
- * # Arguments
864
- *
865
- * * `db_name` - Name of the `IndexedDB` database
866
- *
867
- * # Errors
868
- *
869
- * Returns an error if the database doesn't exist or is corrupted.
870
- *
871
- * # Example
872
- *
873
- * ```javascript
874
- * const store = await VectorStore.load("my-vectors");
875
- * console.log(store.len); // Number of restored vectors
876
- * ```
1418
+ * Loads from `IndexedDB`.
877
1419
  * @param {string} db_name
878
1420
  * @returns {Promise<VectorStore>}
879
1421
  */
@@ -884,26 +1426,7 @@ export class VectorStore {
884
1426
  return takeObject(ret);
885
1427
  }
886
1428
  /**
887
- * Saves the vector store to `IndexedDB`.
888
- *
889
- * This method persists all vectors to the browser's `IndexedDB`,
890
- * enabling offline-first applications.
891
- *
892
- * # Arguments
893
- *
894
- * * `db_name` - Name of the `IndexedDB` database
895
- *
896
- * # Errors
897
- *
898
- * Returns an error if `IndexedDB` is not available or the save fails.
899
- *
900
- * # Example
901
- *
902
- * ```javascript
903
- * const store = new VectorStore(768, "cosine");
904
- * store.insert(1n, vector1);
905
- * await store.save("my-vectors");
906
- * ```
1429
+ * Saves to `IndexedDB`.
907
1430
  * @param {string} db_name
908
1431
  * @returns {Promise<void>}
909
1432
  */
@@ -921,15 +1444,6 @@ export class VectorStore {
921
1444
  }
922
1445
  /**
923
1446
  * Inserts a vector with the given ID.
924
- *
925
- * # Arguments
926
- *
927
- * * `id` - Unique identifier for the vector
928
- * * `vector` - `Float32Array` of the vector data
929
- *
930
- * # Errors
931
- *
932
- * Returns an error if vector dimension doesn't match store dimension.
933
1447
  * @param {bigint} id
934
1448
  * @param {Float32Array} vector
935
1449
  */
@@ -958,20 +1472,7 @@ export class VectorStore {
958
1472
  return ret !== 0;
959
1473
  }
960
1474
  /**
961
- * Searches for the k nearest neighbors to the query vector.
962
- *
963
- * # Arguments
964
- *
965
- * * `query` - Query vector as `Float32Array`
966
- * * `k` - Number of results to return
967
- *
968
- * # Returns
969
- *
970
- * Array of [id, score] pairs sorted by relevance.
971
- *
972
- * # Errors
973
- *
974
- * Returns an error if query dimension doesn't match store dimension.
1475
+ * k-NN search. Returns [[id, score], ...].
975
1476
  * @param {Float32Array} query
976
1477
  * @param {number} k
977
1478
  * @returns {any}
@@ -994,13 +1495,7 @@ export class VectorStore {
994
1495
  }
995
1496
  }
996
1497
  /**
997
- * Pre-allocates memory for the specified number of additional vectors.
998
- *
999
- * Call this before bulk insertions to avoid repeated allocations.
1000
- *
1001
- * # Arguments
1002
- *
1003
- * * `additional` - Number of additional vectors to reserve space for
1498
+ * Pre-allocates memory for additional vectors.
1004
1499
  * @param {number} additional
1005
1500
  */
1006
1501
  reserve(additional) {
@@ -1193,6 +1688,14 @@ function __wbg_get_imports() {
1193
1688
  const ret = Reflect.get(getObject(arg0), getObject(arg1));
1194
1689
  return addHeapObject(ret);
1195
1690
  }, arguments) };
1691
+ imports.wbg.__wbg_graphedge_new = function(arg0) {
1692
+ const ret = GraphEdge.__wrap(arg0);
1693
+ return addHeapObject(ret);
1694
+ };
1695
+ imports.wbg.__wbg_graphnode_new = function(arg0) {
1696
+ const ret = GraphNode.__wrap(arg0);
1697
+ return addHeapObject(ret);
1698
+ };
1196
1699
  imports.wbg.__wbg_indexedDB_23c232e00a1e28ad = function() { return handleError(function (arg0) {
1197
1700
  const ret = getObject(arg0).indexedDB;
1198
1701
  return isLikeNone(ret) ? 0 : addHeapObject(ret);
@@ -1284,7 +1787,7 @@ function __wbg_get_imports() {
1284
1787
  const a = state0.a;
1285
1788
  state0.a = 0;
1286
1789
  try {
1287
- return __wasm_bindgen_func_elem_577(a, state0.b, arg0, arg1);
1790
+ return __wasm_bindgen_func_elem_689(a, state0.b, arg0, arg1);
1288
1791
  } finally {
1289
1792
  state0.a = a;
1290
1793
  }
@@ -1405,11 +1908,6 @@ function __wbg_get_imports() {
1405
1908
  const ret = getStringFromWasm0(arg0, arg1);
1406
1909
  return addHeapObject(ret);
1407
1910
  };
1408
- imports.wbg.__wbindgen_cast_257c51b8abf9285e = function(arg0, arg1) {
1409
- // Cast intrinsic for `Closure(Closure { dtor_idx: 57, function: Function { arguments: [Externref], shim_idx: 58, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1410
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_527, __wasm_bindgen_func_elem_528);
1411
- return addHeapObject(ret);
1412
- };
1413
1911
  imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
1414
1912
  // Cast intrinsic for `U64 -> Externref`.
1415
1913
  const ret = BigInt.asUintN(64, arg0);
@@ -1417,7 +1915,7 @@ function __wbg_get_imports() {
1417
1915
  };
1418
1916
  imports.wbg.__wbindgen_cast_59e89726c7c5a9af = function(arg0, arg1) {
1419
1917
  // Cast intrinsic for `Closure(Closure { dtor_idx: 8, function: Function { arguments: [NamedExternref("Event")], shim_idx: 9, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1420
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_147, __wasm_bindgen_func_elem_148);
1918
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_197, __wasm_bindgen_func_elem_198);
1421
1919
  return addHeapObject(ret);
1422
1920
  };
1423
1921
  imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
@@ -1430,6 +1928,11 @@ function __wbg_get_imports() {
1430
1928
  const ret = arg0;
1431
1929
  return addHeapObject(ret);
1432
1930
  };
1931
+ imports.wbg.__wbindgen_cast_eecb66c58f878696 = function(arg0, arg1) {
1932
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 67, function: Function { arguments: [Externref], shim_idx: 68, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1933
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_639, __wasm_bindgen_func_elem_640);
1934
+ return addHeapObject(ret);
1935
+ };
1433
1936
  imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
1434
1937
  const ret = getObject(arg0);
1435
1938
  return addHeapObject(ret);
@@ -1444,6 +1947,7 @@ function __wbg_get_imports() {
1444
1947
  function __wbg_finalize_init(instance, module) {
1445
1948
  wasm = instance.exports;
1446
1949
  __wbg_init.__wbindgen_wasm_module = module;
1950
+ cachedBigUint64ArrayMemory0 = null;
1447
1951
  cachedDataViewMemory0 = null;
1448
1952
  cachedFloat32ArrayMemory0 = null;
1449
1953
  cachedUint8ArrayMemory0 = null;