ruvector 0.1.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.
@@ -0,0 +1,211 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * ruvector API Usage Examples
5
+ *
6
+ * This demonstrates how to use ruvector in your Node.js applications
7
+ */
8
+
9
+ // For this demo, we use the mock implementation
10
+ // In production, you would use: const { VectorDB } = require('ruvector');
11
+ const { VectorDB } = require('../test/mock-implementation.js');
12
+
13
+ console.log('ruvector API Examples\n');
14
+ console.log('='.repeat(60));
15
+
16
+ // Show info
17
+ console.log('\nUsing: Mock implementation (for demo purposes)');
18
+ console.log('In production: npm install ruvector\n');
19
+
20
+ // Example 1: Basic usage
21
+ console.log('Example 1: Basic Vector Operations');
22
+ console.log('-'.repeat(60));
23
+
24
+ const db = new VectorDB({
25
+ dimension: 3,
26
+ metric: 'cosine'
27
+ });
28
+
29
+ // Insert some vectors
30
+ db.insert({
31
+ id: 'doc1',
32
+ vector: [1, 0, 0],
33
+ metadata: { title: 'First Document', category: 'A' }
34
+ });
35
+
36
+ db.insertBatch([
37
+ { id: 'doc2', vector: [0, 1, 0], metadata: { title: 'Second Document', category: 'B' } },
38
+ { id: 'doc3', vector: [0, 0, 1], metadata: { title: 'Third Document', category: 'C' } },
39
+ { id: 'doc4', vector: [0.7, 0.7, 0], metadata: { title: 'Fourth Document', category: 'A' } }
40
+ ]);
41
+
42
+ console.log('✓ Inserted 4 vectors');
43
+
44
+ // Get stats
45
+ const stats = db.stats();
46
+ console.log(`✓ Database has ${stats.count} vectors, dimension ${stats.dimension}`);
47
+
48
+ // Search
49
+ const results = db.search({
50
+ vector: [1, 0, 0],
51
+ k: 3
52
+ });
53
+
54
+ console.log(`✓ Search returned ${results.length} results:`);
55
+ results.forEach((result, i) => {
56
+ console.log(` ${i + 1}. ${result.id} (score: ${result.score.toFixed(4)}) - ${result.metadata.title}`);
57
+ });
58
+
59
+ // Get by ID
60
+ const doc = db.get('doc2');
61
+ console.log(`✓ Retrieved document: ${doc.metadata.title}`);
62
+
63
+ // Update metadata
64
+ db.updateMetadata('doc1', { updated: true, timestamp: Date.now() });
65
+ console.log('✓ Updated metadata');
66
+
67
+ // Delete
68
+ db.delete('doc3');
69
+ console.log('✓ Deleted doc3');
70
+ console.log(`✓ Database now has ${db.stats().count} vectors\n`);
71
+
72
+ // Example 2: Semantic Search Simulation
73
+ console.log('Example 2: Semantic Search Simulation');
74
+ console.log('-'.repeat(60));
75
+
76
+ const semanticDb = new VectorDB({
77
+ dimension: 5,
78
+ metric: 'cosine'
79
+ });
80
+
81
+ // Simulate document embeddings
82
+ const documents = [
83
+ { id: 'machine-learning', vector: [0.9, 0.8, 0.1, 0.2, 0.1], metadata: { title: 'Introduction to Machine Learning', topic: 'AI' } },
84
+ { id: 'deep-learning', vector: [0.85, 0.9, 0.15, 0.25, 0.1], metadata: { title: 'Deep Learning Fundamentals', topic: 'AI' } },
85
+ { id: 'web-dev', vector: [0.1, 0.2, 0.9, 0.8, 0.1], metadata: { title: 'Web Development Guide', topic: 'Web' } },
86
+ { id: 'react', vector: [0.15, 0.2, 0.85, 0.9, 0.1], metadata: { title: 'React Tutorial', topic: 'Web' } },
87
+ { id: 'database', vector: [0.2, 0.3, 0.3, 0.4, 0.9], metadata: { title: 'Database Design', topic: 'Data' } }
88
+ ];
89
+
90
+ semanticDb.insertBatch(documents);
91
+ console.log(`✓ Indexed ${documents.length} documents`);
92
+
93
+ // Search for AI-related content
94
+ const aiQuery = [0.9, 0.85, 0.1, 0.2, 0.1];
95
+ const aiResults = semanticDb.search({ vector: aiQuery, k: 2 });
96
+
97
+ console.log('\nQuery: AI-related content');
98
+ console.log('Results:');
99
+ aiResults.forEach((result, i) => {
100
+ console.log(` ${i + 1}. ${result.metadata.title} (score: ${result.score.toFixed(4)})`);
101
+ });
102
+
103
+ // Search for Web-related content
104
+ const webQuery = [0.1, 0.2, 0.9, 0.85, 0.1];
105
+ const webResults = semanticDb.search({ vector: webQuery, k: 2 });
106
+
107
+ console.log('\nQuery: Web-related content');
108
+ console.log('Results:');
109
+ webResults.forEach((result, i) => {
110
+ console.log(` ${i + 1}. ${result.metadata.title} (score: ${result.score.toFixed(4)})`);
111
+ });
112
+
113
+ // Example 3: Different Distance Metrics
114
+ console.log('\n\nExample 3: Distance Metrics Comparison');
115
+ console.log('-'.repeat(60));
116
+
117
+ const metrics = ['cosine', 'euclidean', 'dot'];
118
+ const testVectors = [
119
+ { id: 'v1', vector: [1, 0, 0] },
120
+ { id: 'v2', vector: [0.7, 0.7, 0] },
121
+ { id: 'v3', vector: [0, 1, 0] }
122
+ ];
123
+
124
+ metrics.forEach(metric => {
125
+ const metricDb = new VectorDB({ dimension: 3, metric });
126
+ metricDb.insertBatch(testVectors);
127
+
128
+ const results = metricDb.search({ vector: [1, 0, 0], k: 3 });
129
+
130
+ console.log(`\n${metric.toUpperCase()} metric:`);
131
+ results.forEach((result, i) => {
132
+ console.log(` ${i + 1}. ${result.id}: ${result.score.toFixed(4)}`);
133
+ });
134
+ });
135
+
136
+ // Example 4: Batch Operations Performance
137
+ console.log('\n\nExample 4: Batch Operations Performance');
138
+ console.log('-'.repeat(60));
139
+
140
+ const perfDb = new VectorDB({ dimension: 128, metric: 'cosine' });
141
+
142
+ // Generate random vectors
143
+ const numVectors = 1000;
144
+ const vectors = [];
145
+ for (let i = 0; i < numVectors; i++) {
146
+ vectors.push({
147
+ id: `vec_${i}`,
148
+ vector: Array.from({ length: 128 }, () => Math.random()),
149
+ metadata: { index: i, batch: Math.floor(i / 100) }
150
+ });
151
+ }
152
+
153
+ console.log(`Inserting ${numVectors} vectors...`);
154
+ const insertStart = Date.now();
155
+ perfDb.insertBatch(vectors);
156
+ const insertTime = Date.now() - insertStart;
157
+
158
+ console.log(`✓ Inserted ${numVectors} vectors in ${insertTime}ms`);
159
+ console.log(`✓ Rate: ${Math.round(numVectors / (insertTime / 1000))} vectors/sec`);
160
+
161
+ // Search performance
162
+ const numQueries = 100;
163
+ console.log(`\nRunning ${numQueries} searches...`);
164
+ const searchStart = Date.now();
165
+
166
+ for (let i = 0; i < numQueries; i++) {
167
+ const query = {
168
+ vector: Array.from({ length: 128 }, () => Math.random()),
169
+ k: 10
170
+ };
171
+ perfDb.search(query);
172
+ }
173
+
174
+ const searchTime = Date.now() - searchStart;
175
+ console.log(`✓ Completed ${numQueries} searches in ${searchTime}ms`);
176
+ console.log(`✓ Rate: ${Math.round(numQueries / (searchTime / 1000))} queries/sec`);
177
+ console.log(`✓ Avg latency: ${(searchTime / numQueries).toFixed(2)}ms`);
178
+
179
+ // Example 5: Persistence (conceptual, would need real implementation)
180
+ console.log('\n\nExample 5: Persistence');
181
+ console.log('-'.repeat(60));
182
+
183
+ const persistDb = new VectorDB({
184
+ dimension: 3,
185
+ metric: 'cosine',
186
+ path: './my-vectors.db',
187
+ autoPersist: true
188
+ });
189
+
190
+ persistDb.insertBatch([
191
+ { id: 'p1', vector: [1, 0, 0], metadata: { name: 'First' } },
192
+ { id: 'p2', vector: [0, 1, 0], metadata: { name: 'Second' } }
193
+ ]);
194
+
195
+ console.log('✓ Created database with auto-persist enabled');
196
+ console.log('✓ Insert operations will automatically save to disk');
197
+ console.log('✓ Use db.save(path) for manual saves');
198
+ console.log('✓ Use db.load(path) to restore from disk');
199
+
200
+ // Summary
201
+ console.log('\n' + '='.repeat(60));
202
+ console.log('\n✅ All examples completed successfully!');
203
+ console.log('\nKey Features Demonstrated:');
204
+ console.log(' • Basic CRUD operations (insert, search, get, update, delete)');
205
+ console.log(' • Batch operations for better performance');
206
+ console.log(' • Multiple distance metrics (cosine, euclidean, dot)');
207
+ console.log(' • Semantic search simulation');
208
+ console.log(' • Performance benchmarking');
209
+ console.log(' • Metadata filtering and updates');
210
+ console.log(' • Persistence (save/load)');
211
+ console.log('\nFor more examples, see: /workspaces/ruvector/npm/packages/ruvector/examples/');
@@ -0,0 +1,85 @@
1
+ #!/bin/bash
2
+
3
+ # ruvector CLI Demo
4
+ # This demonstrates the CLI functionality with a simple example
5
+
6
+ echo "🚀 ruvector CLI Demo"
7
+ echo "===================="
8
+ echo ""
9
+
10
+ # 1. Show version info
11
+ echo "1. Checking ruvector info..."
12
+ ruvector info
13
+ echo ""
14
+
15
+ # 2. Create a database
16
+ echo "2. Creating a new database..."
17
+ ruvector create demo.vec --dimension 3 --metric cosine
18
+ echo ""
19
+
20
+ # 3. Create sample data
21
+ echo "3. Creating sample vectors..."
22
+ cat > demo-vectors.json << 'EOF'
23
+ [
24
+ {
25
+ "id": "cat",
26
+ "vector": [0.9, 0.1, 0.1],
27
+ "metadata": {"animal": "cat", "category": "feline"}
28
+ },
29
+ {
30
+ "id": "dog",
31
+ "vector": [0.1, 0.9, 0.1],
32
+ "metadata": {"animal": "dog", "category": "canine"}
33
+ },
34
+ {
35
+ "id": "tiger",
36
+ "vector": [0.8, 0.2, 0.15],
37
+ "metadata": {"animal": "tiger", "category": "feline"}
38
+ },
39
+ {
40
+ "id": "wolf",
41
+ "vector": [0.2, 0.8, 0.15],
42
+ "metadata": {"animal": "wolf", "category": "canine"}
43
+ },
44
+ {
45
+ "id": "lion",
46
+ "vector": [0.85, 0.15, 0.1],
47
+ "metadata": {"animal": "lion", "category": "feline"}
48
+ }
49
+ ]
50
+ EOF
51
+ echo " Created demo-vectors.json with 5 animals"
52
+ echo ""
53
+
54
+ # 4. Insert vectors
55
+ echo "4. Inserting vectors into database..."
56
+ ruvector insert demo.vec demo-vectors.json
57
+ echo ""
58
+
59
+ # 5. Show statistics
60
+ echo "5. Database statistics..."
61
+ ruvector stats demo.vec
62
+ echo ""
63
+
64
+ # 6. Search for cat-like animals
65
+ echo "6. Searching for cat-like animals (vector: [0.9, 0.1, 0.1])..."
66
+ ruvector search demo.vec --vector "[0.9, 0.1, 0.1]" --top-k 3
67
+ echo ""
68
+
69
+ # 7. Search for dog-like animals
70
+ echo "7. Searching for dog-like animals (vector: [0.1, 0.9, 0.1])..."
71
+ ruvector search demo.vec --vector "[0.1, 0.9, 0.1]" --top-k 3
72
+ echo ""
73
+
74
+ # 8. Run benchmark
75
+ echo "8. Running performance benchmark..."
76
+ ruvector benchmark --dimension 128 --num-vectors 1000 --num-queries 100
77
+ echo ""
78
+
79
+ # Cleanup
80
+ echo "9. Cleanup (removing demo files)..."
81
+ rm -f demo.vec demo-vectors.json
82
+ echo " ✓ Demo files removed"
83
+ echo ""
84
+
85
+ echo "✅ Demo complete!"
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "ruvector",
3
+ "version": "0.1.1",
4
+ "description": "High-performance vector database for Node.js with automatic native/WASM fallback",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "ruvector": "./bin/cli.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "prepublishOnly": "npm run build",
13
+ "test": "node test/integration.js"
14
+ },
15
+ "keywords": [
16
+ "vector",
17
+ "database",
18
+ "vector-database",
19
+ "vector-search",
20
+ "similarity-search",
21
+ "semantic-search",
22
+ "embeddings",
23
+ "hnsw",
24
+ "ann",
25
+ "ai",
26
+ "machine-learning",
27
+ "rag",
28
+ "rust",
29
+ "wasm",
30
+ "native",
31
+ "ruv",
32
+ "ruvector"
33
+ ],
34
+ "author": "ruv.io Team <info@ruv.io> (https://ruv.io)",
35
+ "homepage": "https://ruv.io",
36
+ "bugs": {
37
+ "url": "https://github.com/ruvnet/ruvector/issues"
38
+ },
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/ruvnet/ruvector.git",
43
+ "directory": "npm/packages/ruvector"
44
+ },
45
+ "dependencies": {
46
+ "ruvector-core": "^0.1.1",
47
+ "commander": "^11.1.0",
48
+ "chalk": "^4.1.2",
49
+ "ora": "^5.4.1"
50
+ },
51
+ "optionalDependencies": {
52
+ "ruvector-wasm": "^0.1.1"
53
+ },
54
+ "devDependencies": {
55
+ "@types/node": "^20.10.5",
56
+ "typescript": "^5.3.3"
57
+ },
58
+ "engines": {
59
+ "node": ">=14.0.0"
60
+ }
61
+ }