ruvector 0.1.21 → 0.1.22

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.
Files changed (4) hide show
  1. package/README.md +392 -162
  2. package/dist/index.js +59 -14
  3. package/dist/index.mjs +59 -14
  4. package/package.json +59 -14
package/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  [![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
4
4
  [![npm](https://img.shields.io/npm/v/ruvector.svg)](https://www.npmjs.com/package/ruvector)
5
5
  [![npm downloads](https://img.shields.io/npm/dm/ruvector.svg)](https://www.npmjs.com/package/ruvector)
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
7
+ [![Node.js](https://img.shields.io/badge/Node.js-16+-green.svg)](https://nodejs.org/)
6
8
 
7
9
  **A distributed vector database that learns.** Store embeddings, query with Cypher, scale horizontally, and let the index improve itself through Graph Neural Networks.
8
10
 
@@ -10,20 +12,21 @@
10
12
  npx ruvector
11
13
  ```
12
14
 
13
- > **All-in-One Package**: The `ruvector` package includes everything — vector search, graph queries, GNN layers, distributed clustering, AI routing, and WASM support. No additional packages needed.
15
+ > **All-in-One Package**: The `ruvector` package includes everything — vector search, graph queries, GNN layers, AI agent routing, and WASM support. No additional packages needed.
14
16
 
15
- ## What Problem Does RuVector Solve?
17
+ ## Why RuVector?
16
18
 
17
- Traditional vector databases just store and search. When you ask "find similar items," they return results but never get smarter.
19
+ Traditional vector databases just store and search. When you ask "find similar items," they return results but never get smarter. They can't handle complex relationships. They don't optimize your AI costs.
18
20
 
19
- **RuVector is different:**
21
+ **RuVector is built for the agentic AI era:**
20
22
 
21
- 1. **Store vectors** like any vector DB (embeddings from OpenAI, Cohere, etc.)
22
- 2. **Query with Cypher** like Neo4j (`MATCH (a)-[:SIMILAR]->(b) RETURN b`)
23
- 3. **The index learns** GNN layers make search results improve over time
24
- 4. **Route AI requests** Semantic routing and FastGRNN neural inference for LLM optimization
25
- 5. **Compress automatically** 2-32x memory reduction with adaptive tiered compression
26
- 6. **Run anywhere** Node.js, browser (WASM), or native Rust
23
+ | Challenge | RuVector Solution |
24
+ |-----------|-------------------|
25
+ | RAG retrieval quality plateaus | **Self-learning GNN** improves results over time |
26
+ | Knowledge graphs need separate DB | **Cypher queries** built-in (Neo4j syntax) |
27
+ | LLM costs spiral out of control | **AI Router** sends simple queries to cheaper models |
28
+ | Memory usage explodes at scale | **Adaptive compression** (2-32x reduction) |
29
+ | Can't run AI in the browser | **Full WASM support** for client-side inference |
27
30
 
28
31
  ## Quick Start
29
32
 
@@ -35,102 +38,215 @@ npm install ruvector
35
38
 
36
39
  # Or try instantly without installing
37
40
  npx ruvector
41
+
42
+ # With yarn
43
+ yarn add ruvector
44
+
45
+ # With pnpm
46
+ pnpm add ruvector
38
47
  ```
39
48
 
40
- ### Basic Usage
49
+ ### Basic Vector Search
41
50
 
42
51
  ```javascript
43
- const ruvector = require('ruvector');
52
+ const { VectorDB } = require('ruvector');
44
53
 
45
- // Create a vector database
46
- const db = new ruvector.VectorDB(384); // 384 dimensions
54
+ // Create a vector database (384 = OpenAI ada-002 dimensions)
55
+ const db = new VectorDB(384);
47
56
 
48
57
  // Insert vectors with metadata
49
- db.insert('doc1', embedding1, { title: 'Introduction', category: 'tech' });
50
- db.insert('doc2', embedding2, { title: 'Advanced Topics', category: 'tech' });
58
+ await db.insert('doc1', embedding1, {
59
+ title: 'Introduction to AI',
60
+ category: 'tech',
61
+ date: '2024-01-15'
62
+ });
51
63
 
52
- // Search for similar vectors
53
- const results = db.search(queryEmbedding, 10);
54
- console.log(results); // Top 10 similar documents
64
+ // Semantic search
65
+ const results = await db.search(queryEmbedding, 10);
55
66
 
56
67
  // Filter by metadata
57
- const filtered = db.search(queryEmbedding, 10, { category: 'tech' });
68
+ const filtered = await db.search(queryEmbedding, 10, {
69
+ category: 'tech',
70
+ date: { $gte: '2024-01-01' }
71
+ });
72
+ ```
73
+
74
+ ### RAG (Retrieval-Augmented Generation)
75
+
76
+ ```javascript
77
+ const { VectorDB } = require('ruvector');
78
+ const OpenAI = require('openai');
79
+
80
+ const db = new VectorDB(1536); // text-embedding-3-small dimensions
81
+ const openai = new OpenAI();
82
+
83
+ // Index your documents
84
+ async function indexDocument(doc) {
85
+ const embedding = await openai.embeddings.create({
86
+ model: 'text-embedding-3-small',
87
+ input: doc.content
88
+ });
89
+ await db.insert(doc.id, embedding.data[0].embedding, {
90
+ title: doc.title,
91
+ content: doc.content
92
+ });
93
+ }
94
+
95
+ // RAG query
96
+ async function ragQuery(question) {
97
+ // 1. Embed the question
98
+ const questionEmb = await openai.embeddings.create({
99
+ model: 'text-embedding-3-small',
100
+ input: question
101
+ });
102
+
103
+ // 2. Retrieve relevant context
104
+ const context = await db.search(questionEmb.data[0].embedding, 5);
105
+
106
+ // 3. Generate answer with context
107
+ const response = await openai.chat.completions.create({
108
+ model: 'gpt-4-turbo',
109
+ messages: [{
110
+ role: 'user',
111
+ content: `Context:\n${context.map(c => c.metadata.content).join('\n\n')}
112
+
113
+ Question: ${question}
114
+ Answer based only on the context above:`
115
+ }]
116
+ });
117
+
118
+ return response.choices[0].message.content;
119
+ }
58
120
  ```
59
121
 
60
- ### Graph Queries (Cypher)
122
+ ### Knowledge Graphs (Cypher)
61
123
 
62
124
  ```javascript
63
125
  const { GraphDB } = require('ruvector');
64
126
 
65
127
  const graph = new GraphDB();
66
128
 
67
- // Create nodes and relationships
68
- graph.execute("CREATE (a:Person {name: 'Alice'})-[:KNOWS]->(b:Person {name: 'Bob'})");
69
- graph.execute("CREATE (b)-[:WORKS_AT]->(c:Company {name: 'TechCorp'})");
129
+ // Create entities and relationships
130
+ graph.execute(`
131
+ CREATE (alice:Person {name: 'Alice', role: 'Engineer'})
132
+ CREATE (bob:Person {name: 'Bob', role: 'Manager'})
133
+ CREATE (techcorp:Company {name: 'TechCorp', industry: 'AI'})
134
+ CREATE (alice)-[:WORKS_AT {since: 2022}]->(techcorp)
135
+ CREATE (bob)-[:WORKS_AT {since: 2020}]->(techcorp)
136
+ CREATE (alice)-[:REPORTS_TO]->(bob)
137
+ `);
70
138
 
71
139
  // Query relationships
72
- const friends = graph.execute("MATCH (p:Person)-[:KNOWS]->(friend) RETURN friend.name");
73
- const colleagues = graph.execute(`
74
- MATCH (p:Person {name: 'Alice'})-[:KNOWS]->(friend)-[:WORKS_AT]->(company)
75
- RETURN friend.name, company.name
140
+ const team = graph.execute(`
141
+ MATCH (p:Person)-[:WORKS_AT]->(c:Company {name: 'TechCorp'})
142
+ RETURN p.name, p.role
76
143
  `);
77
- ```
78
144
 
79
- ### GNN-Enhanced Search
145
+ // Find paths
146
+ const chain = graph.execute(`
147
+ MATCH path = (a:Person {name: 'Alice'})-[:REPORTS_TO*1..3]->(manager)
148
+ RETURN path
149
+ `);
80
150
 
81
- ```javascript
82
- const { GNNLayer } = require('ruvector');
151
+ // Combine with vector search
152
+ const similarPeople = graph.execute(`
153
+ MATCH (p:Person)
154
+ WHERE vector.similarity(p.embedding, $queryEmbedding) > 0.8
155
+ RETURN p ORDER BY vector.similarity(p.embedding, $queryEmbedding) DESC
156
+ LIMIT 10
157
+ `);
158
+ ```
83
159
 
84
- // Create a GNN layer (input_dim, output_dim, num_heads)
85
- const layer = new GNNLayer(384, 512, 4);
160
+ ### GNN-Enhanced Search (Self-Learning)
86
161
 
87
- // Enhance query with graph context
88
- const query = getQueryEmbedding();
89
- const neighbors = getNeighborEmbeddings();
90
- const weights = computeEdgeWeights();
162
+ ```javascript
163
+ const { GNNLayer, VectorDB } = require('ruvector');
91
164
 
92
- const enhanced = layer.forward(query, neighbors, weights);
93
- // Use enhanced embedding for better search results
94
- ```
165
+ // Create GNN layer for query enhancement
166
+ const gnn = new GNNLayer(384, 512, 4); // input_dim, output_dim, num_heads
95
167
 
96
- ### Compression (2-32x Memory Savings)
168
+ // The GNN learns from your search patterns
169
+ async function enhancedSearch(query) {
170
+ // Get initial results
171
+ const neighbors = await db.search(query, 20);
97
172
 
98
- ```javascript
99
- const { compress, decompress, CompressionTier } = require('ruvector');
173
+ // Compute attention weights based on user clicks/relevance
174
+ const weights = computeRelevanceWeights(neighbors);
100
175
 
101
- // Automatic tier selection based on quality threshold
102
- const compressed = compress(embedding, 0.3); // 30% quality threshold
176
+ // GNN enhances the query using graph structure
177
+ const enhancedQuery = gnn.forward(query,
178
+ neighbors.map(n => n.embedding),
179
+ weights
180
+ );
103
181
 
104
- // Or specify tier explicitly
105
- const pq8 = compress(embedding, CompressionTier.PQ8); // 8x compression
106
- const pq4 = compress(embedding, CompressionTier.PQ4); // 16x compression
107
- const binary = compress(embedding, CompressionTier.Binary); // 32x compression
182
+ // Re-rank with enhanced understanding
183
+ return db.search(enhancedQuery, 10);
184
+ }
108
185
 
109
- // Decompress when needed
110
- const restored = decompress(compressed);
186
+ // Train on user feedback
187
+ gnn.train({
188
+ queries: historicalQueries,
189
+ clicks: userClickData,
190
+ relevance: expertLabels
191
+ }, { epochs: 100 });
111
192
  ```
112
193
 
113
194
  ### AI Agent Routing (Tiny Dancer)
114
195
 
196
+ Route queries to the optimal LLM based on complexity — save 60-80% on API costs:
197
+
115
198
  ```javascript
116
199
  const { Router } = require('ruvector');
117
200
 
118
- // Create router for AI model selection
119
201
  const router = new Router({
120
202
  confidenceThreshold: 0.85,
121
- maxUncertainty: 0.15
203
+ maxUncertainty: 0.15,
204
+ enableCircuitBreaker: true
122
205
  });
123
206
 
124
- // Route to optimal model based on query complexity
125
- const candidates = [
126
- { id: 'gpt-4', embedding: gpt4Embedding, cost: 0.03 },
127
- { id: 'gpt-3.5', embedding: gpt35Embedding, cost: 0.002 },
128
- { id: 'claude', embedding: claudeEmbedding, cost: 0.015 }
207
+ // Define your model candidates
208
+ const models = [
209
+ { id: 'gpt-4-turbo', embedding: gpt4Emb, cost: 0.03, quality: 0.95 },
210
+ { id: 'gpt-3.5-turbo', embedding: gpt35Emb, cost: 0.002, quality: 0.80 },
211
+ { id: 'claude-3-haiku', embedding: haikuEmb, cost: 0.001, quality: 0.75 },
212
+ { id: 'llama-3-8b', embedding: llamaEmb, cost: 0.0005, quality: 0.70 }
129
213
  ];
130
214
 
131
- const decision = router.route(queryEmbedding, candidates);
132
- console.log(decision);
133
- // { candidateId: 'gpt-3.5', confidence: 0.92, useLightweight: true }
215
+ async function smartComplete(prompt) {
216
+ const promptEmb = await embed(prompt);
217
+
218
+ // Router decides optimal model
219
+ const decision = router.route(promptEmb, models);
220
+
221
+ console.log(`Routing to ${decision.candidateId} (confidence: ${decision.confidence})`);
222
+ // Output: "Routing to gpt-3.5-turbo (confidence: 0.92)"
223
+
224
+ // Call the selected model
225
+ return callModel(decision.candidateId, prompt);
226
+ }
227
+ ```
228
+
229
+ ### Compression (2-32x Memory Savings)
230
+
231
+ ```javascript
232
+ const { compress, decompress, CompressionTier } = require('ruvector');
233
+
234
+ // Automatic tier selection
235
+ const auto = compress(embedding, 0.3); // 30% quality threshold
236
+
237
+ // Explicit tiers
238
+ const f16 = compress(embedding, CompressionTier.F16); // 2x compression
239
+ const pq8 = compress(embedding, CompressionTier.PQ8); // 8x compression
240
+ const pq4 = compress(embedding, CompressionTier.PQ4); // 16x compression
241
+ const binary = compress(embedding, CompressionTier.Binary); // 32x compression
242
+
243
+ // Adaptive tiering based on access frequency
244
+ db.enableAdaptiveCompression({
245
+ hotThreshold: 0.8, // Keep hot data in f32
246
+ warmThreshold: 0.4, // Compress to f16
247
+ coldThreshold: 0.1, // Compress to PQ8
248
+ archiveThreshold: 0.01 // Compress to binary
249
+ });
134
250
  ```
135
251
 
136
252
  ## CLI Usage
@@ -140,51 +256,79 @@ console.log(decision);
140
256
  npx ruvector info
141
257
 
142
258
  # Initialize a new index
143
- npx ruvector init my-index.bin --dimension 384 --type hnsw
259
+ npx ruvector init my-index --dimension 384 --type hnsw
144
260
 
145
- # Insert vectors from JSON file
146
- npx ruvector insert my-index.bin vectors.json
261
+ # Insert vectors from JSON/JSONL
262
+ npx ruvector insert my-index vectors.json
263
+ npx ruvector insert my-index vectors.jsonl --format jsonl
147
264
 
148
- # Search with a query vector
149
- npx ruvector search my-index.bin --query "[0.1, 0.2, ...]" -k 10
265
+ # Search with a query
266
+ npx ruvector search my-index --query "[0.1, 0.2, ...]" -k 10
267
+ npx ruvector search my-index --text "machine learning" -k 10 # Auto-embed
150
268
 
151
269
  # Show index statistics
152
- npx ruvector stats my-index.bin
270
+ npx ruvector stats my-index
153
271
 
154
272
  # Run performance benchmarks
155
273
  npx ruvector benchmark --dimension 384 --num-vectors 10000
274
+
275
+ # Export/import
276
+ npx ruvector export my-index backup.bin
277
+ npx ruvector import backup.bin restored-index
156
278
  ```
157
279
 
158
- ## Features
280
+ ## Integrations
159
281
 
160
- ### Core Capabilities
282
+ ### LangChain
161
283
 
162
- | Feature | Description |
163
- |---------|-------------|
164
- | **Vector Search** | HNSW index, <0.5ms latency, SIMD acceleration |
165
- | **Cypher Queries** | `MATCH`, `WHERE`, `CREATE`, `RETURN` — Neo4j syntax |
166
- | **GNN Layers** | Multi-head attention on graph topology |
167
- | **Hyperedges** | Connect 3+ nodes simultaneously |
168
- | **Metadata Filtering** | Combine semantic + structured search |
169
- | **Collections** | Namespace isolation, multi-tenancy |
284
+ ```javascript
285
+ const { RuVectorStore } = require('ruvector/langchain');
286
+ const { OpenAIEmbeddings } = require('@langchain/openai');
170
287
 
171
- ### AI & ML
288
+ const vectorStore = new RuVectorStore(
289
+ new OpenAIEmbeddings(),
290
+ { dimension: 1536 }
291
+ );
172
292
 
173
- | Feature | Description |
174
- |---------|-------------|
175
- | **Tensor Compression** | f32→f16→PQ8→PQ4→Binary (2-32x reduction) |
176
- | **Differentiable Search** | Soft attention k-NN for end-to-end training |
177
- | **Semantic Router** | Route queries to optimal endpoints |
178
- | **Tiny Dancer** | FastGRNN neural inference for LLM cost optimization |
293
+ await vectorStore.addDocuments(documents);
294
+ const results = await vectorStore.similaritySearch("query", 5);
295
+ ```
296
+
297
+ ### LlamaIndex
298
+
299
+ ```javascript
300
+ const { RuVectorIndex } = require('ruvector/llamaindex');
301
+
302
+ const index = new RuVectorIndex({
303
+ dimension: 384,
304
+ enableGNN: true
305
+ });
179
306
 
180
- ### Platform Support
307
+ await index.insert(documents);
308
+ const queryEngine = index.asQueryEngine();
309
+ const response = await queryEngine.query("What is machine learning?");
310
+ ```
311
+
312
+ ### OpenAI / Anthropic
313
+
314
+ ```javascript
315
+ const { createEmbedder } = require('ruvector');
181
316
 
182
- | Platform | Package | Notes |
183
- |----------|---------|-------|
184
- | **Node.js** | `ruvector` | Native bindings via napi-rs |
185
- | **Browser** | `@ruvector/wasm` | Full WASM support |
186
- | **Bun** | `ruvector` | Native bindings |
187
- | **Deno** | `@ruvector/wasm` | WASM fallback |
317
+ // OpenAI
318
+ const openaiEmbed = createEmbedder('openai', {
319
+ model: 'text-embedding-3-small'
320
+ });
321
+
322
+ // Anthropic (via Voyage)
323
+ const anthropicEmbed = createEmbedder('voyage', {
324
+ model: 'voyage-2'
325
+ });
326
+
327
+ // Cohere
328
+ const cohereEmbed = createEmbedder('cohere', {
329
+ model: 'embed-english-v3.0'
330
+ });
331
+ ```
188
332
 
189
333
  ## Benchmarks
190
334
 
@@ -192,20 +336,37 @@ npx ruvector benchmark --dimension 384 --num-vectors 10000
192
336
  |-----------|------------|------|------------|
193
337
  | **HNSW Search (k=10)** | 384 | 61µs | 16,400 QPS |
194
338
  | **HNSW Search (k=100)** | 384 | 164µs | 6,100 QPS |
195
- | **Cosine Distance** | 1536 | 143ns | 7M ops/sec |
339
+ | **Cosine Similarity** | 1536 | 143ns | 7M ops/sec |
196
340
  | **Dot Product** | 384 | 33ns | 30M ops/sec |
197
341
  | **Insert** | 384 | 20µs | 50,000/sec |
342
+ | **GNN Forward** | 384→512 | 89µs | 11,200/sec |
343
+ | **Compression (PQ8)** | 384 | 12µs | 83,000/sec |
198
344
 
199
345
  Run your own benchmarks:
200
346
  ```bash
201
- npx ruvector benchmark --dimension 384 --num-vectors 10000
347
+ npx ruvector benchmark --dimension 384 --num-vectors 100000
202
348
  ```
203
349
 
350
+ ## Comparison
351
+
352
+ | Feature | RuVector | Pinecone | Qdrant | ChromaDB | Milvus | Weaviate |
353
+ |---------|----------|----------|--------|----------|--------|----------|
354
+ | **Latency (p50)** | **61µs** | ~2ms | ~1ms | ~50ms | ~5ms | ~3ms |
355
+ | **Graph Queries** | ✅ Cypher | ❌ | ❌ | ❌ | ❌ | ✅ GraphQL |
356
+ | **Self-Learning** | ✅ GNN | ❌ | ❌ | ❌ | ❌ | ❌ |
357
+ | **AI Routing** | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
358
+ | **Browser/WASM** | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
359
+ | **Compression** | 2-32x | ❌ | ✅ | ❌ | ✅ | ✅ |
360
+ | **Hybrid Search** | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ |
361
+ | **Multi-tenancy** | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
362
+ | **Open Source** | ✅ MIT | ❌ | ✅ Apache | ✅ Apache | ✅ Apache | ✅ BSD |
363
+ | **Pricing** | Free | $70+/mo | Free | Free | Free | Free |
364
+
204
365
  ## npm Packages
205
366
 
206
367
  | Package | Description |
207
368
  |---------|-------------|
208
- | [`ruvector`](https://www.npmjs.com/package/ruvector) | All-in-one package (recommended) |
369
+ | [`ruvector`](https://www.npmjs.com/package/ruvector) | **All-in-one package (recommended)** |
209
370
  | [`@ruvector/wasm`](https://www.npmjs.com/package/@ruvector/wasm) | Browser/WASM bindings |
210
371
  | [`@ruvector/graph`](https://www.npmjs.com/package/@ruvector/graph) | Graph database with Cypher |
211
372
  | [`@ruvector/gnn`](https://www.npmjs.com/package/@ruvector/gnn) | Graph Neural Network layers |
@@ -228,13 +389,25 @@ npm install @ruvector/graph @ruvector/gnn
228
389
  class VectorDB {
229
390
  constructor(dimension: number, options?: VectorDBOptions);
230
391
 
231
- insert(id: string, values: number[], metadata?: object): void;
232
- insertBatch(vectors: Vector[]): void;
233
- search(query: number[], k?: number, filter?: object): SearchResult[];
234
- get(id: string): Vector | null;
235
- delete(id: string): boolean;
236
- save(path: string): void;
237
- static load(path: string): VectorDB;
392
+ // CRUD operations
393
+ insert(id: string, values: number[], metadata?: object): Promise<void>;
394
+ insertBatch(vectors: Vector[], options?: BatchOptions): Promise<void>;
395
+ get(id: string): Promise<Vector | null>;
396
+ update(id: string, values?: number[], metadata?: object): Promise<void>;
397
+ delete(id: string): Promise<boolean>;
398
+
399
+ // Search
400
+ search(query: number[], k?: number, filter?: Filter): Promise<SearchResult[]>;
401
+ hybridSearch(query: number[], text: string, k?: number): Promise<SearchResult[]>;
402
+
403
+ // Persistence
404
+ save(path: string): Promise<void>;
405
+ static load(path: string): Promise<VectorDB>;
406
+
407
+ // Management
408
+ stats(): Promise<IndexStats>;
409
+ optimize(): Promise<void>;
410
+ clear(): Promise<void>;
238
411
  }
239
412
  ```
240
413
 
@@ -242,12 +415,19 @@ class VectorDB {
242
415
 
243
416
  ```typescript
244
417
  class GraphDB {
245
- constructor();
418
+ constructor(options?: GraphDBOptions);
419
+
420
+ // Cypher execution
421
+ execute(cypher: string, params?: object): QueryResult;
246
422
 
247
- execute(cypher: string): QueryResult;
423
+ // Direct API
248
424
  createNode(label: string, properties: object): string;
249
- createRelationship(from: string, to: string, type: string): void;
250
- createHyperedge(nodeIds: string[], type: string): string;
425
+ createRelationship(from: string, to: string, type: string, props?: object): void;
426
+ createHyperedge(nodeIds: string[], type: string, props?: object): string;
427
+
428
+ // Traversal
429
+ shortestPath(from: string, to: string): Path | null;
430
+ neighbors(nodeId: string, depth?: number): Node[];
251
431
  }
252
432
  ```
253
433
 
@@ -257,103 +437,148 @@ class GraphDB {
257
437
  class GNNLayer {
258
438
  constructor(inputDim: number, outputDim: number, numHeads: number);
259
439
 
440
+ // Inference
260
441
  forward(query: number[], neighbors: number[][], weights: number[]): number[];
261
- train(data: TrainingData, epochs: number): void;
442
+
443
+ // Training
444
+ train(data: TrainingData, config?: TrainingConfig): TrainingMetrics;
445
+ save(path: string): void;
446
+ static load(path: string): GNNLayer;
262
447
  }
263
448
  ```
264
449
 
265
- ### Router (Tiny Dancer)
450
+ ### Router
266
451
 
267
452
  ```typescript
268
453
  class Router {
269
454
  constructor(config?: RouterConfig);
270
455
 
456
+ // Routing
271
457
  route(query: number[], candidates: Candidate[]): RoutingDecision;
458
+ routeBatch(queries: number[][], candidates: Candidate[]): RoutingDecision[];
459
+
460
+ // Management
272
461
  reloadModel(): void;
273
462
  circuitBreakerStatus(): 'closed' | 'open' | 'half-open';
463
+ resetCircuitBreaker(): void;
274
464
  }
275
465
  ```
276
466
 
277
467
  ## Use Cases
278
468
 
279
- ### RAG (Retrieval-Augmented Generation)
469
+ ### Agentic AI / Multi-Agent Systems
280
470
 
281
471
  ```javascript
282
- const ruvector = require('ruvector');
283
-
284
- async function ragQuery(question) {
285
- const questionEmbedding = await embed(question);
286
- const context = db.search(questionEmbedding, 5);
287
-
288
- const prompt = `
289
- Context: ${context.map(c => c.metadata.text).join('\n')}
290
-
291
- Question: ${question}
292
- Answer:
293
- `;
472
+ // Route tasks to specialized agents
473
+ const agents = [
474
+ { id: 'researcher', embedding: researchEmb, capabilities: ['search', 'summarize'] },
475
+ { id: 'coder', embedding: codeEmb, capabilities: ['code', 'debug'] },
476
+ { id: 'analyst', embedding: analysisEmb, capabilities: ['data', 'visualize'] }
477
+ ];
294
478
 
295
- return await llm.complete(prompt);
296
- }
479
+ const taskEmb = await embed("Write a Python script to analyze sales data");
480
+ const decision = router.route(taskEmb, agents);
481
+ // Routes to 'coder' agent with high confidence
297
482
  ```
298
483
 
299
- ### Recommendation System
484
+ ### Recommendation Systems
300
485
 
301
486
  ```javascript
302
- const { GraphDB } = require('ruvector');
303
-
304
- const graph = new GraphDB();
305
-
306
- // Find recommendations based on user behavior
307
487
  const recommendations = graph.execute(`
308
488
  MATCH (user:User {id: $userId})-[:VIEWED]->(item:Product)
309
489
  MATCH (item)-[:SIMILAR_TO]->(rec:Product)
310
490
  WHERE NOT (user)-[:VIEWED]->(rec)
311
- RETURN rec ORDER BY rec.score DESC LIMIT 10
491
+ AND vector.similarity(rec.embedding, $userPreference) > 0.7
492
+ RETURN rec
493
+ ORDER BY vector.similarity(rec.embedding, $userPreference) DESC
494
+ LIMIT 10
312
495
  `);
313
496
  ```
314
497
 
315
- ### Semantic Search with Filters
498
+ ### Semantic Caching
316
499
 
317
500
  ```javascript
318
- const results = db.search(queryEmbedding, 20, {
319
- category: 'electronics',
320
- price: { $lt: 500 },
321
- inStock: true
322
- });
501
+ const cache = new VectorDB(1536);
502
+
503
+ async function cachedLLMCall(prompt) {
504
+ const promptEmb = await embed(prompt);
505
+
506
+ // Check semantic cache
507
+ const cached = await cache.search(promptEmb, 1);
508
+ if (cached[0]?.score > 0.95) {
509
+ return cached[0].metadata.response; // Cache hit
510
+ }
511
+
512
+ // Cache miss - call LLM
513
+ const response = await llm.complete(prompt);
514
+ await cache.insert(generateId(), promptEmb, { prompt, response });
515
+
516
+ return response;
517
+ }
518
+ ```
519
+
520
+ ### Document Q&A with Sources
521
+
522
+ ```javascript
523
+ async function qaWithSources(question) {
524
+ const results = await db.search(await embed(question), 5);
525
+
526
+ const answer = await llm.complete({
527
+ prompt: `Answer based on these sources:\n${results.map(r =>
528
+ `[${r.id}] ${r.metadata.content}`
529
+ ).join('\n')}\n\nQuestion: ${question}`,
530
+ });
531
+
532
+ return {
533
+ answer,
534
+ sources: results.map(r => ({
535
+ id: r.id,
536
+ title: r.metadata.title,
537
+ relevance: r.score
538
+ }))
539
+ };
540
+ }
323
541
  ```
324
542
 
325
543
  ## Architecture
326
544
 
327
545
  ```
328
- ┌─────────────────────────────────────────────────────────┐
329
- ruvector
330
- (All-in-One npm Package)
331
- ├─────────────┬─────────────┬─────────────┬──────────────┤
332
- VectorDB │ GraphDB GNNLayer │ Router
333
- (Search) │ (Cypher) │ (ML) (AI Routing)
334
- └─────────────┴─────────────┴─────────────┴──────────────┘
335
-
336
- ┌──────────────────┼──────────────────┐
337
-
338
- ┌────▼────┐ ┌────▼────┐ ┌────▼────┐
339
- Native │ │ WASM │ │ FFI │
340
- │ (napi) │ │(wasm32) │ │ (C) │
341
- └─────────┘ └─────────┘ └─────────┘
546
+ ┌──────────────────────────────────────────────────────────────┐
547
+ ruvector
548
+ (All-in-One npm Package)
549
+ ├──────────────┬──────────────┬──────────────┬─────────────────┤
550
+ VectorDB │ GraphDB GNNLayer │ Router
551
+ (Search) │ (Cypher) │ (ML) (AI Routing)
552
+ ├──────────────┴──────────────┴──────────────┴─────────────────┤
553
+ Rust Core Engine │
554
+ │ • HNSW Index • Cypher Parser • Attention • FastGRNN │
555
+ • SIMD Ops • Hyperedges • Training • Uncertainty
556
+ └──────────────────────────────────────────────────────────────┘
557
+
558
+ ┌──────────────────┼──────────────────┐
559
+ │ │ │
560
+ ┌────▼────┐ ┌────▼────┐ ┌────▼────┐
561
+ │ Native │ │ WASM │ │ FFI │
562
+ │(napi-rs)│ │(wasm32) │ │ (C) │
563
+ └─────────┘ └─────────┘ └─────────┘
564
+ │ │ │
565
+ ┌────▼────┐ ┌────▼────┐ ┌────▼────┐
566
+ │ Node.js │ │ Browser │ │ Python │
567
+ │ Bun │ │ Deno │ │ Go │
568
+ └─────────┘ └─────────┘ └─────────┘
342
569
  ```
343
570
 
344
- The package automatically selects the best available backend (native > WASM).
345
-
346
- ## Comparison
571
+ ## Platform Support
347
572
 
348
- | Feature | RuVector | Pinecone | Qdrant | ChromaDB |
349
- |---------|----------|----------|--------|----------|
350
- | **Latency** | **61µs** | ~2ms | ~1ms | ~50ms |
351
- | **Graph Queries** | Cypher | | | |
352
- | **Self-Learning** | GNN | | | ❌ |
353
- | **AI Routing** | | | | ❌ |
354
- | **Browser/WASM** | | | | ❌ |
355
- | **Compression** | 2-32x | | | ❌ |
356
- | **Open Source** | MIT | | | ✅ |
573
+ | Platform | Backend | Installation |
574
+ |----------|---------|--------------|
575
+ | **Node.js 16+** | Native (napi-rs) | `npm install ruvector` |
576
+ | **Node.js (fallback)** | WASM | Automatic if native fails |
577
+ | **Bun** | Native | `bun add ruvector` |
578
+ | **Deno** | WASM | `import from "npm:ruvector"` |
579
+ | **Browser** | WASM | `npm install @ruvector/wasm` |
580
+ | **Cloudflare Workers** | WASM | `npm install @ruvector/wasm` |
581
+ | **Vercel Edge** | WASM | `npm install @ruvector/wasm` |
357
582
 
358
583
  ## Documentation
359
584
 
@@ -378,6 +603,9 @@ npm test
378
603
 
379
604
  # Build
380
605
  npm run build
606
+
607
+ # Benchmarks
608
+ npm run bench
381
609
  ```
382
610
 
383
611
  See [CONTRIBUTING.md](https://github.com/ruvnet/ruvector/blob/main/docs/development/CONTRIBUTING.md) for guidelines.
@@ -394,4 +622,6 @@ MIT License — free for commercial and personal use.
394
622
 
395
623
  *Vector search that gets smarter over time.*
396
624
 
625
+ **[⭐ Star on GitHub](https://github.com/ruvnet/ruvector)** if RuVector helps your project!
626
+
397
627
  </div>
package/dist/index.js CHANGED
@@ -98,8 +98,8 @@ var require_package = __commonJS({
98
98
  "package.json"(exports2, module2) {
99
99
  module2.exports = {
100
100
  name: "ruvector",
101
- version: "0.1.21",
102
- description: "All-in-one vector database: HNSW search, Cypher queries, GNN layers, compression. Pinecone + Neo4j + PyTorch in one package.",
101
+ version: "0.1.22",
102
+ description: "High-performance vector database with Graph Neural Networks, Cypher queries, and AI agent routing. Build RAG apps, semantic search, recommendations, and agentic AI systems. Pinecone + Neo4j + PyTorch alternative.",
103
103
  main: "./dist/index.js",
104
104
  types: "./dist/index.d.ts",
105
105
  bin: {
@@ -124,31 +124,76 @@ var require_package = __commonJS({
124
124
  prepublishOnly: "npm run build"
125
125
  },
126
126
  keywords: [
127
- "vector",
128
- "database",
127
+ "vector-database",
128
+ "vector-search",
129
129
  "embeddings",
130
130
  "similarity-search",
131
- "machine-learning",
131
+ "semantic-search",
132
+ "rag",
133
+ "retrieval-augmented-generation",
134
+ "llm",
135
+ "langchain",
136
+ "openai",
137
+ "gpt",
138
+ "claude",
139
+ "anthropic",
132
140
  "ai",
141
+ "artificial-intelligence",
142
+ "machine-learning",
143
+ "deep-learning",
144
+ "neural-network",
145
+ "gnn",
146
+ "graph-neural-network",
147
+ "knowledge-graph",
148
+ "graph-database",
149
+ "cypher",
150
+ "neo4j",
151
+ "hnsw",
152
+ "ann",
153
+ "approximate-nearest-neighbor",
154
+ "knn",
155
+ "cosine-similarity",
156
+ "recommendation-system",
157
+ "chatbot",
158
+ "conversational-ai",
159
+ "agentic-ai",
160
+ "ai-agents",
161
+ "multi-agent",
162
+ "agent-routing",
163
+ "model-router",
164
+ "llm-router",
133
165
  "rust",
134
166
  "napi",
167
+ "napi-rs",
135
168
  "wasm",
136
- "graph",
137
- "cypher",
138
- "neo4j",
139
- "gnn",
140
- "neural-network",
169
+ "webassembly",
141
170
  "compression",
142
- "hnsw",
143
- "rag"
171
+ "quantization",
172
+ "product-quantization",
173
+ "pinecone-alternative",
174
+ "chromadb-alternative",
175
+ "milvus-alternative",
176
+ "qdrant-alternative",
177
+ "weaviate-alternative"
144
178
  ],
145
- author: "rUv",
179
+ author: {
180
+ name: "rUv",
181
+ url: "https://ruv.io"
182
+ },
146
183
  license: "MIT",
184
+ homepage: "https://github.com/ruvnet/ruvector#readme",
147
185
  repository: {
148
186
  type: "git",
149
- url: "https://github.com/ruvnet/ruvector.git",
187
+ url: "git+https://github.com/ruvnet/ruvector.git",
150
188
  directory: "npm/ruvector"
151
189
  },
190
+ bugs: {
191
+ url: "https://github.com/ruvnet/ruvector/issues"
192
+ },
193
+ funding: {
194
+ type: "github",
195
+ url: "https://github.com/sponsors/ruvnet"
196
+ },
152
197
  dependencies: {
153
198
  commander: "^11.1.0",
154
199
  chalk: "^4.1.2",
package/dist/index.mjs CHANGED
@@ -77,8 +77,8 @@ var require_package = __commonJS({
77
77
  "package.json"(exports, module) {
78
78
  module.exports = {
79
79
  name: "ruvector",
80
- version: "0.1.21",
81
- description: "All-in-one vector database: HNSW search, Cypher queries, GNN layers, compression. Pinecone + Neo4j + PyTorch in one package.",
80
+ version: "0.1.22",
81
+ description: "High-performance vector database with Graph Neural Networks, Cypher queries, and AI agent routing. Build RAG apps, semantic search, recommendations, and agentic AI systems. Pinecone + Neo4j + PyTorch alternative.",
82
82
  main: "./dist/index.js",
83
83
  types: "./dist/index.d.ts",
84
84
  bin: {
@@ -103,31 +103,76 @@ var require_package = __commonJS({
103
103
  prepublishOnly: "npm run build"
104
104
  },
105
105
  keywords: [
106
- "vector",
107
- "database",
106
+ "vector-database",
107
+ "vector-search",
108
108
  "embeddings",
109
109
  "similarity-search",
110
- "machine-learning",
110
+ "semantic-search",
111
+ "rag",
112
+ "retrieval-augmented-generation",
113
+ "llm",
114
+ "langchain",
115
+ "openai",
116
+ "gpt",
117
+ "claude",
118
+ "anthropic",
111
119
  "ai",
120
+ "artificial-intelligence",
121
+ "machine-learning",
122
+ "deep-learning",
123
+ "neural-network",
124
+ "gnn",
125
+ "graph-neural-network",
126
+ "knowledge-graph",
127
+ "graph-database",
128
+ "cypher",
129
+ "neo4j",
130
+ "hnsw",
131
+ "ann",
132
+ "approximate-nearest-neighbor",
133
+ "knn",
134
+ "cosine-similarity",
135
+ "recommendation-system",
136
+ "chatbot",
137
+ "conversational-ai",
138
+ "agentic-ai",
139
+ "ai-agents",
140
+ "multi-agent",
141
+ "agent-routing",
142
+ "model-router",
143
+ "llm-router",
112
144
  "rust",
113
145
  "napi",
146
+ "napi-rs",
114
147
  "wasm",
115
- "graph",
116
- "cypher",
117
- "neo4j",
118
- "gnn",
119
- "neural-network",
148
+ "webassembly",
120
149
  "compression",
121
- "hnsw",
122
- "rag"
150
+ "quantization",
151
+ "product-quantization",
152
+ "pinecone-alternative",
153
+ "chromadb-alternative",
154
+ "milvus-alternative",
155
+ "qdrant-alternative",
156
+ "weaviate-alternative"
123
157
  ],
124
- author: "rUv",
158
+ author: {
159
+ name: "rUv",
160
+ url: "https://ruv.io"
161
+ },
125
162
  license: "MIT",
163
+ homepage: "https://github.com/ruvnet/ruvector#readme",
126
164
  repository: {
127
165
  type: "git",
128
- url: "https://github.com/ruvnet/ruvector.git",
166
+ url: "git+https://github.com/ruvnet/ruvector.git",
129
167
  directory: "npm/ruvector"
130
168
  },
169
+ bugs: {
170
+ url: "https://github.com/ruvnet/ruvector/issues"
171
+ },
172
+ funding: {
173
+ type: "github",
174
+ url: "https://github.com/sponsors/ruvnet"
175
+ },
131
176
  dependencies: {
132
177
  commander: "^11.1.0",
133
178
  chalk: "^4.1.2",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ruvector",
3
- "version": "0.1.21",
4
- "description": "All-in-one vector database: HNSW search, Cypher queries, GNN layers, compression. Pinecone + Neo4j + PyTorch in one package.",
3
+ "version": "0.1.22",
4
+ "description": "High-performance vector database with Graph Neural Networks, Cypher queries, and AI agent routing. Build RAG apps, semantic search, recommendations, and agentic AI systems. Pinecone + Neo4j + PyTorch alternative.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "bin": {
@@ -26,31 +26,76 @@
26
26
  "prepublishOnly": "npm run build"
27
27
  },
28
28
  "keywords": [
29
- "vector",
30
- "database",
29
+ "vector-database",
30
+ "vector-search",
31
31
  "embeddings",
32
32
  "similarity-search",
33
- "machine-learning",
33
+ "semantic-search",
34
+ "rag",
35
+ "retrieval-augmented-generation",
36
+ "llm",
37
+ "langchain",
38
+ "openai",
39
+ "gpt",
40
+ "claude",
41
+ "anthropic",
34
42
  "ai",
43
+ "artificial-intelligence",
44
+ "machine-learning",
45
+ "deep-learning",
46
+ "neural-network",
47
+ "gnn",
48
+ "graph-neural-network",
49
+ "knowledge-graph",
50
+ "graph-database",
51
+ "cypher",
52
+ "neo4j",
53
+ "hnsw",
54
+ "ann",
55
+ "approximate-nearest-neighbor",
56
+ "knn",
57
+ "cosine-similarity",
58
+ "recommendation-system",
59
+ "chatbot",
60
+ "conversational-ai",
61
+ "agentic-ai",
62
+ "ai-agents",
63
+ "multi-agent",
64
+ "agent-routing",
65
+ "model-router",
66
+ "llm-router",
35
67
  "rust",
36
68
  "napi",
69
+ "napi-rs",
37
70
  "wasm",
38
- "graph",
39
- "cypher",
40
- "neo4j",
41
- "gnn",
42
- "neural-network",
71
+ "webassembly",
43
72
  "compression",
44
- "hnsw",
45
- "rag"
73
+ "quantization",
74
+ "product-quantization",
75
+ "pinecone-alternative",
76
+ "chromadb-alternative",
77
+ "milvus-alternative",
78
+ "qdrant-alternative",
79
+ "weaviate-alternative"
46
80
  ],
47
- "author": "rUv",
81
+ "author": {
82
+ "name": "rUv",
83
+ "url": "https://ruv.io"
84
+ },
48
85
  "license": "MIT",
86
+ "homepage": "https://github.com/ruvnet/ruvector#readme",
49
87
  "repository": {
50
88
  "type": "git",
51
- "url": "https://github.com/ruvnet/ruvector.git",
89
+ "url": "git+https://github.com/ruvnet/ruvector.git",
52
90
  "directory": "npm/ruvector"
53
91
  },
92
+ "bugs": {
93
+ "url": "https://github.com/ruvnet/ruvector/issues"
94
+ },
95
+ "funding": {
96
+ "type": "github",
97
+ "url": "https://github.com/sponsors/ruvnet"
98
+ },
54
99
  "dependencies": {
55
100
  "commander": "^11.1.0",
56
101
  "chalk": "^4.1.2",