@wiscale/velesdb-wasm 0.8.6 → 0.8.7

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
@@ -89,8 +89,12 @@ class VectorStore {
89
89
 
90
90
  // Methods
91
91
  insert(id: bigint, vector: Float32Array): void;
92
+ insert_with_payload(id: bigint, vector: Float32Array, payload: object): void; // v0.8.5+
92
93
  insert_batch(batch: Array<[bigint, number[]]>): void; // Bulk insert
93
94
  search(query: Float32Array, k: number): Array<[bigint, number]>;
95
+ search_with_filter(query: Float32Array, k: number, filter: object): Array<{id, score, payload}>; // v0.8.5+
96
+ text_search(query: string, k: number, field?: string): Array<{id, score, payload}>; // v0.8.5+
97
+ get(id: bigint): {id, vector, payload} | null; // v0.8.5+
94
98
  remove(id: bigint): boolean;
95
99
  clear(): void;
96
100
  reserve(additional: number): void; // Pre-allocate memory
@@ -98,6 +102,31 @@ class VectorStore {
98
102
  }
99
103
  ```
100
104
 
105
+ ### Filter Format (v0.8.5+)
106
+
107
+ ```javascript
108
+ // Equality filter
109
+ const filter = {
110
+ condition: { type: "eq", field: "category", value: "tech" }
111
+ };
112
+
113
+ // Comparison filters
114
+ const filter = {
115
+ condition: { type: "gt", field: "price", value: 100 }
116
+ }; // Also: gte, lt, lte, neq
117
+
118
+ // Logical operators
119
+ const filter = {
120
+ condition: {
121
+ type: "and",
122
+ conditions: [
123
+ { type: "eq", field: "category", value: "tech" },
124
+ { type: "gt", field: "views", value: 1000 }
125
+ ]
126
+ }
127
+ }; // Also: or, not
128
+ ```
129
+
101
130
  ## Distance Metrics
102
131
 
103
132
  | Metric | Description | Best For |
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "VelesDB Team <contact@wiscale.fr>"
6
6
  ],
7
7
  "description": "VelesDB for WebAssembly - Vector search in the browser",
8
- "version": "0.8.6",
8
+ "version": "0.8.7",
9
9
  "license": "SEE LICENSE IN ../../LICENSE",
10
10
  "repository": {
11
11
  "type": "git",
package/velesdb_wasm.d.ts CHANGED
@@ -22,6 +22,23 @@ export enum StorageMode {
22
22
  export class VectorStore {
23
23
  free(): void;
24
24
  [Symbol.dispose](): void;
25
+ /**
26
+ * Performs text search on payload fields.
27
+ *
28
+ * This is a simple substring-based search on payload text fields.
29
+ * For full BM25 text search, use the REST API backend.
30
+ *
31
+ * # Arguments
32
+ *
33
+ * * `query` - Text query to search for
34
+ * * `k` - Number of results
35
+ * * `field` - Optional field name to search in (default: searches all string fields)
36
+ *
37
+ * # Returns
38
+ *
39
+ * Array of results with matching payloads.
40
+ */
41
+ text_search(query: string, k: number, field?: string | null): any;
25
42
  /**
26
43
  * Inserts multiple vectors in a single batch operation.
27
44
  *
@@ -126,6 +143,46 @@ export class VectorStore {
126
143
  * - The metric byte is invalid
127
144
  */
128
145
  static import_from_bytes(bytes: Uint8Array): VectorStore;
146
+ /**
147
+ * Searches with metadata filtering.
148
+ *
149
+ * # Arguments
150
+ *
151
+ * * `query` - Query vector
152
+ * * `k` - Number of results
153
+ * * `filter` - JSON filter object (e.g., `{"condition": {"type": "eq", "field": "category", "value": "tech"}}`)
154
+ *
155
+ * # Returns
156
+ *
157
+ * Array of `[id, score, payload]` tuples sorted by relevance.
158
+ */
159
+ search_with_filter(query: Float32Array, k: number, filter: any): any;
160
+ /**
161
+ * Inserts a vector with the given ID and optional JSON payload.
162
+ *
163
+ * # Arguments
164
+ *
165
+ * * `id` - Unique identifier for the vector
166
+ * * `vector` - `Float32Array` of the vector data
167
+ * * `payload` - Optional JSON payload (metadata)
168
+ *
169
+ * # Errors
170
+ *
171
+ * Returns an error if vector dimension doesn't match store dimension.
172
+ */
173
+ insert_with_payload(id: bigint, vector: Float32Array, payload: any): void;
174
+ /**
175
+ * Gets a vector by ID.
176
+ *
177
+ * # Arguments
178
+ *
179
+ * * `id` - The vector ID to retrieve
180
+ *
181
+ * # Returns
182
+ *
183
+ * An object with `id`, `vector`, and `payload` fields, or null if not found.
184
+ */
185
+ get(id: bigint): any;
129
186
  /**
130
187
  * Creates a new vector store with the specified dimension and distance metric.
131
188
  *
@@ -258,9 +315,11 @@ export interface InitOutput {
258
315
  readonly vectorstore_delete_database: (a: number, b: number) => number;
259
316
  readonly vectorstore_dimension: (a: number) => number;
260
317
  readonly vectorstore_export_to_bytes: (a: number, b: number) => void;
318
+ readonly vectorstore_get: (a: number, b: number, c: bigint) => void;
261
319
  readonly vectorstore_import_from_bytes: (a: number, b: number, c: number) => void;
262
320
  readonly vectorstore_insert: (a: number, b: number, c: bigint, d: number, e: number) => void;
263
321
  readonly vectorstore_insert_batch: (a: number, b: number, c: number) => void;
322
+ readonly vectorstore_insert_with_payload: (a: number, b: number, c: bigint, d: number, e: number, f: number) => void;
264
323
  readonly vectorstore_is_empty: (a: number) => number;
265
324
  readonly vectorstore_len: (a: number) => number;
266
325
  readonly vectorstore_load: (a: number, b: number) => number;
@@ -271,13 +330,15 @@ export interface InitOutput {
271
330
  readonly vectorstore_reserve: (a: number, b: number) => void;
272
331
  readonly vectorstore_save: (a: number, b: number, c: number) => number;
273
332
  readonly vectorstore_search: (a: number, b: number, c: number, d: number, e: number) => void;
333
+ readonly vectorstore_search_with_filter: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
274
334
  readonly vectorstore_storage_mode: (a: number, b: number) => void;
335
+ readonly vectorstore_text_search: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
275
336
  readonly vectorstore_with_capacity: (a: number, b: number, c: number, d: number, e: number) => void;
276
- readonly __wasm_bindgen_func_elem_98: (a: number, b: number, c: number) => void;
277
- readonly __wasm_bindgen_func_elem_97: (a: number, b: number) => void;
278
- readonly __wasm_bindgen_func_elem_397: (a: number, b: number, c: number) => void;
279
- readonly __wasm_bindgen_func_elem_396: (a: number, b: number) => void;
280
- readonly __wasm_bindgen_func_elem_444: (a: number, b: number, c: number, d: number) => void;
337
+ readonly __wasm_bindgen_func_elem_133: (a: number, b: number, c: number) => void;
338
+ readonly __wasm_bindgen_func_elem_132: (a: number, b: number) => void;
339
+ readonly __wasm_bindgen_func_elem_489: (a: number, b: number, c: number) => void;
340
+ readonly __wasm_bindgen_func_elem_488: (a: number, b: number) => void;
341
+ readonly __wasm_bindgen_func_elem_536: (a: number, b: number, c: number, d: number) => void;
281
342
  readonly __wbindgen_export: (a: number, b: number) => number;
282
343
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
283
344
  readonly __wbindgen_export3: (a: number) => void;
package/velesdb_wasm.js CHANGED
@@ -251,16 +251,16 @@ if (!('encodeInto' in cachedTextEncoder)) {
251
251
 
252
252
  let WASM_VECTOR_LEN = 0;
253
253
 
254
- function __wasm_bindgen_func_elem_98(arg0, arg1, arg2) {
255
- wasm.__wasm_bindgen_func_elem_98(arg0, arg1, addHeapObject(arg2));
254
+ function __wasm_bindgen_func_elem_133(arg0, arg1, arg2) {
255
+ wasm.__wasm_bindgen_func_elem_133(arg0, arg1, addHeapObject(arg2));
256
256
  }
257
257
 
258
- function __wasm_bindgen_func_elem_397(arg0, arg1, arg2) {
259
- wasm.__wasm_bindgen_func_elem_397(arg0, arg1, addHeapObject(arg2));
258
+ function __wasm_bindgen_func_elem_489(arg0, arg1, arg2) {
259
+ wasm.__wasm_bindgen_func_elem_489(arg0, arg1, addHeapObject(arg2));
260
260
  }
261
261
 
262
- function __wasm_bindgen_func_elem_444(arg0, arg1, arg2, arg3) {
263
- wasm.__wasm_bindgen_func_elem_444(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
262
+ function __wasm_bindgen_func_elem_536(arg0, arg1, arg2, arg3) {
263
+ wasm.__wasm_bindgen_func_elem_536(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
264
264
  }
265
265
 
266
266
  const __wbindgen_enum_IdbTransactionMode = ["readonly", "readwrite", "versionchange", "readwriteflush", "cleanup"];
@@ -321,6 +321,45 @@ export class VectorStore {
321
321
  const ptr = this.__destroy_into_raw();
322
322
  wasm.__wbg_vectorstore_free(ptr, 0);
323
323
  }
324
+ /**
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.
339
+ * @param {string} query
340
+ * @param {number} k
341
+ * @param {string | null} [field]
342
+ * @returns {any}
343
+ */
344
+ text_search(query, k, field) {
345
+ try {
346
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
347
+ const ptr0 = passStringToWasm0(query, wasm.__wbindgen_export, wasm.__wbindgen_export2);
348
+ const len0 = WASM_VECTOR_LEN;
349
+ var ptr1 = isLikeNone(field) ? 0 : passStringToWasm0(field, wasm.__wbindgen_export, wasm.__wbindgen_export2);
350
+ var len1 = WASM_VECTOR_LEN;
351
+ wasm.vectorstore_text_search(retptr, this.__wbg_ptr, ptr0, len0, k, ptr1, len1);
352
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
353
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
354
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
355
+ if (r2) {
356
+ throw takeObject(r1);
357
+ }
358
+ return takeObject(r0);
359
+ } finally {
360
+ wasm.__wbindgen_add_to_stack_pointer(16);
361
+ }
362
+ }
324
363
  /**
325
364
  * Inserts multiple vectors in a single batch operation.
326
365
  *
@@ -547,6 +586,99 @@ export class VectorStore {
547
586
  wasm.__wbindgen_add_to_stack_pointer(16);
548
587
  }
549
588
  }
589
+ /**
590
+ * Searches with metadata filtering.
591
+ *
592
+ * # Arguments
593
+ *
594
+ * * `query` - Query vector
595
+ * * `k` - Number of results
596
+ * * `filter` - JSON filter object (e.g., `{"condition": {"type": "eq", "field": "category", "value": "tech"}}`)
597
+ *
598
+ * # Returns
599
+ *
600
+ * Array of `[id, score, payload]` tuples sorted by relevance.
601
+ * @param {Float32Array} query
602
+ * @param {number} k
603
+ * @param {any} filter
604
+ * @returns {any}
605
+ */
606
+ search_with_filter(query, k, filter) {
607
+ try {
608
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
609
+ const ptr0 = passArrayF32ToWasm0(query, wasm.__wbindgen_export);
610
+ const len0 = WASM_VECTOR_LEN;
611
+ wasm.vectorstore_search_with_filter(retptr, this.__wbg_ptr, ptr0, len0, k, addHeapObject(filter));
612
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
613
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
614
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
615
+ if (r2) {
616
+ throw takeObject(r1);
617
+ }
618
+ return takeObject(r0);
619
+ } finally {
620
+ wasm.__wbindgen_add_to_stack_pointer(16);
621
+ }
622
+ }
623
+ /**
624
+ * Inserts a vector with the given ID and optional JSON payload.
625
+ *
626
+ * # Arguments
627
+ *
628
+ * * `id` - Unique identifier for the vector
629
+ * * `vector` - `Float32Array` of the vector data
630
+ * * `payload` - Optional JSON payload (metadata)
631
+ *
632
+ * # Errors
633
+ *
634
+ * Returns an error if vector dimension doesn't match store dimension.
635
+ * @param {bigint} id
636
+ * @param {Float32Array} vector
637
+ * @param {any} payload
638
+ */
639
+ insert_with_payload(id, vector, payload) {
640
+ try {
641
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
642
+ const ptr0 = passArrayF32ToWasm0(vector, wasm.__wbindgen_export);
643
+ const len0 = WASM_VECTOR_LEN;
644
+ wasm.vectorstore_insert_with_payload(retptr, this.__wbg_ptr, id, ptr0, len0, addHeapObject(payload));
645
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
646
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
647
+ if (r1) {
648
+ throw takeObject(r0);
649
+ }
650
+ } finally {
651
+ wasm.__wbindgen_add_to_stack_pointer(16);
652
+ }
653
+ }
654
+ /**
655
+ * Gets a vector by ID.
656
+ *
657
+ * # Arguments
658
+ *
659
+ * * `id` - The vector ID to retrieve
660
+ *
661
+ * # Returns
662
+ *
663
+ * An object with `id`, `vector`, and `payload` fields, or null if not found.
664
+ * @param {bigint} id
665
+ * @returns {any}
666
+ */
667
+ get(id) {
668
+ try {
669
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
670
+ wasm.vectorstore_get(retptr, this.__wbg_ptr, id);
671
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
672
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
673
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
674
+ if (r2) {
675
+ throw takeObject(r1);
676
+ }
677
+ return takeObject(r0);
678
+ } finally {
679
+ wasm.__wbindgen_add_to_stack_pointer(16);
680
+ }
681
+ }
550
682
  /**
551
683
  * Returns the number of vectors in the store.
552
684
  * @returns {number}
@@ -826,6 +958,10 @@ function __wbg_get_imports() {
826
958
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
827
959
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
828
960
  };
961
+ imports.wbg.__wbg___wbindgen_in_0d3e1e8f0c669317 = function(arg0, arg1) {
962
+ const ret = getObject(arg0) in getObject(arg1);
963
+ return ret;
964
+ };
829
965
  imports.wbg.__wbg___wbindgen_is_bigint_0e1a2e3f55cfae27 = function(arg0) {
830
966
  const ret = typeof(getObject(arg0)) === 'bigint';
831
967
  return ret;
@@ -843,6 +979,10 @@ function __wbg_get_imports() {
843
979
  const ret = typeof(val) === 'object' && val !== null;
844
980
  return ret;
845
981
  };
982
+ imports.wbg.__wbg___wbindgen_is_string_704ef9c8fc131030 = function(arg0) {
983
+ const ret = typeof(getObject(arg0)) === 'string';
984
+ return ret;
985
+ };
846
986
  imports.wbg.__wbg___wbindgen_is_undefined_f6b95eab589e0269 = function(arg0) {
847
987
  const ret = getObject(arg0) === undefined;
848
988
  return ret;
@@ -895,6 +1035,10 @@ function __wbg_get_imports() {
895
1035
  const ret = getObject(arg0).done;
896
1036
  return ret;
897
1037
  };
1038
+ imports.wbg.__wbg_entries_83c79938054e065f = function(arg0) {
1039
+ const ret = Object.entries(getObject(arg0));
1040
+ return addHeapObject(ret);
1041
+ };
898
1042
  imports.wbg.__wbg_get_6b7bd52aca3f9671 = function(arg0, arg1) {
899
1043
  const ret = getObject(arg0)[arg1 >>> 0];
900
1044
  return addHeapObject(ret);
@@ -928,6 +1072,16 @@ function __wbg_get_imports() {
928
1072
  const ret = result;
929
1073
  return ret;
930
1074
  };
1075
+ imports.wbg.__wbg_instanceof_Map_084be8da74364158 = function(arg0) {
1076
+ let result;
1077
+ try {
1078
+ result = getObject(arg0) instanceof Map;
1079
+ } catch (_) {
1080
+ result = false;
1081
+ }
1082
+ const ret = result;
1083
+ return ret;
1084
+ };
931
1085
  imports.wbg.__wbg_instanceof_Uint8Array_da54ccc9d3e09434 = function(arg0) {
932
1086
  let result;
933
1087
  try {
@@ -972,6 +1126,10 @@ function __wbg_get_imports() {
972
1126
  const ret = getObject(arg0).length;
973
1127
  return ret;
974
1128
  };
1129
+ imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
1130
+ const ret = new Object();
1131
+ return addHeapObject(ret);
1132
+ };
975
1133
  imports.wbg.__wbg_new_25f239778d6112b9 = function() {
976
1134
  const ret = new Array();
977
1135
  return addHeapObject(ret);
@@ -980,6 +1138,10 @@ function __wbg_get_imports() {
980
1138
  const ret = new Uint8Array(getObject(arg0));
981
1139
  return addHeapObject(ret);
982
1140
  };
1141
+ imports.wbg.__wbg_new_b546ae120718850e = function() {
1142
+ const ret = new Map();
1143
+ return addHeapObject(ret);
1144
+ };
983
1145
  imports.wbg.__wbg_new_ff12d2b041fb48f1 = function(arg0, arg1) {
984
1146
  try {
985
1147
  var state0 = {a: arg0, b: arg1};
@@ -987,7 +1149,7 @@ function __wbg_get_imports() {
987
1149
  const a = state0.a;
988
1150
  state0.a = 0;
989
1151
  try {
990
- return __wasm_bindgen_func_elem_444(a, state0.b, arg0, arg1);
1152
+ return __wasm_bindgen_func_elem_536(a, state0.b, arg0, arg1);
991
1153
  } finally {
992
1154
  state0.a = a;
993
1155
  }
@@ -1048,9 +1210,16 @@ function __wbg_get_imports() {
1048
1210
  const ret = getObject(arg0).result;
1049
1211
  return addHeapObject(ret);
1050
1212
  }, arguments) };
1213
+ imports.wbg.__wbg_set_3f1d0b984ed272ed = function(arg0, arg1, arg2) {
1214
+ getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
1215
+ };
1051
1216
  imports.wbg.__wbg_set_7df433eea03a5c14 = function(arg0, arg1, arg2) {
1052
1217
  getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
1053
1218
  };
1219
+ imports.wbg.__wbg_set_efaaf145b9377369 = function(arg0, arg1, arg2) {
1220
+ const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
1221
+ return addHeapObject(ret);
1222
+ };
1054
1223
  imports.wbg.__wbg_set_onerror_08fecec3bdc9d24d = function(arg0, arg1) {
1055
1224
  getObject(arg0).onerror = getObject(arg1);
1056
1225
  };
@@ -1101,19 +1270,19 @@ function __wbg_get_imports() {
1101
1270
  const ret = getStringFromWasm0(arg0, arg1);
1102
1271
  return addHeapObject(ret);
1103
1272
  };
1273
+ imports.wbg.__wbindgen_cast_245e75e6849de722 = function(arg0, arg1) {
1274
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 7, function: Function { arguments: [NamedExternref("Event")], shim_idx: 8, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1275
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_132, __wasm_bindgen_func_elem_133);
1276
+ return addHeapObject(ret);
1277
+ };
1104
1278
  imports.wbg.__wbindgen_cast_4625c577ab2ec9ee = function(arg0) {
1105
1279
  // Cast intrinsic for `U64 -> Externref`.
1106
1280
  const ret = BigInt.asUintN(64, arg0);
1107
1281
  return addHeapObject(ret);
1108
1282
  };
1109
- imports.wbg.__wbindgen_cast_5672704bc77a612c = function(arg0, arg1) {
1110
- // Cast intrinsic for `Closure(Closure { dtor_idx: 44, function: Function { arguments: [Externref], shim_idx: 45, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1111
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_396, __wasm_bindgen_func_elem_397);
1112
- return addHeapObject(ret);
1113
- };
1114
- imports.wbg.__wbindgen_cast_9cdd8d1a79740578 = function(arg0, arg1) {
1115
- // Cast intrinsic for `Closure(Closure { dtor_idx: 6, function: Function { arguments: [NamedExternref("Event")], shim_idx: 7, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1116
- const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_97, __wasm_bindgen_func_elem_98);
1283
+ imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
1284
+ // Cast intrinsic for `I64 -> Externref`.
1285
+ const ret = arg0;
1117
1286
  return addHeapObject(ret);
1118
1287
  };
1119
1288
  imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
@@ -1121,6 +1290,11 @@ function __wbg_get_imports() {
1121
1290
  const ret = arg0;
1122
1291
  return addHeapObject(ret);
1123
1292
  };
1293
+ imports.wbg.__wbindgen_cast_e7ad0d7b317830d5 = function(arg0, arg1) {
1294
+ // Cast intrinsic for `Closure(Closure { dtor_idx: 56, function: Function { arguments: [Externref], shim_idx: 57, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
1295
+ const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_488, __wasm_bindgen_func_elem_489);
1296
+ return addHeapObject(ret);
1297
+ };
1124
1298
  imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
1125
1299
  const ret = getObject(arg0);
1126
1300
  return addHeapObject(ret);
Binary file