@wiscale/velesdb-wasm 2.0.0 → 3.0.1

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/README.md CHANGED
@@ -94,6 +94,7 @@ class VectorStore {
94
94
  insert(id: bigint, vector: Float32Array): void;
95
95
  insert_with_payload(id: bigint, vector: Float32Array, payload: object): void;
96
96
  insert_batch(batch: Array<[bigint, number[]]>): void; // Bulk insert
97
+ insertBatchRaw(ids: BigUint64Array, vectors: Float32Array, dimension: number): void; // Flat raw-bulk insert (since 2026-06-14)
97
98
  search(query: Float32Array, k: number): Array<[bigint, number]>;
98
99
  search_with_filter(query: Float32Array, k: number, filter: object): Array<{id, score, payload}>;
99
100
  text_search(query: string, k: number, field?: string): Array<{id, score, payload}>;
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Julien Lange <contact@wiscale.fr>"
6
6
  ],
7
7
  "description": "VelesDB for WebAssembly - Vector search in the browser",
8
- "version": "2.0.0",
8
+ "version": "3.0.1",
9
9
  "license": "SEE LICENSE IN LICENSE",
10
10
  "repository": {
11
11
  "type": "git",
package/velesdb_wasm.d.ts CHANGED
@@ -802,6 +802,12 @@ export class VectorStore {
802
802
  * Inserts a vector with the given ID.
803
803
  */
804
804
  insert(id: bigint, vector: Float32Array): void;
805
+ /**
806
+ * Bulk insert from a flat contiguous `Float32Array` (zero-copy layout),
807
+ * mirroring the VRB1 raw-bulk contract: `ids` + flat row-major `vectors`
808
+ * + `dimension`. No payloads (use `insert_batch` for those).
809
+ */
810
+ insertBatchRaw(ids: BigUint64Array, vectors: Float32Array, dimension: number): void;
805
811
  /**
806
812
  * Batch insert. Input: `[[id, Float32Array], ...]`.
807
813
  */
@@ -864,6 +870,20 @@ export class VectorStore {
864
870
  * k-NN search. Returns [[id, score], ...].
865
871
  */
866
872
  search(query: Float32Array, k: number): any;
873
+ /**
874
+ * Sparse k-NN search over the store's pre-built sparse index.
875
+ *
876
+ * Unlike [`sparse_search`](Self::sparse_search) — which returns an empty
877
+ * result set when no sparse data has been inserted — this method mirrors
878
+ * the core `sparse_search` contract and returns an **error** when the
879
+ * store has no sparse index, so callers can distinguish "index missing"
880
+ * from "no matches". Scoring is delegated unchanged to the
881
+ * recall-verified [`sparse::SparseIndex`] kernel.
882
+ *
883
+ * Returns a JSON array of `{doc_id, score}` objects sorted by score
884
+ * descending, truncated to `k`.
885
+ */
886
+ search_sparse(query_indices: Uint32Array, query_values: Float32Array, k: number): any;
867
887
  /**
868
888
  * Searches with metadata filtering. Returns [{id, score, payload}].
869
889
  */
@@ -993,6 +1013,15 @@ export class WasmCollectionHandle {
993
1013
  * Returns an error if the vector dimension does not match the collection.
994
1014
  */
995
1015
  insert(id: bigint, vector: Float32Array): void;
1016
+ /**
1017
+ * Bulk insert from a flat row-major `vectors` buffer plus parallel `ids`
1018
+ * (VRB1 raw-bulk contract). No payloads.
1019
+ *
1020
+ * # Errors
1021
+ * Returns an error on dimension mismatch or when
1022
+ * `vectors.len() != ids.len() * dimension`.
1023
+ */
1024
+ insertBatchRaw(ids: BigUint64Array, vectors: Float32Array, dimension: number): void;
996
1025
  /**
997
1026
  * Removes a vector by ID. Returns `true` if found.
998
1027
  */
@@ -1309,6 +1338,7 @@ export interface InitOutput {
1309
1338
  readonly vectorstore_hybrid_search: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
1310
1339
  readonly vectorstore_import_from_bytes: (a: number, b: number, c: number) => void;
1311
1340
  readonly vectorstore_insert: (a: number, b: number, c: bigint, d: number, e: number) => void;
1341
+ readonly vectorstore_insertBatchRaw: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
1312
1342
  readonly vectorstore_insert_batch: (a: number, b: number, c: number) => void;
1313
1343
  readonly vectorstore_insert_with_payload: (a: number, b: number, c: bigint, d: number, e: number, f: number) => void;
1314
1344
  readonly vectorstore_is_metadata_only: (a: number) => number;
@@ -1323,6 +1353,7 @@ export interface InitOutput {
1323
1353
  readonly vectorstore_reserve: (a: number, b: number) => void;
1324
1354
  readonly vectorstore_save: (a: number, b: number, c: number) => number;
1325
1355
  readonly vectorstore_search: (a: number, b: number, c: number, d: number, e: number) => void;
1356
+ readonly vectorstore_search_sparse: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
1326
1357
  readonly vectorstore_search_with_filter: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
1327
1358
  readonly vectorstore_search_with_quality: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
1328
1359
  readonly vectorstore_similarity_search: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
@@ -1335,6 +1366,7 @@ export interface InitOutput {
1335
1366
  readonly velesql_parse: (a: number, b: number, c: number) => void;
1336
1367
  readonly wasmcollectionhandle_dimension: (a: number) => number;
1337
1368
  readonly wasmcollectionhandle_insert: (a: number, b: number, c: bigint, d: number, e: number) => void;
1369
+ readonly wasmcollectionhandle_insertBatchRaw: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
1338
1370
  readonly wasmcollectionhandle_is_empty: (a: number) => number;
1339
1371
  readonly wasmcollectionhandle_len: (a: number) => number;
1340
1372
  readonly wasmcollectionhandle_remove: (a: number, b: bigint) => number;
@@ -1358,9 +1390,9 @@ export interface InitOutput {
1358
1390
  readonly graphnode_id: (a: number) => bigint;
1359
1391
  readonly vectorstore_dimension: (a: number) => number;
1360
1392
  readonly wasmdatabase_collection_count: (a: number) => number;
1361
- readonly __wasm_bindgen_func_elem_1850: (a: number, b: number, c: number, d: number) => void;
1362
- readonly __wasm_bindgen_func_elem_1866: (a: number, b: number, c: number, d: number) => void;
1363
- readonly __wasm_bindgen_func_elem_401: (a: number, b: number, c: number) => void;
1393
+ readonly __wasm_bindgen_func_elem_1267: (a: number, b: number, c: number, d: number) => void;
1394
+ readonly __wasm_bindgen_func_elem_1283: (a: number, b: number, c: number, d: number) => void;
1395
+ readonly __wasm_bindgen_func_elem_412: (a: number, b: number, c: number) => void;
1364
1396
  readonly __wbindgen_export: (a: number, b: number) => number;
1365
1397
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
1366
1398
  readonly __wbindgen_export3: (a: number) => void;
package/velesdb_wasm.js CHANGED
@@ -2002,6 +2002,31 @@ export class VectorStore {
2002
2002
  wasm.__wbindgen_add_to_stack_pointer(16);
2003
2003
  }
2004
2004
  }
2005
+ /**
2006
+ * Bulk insert from a flat contiguous `Float32Array` (zero-copy layout),
2007
+ * mirroring the VRB1 raw-bulk contract: `ids` + flat row-major `vectors`
2008
+ * + `dimension`. No payloads (use `insert_batch` for those).
2009
+ * @param {BigUint64Array} ids
2010
+ * @param {Float32Array} vectors
2011
+ * @param {number} dimension
2012
+ */
2013
+ insertBatchRaw(ids, vectors, dimension) {
2014
+ try {
2015
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2016
+ const ptr0 = passArray64ToWasm0(ids, wasm.__wbindgen_export);
2017
+ const len0 = WASM_VECTOR_LEN;
2018
+ const ptr1 = passArrayF32ToWasm0(vectors, wasm.__wbindgen_export);
2019
+ const len1 = WASM_VECTOR_LEN;
2020
+ wasm.vectorstore_insertBatchRaw(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, dimension);
2021
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2022
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2023
+ if (r1) {
2024
+ throw takeObject(r0);
2025
+ }
2026
+ } finally {
2027
+ wasm.__wbindgen_add_to_stack_pointer(16);
2028
+ }
2029
+ }
2005
2030
  /**
2006
2031
  * Batch insert. Input: `[[id, Float32Array], ...]`.
2007
2032
  * @param {any} batch
@@ -2252,6 +2277,42 @@ export class VectorStore {
2252
2277
  wasm.__wbindgen_add_to_stack_pointer(16);
2253
2278
  }
2254
2279
  }
2280
+ /**
2281
+ * Sparse k-NN search over the store's pre-built sparse index.
2282
+ *
2283
+ * Unlike [`sparse_search`](Self::sparse_search) — which returns an empty
2284
+ * result set when no sparse data has been inserted — this method mirrors
2285
+ * the core `sparse_search` contract and returns an **error** when the
2286
+ * store has no sparse index, so callers can distinguish "index missing"
2287
+ * from "no matches". Scoring is delegated unchanged to the
2288
+ * recall-verified [`sparse::SparseIndex`] kernel.
2289
+ *
2290
+ * Returns a JSON array of `{doc_id, score}` objects sorted by score
2291
+ * descending, truncated to `k`.
2292
+ * @param {Uint32Array} query_indices
2293
+ * @param {Float32Array} query_values
2294
+ * @param {number} k
2295
+ * @returns {any}
2296
+ */
2297
+ search_sparse(query_indices, query_values, k) {
2298
+ try {
2299
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2300
+ const ptr0 = passArray32ToWasm0(query_indices, wasm.__wbindgen_export);
2301
+ const len0 = WASM_VECTOR_LEN;
2302
+ const ptr1 = passArrayF32ToWasm0(query_values, wasm.__wbindgen_export);
2303
+ const len1 = WASM_VECTOR_LEN;
2304
+ wasm.vectorstore_search_sparse(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, k);
2305
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2306
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2307
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
2308
+ if (r2) {
2309
+ throw takeObject(r1);
2310
+ }
2311
+ return takeObject(r0);
2312
+ } finally {
2313
+ wasm.__wbindgen_add_to_stack_pointer(16);
2314
+ }
2315
+ }
2255
2316
  /**
2256
2317
  * Searches with metadata filtering. Returns [{id, score, payload}].
2257
2318
  * @param {Float32Array} query
@@ -2600,6 +2661,34 @@ export class WasmCollectionHandle {
2600
2661
  wasm.__wbindgen_add_to_stack_pointer(16);
2601
2662
  }
2602
2663
  }
2664
+ /**
2665
+ * Bulk insert from a flat row-major `vectors` buffer plus parallel `ids`
2666
+ * (VRB1 raw-bulk contract). No payloads.
2667
+ *
2668
+ * # Errors
2669
+ * Returns an error on dimension mismatch or when
2670
+ * `vectors.len() != ids.len() * dimension`.
2671
+ * @param {BigUint64Array} ids
2672
+ * @param {Float32Array} vectors
2673
+ * @param {number} dimension
2674
+ */
2675
+ insertBatchRaw(ids, vectors, dimension) {
2676
+ try {
2677
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
2678
+ const ptr0 = passArray64ToWasm0(ids, wasm.__wbindgen_export);
2679
+ const len0 = WASM_VECTOR_LEN;
2680
+ const ptr1 = passArrayF32ToWasm0(vectors, wasm.__wbindgen_export);
2681
+ const len1 = WASM_VECTOR_LEN;
2682
+ wasm.wasmcollectionhandle_insertBatchRaw(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1, dimension);
2683
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
2684
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
2685
+ if (r1) {
2686
+ throw takeObject(r0);
2687
+ }
2688
+ } finally {
2689
+ wasm.__wbindgen_add_to_stack_pointer(16);
2690
+ }
2691
+ }
2603
2692
  /**
2604
2693
  * Returns `true` if the collection has no vectors.
2605
2694
  * @returns {boolean}
@@ -3216,7 +3305,7 @@ function __wbg_get_imports() {
3216
3305
  const a = state0.a;
3217
3306
  state0.a = 0;
3218
3307
  try {
3219
- return __wasm_bindgen_func_elem_1866(a, state0.b, arg0, arg1);
3308
+ return __wasm_bindgen_func_elem_1283(a, state0.b, arg0, arg1);
3220
3309
  } finally {
3221
3310
  state0.a = a;
3222
3311
  }
@@ -3238,7 +3327,7 @@ function __wbg_get_imports() {
3238
3327
  const a = state0.a;
3239
3328
  state0.a = 0;
3240
3329
  try {
3241
- return __wasm_bindgen_func_elem_1866(a, state0.b, arg0, arg1);
3330
+ return __wasm_bindgen_func_elem_1283(a, state0.b, arg0, arg1);
3242
3331
  } finally {
3243
3332
  state0.a = a;
3244
3333
  }
@@ -3371,13 +3460,13 @@ function __wbg_get_imports() {
3371
3460
  return addHeapObject(ret);
3372
3461
  },
3373
3462
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
3374
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 330, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
3375
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1850);
3463
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 274, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
3464
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_1267);
3376
3465
  return addHeapObject(ret);
3377
3466
  },
3378
3467
  __wbindgen_cast_0000000000000002: function(arg0, arg1) {
3379
3468
  // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 7, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
3380
- const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_401);
3469
+ const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_412);
3381
3470
  return addHeapObject(ret);
3382
3471
  },
3383
3472
  __wbindgen_cast_0000000000000003: function(arg0) {
@@ -3414,14 +3503,14 @@ function __wbg_get_imports() {
3414
3503
  };
3415
3504
  }
3416
3505
 
3417
- function __wasm_bindgen_func_elem_401(arg0, arg1, arg2) {
3418
- wasm.__wasm_bindgen_func_elem_401(arg0, arg1, addHeapObject(arg2));
3506
+ function __wasm_bindgen_func_elem_412(arg0, arg1, arg2) {
3507
+ wasm.__wasm_bindgen_func_elem_412(arg0, arg1, addHeapObject(arg2));
3419
3508
  }
3420
3509
 
3421
- function __wasm_bindgen_func_elem_1850(arg0, arg1, arg2) {
3510
+ function __wasm_bindgen_func_elem_1267(arg0, arg1, arg2) {
3422
3511
  try {
3423
3512
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
3424
- wasm.__wasm_bindgen_func_elem_1850(retptr, arg0, arg1, addHeapObject(arg2));
3513
+ wasm.__wasm_bindgen_func_elem_1267(retptr, arg0, arg1, addHeapObject(arg2));
3425
3514
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
3426
3515
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
3427
3516
  if (r1) {
@@ -3432,8 +3521,8 @@ function __wasm_bindgen_func_elem_1850(arg0, arg1, arg2) {
3432
3521
  }
3433
3522
  }
3434
3523
 
3435
- function __wasm_bindgen_func_elem_1866(arg0, arg1, arg2, arg3) {
3436
- wasm.__wasm_bindgen_func_elem_1866(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
3524
+ function __wasm_bindgen_func_elem_1283(arg0, arg1, arg2, arg3) {
3525
+ wasm.__wasm_bindgen_func_elem_1283(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
3437
3526
  }
3438
3527
 
3439
3528
 
@@ -3692,6 +3781,13 @@ function passArray32ToWasm0(arg, malloc) {
3692
3781
  return ptr;
3693
3782
  }
3694
3783
 
3784
+ function passArray64ToWasm0(arg, malloc) {
3785
+ const ptr = malloc(arg.length * 8, 8) >>> 0;
3786
+ getBigUint64ArrayMemory0().set(arg, ptr / 8);
3787
+ WASM_VECTOR_LEN = arg.length;
3788
+ return ptr;
3789
+ }
3790
+
3695
3791
  function passArray8ToWasm0(arg, malloc) {
3696
3792
  const ptr = malloc(arg.length * 1, 1) >>> 0;
3697
3793
  getUint8ArrayMemory0().set(arg, ptr / 1);
Binary file