@wiscale/velesdb-wasm 1.2.0 → 1.3.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/package.json +1 -1
- package/velesdb_wasm.d.ts +99 -253
- package/velesdb_wasm.js +220 -261
- package/velesdb_wasm_bg.wasm +0 -0
package/package.json
CHANGED
package/velesdb_wasm.d.ts
CHANGED
|
@@ -94,6 +94,10 @@ export class GraphNode {
|
|
|
94
94
|
export class GraphStore {
|
|
95
95
|
free(): void;
|
|
96
96
|
[Symbol.dispose](): void;
|
|
97
|
+
/**
|
|
98
|
+
* Gets the degree (number of outgoing edges) of a node.
|
|
99
|
+
*/
|
|
100
|
+
out_degree(node_id: bigint): number;
|
|
97
101
|
/**
|
|
98
102
|
* Removes an edge by ID.
|
|
99
103
|
*/
|
|
@@ -116,6 +120,20 @@ export class GraphStore {
|
|
|
116
120
|
* Array of reachable node IDs with their depths.
|
|
117
121
|
*/
|
|
118
122
|
bfs_traverse(source_id: bigint, max_depth: number, limit: number): any;
|
|
123
|
+
/**
|
|
124
|
+
* Performs DFS traversal from a source node.
|
|
125
|
+
*
|
|
126
|
+
* # Arguments
|
|
127
|
+
*
|
|
128
|
+
* * `source_id` - Starting node ID
|
|
129
|
+
* * `max_depth` - Maximum traversal depth
|
|
130
|
+
* * `limit` - Maximum number of results
|
|
131
|
+
*
|
|
132
|
+
* # Returns
|
|
133
|
+
*
|
|
134
|
+
* Array of reachable node IDs with their depths (depth-first order).
|
|
135
|
+
*/
|
|
136
|
+
dfs_traverse(source_id: bigint, max_depth: number, limit: number): any;
|
|
119
137
|
/**
|
|
120
138
|
* Gets incoming edges to a node.
|
|
121
139
|
*/
|
|
@@ -128,6 +146,38 @@ export class GraphStore {
|
|
|
128
146
|
* Gets neighbors reachable from a node (1-hop).
|
|
129
147
|
*/
|
|
130
148
|
get_neighbors(node_id: bigint): BigUint64Array;
|
|
149
|
+
/**
|
|
150
|
+
* Gets all edge IDs in the graph.
|
|
151
|
+
*/
|
|
152
|
+
get_all_edge_ids(): BigUint64Array;
|
|
153
|
+
/**
|
|
154
|
+
* Gets all node IDs in the graph.
|
|
155
|
+
*/
|
|
156
|
+
get_all_node_ids(): BigUint64Array;
|
|
157
|
+
/**
|
|
158
|
+
* Gets all edges with a specific label.
|
|
159
|
+
*
|
|
160
|
+
* # Arguments
|
|
161
|
+
*
|
|
162
|
+
* * `label` - The relationship type to filter by
|
|
163
|
+
*
|
|
164
|
+
* # Returns
|
|
165
|
+
*
|
|
166
|
+
* Array of edges matching the label.
|
|
167
|
+
*/
|
|
168
|
+
get_edges_by_label(label: string): GraphEdge[];
|
|
169
|
+
/**
|
|
170
|
+
* Gets all nodes with a specific label.
|
|
171
|
+
*
|
|
172
|
+
* # Arguments
|
|
173
|
+
*
|
|
174
|
+
* * `label` - The label to filter by
|
|
175
|
+
*
|
|
176
|
+
* # Returns
|
|
177
|
+
*
|
|
178
|
+
* Array of nodes matching the label.
|
|
179
|
+
*/
|
|
180
|
+
get_nodes_by_label(label: string): GraphNode[];
|
|
131
181
|
/**
|
|
132
182
|
* Gets outgoing edges filtered by label.
|
|
133
183
|
*/
|
|
@@ -158,6 +208,18 @@ export class GraphStore {
|
|
|
158
208
|
* Gets a node by ID.
|
|
159
209
|
*/
|
|
160
210
|
get_node(id: bigint): GraphNode | undefined;
|
|
211
|
+
/**
|
|
212
|
+
* Checks if an edge exists.
|
|
213
|
+
*/
|
|
214
|
+
has_edge(id: bigint): boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Checks if a node exists.
|
|
217
|
+
*/
|
|
218
|
+
has_node(id: bigint): boolean;
|
|
219
|
+
/**
|
|
220
|
+
* Gets the in-degree (number of incoming edges) of a node.
|
|
221
|
+
*/
|
|
222
|
+
in_degree(node_id: bigint): number;
|
|
161
223
|
/**
|
|
162
224
|
* Returns the number of edges.
|
|
163
225
|
*/
|
|
@@ -190,49 +252,15 @@ export class VectorStore {
|
|
|
190
252
|
free(): void;
|
|
191
253
|
[Symbol.dispose](): void;
|
|
192
254
|
/**
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
* This is a simple substring-based search on payload text fields.
|
|
196
|
-
* For full BM25 text search, use the REST API backend.
|
|
197
|
-
*
|
|
198
|
-
* # Arguments
|
|
199
|
-
*
|
|
200
|
-
* * `query` - Text query to search for
|
|
201
|
-
* * `k` - Number of results
|
|
202
|
-
* * `field` - Optional field name to search in (default: searches all string fields)
|
|
203
|
-
*
|
|
204
|
-
* # Returns
|
|
205
|
-
*
|
|
206
|
-
* Array of results with matching payloads.
|
|
255
|
+
* Text search on payload fields (substring matching).
|
|
207
256
|
*/
|
|
208
257
|
text_search(query: string, k: number, field?: string | null): any;
|
|
209
258
|
/**
|
|
210
|
-
* Batch search for multiple vectors
|
|
211
|
-
*
|
|
212
|
-
* # Arguments
|
|
213
|
-
*
|
|
214
|
-
* * `vectors` - Flat array of query vectors (concatenated)
|
|
215
|
-
* * `num_vectors` - Number of vectors
|
|
216
|
-
* * `k` - Results per query
|
|
217
|
-
*
|
|
218
|
-
* # Returns
|
|
219
|
-
*
|
|
220
|
-
* Array of arrays of (id, score) tuples.
|
|
259
|
+
* Batch search for multiple vectors. Returns [[[id, score], ...], ...].
|
|
221
260
|
*/
|
|
222
261
|
batch_search(vectors: Float32Array, num_vectors: number, k: number): any;
|
|
223
262
|
/**
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* This is significantly faster than calling `insert()` multiple times
|
|
227
|
-
* because it pre-allocates memory and reduces per-call overhead.
|
|
228
|
-
*
|
|
229
|
-
* # Arguments
|
|
230
|
-
*
|
|
231
|
-
* * `batch` - JavaScript array of `[id, Float32Array]` pairs
|
|
232
|
-
*
|
|
233
|
-
* # Errors
|
|
234
|
-
*
|
|
235
|
-
* Returns an error if any vector dimension doesn't match store dimension.
|
|
263
|
+
* Batch insert. Input: `[[id, Float32Array], ...]`.
|
|
236
264
|
*/
|
|
237
265
|
insert_batch(batch: any): void;
|
|
238
266
|
/**
|
|
@@ -240,227 +268,63 @@ export class VectorStore {
|
|
|
240
268
|
*/
|
|
241
269
|
memory_usage(): number;
|
|
242
270
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* Uses a simple weighted fusion of vector search and text search results.
|
|
246
|
-
*
|
|
247
|
-
* # Arguments
|
|
248
|
-
*
|
|
249
|
-
* * `query_vector` - Query vector for similarity search
|
|
250
|
-
* * `text_query` - Text query for payload search
|
|
251
|
-
* * `k` - Number of results to return
|
|
252
|
-
* * `vector_weight` - Weight for vector results (0.0-1.0, default 0.5)
|
|
253
|
-
*
|
|
254
|
-
* # Returns
|
|
255
|
-
*
|
|
256
|
-
* Array of fused results with id, score, and payload.
|
|
271
|
+
* Hybrid search (vector + text). `vector_weight` 0-1 (default 0.5).
|
|
257
272
|
*/
|
|
258
273
|
hybrid_search(query_vector: Float32Array, text_query: string, k: number, vector_weight?: number | null): any;
|
|
259
274
|
/**
|
|
260
|
-
* Creates
|
|
261
|
-
*
|
|
262
|
-
* # Arguments
|
|
263
|
-
*
|
|
264
|
-
* * `dimension` - Vector dimension
|
|
265
|
-
* * `metric` - Distance metric
|
|
266
|
-
* * `mode` - Storage mode: "full", "sq8", or "binary"
|
|
267
|
-
*
|
|
268
|
-
* # Storage Modes
|
|
269
|
-
*
|
|
270
|
-
* - `full`: Best recall, 4 bytes/dimension
|
|
271
|
-
* - `sq8`: 4x compression, ~1% recall loss
|
|
272
|
-
* - `binary`: 32x compression, ~5-10% recall loss
|
|
273
|
-
*
|
|
274
|
-
* # Errors
|
|
275
|
-
*
|
|
276
|
-
* Returns an error if the metric or storage mode is unknown.
|
|
275
|
+
* Creates store with mode: full (4B/dim), sq8 (4x compression), binary (32x).
|
|
277
276
|
*/
|
|
278
277
|
static new_with_mode(dimension: number, metric: string, mode: string): VectorStore;
|
|
279
278
|
/**
|
|
280
|
-
* Creates
|
|
281
|
-
*
|
|
282
|
-
* This is more efficient when you know the approximate number of vectors
|
|
283
|
-
* you'll be inserting, as it avoids repeated memory allocations.
|
|
284
|
-
*
|
|
285
|
-
* # Arguments
|
|
286
|
-
*
|
|
287
|
-
* * `dimension` - Vector dimension
|
|
288
|
-
* * `metric` - Distance metric: "cosine", "euclidean", or "dot"
|
|
289
|
-
* * `capacity` - Number of vectors to pre-allocate space for
|
|
290
|
-
*
|
|
291
|
-
* # Errors
|
|
292
|
-
*
|
|
293
|
-
* Returns an error if the metric is not recognized.
|
|
279
|
+
* Creates store with pre-allocated capacity.
|
|
294
280
|
*/
|
|
295
281
|
static with_capacity(dimension: number, metric: string, capacity: number): VectorStore;
|
|
296
282
|
/**
|
|
297
|
-
* Deletes
|
|
298
|
-
*
|
|
299
|
-
* Use this to clear all persisted data.
|
|
300
|
-
*
|
|
301
|
-
* # Arguments
|
|
302
|
-
*
|
|
303
|
-
* * `db_name` - Name of the `IndexedDB` database to delete
|
|
304
|
-
*
|
|
305
|
-
* # Errors
|
|
306
|
-
*
|
|
307
|
-
* Returns an error if the deletion fails.
|
|
283
|
+
* Deletes `IndexedDB` database.
|
|
308
284
|
*/
|
|
309
285
|
static delete_database(db_name: string): Promise<void>;
|
|
310
286
|
/**
|
|
311
|
-
* Exports
|
|
312
|
-
*
|
|
313
|
-
* The binary format contains:
|
|
314
|
-
* - Header: dimension (u32), metric (u8), count (u64)
|
|
315
|
-
* - For each vector: id (u64), data (f32 array)
|
|
316
|
-
*
|
|
317
|
-
* Use this to persist data to `IndexedDB` or `localStorage`.
|
|
318
|
-
*
|
|
319
|
-
* # Errors
|
|
320
|
-
*
|
|
321
|
-
* This function currently does not return errors but uses `Result`
|
|
322
|
-
* for future extensibility.
|
|
323
|
-
*
|
|
324
|
-
* # Performance
|
|
325
|
-
*
|
|
326
|
-
* Perf: Pre-allocates exact buffer size to avoid reallocations.
|
|
327
|
-
* Throughput: ~1600 MB/s on 10k vectors (768D)
|
|
287
|
+
* Exports to binary format for IndexedDB/localStorage.
|
|
328
288
|
*/
|
|
329
289
|
export_to_bytes(): Uint8Array;
|
|
330
290
|
/**
|
|
331
|
-
* Imports
|
|
332
|
-
*
|
|
333
|
-
* Use this to restore data from `IndexedDB` or `localStorage`.
|
|
334
|
-
*
|
|
335
|
-
* # Errors
|
|
336
|
-
*
|
|
337
|
-
* Returns an error if:
|
|
338
|
-
* - The data is too short or corrupted
|
|
339
|
-
* - The magic number is invalid
|
|
340
|
-
* - The version is unsupported
|
|
341
|
-
* - The metric byte is invalid
|
|
291
|
+
* Imports from binary format.
|
|
342
292
|
*/
|
|
343
293
|
static import_from_bytes(bytes: Uint8Array): VectorStore;
|
|
344
294
|
/**
|
|
345
295
|
* Creates a metadata-only store (no vectors, only payloads).
|
|
346
|
-
*
|
|
347
|
-
* Useful for storing auxiliary data without vector embeddings.
|
|
348
296
|
*/
|
|
349
297
|
static new_metadata_only(): VectorStore;
|
|
350
298
|
/**
|
|
351
|
-
*
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
*
|
|
356
|
-
* # Arguments
|
|
357
|
-
*
|
|
358
|
-
* * `vectors` - Array of query vectors (as flat array with dimension stride)
|
|
359
|
-
* * `num_vectors` - Number of vectors in the array
|
|
360
|
-
* * `k` - Number of results to return
|
|
361
|
-
* * `strategy` - Fusion strategy: "average", "maximum", "rrf"
|
|
362
|
-
* * `rrf_k` - RRF k parameter (only used when strategy = "rrf", default 60)
|
|
363
|
-
*
|
|
364
|
-
* # Returns
|
|
365
|
-
*
|
|
366
|
-
* Array of fused results with id and score.
|
|
299
|
+
* Similarity search with threshold. Operators: >, >=, <, <=, =, !=.
|
|
300
|
+
*/
|
|
301
|
+
similarity_search(query: Float32Array, threshold: number, operator: string, k: number): any;
|
|
302
|
+
/**
|
|
303
|
+
* Multi-query search with fusion. Strategies: average, maximum, rrf.
|
|
367
304
|
*/
|
|
368
305
|
multi_query_search(vectors: Float32Array, num_vectors: number, k: number, strategy: string, rrf_k?: number | null): any;
|
|
369
306
|
/**
|
|
370
|
-
* Searches with metadata filtering.
|
|
371
|
-
*
|
|
372
|
-
* # Arguments
|
|
373
|
-
*
|
|
374
|
-
* * `query` - Query vector
|
|
375
|
-
* * `k` - Number of results
|
|
376
|
-
* * `filter` - JSON filter object (e.g., `{"condition": {"type": "eq", "field": "category", "value": "tech"}}`)
|
|
377
|
-
*
|
|
378
|
-
* # Returns
|
|
379
|
-
*
|
|
380
|
-
* Array of `[id, score, payload]` tuples sorted by relevance.
|
|
307
|
+
* Searches with metadata filtering. Returns [{id, score, payload}].
|
|
381
308
|
*/
|
|
382
309
|
search_with_filter(query: Float32Array, k: number, filter: any): any;
|
|
383
310
|
/**
|
|
384
|
-
* Inserts a vector with
|
|
385
|
-
*
|
|
386
|
-
* # Arguments
|
|
387
|
-
*
|
|
388
|
-
* * `id` - Unique identifier for the vector
|
|
389
|
-
* * `vector` - `Float32Array` of the vector data
|
|
390
|
-
* * `payload` - Optional JSON payload (metadata)
|
|
391
|
-
*
|
|
392
|
-
* # Errors
|
|
393
|
-
*
|
|
394
|
-
* Returns an error if vector dimension doesn't match store dimension.
|
|
311
|
+
* Inserts a vector with ID and optional JSON payload.
|
|
395
312
|
*/
|
|
396
313
|
insert_with_payload(id: bigint, vector: Float32Array, payload: any): void;
|
|
397
314
|
/**
|
|
398
|
-
* Gets a vector by ID.
|
|
399
|
-
*
|
|
400
|
-
* # Arguments
|
|
401
|
-
*
|
|
402
|
-
* * `id` - The vector ID to retrieve
|
|
403
|
-
*
|
|
404
|
-
* # Returns
|
|
405
|
-
*
|
|
406
|
-
* An object with `id`, `vector`, and `payload` fields, or null if not found.
|
|
315
|
+
* Gets a vector by ID. Returns {id, vector, payload} or null.
|
|
407
316
|
*/
|
|
408
317
|
get(id: bigint): any;
|
|
409
318
|
/**
|
|
410
|
-
* Creates a new vector store
|
|
411
|
-
*
|
|
412
|
-
* # Arguments
|
|
413
|
-
*
|
|
414
|
-
* * `dimension` - Vector dimension (e.g., 768 for BERT, 1536 for GPT)
|
|
415
|
-
* * `metric` - Distance metric: "cosine", "euclidean", or "dot"
|
|
416
|
-
*
|
|
417
|
-
* # Errors
|
|
418
|
-
*
|
|
419
|
-
* Returns an error if the metric is not recognized.
|
|
319
|
+
* Creates a new vector store. Metrics: cosine, euclidean, dot, hamming, jaccard.
|
|
420
320
|
*/
|
|
421
321
|
constructor(dimension: number, metric: string);
|
|
422
322
|
/**
|
|
423
|
-
* Loads
|
|
424
|
-
*
|
|
425
|
-
* This method restores all vectors from the browser's `IndexedDB`.
|
|
426
|
-
*
|
|
427
|
-
* # Arguments
|
|
428
|
-
*
|
|
429
|
-
* * `db_name` - Name of the `IndexedDB` database
|
|
430
|
-
*
|
|
431
|
-
* # Errors
|
|
432
|
-
*
|
|
433
|
-
* Returns an error if the database doesn't exist or is corrupted.
|
|
434
|
-
*
|
|
435
|
-
* # Example
|
|
436
|
-
*
|
|
437
|
-
* ```javascript
|
|
438
|
-
* const store = await VectorStore.load("my-vectors");
|
|
439
|
-
* console.log(store.len); // Number of restored vectors
|
|
440
|
-
* ```
|
|
323
|
+
* Loads from `IndexedDB`.
|
|
441
324
|
*/
|
|
442
325
|
static load(db_name: string): Promise<VectorStore>;
|
|
443
326
|
/**
|
|
444
|
-
* Saves
|
|
445
|
-
*
|
|
446
|
-
* This method persists all vectors to the browser's `IndexedDB`,
|
|
447
|
-
* enabling offline-first applications.
|
|
448
|
-
*
|
|
449
|
-
* # Arguments
|
|
450
|
-
*
|
|
451
|
-
* * `db_name` - Name of the `IndexedDB` database
|
|
452
|
-
*
|
|
453
|
-
* # Errors
|
|
454
|
-
*
|
|
455
|
-
* Returns an error if `IndexedDB` is not available or the save fails.
|
|
456
|
-
*
|
|
457
|
-
* # Example
|
|
458
|
-
*
|
|
459
|
-
* ```javascript
|
|
460
|
-
* const store = new VectorStore(768, "cosine");
|
|
461
|
-
* store.insert(1n, vector1);
|
|
462
|
-
* await store.save("my-vectors");
|
|
463
|
-
* ```
|
|
327
|
+
* Saves to `IndexedDB`.
|
|
464
328
|
*/
|
|
465
329
|
save(db_name: string): Promise<void>;
|
|
466
330
|
/**
|
|
@@ -469,15 +333,6 @@ export class VectorStore {
|
|
|
469
333
|
clear(): void;
|
|
470
334
|
/**
|
|
471
335
|
* Inserts a vector with the given ID.
|
|
472
|
-
*
|
|
473
|
-
* # Arguments
|
|
474
|
-
*
|
|
475
|
-
* * `id` - Unique identifier for the vector
|
|
476
|
-
* * `vector` - `Float32Array` of the vector data
|
|
477
|
-
*
|
|
478
|
-
* # Errors
|
|
479
|
-
*
|
|
480
|
-
* Returns an error if vector dimension doesn't match store dimension.
|
|
481
336
|
*/
|
|
482
337
|
insert(id: bigint, vector: Float32Array): void;
|
|
483
338
|
/**
|
|
@@ -485,30 +340,11 @@ export class VectorStore {
|
|
|
485
340
|
*/
|
|
486
341
|
remove(id: bigint): boolean;
|
|
487
342
|
/**
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
* # Arguments
|
|
491
|
-
*
|
|
492
|
-
* * `query` - Query vector as `Float32Array`
|
|
493
|
-
* * `k` - Number of results to return
|
|
494
|
-
*
|
|
495
|
-
* # Returns
|
|
496
|
-
*
|
|
497
|
-
* Array of [id, score] pairs sorted by relevance.
|
|
498
|
-
*
|
|
499
|
-
* # Errors
|
|
500
|
-
*
|
|
501
|
-
* Returns an error if query dimension doesn't match store dimension.
|
|
343
|
+
* k-NN search. Returns [[id, score], ...].
|
|
502
344
|
*/
|
|
503
345
|
search(query: Float32Array, k: number): any;
|
|
504
346
|
/**
|
|
505
|
-
* Pre-allocates memory for
|
|
506
|
-
*
|
|
507
|
-
* Call this before bulk insertions to avoid repeated allocations.
|
|
508
|
-
*
|
|
509
|
-
* # Arguments
|
|
510
|
-
*
|
|
511
|
-
* * `additional` - Number of additional vectors to reserve space for
|
|
347
|
+
* Pre-allocates memory for additional vectors.
|
|
512
348
|
*/
|
|
513
349
|
reserve(additional: number): void;
|
|
514
350
|
/**
|
|
@@ -561,15 +397,24 @@ export interface InitOutput {
|
|
|
561
397
|
readonly graphstore_add_node: (a: number, b: number) => void;
|
|
562
398
|
readonly graphstore_bfs_traverse: (a: number, b: number, c: bigint, d: number, e: number) => void;
|
|
563
399
|
readonly graphstore_clear: (a: number) => void;
|
|
400
|
+
readonly graphstore_dfs_traverse: (a: number, b: number, c: bigint, d: number, e: number) => void;
|
|
564
401
|
readonly graphstore_edge_count: (a: number) => number;
|
|
402
|
+
readonly graphstore_get_all_edge_ids: (a: number, b: number) => void;
|
|
403
|
+
readonly graphstore_get_all_node_ids: (a: number, b: number) => void;
|
|
565
404
|
readonly graphstore_get_edge: (a: number, b: bigint) => number;
|
|
405
|
+
readonly graphstore_get_edges_by_label: (a: number, b: number, c: number, d: number) => void;
|
|
566
406
|
readonly graphstore_get_incoming: (a: number, b: number, c: bigint) => void;
|
|
567
407
|
readonly graphstore_get_neighbors: (a: number, b: number, c: bigint) => void;
|
|
568
408
|
readonly graphstore_get_node: (a: number, b: bigint) => number;
|
|
409
|
+
readonly graphstore_get_nodes_by_label: (a: number, b: number, c: number, d: number) => void;
|
|
569
410
|
readonly graphstore_get_outgoing: (a: number, b: number, c: bigint) => void;
|
|
570
411
|
readonly graphstore_get_outgoing_by_label: (a: number, b: number, c: bigint, d: number, e: number) => void;
|
|
412
|
+
readonly graphstore_has_edge: (a: number, b: bigint) => number;
|
|
413
|
+
readonly graphstore_has_node: (a: number, b: bigint) => number;
|
|
414
|
+
readonly graphstore_in_degree: (a: number, b: bigint) => number;
|
|
571
415
|
readonly graphstore_new: () => number;
|
|
572
416
|
readonly graphstore_node_count: (a: number) => number;
|
|
417
|
+
readonly graphstore_out_degree: (a: number, b: bigint) => number;
|
|
573
418
|
readonly graphstore_remove_edge: (a: number, b: bigint) => void;
|
|
574
419
|
readonly graphstore_remove_node: (a: number, b: bigint) => void;
|
|
575
420
|
readonly vectorstore_batch_search: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
@@ -597,15 +442,16 @@ export interface InitOutput {
|
|
|
597
442
|
readonly vectorstore_save: (a: number, b: number, c: number) => number;
|
|
598
443
|
readonly vectorstore_search: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
599
444
|
readonly vectorstore_search_with_filter: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
|
445
|
+
readonly vectorstore_similarity_search: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
|
|
600
446
|
readonly vectorstore_storage_mode: (a: number, b: number) => void;
|
|
601
447
|
readonly vectorstore_text_search: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
|
|
602
448
|
readonly vectorstore_with_capacity: (a: number, b: number, c: number, d: number, e: number) => void;
|
|
603
449
|
readonly graphnode_id: (a: number) => bigint;
|
|
604
|
-
readonly
|
|
605
|
-
readonly
|
|
606
|
-
readonly
|
|
607
|
-
readonly
|
|
608
|
-
readonly
|
|
450
|
+
readonly __wasm_bindgen_func_elem_640: (a: number, b: number, c: number) => void;
|
|
451
|
+
readonly __wasm_bindgen_func_elem_639: (a: number, b: number) => void;
|
|
452
|
+
readonly __wasm_bindgen_func_elem_198: (a: number, b: number, c: number) => void;
|
|
453
|
+
readonly __wasm_bindgen_func_elem_197: (a: number, b: number) => void;
|
|
454
|
+
readonly __wasm_bindgen_func_elem_689: (a: number, b: number, c: number, d: number) => void;
|
|
609
455
|
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
610
456
|
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
611
457
|
readonly __wbindgen_export3: (a: number) => void;
|
package/velesdb_wasm.js
CHANGED
|
@@ -280,16 +280,16 @@ if (!('encodeInto' in cachedTextEncoder)) {
|
|
|
280
280
|
|
|
281
281
|
let WASM_VECTOR_LEN = 0;
|
|
282
282
|
|
|
283
|
-
function
|
|
284
|
-
wasm.
|
|
283
|
+
function __wasm_bindgen_func_elem_640(arg0, arg1, arg2) {
|
|
284
|
+
wasm.__wasm_bindgen_func_elem_640(arg0, arg1, addHeapObject(arg2));
|
|
285
285
|
}
|
|
286
286
|
|
|
287
|
-
function
|
|
288
|
-
wasm.
|
|
287
|
+
function __wasm_bindgen_func_elem_198(arg0, arg1, arg2) {
|
|
288
|
+
wasm.__wasm_bindgen_func_elem_198(arg0, arg1, addHeapObject(arg2));
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
function
|
|
292
|
-
wasm.
|
|
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
293
|
}
|
|
294
294
|
|
|
295
295
|
const __wbindgen_enum_IdbTransactionMode = ["readonly", "readwrite", "versionchange", "readwriteflush", "cleanup"];
|
|
@@ -622,6 +622,15 @@ export class GraphStore {
|
|
|
622
622
|
const ret = wasm.graphstore_node_count(this.__wbg_ptr);
|
|
623
623
|
return ret >>> 0;
|
|
624
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
|
+
}
|
|
625
634
|
/**
|
|
626
635
|
* Removes an edge by ID.
|
|
627
636
|
* @param {bigint} edge_id
|
|
@@ -668,6 +677,38 @@ export class GraphStore {
|
|
|
668
677
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
669
678
|
}
|
|
670
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
|
+
}
|
|
671
712
|
/**
|
|
672
713
|
* Gets incoming edges to a node.
|
|
673
714
|
* @param {bigint} node_id
|
|
@@ -722,6 +763,96 @@ export class GraphStore {
|
|
|
722
763
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
723
764
|
}
|
|
724
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
|
+
}
|
|
725
856
|
/**
|
|
726
857
|
* Gets outgoing edges filtered by label.
|
|
727
858
|
* @param {bigint} node_id
|
|
@@ -806,6 +937,33 @@ export class GraphStore {
|
|
|
806
937
|
const ret = wasm.graphstore_get_node(this.__wbg_ptr, id);
|
|
807
938
|
return ret === 0 ? undefined : GraphNode.__wrap(ret);
|
|
808
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;
|
|
966
|
+
}
|
|
809
967
|
}
|
|
810
968
|
if (Symbol.dispose) GraphStore.prototype[Symbol.dispose] = GraphStore.prototype.free;
|
|
811
969
|
|
|
@@ -862,20 +1020,7 @@ export class VectorStore {
|
|
|
862
1020
|
wasm.__wbg_vectorstore_free(ptr, 0);
|
|
863
1021
|
}
|
|
864
1022
|
/**
|
|
865
|
-
*
|
|
866
|
-
*
|
|
867
|
-
* This is a simple substring-based search on payload text fields.
|
|
868
|
-
* For full BM25 text search, use the REST API backend.
|
|
869
|
-
*
|
|
870
|
-
* # Arguments
|
|
871
|
-
*
|
|
872
|
-
* * `query` - Text query to search for
|
|
873
|
-
* * `k` - Number of results
|
|
874
|
-
* * `field` - Optional field name to search in (default: searches all string fields)
|
|
875
|
-
*
|
|
876
|
-
* # Returns
|
|
877
|
-
*
|
|
878
|
-
* Array of results with matching payloads.
|
|
1023
|
+
* Text search on payload fields (substring matching).
|
|
879
1024
|
* @param {string} query
|
|
880
1025
|
* @param {number} k
|
|
881
1026
|
* @param {string | null} [field]
|
|
@@ -901,17 +1046,7 @@ export class VectorStore {
|
|
|
901
1046
|
}
|
|
902
1047
|
}
|
|
903
1048
|
/**
|
|
904
|
-
* Batch search for multiple vectors
|
|
905
|
-
*
|
|
906
|
-
* # Arguments
|
|
907
|
-
*
|
|
908
|
-
* * `vectors` - Flat array of query vectors (concatenated)
|
|
909
|
-
* * `num_vectors` - Number of vectors
|
|
910
|
-
* * `k` - Results per query
|
|
911
|
-
*
|
|
912
|
-
* # Returns
|
|
913
|
-
*
|
|
914
|
-
* Array of arrays of (id, score) tuples.
|
|
1049
|
+
* Batch search for multiple vectors. Returns [[[id, score], ...], ...].
|
|
915
1050
|
* @param {Float32Array} vectors
|
|
916
1051
|
* @param {number} num_vectors
|
|
917
1052
|
* @param {number} k
|
|
@@ -935,18 +1070,7 @@ export class VectorStore {
|
|
|
935
1070
|
}
|
|
936
1071
|
}
|
|
937
1072
|
/**
|
|
938
|
-
*
|
|
939
|
-
*
|
|
940
|
-
* This is significantly faster than calling `insert()` multiple times
|
|
941
|
-
* because it pre-allocates memory and reduces per-call overhead.
|
|
942
|
-
*
|
|
943
|
-
* # Arguments
|
|
944
|
-
*
|
|
945
|
-
* * `batch` - JavaScript array of `[id, Float32Array]` pairs
|
|
946
|
-
*
|
|
947
|
-
* # Errors
|
|
948
|
-
*
|
|
949
|
-
* Returns an error if any vector dimension doesn't match store dimension.
|
|
1073
|
+
* Batch insert. Input: `[[id, Float32Array], ...]`.
|
|
950
1074
|
* @param {any} batch
|
|
951
1075
|
*/
|
|
952
1076
|
insert_batch(batch) {
|
|
@@ -991,20 +1115,7 @@ export class VectorStore {
|
|
|
991
1115
|
}
|
|
992
1116
|
}
|
|
993
1117
|
/**
|
|
994
|
-
*
|
|
995
|
-
*
|
|
996
|
-
* Uses a simple weighted fusion of vector search and text search results.
|
|
997
|
-
*
|
|
998
|
-
* # Arguments
|
|
999
|
-
*
|
|
1000
|
-
* * `query_vector` - Query vector for similarity search
|
|
1001
|
-
* * `text_query` - Text query for payload search
|
|
1002
|
-
* * `k` - Number of results to return
|
|
1003
|
-
* * `vector_weight` - Weight for vector results (0.0-1.0, default 0.5)
|
|
1004
|
-
*
|
|
1005
|
-
* # Returns
|
|
1006
|
-
*
|
|
1007
|
-
* Array of fused results with id, score, and payload.
|
|
1118
|
+
* Hybrid search (vector + text). `vector_weight` 0-1 (default 0.5).
|
|
1008
1119
|
* @param {Float32Array} query_vector
|
|
1009
1120
|
* @param {string} text_query
|
|
1010
1121
|
* @param {number} k
|
|
@@ -1031,23 +1142,7 @@ export class VectorStore {
|
|
|
1031
1142
|
}
|
|
1032
1143
|
}
|
|
1033
1144
|
/**
|
|
1034
|
-
* Creates
|
|
1035
|
-
*
|
|
1036
|
-
* # Arguments
|
|
1037
|
-
*
|
|
1038
|
-
* * `dimension` - Vector dimension
|
|
1039
|
-
* * `metric` - Distance metric
|
|
1040
|
-
* * `mode` - Storage mode: "full", "sq8", or "binary"
|
|
1041
|
-
*
|
|
1042
|
-
* # Storage Modes
|
|
1043
|
-
*
|
|
1044
|
-
* - `full`: Best recall, 4 bytes/dimension
|
|
1045
|
-
* - `sq8`: 4x compression, ~1% recall loss
|
|
1046
|
-
* - `binary`: 32x compression, ~5-10% recall loss
|
|
1047
|
-
*
|
|
1048
|
-
* # Errors
|
|
1049
|
-
*
|
|
1050
|
-
* Returns an error if the metric or storage mode is unknown.
|
|
1145
|
+
* Creates store with mode: full (4B/dim), sq8 (4x compression), binary (32x).
|
|
1051
1146
|
* @param {number} dimension
|
|
1052
1147
|
* @param {string} metric
|
|
1053
1148
|
* @param {string} mode
|
|
@@ -1073,20 +1168,7 @@ export class VectorStore {
|
|
|
1073
1168
|
}
|
|
1074
1169
|
}
|
|
1075
1170
|
/**
|
|
1076
|
-
* Creates
|
|
1077
|
-
*
|
|
1078
|
-
* This is more efficient when you know the approximate number of vectors
|
|
1079
|
-
* you'll be inserting, as it avoids repeated memory allocations.
|
|
1080
|
-
*
|
|
1081
|
-
* # Arguments
|
|
1082
|
-
*
|
|
1083
|
-
* * `dimension` - Vector dimension
|
|
1084
|
-
* * `metric` - Distance metric: "cosine", "euclidean", or "dot"
|
|
1085
|
-
* * `capacity` - Number of vectors to pre-allocate space for
|
|
1086
|
-
*
|
|
1087
|
-
* # Errors
|
|
1088
|
-
*
|
|
1089
|
-
* Returns an error if the metric is not recognized.
|
|
1171
|
+
* Creates store with pre-allocated capacity.
|
|
1090
1172
|
* @param {number} dimension
|
|
1091
1173
|
* @param {string} metric
|
|
1092
1174
|
* @param {number} capacity
|
|
@@ -1110,17 +1192,7 @@ export class VectorStore {
|
|
|
1110
1192
|
}
|
|
1111
1193
|
}
|
|
1112
1194
|
/**
|
|
1113
|
-
* Deletes
|
|
1114
|
-
*
|
|
1115
|
-
* Use this to clear all persisted data.
|
|
1116
|
-
*
|
|
1117
|
-
* # Arguments
|
|
1118
|
-
*
|
|
1119
|
-
* * `db_name` - Name of the `IndexedDB` database to delete
|
|
1120
|
-
*
|
|
1121
|
-
* # Errors
|
|
1122
|
-
*
|
|
1123
|
-
* Returns an error if the deletion fails.
|
|
1195
|
+
* Deletes `IndexedDB` database.
|
|
1124
1196
|
* @param {string} db_name
|
|
1125
1197
|
* @returns {Promise<void>}
|
|
1126
1198
|
*/
|
|
@@ -1131,23 +1203,7 @@ export class VectorStore {
|
|
|
1131
1203
|
return takeObject(ret);
|
|
1132
1204
|
}
|
|
1133
1205
|
/**
|
|
1134
|
-
* Exports
|
|
1135
|
-
*
|
|
1136
|
-
* The binary format contains:
|
|
1137
|
-
* - Header: dimension (u32), metric (u8), count (u64)
|
|
1138
|
-
* - For each vector: id (u64), data (f32 array)
|
|
1139
|
-
*
|
|
1140
|
-
* Use this to persist data to `IndexedDB` or `localStorage`.
|
|
1141
|
-
*
|
|
1142
|
-
* # Errors
|
|
1143
|
-
*
|
|
1144
|
-
* This function currently does not return errors but uses `Result`
|
|
1145
|
-
* for future extensibility.
|
|
1146
|
-
*
|
|
1147
|
-
* # Performance
|
|
1148
|
-
*
|
|
1149
|
-
* Perf: Pre-allocates exact buffer size to avoid reallocations.
|
|
1150
|
-
* Throughput: ~1600 MB/s on 10k vectors (768D)
|
|
1206
|
+
* Exports to binary format for IndexedDB/localStorage.
|
|
1151
1207
|
* @returns {Uint8Array}
|
|
1152
1208
|
*/
|
|
1153
1209
|
export_to_bytes() {
|
|
@@ -1177,17 +1233,7 @@ export class VectorStore {
|
|
|
1177
1233
|
return ret !== 0;
|
|
1178
1234
|
}
|
|
1179
1235
|
/**
|
|
1180
|
-
* Imports
|
|
1181
|
-
*
|
|
1182
|
-
* Use this to restore data from `IndexedDB` or `localStorage`.
|
|
1183
|
-
*
|
|
1184
|
-
* # Errors
|
|
1185
|
-
*
|
|
1186
|
-
* Returns an error if:
|
|
1187
|
-
* - The data is too short or corrupted
|
|
1188
|
-
* - The magic number is invalid
|
|
1189
|
-
* - The version is unsupported
|
|
1190
|
-
* - The metric byte is invalid
|
|
1236
|
+
* Imports from binary format.
|
|
1191
1237
|
* @param {Uint8Array} bytes
|
|
1192
1238
|
* @returns {VectorStore}
|
|
1193
1239
|
*/
|
|
@@ -1210,8 +1256,6 @@ export class VectorStore {
|
|
|
1210
1256
|
}
|
|
1211
1257
|
/**
|
|
1212
1258
|
* Creates a metadata-only store (no vectors, only payloads).
|
|
1213
|
-
*
|
|
1214
|
-
* Useful for storing auxiliary data without vector embeddings.
|
|
1215
1259
|
* @returns {VectorStore}
|
|
1216
1260
|
*/
|
|
1217
1261
|
static new_metadata_only() {
|
|
@@ -1219,22 +1263,34 @@ export class VectorStore {
|
|
|
1219
1263
|
return VectorStore.__wrap(ret);
|
|
1220
1264
|
}
|
|
1221
1265
|
/**
|
|
1222
|
-
*
|
|
1223
|
-
*
|
|
1224
|
-
*
|
|
1225
|
-
*
|
|
1226
|
-
*
|
|
1227
|
-
*
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
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.
|
|
1238
1294
|
* @param {Float32Array} vectors
|
|
1239
1295
|
* @param {number} num_vectors
|
|
1240
1296
|
* @param {number} k
|
|
@@ -1262,17 +1318,7 @@ export class VectorStore {
|
|
|
1262
1318
|
}
|
|
1263
1319
|
}
|
|
1264
1320
|
/**
|
|
1265
|
-
* Searches with metadata filtering.
|
|
1266
|
-
*
|
|
1267
|
-
* # Arguments
|
|
1268
|
-
*
|
|
1269
|
-
* * `query` - Query vector
|
|
1270
|
-
* * `k` - Number of results
|
|
1271
|
-
* * `filter` - JSON filter object (e.g., `{"condition": {"type": "eq", "field": "category", "value": "tech"}}`)
|
|
1272
|
-
*
|
|
1273
|
-
* # Returns
|
|
1274
|
-
*
|
|
1275
|
-
* Array of `[id, score, payload]` tuples sorted by relevance.
|
|
1321
|
+
* Searches with metadata filtering. Returns [{id, score, payload}].
|
|
1276
1322
|
* @param {Float32Array} query
|
|
1277
1323
|
* @param {number} k
|
|
1278
1324
|
* @param {any} filter
|
|
@@ -1296,17 +1342,7 @@ export class VectorStore {
|
|
|
1296
1342
|
}
|
|
1297
1343
|
}
|
|
1298
1344
|
/**
|
|
1299
|
-
* Inserts a vector with
|
|
1300
|
-
*
|
|
1301
|
-
* # Arguments
|
|
1302
|
-
*
|
|
1303
|
-
* * `id` - Unique identifier for the vector
|
|
1304
|
-
* * `vector` - `Float32Array` of the vector data
|
|
1305
|
-
* * `payload` - Optional JSON payload (metadata)
|
|
1306
|
-
*
|
|
1307
|
-
* # Errors
|
|
1308
|
-
*
|
|
1309
|
-
* Returns an error if vector dimension doesn't match store dimension.
|
|
1345
|
+
* Inserts a vector with ID and optional JSON payload.
|
|
1310
1346
|
* @param {bigint} id
|
|
1311
1347
|
* @param {Float32Array} vector
|
|
1312
1348
|
* @param {any} payload
|
|
@@ -1327,15 +1363,7 @@ export class VectorStore {
|
|
|
1327
1363
|
}
|
|
1328
1364
|
}
|
|
1329
1365
|
/**
|
|
1330
|
-
* Gets a vector by ID.
|
|
1331
|
-
*
|
|
1332
|
-
* # Arguments
|
|
1333
|
-
*
|
|
1334
|
-
* * `id` - The vector ID to retrieve
|
|
1335
|
-
*
|
|
1336
|
-
* # Returns
|
|
1337
|
-
*
|
|
1338
|
-
* 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.
|
|
1339
1367
|
* @param {bigint} id
|
|
1340
1368
|
* @returns {any}
|
|
1341
1369
|
*/
|
|
@@ -1363,16 +1391,7 @@ export class VectorStore {
|
|
|
1363
1391
|
return ret >>> 0;
|
|
1364
1392
|
}
|
|
1365
1393
|
/**
|
|
1366
|
-
* Creates a new vector store
|
|
1367
|
-
*
|
|
1368
|
-
* # Arguments
|
|
1369
|
-
*
|
|
1370
|
-
* * `dimension` - Vector dimension (e.g., 768 for BERT, 1536 for GPT)
|
|
1371
|
-
* * `metric` - Distance metric: "cosine", "euclidean", or "dot"
|
|
1372
|
-
*
|
|
1373
|
-
* # Errors
|
|
1374
|
-
*
|
|
1375
|
-
* Returns an error if the metric is not recognized.
|
|
1394
|
+
* Creates a new vector store. Metrics: cosine, euclidean, dot, hamming, jaccard.
|
|
1376
1395
|
* @param {number} dimension
|
|
1377
1396
|
* @param {string} metric
|
|
1378
1397
|
*/
|
|
@@ -1396,24 +1415,7 @@ export class VectorStore {
|
|
|
1396
1415
|
}
|
|
1397
1416
|
}
|
|
1398
1417
|
/**
|
|
1399
|
-
* Loads
|
|
1400
|
-
*
|
|
1401
|
-
* This method restores all vectors from the browser's `IndexedDB`.
|
|
1402
|
-
*
|
|
1403
|
-
* # Arguments
|
|
1404
|
-
*
|
|
1405
|
-
* * `db_name` - Name of the `IndexedDB` database
|
|
1406
|
-
*
|
|
1407
|
-
* # Errors
|
|
1408
|
-
*
|
|
1409
|
-
* Returns an error if the database doesn't exist or is corrupted.
|
|
1410
|
-
*
|
|
1411
|
-
* # Example
|
|
1412
|
-
*
|
|
1413
|
-
* ```javascript
|
|
1414
|
-
* const store = await VectorStore.load("my-vectors");
|
|
1415
|
-
* console.log(store.len); // Number of restored vectors
|
|
1416
|
-
* ```
|
|
1418
|
+
* Loads from `IndexedDB`.
|
|
1417
1419
|
* @param {string} db_name
|
|
1418
1420
|
* @returns {Promise<VectorStore>}
|
|
1419
1421
|
*/
|
|
@@ -1424,26 +1426,7 @@ export class VectorStore {
|
|
|
1424
1426
|
return takeObject(ret);
|
|
1425
1427
|
}
|
|
1426
1428
|
/**
|
|
1427
|
-
* Saves
|
|
1428
|
-
*
|
|
1429
|
-
* This method persists all vectors to the browser's `IndexedDB`,
|
|
1430
|
-
* enabling offline-first applications.
|
|
1431
|
-
*
|
|
1432
|
-
* # Arguments
|
|
1433
|
-
*
|
|
1434
|
-
* * `db_name` - Name of the `IndexedDB` database
|
|
1435
|
-
*
|
|
1436
|
-
* # Errors
|
|
1437
|
-
*
|
|
1438
|
-
* Returns an error if `IndexedDB` is not available or the save fails.
|
|
1439
|
-
*
|
|
1440
|
-
* # Example
|
|
1441
|
-
*
|
|
1442
|
-
* ```javascript
|
|
1443
|
-
* const store = new VectorStore(768, "cosine");
|
|
1444
|
-
* store.insert(1n, vector1);
|
|
1445
|
-
* await store.save("my-vectors");
|
|
1446
|
-
* ```
|
|
1429
|
+
* Saves to `IndexedDB`.
|
|
1447
1430
|
* @param {string} db_name
|
|
1448
1431
|
* @returns {Promise<void>}
|
|
1449
1432
|
*/
|
|
@@ -1461,15 +1444,6 @@ export class VectorStore {
|
|
|
1461
1444
|
}
|
|
1462
1445
|
/**
|
|
1463
1446
|
* Inserts a vector with the given ID.
|
|
1464
|
-
*
|
|
1465
|
-
* # Arguments
|
|
1466
|
-
*
|
|
1467
|
-
* * `id` - Unique identifier for the vector
|
|
1468
|
-
* * `vector` - `Float32Array` of the vector data
|
|
1469
|
-
*
|
|
1470
|
-
* # Errors
|
|
1471
|
-
*
|
|
1472
|
-
* Returns an error if vector dimension doesn't match store dimension.
|
|
1473
1447
|
* @param {bigint} id
|
|
1474
1448
|
* @param {Float32Array} vector
|
|
1475
1449
|
*/
|
|
@@ -1498,20 +1472,7 @@ export class VectorStore {
|
|
|
1498
1472
|
return ret !== 0;
|
|
1499
1473
|
}
|
|
1500
1474
|
/**
|
|
1501
|
-
*
|
|
1502
|
-
*
|
|
1503
|
-
* # Arguments
|
|
1504
|
-
*
|
|
1505
|
-
* * `query` - Query vector as `Float32Array`
|
|
1506
|
-
* * `k` - Number of results to return
|
|
1507
|
-
*
|
|
1508
|
-
* # Returns
|
|
1509
|
-
*
|
|
1510
|
-
* Array of [id, score] pairs sorted by relevance.
|
|
1511
|
-
*
|
|
1512
|
-
* # Errors
|
|
1513
|
-
*
|
|
1514
|
-
* Returns an error if query dimension doesn't match store dimension.
|
|
1475
|
+
* k-NN search. Returns [[id, score], ...].
|
|
1515
1476
|
* @param {Float32Array} query
|
|
1516
1477
|
* @param {number} k
|
|
1517
1478
|
* @returns {any}
|
|
@@ -1534,13 +1495,7 @@ export class VectorStore {
|
|
|
1534
1495
|
}
|
|
1535
1496
|
}
|
|
1536
1497
|
/**
|
|
1537
|
-
* Pre-allocates memory for
|
|
1538
|
-
*
|
|
1539
|
-
* Call this before bulk insertions to avoid repeated allocations.
|
|
1540
|
-
*
|
|
1541
|
-
* # Arguments
|
|
1542
|
-
*
|
|
1543
|
-
* * `additional` - Number of additional vectors to reserve space for
|
|
1498
|
+
* Pre-allocates memory for additional vectors.
|
|
1544
1499
|
* @param {number} additional
|
|
1545
1500
|
*/
|
|
1546
1501
|
reserve(additional) {
|
|
@@ -1737,6 +1692,10 @@ function __wbg_get_imports() {
|
|
|
1737
1692
|
const ret = GraphEdge.__wrap(arg0);
|
|
1738
1693
|
return addHeapObject(ret);
|
|
1739
1694
|
};
|
|
1695
|
+
imports.wbg.__wbg_graphnode_new = function(arg0) {
|
|
1696
|
+
const ret = GraphNode.__wrap(arg0);
|
|
1697
|
+
return addHeapObject(ret);
|
|
1698
|
+
};
|
|
1740
1699
|
imports.wbg.__wbg_indexedDB_23c232e00a1e28ad = function() { return handleError(function (arg0) {
|
|
1741
1700
|
const ret = getObject(arg0).indexedDB;
|
|
1742
1701
|
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
@@ -1828,7 +1787,7 @@ function __wbg_get_imports() {
|
|
|
1828
1787
|
const a = state0.a;
|
|
1829
1788
|
state0.a = 0;
|
|
1830
1789
|
try {
|
|
1831
|
-
return
|
|
1790
|
+
return __wasm_bindgen_func_elem_689(a, state0.b, arg0, arg1);
|
|
1832
1791
|
} finally {
|
|
1833
1792
|
state0.a = a;
|
|
1834
1793
|
}
|
|
@@ -1956,7 +1915,7 @@ function __wbg_get_imports() {
|
|
|
1956
1915
|
};
|
|
1957
1916
|
imports.wbg.__wbindgen_cast_59e89726c7c5a9af = function(arg0, arg1) {
|
|
1958
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`.
|
|
1959
|
-
const ret = makeMutClosure(arg0, arg1, wasm.
|
|
1918
|
+
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_197, __wasm_bindgen_func_elem_198);
|
|
1960
1919
|
return addHeapObject(ret);
|
|
1961
1920
|
};
|
|
1962
1921
|
imports.wbg.__wbindgen_cast_9ae0607507abb057 = function(arg0) {
|
|
@@ -1964,16 +1923,16 @@ function __wbg_get_imports() {
|
|
|
1964
1923
|
const ret = arg0;
|
|
1965
1924
|
return addHeapObject(ret);
|
|
1966
1925
|
};
|
|
1967
|
-
imports.wbg.__wbindgen_cast_c060e19e7a983f38 = function(arg0, arg1) {
|
|
1968
|
-
// Cast intrinsic for `Closure(Closure { dtor_idx: 55, function: Function { arguments: [Externref], shim_idx: 56, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
1969
|
-
const ret = makeMutClosure(arg0, arg1, wasm.__wasm_bindgen_func_elem_611, __wasm_bindgen_func_elem_612);
|
|
1970
|
-
return addHeapObject(ret);
|
|
1971
|
-
};
|
|
1972
1926
|
imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
|
|
1973
1927
|
// Cast intrinsic for `F64 -> Externref`.
|
|
1974
1928
|
const ret = arg0;
|
|
1975
1929
|
return addHeapObject(ret);
|
|
1976
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
|
+
};
|
|
1977
1936
|
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
|
1978
1937
|
const ret = getObject(arg0);
|
|
1979
1938
|
return addHeapObject(ret);
|
package/velesdb_wasm_bg.wasm
CHANGED
|
Binary file
|