@wiscale/velesdb-wasm 1.4.1 → 1.6.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/LICENSE +21 -0
- package/README.md +117 -33
- package/package.json +2 -2
- package/velesdb_wasm.d.ts +940 -794
- package/velesdb_wasm.js +1949 -1718
- package/velesdb_wasm_bg.wasm +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2026 Wiscale France
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# VelesDB WASM
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@wiscale/velesdb-wasm)
|
|
4
|
-
[](LICENSE)
|
|
5
5
|
|
|
6
6
|
WebAssembly build of [VelesDB](https://github.com/cyberlife-coder/VelesDB) - vector search in the browser.
|
|
7
7
|
|
|
@@ -11,6 +11,10 @@ WebAssembly build of [VelesDB](https://github.com/cyberlife-coder/VelesDB) - vec
|
|
|
11
11
|
- **SIMD optimized** - Uses WASM SIMD128 for fast distance calculations
|
|
12
12
|
- **Multiple metrics** - Cosine, Euclidean, Dot Product, Hamming, Jaccard
|
|
13
13
|
- **Memory optimization** - SQ8 (4x) and Binary (32x) quantization
|
|
14
|
+
- **Knowledge Graph** - In-memory graph store with BFS/DFS traversal
|
|
15
|
+
- **Agent Memory** - Semantic memory for AI agents (store/query knowledge facts)
|
|
16
|
+
- **VelesQL parser** - Parse and validate VelesQL queries client-side
|
|
17
|
+
- **Sparse search** - Inverted index with RRF hybrid fusion
|
|
14
18
|
- **Lightweight** - Minimal bundle size
|
|
15
19
|
|
|
16
20
|
## Installation
|
|
@@ -89,29 +93,33 @@ class VectorStore {
|
|
|
89
93
|
|
|
90
94
|
// Methods
|
|
91
95
|
insert(id: bigint, vector: Float32Array): void;
|
|
92
|
-
insert_with_payload(id: bigint, vector: Float32Array, payload: object): void;
|
|
96
|
+
insert_with_payload(id: bigint, vector: Float32Array, payload: object): void;
|
|
93
97
|
insert_batch(batch: Array<[bigint, number[]]>): void; // Bulk insert
|
|
94
98
|
search(query: Float32Array, k: number): Array<[bigint, number]>;
|
|
95
|
-
search_with_filter(query: Float32Array, k: number, filter: object): Array<{id, score, payload}>;
|
|
96
|
-
text_search(query: string, k: number, field?: string): Array<{id, score, payload}>;
|
|
97
|
-
get(id: bigint): {id, vector, payload} | null;
|
|
99
|
+
search_with_filter(query: Float32Array, k: number, filter: object): Array<{id, score, payload}>;
|
|
100
|
+
text_search(query: string, k: number, field?: string): Array<{id, score, payload}>;
|
|
101
|
+
get(id: bigint): {id, vector, payload} | null;
|
|
98
102
|
remove(id: bigint): boolean;
|
|
99
103
|
clear(): void;
|
|
100
104
|
reserve(additional: number): void; // Pre-allocate memory
|
|
101
105
|
memory_usage(): number; // Accurate for each storage mode
|
|
102
106
|
|
|
103
|
-
//
|
|
107
|
+
//
|
|
104
108
|
multi_query_search(vectors: Float32Array, num_vectors: number, k: number, strategy?: string, rrf_k?: number): Array<[bigint, number]>;
|
|
105
|
-
hybrid_search(vector: Float32Array, text_query: string, k: number, vector_weight?: number
|
|
109
|
+
hybrid_search(vector: Float32Array, text_query: string, k: number, vector_weight?: number): Array<{id, score, payload}>;
|
|
106
110
|
batch_search(vectors: Float32Array, num_vectors: number, k: number): Array<Array<[bigint, number]>>;
|
|
107
111
|
|
|
112
|
+
// Sparse search (inverted index)
|
|
113
|
+
sparse_insert(doc_id: bigint, indices: Uint32Array, values: Float32Array): void;
|
|
114
|
+
sparse_search(indices: Uint32Array, values: Float32Array, k: number): Array<{doc_id, score}>;
|
|
115
|
+
|
|
108
116
|
// Metadata-only store
|
|
109
117
|
static new_metadata_only(): VectorStore;
|
|
110
118
|
readonly is_metadata_only: boolean;
|
|
111
119
|
}
|
|
112
120
|
```
|
|
113
121
|
|
|
114
|
-
### Filter Format
|
|
122
|
+
### Filter Format
|
|
115
123
|
|
|
116
124
|
```javascript
|
|
117
125
|
// Equality filter
|
|
@@ -256,42 +264,118 @@ The WASM build is optimized for client-side use cases but has some limitations c
|
|
|
256
264
|
|---------|------|-------------|
|
|
257
265
|
| Vector search (NEAR) | ✅ | ✅ |
|
|
258
266
|
| Metadata filtering | ✅ | ✅ |
|
|
259
|
-
|
|
|
260
|
-
|
|
|
261
|
-
|
|
|
262
|
-
|
|
|
263
|
-
|
|
|
267
|
+
| Hybrid search (vector + BM25) | ✅ | ✅ |
|
|
268
|
+
| Full-text search (BM25) | ✅ | ✅ |
|
|
269
|
+
| Multi-query fusion (MQG) | ✅ | ✅ |
|
|
270
|
+
| Batch search | ✅ | ✅ |
|
|
271
|
+
| Sparse search | ✅ | ✅ |
|
|
272
|
+
| Knowledge Graph (nodes, edges, traversal) | ✅ | ✅ |
|
|
273
|
+
| Agent Memory (SemanticMemory) | ✅ | ✅ |
|
|
274
|
+
| VelesQL parsing & validation | ✅ | ✅ |
|
|
275
|
+
| VelesQL query execution | ❌ | ✅ |
|
|
264
276
|
| JOIN operations | ❌ | ✅ |
|
|
265
277
|
| Aggregations (GROUP BY) | ❌ | ✅ |
|
|
266
278
|
| Persistence | IndexedDB | Disk (mmap) |
|
|
267
279
|
| Max vectors | ~100K (browser RAM) | Millions |
|
|
268
280
|
|
|
269
|
-
###
|
|
281
|
+
### VelesQL (Parser Only)
|
|
270
282
|
|
|
271
|
-
|
|
283
|
+
VelesQL parsing and validation are available in WASM. You can parse queries, inspect their AST, and validate syntax client-side. However, query **execution** (running queries against data) requires the REST server.
|
|
272
284
|
|
|
273
285
|
```javascript
|
|
274
|
-
|
|
275
|
-
|
|
286
|
+
import { VelesQL } from '@wiscale/velesdb-wasm';
|
|
287
|
+
|
|
288
|
+
// Parse and inspect a query
|
|
289
|
+
const parsed = VelesQL.parse("SELECT * FROM docs WHERE vector NEAR $v LIMIT 10");
|
|
290
|
+
console.log(parsed.tableName); // "docs"
|
|
291
|
+
console.log(parsed.hasVectorSearch); // true
|
|
292
|
+
console.log(parsed.limit); // 10
|
|
293
|
+
|
|
294
|
+
// Validate syntax
|
|
295
|
+
VelesQL.isValid("SELECT * FROM docs"); // true
|
|
296
|
+
VelesQL.isValid("SELEC * FROM docs"); // false
|
|
297
|
+
|
|
298
|
+
// Parse MATCH (graph) queries
|
|
299
|
+
const match = VelesQL.parse("MATCH (p:Person)-[:KNOWS]->(f:Person) RETURN f.name");
|
|
300
|
+
console.log(match.isMatch); // true
|
|
301
|
+
console.log(match.matchNodeCount); // 2
|
|
302
|
+
console.log(match.matchRelationshipCount); // 1
|
|
303
|
+
```
|
|
276
304
|
|
|
277
|
-
|
|
278
|
-
// Use:
|
|
279
|
-
const results = store.search(queryVector, 10);
|
|
305
|
+
### Knowledge Graph (GraphStore)
|
|
280
306
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
307
|
+
Build and traverse in-memory knowledge graphs entirely in the browser:
|
|
308
|
+
|
|
309
|
+
```javascript
|
|
310
|
+
import { GraphStore, GraphNode, GraphEdge } from '@wiscale/velesdb-wasm';
|
|
311
|
+
|
|
312
|
+
const graph = new GraphStore();
|
|
313
|
+
|
|
314
|
+
// Create nodes
|
|
315
|
+
const alice = new GraphNode(1n, "Person");
|
|
316
|
+
alice.set_string_property("name", "Alice");
|
|
317
|
+
const bob = new GraphNode(2n, "Person");
|
|
318
|
+
bob.set_string_property("name", "Bob");
|
|
319
|
+
|
|
320
|
+
graph.add_node(alice);
|
|
321
|
+
graph.add_node(bob);
|
|
322
|
+
|
|
323
|
+
// Create edges
|
|
324
|
+
const edge = new GraphEdge(1n, 1n, 2n, "KNOWS");
|
|
325
|
+
graph.add_edge(edge);
|
|
326
|
+
|
|
327
|
+
// Traverse
|
|
328
|
+
const neighbors = graph.get_neighbors(1n); // [2n]
|
|
329
|
+
const outgoing = graph.get_outgoing(1n); // [GraphEdge]
|
|
330
|
+
const bfsResults = graph.bfs_traverse(1n, 3, 100); // BFS up to depth 3
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Agent Memory (SemanticMemory)
|
|
334
|
+
|
|
335
|
+
Store and retrieve knowledge facts by semantic similarity for AI agent workloads:
|
|
336
|
+
|
|
337
|
+
```javascript
|
|
338
|
+
import { SemanticMemory } from '@wiscale/velesdb-wasm';
|
|
339
|
+
|
|
340
|
+
const memory = new SemanticMemory(384);
|
|
341
|
+
|
|
342
|
+
// Store knowledge with embedding vectors
|
|
343
|
+
memory.store(1n, "Paris is the capital of France", embedding1);
|
|
344
|
+
memory.store(2n, "Berlin is the capital of Germany", embedding2);
|
|
345
|
+
|
|
346
|
+
// Query by similarity
|
|
347
|
+
const results = memory.query(queryEmbedding, 5);
|
|
348
|
+
// [{id, score, content}, ...]
|
|
349
|
+
|
|
350
|
+
console.log(memory.len); // 2
|
|
351
|
+
console.log(memory.dimension); // 384
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
### Sparse Search (SparseIndex)
|
|
355
|
+
|
|
356
|
+
Inverted-index search with sparse vectors and RRF hybrid fusion:
|
|
357
|
+
|
|
358
|
+
```javascript
|
|
359
|
+
import { SparseIndex, hybrid_search_fuse } from '@wiscale/velesdb-wasm';
|
|
360
|
+
|
|
361
|
+
const index = new SparseIndex();
|
|
362
|
+
|
|
363
|
+
// Insert sparse vectors (term indices + weights)
|
|
364
|
+
index.insert(1n, new Uint32Array([10, 20, 30]), new Float32Array([1.0, 0.5, 0.3]));
|
|
365
|
+
index.insert(2n, new Uint32Array([10, 40]), new Float32Array([0.8, 1.2]));
|
|
366
|
+
|
|
367
|
+
// Search
|
|
368
|
+
const results = index.search(new Uint32Array([10, 20]), new Float32Array([1.0, 1.0]), 5);
|
|
369
|
+
|
|
370
|
+
// Fuse dense + sparse results with RRF
|
|
371
|
+
const fused = hybrid_search_fuse(denseResults, sparseResults, 60, 10);
|
|
286
372
|
```
|
|
287
373
|
|
|
288
374
|
### When to Use REST Backend
|
|
289
375
|
|
|
290
376
|
Consider using the [REST server](https://github.com/cyberlife-coder/VelesDB) if you need:
|
|
291
377
|
|
|
292
|
-
- **
|
|
293
|
-
- **Hybrid search** - Combine semantic + keyword search
|
|
294
|
-
- **Knowledge Graph** - Entity relationships and graph traversal
|
|
378
|
+
- **VelesQL query execution** - Running queries against data (JOINs, aggregations, server-side filtering)
|
|
295
379
|
- **Large datasets** - More than 100K vectors
|
|
296
380
|
- **Server-side processing** - Centralized vector database
|
|
297
381
|
|
|
@@ -304,15 +388,15 @@ const store = new VectorStore(768, 'cosine');
|
|
|
304
388
|
const results = store.search(query, 10);
|
|
305
389
|
|
|
306
390
|
// REST (server-side) - using fetch
|
|
307
|
-
const response = await fetch('http://localhost:8080/
|
|
391
|
+
const response = await fetch('http://localhost:8080/collections/docs/search', {
|
|
308
392
|
method: 'POST',
|
|
309
393
|
headers: { 'Content-Type': 'application/json' },
|
|
310
|
-
body: JSON.stringify({ vector: query,
|
|
394
|
+
body: JSON.stringify({ vector: query, top_k: 10 })
|
|
311
395
|
});
|
|
312
396
|
const results = await response.json();
|
|
313
397
|
|
|
314
398
|
// REST with VelesQL
|
|
315
|
-
const response = await fetch('http://localhost:8080/
|
|
399
|
+
const response = await fetch('http://localhost:8080/query', {
|
|
316
400
|
method: 'POST',
|
|
317
401
|
headers: { 'Content-Type': 'application/json' },
|
|
318
402
|
body: JSON.stringify({
|
|
@@ -346,6 +430,6 @@ Typical latencies on modern browsers:
|
|
|
346
430
|
|
|
347
431
|
## License
|
|
348
432
|
|
|
349
|
-
|
|
433
|
+
MIT License (bindings). The core engine (`velesdb-core` and `velesdb-server`) is under VelesDB Core License 1.0.
|
|
350
434
|
|
|
351
|
-
See [LICENSE](https://github.com/cyberlife-coder/VelesDB/blob/main/LICENSE) for
|
|
435
|
+
See [LICENSE](./LICENSE) for WASM bindings license, [root LICENSE](https://github.com/cyberlife-coder/VelesDB/blob/main/LICENSE) for core engine.
|
package/package.json
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"Julien Lange <contact@wiscale.fr>"
|
|
6
6
|
],
|
|
7
7
|
"description": "VelesDB for WebAssembly - Vector search in the browser",
|
|
8
|
-
"version": "1.
|
|
9
|
-
"license": "
|
|
8
|
+
"version": "1.6.0",
|
|
9
|
+
"license": "MIT",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/cyberlife-coder/velesdb"
|