ruvector 0.1.20 → 0.1.21

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/dist/types.d.ts DELETED
@@ -1,145 +0,0 @@
1
- /**
2
- * Vector entry representing a document with its embedding
3
- */
4
- export interface VectorEntry {
5
- /** Unique identifier for the vector */
6
- id: string;
7
- /** Vector embedding (array of floats) */
8
- vector: number[];
9
- /** Optional metadata associated with the vector */
10
- metadata?: Record<string, any>;
11
- }
12
- /**
13
- * Search query parameters
14
- */
15
- export interface SearchQuery {
16
- /** Query vector to search for */
17
- vector: number[];
18
- /** Number of results to return */
19
- k?: number;
20
- /** Optional metadata filters */
21
- filter?: Record<string, any>;
22
- /** Minimum similarity threshold (0-1) */
23
- threshold?: number;
24
- }
25
- /**
26
- * Search result containing matched vector and similarity score
27
- */
28
- export interface SearchResult {
29
- /** ID of the matched vector */
30
- id: string;
31
- /** Similarity score (0-1, higher is better) */
32
- score: number;
33
- /** Vector data */
34
- vector: number[];
35
- /** Associated metadata */
36
- metadata?: Record<string, any>;
37
- }
38
- /**
39
- * Database configuration options
40
- */
41
- export interface DbOptions {
42
- /** Vector dimension size */
43
- dimension: number;
44
- /** Distance metric to use */
45
- metric?: 'cosine' | 'euclidean' | 'dot';
46
- /** Path to persist database */
47
- path?: string;
48
- /** Enable auto-persistence */
49
- autoPersist?: boolean;
50
- /** HNSW index parameters */
51
- hnsw?: {
52
- /** Maximum number of connections per layer */
53
- m?: number;
54
- /** Size of the dynamic candidate list */
55
- efConstruction?: number;
56
- /** Size of the dynamic candidate list for search */
57
- efSearch?: number;
58
- };
59
- }
60
- /**
61
- * Database statistics
62
- */
63
- export interface DbStats {
64
- /** Total number of vectors */
65
- count: number;
66
- /** Vector dimension */
67
- dimension: number;
68
- /** Distance metric */
69
- metric: string;
70
- /** Memory usage in bytes */
71
- memoryUsage?: number;
72
- /** Index type */
73
- indexType?: string;
74
- }
75
- /**
76
- * Main VectorDB class interface
77
- */
78
- export interface VectorDB {
79
- /**
80
- * Create a new vector database
81
- * @param options Database configuration
82
- */
83
- new (options: DbOptions): VectorDB;
84
- /**
85
- * Insert a single vector
86
- * @param entry Vector entry to insert
87
- */
88
- insert(entry: VectorEntry): void;
89
- /**
90
- * Insert multiple vectors in batch
91
- * @param entries Array of vector entries
92
- */
93
- insertBatch(entries: VectorEntry[]): void;
94
- /**
95
- * Search for similar vectors
96
- * @param query Search query parameters
97
- * @returns Array of search results
98
- */
99
- search(query: SearchQuery): SearchResult[];
100
- /**
101
- * Get vector by ID
102
- * @param id Vector ID
103
- * @returns Vector entry or null
104
- */
105
- get(id: string): VectorEntry | null;
106
- /**
107
- * Delete vector by ID
108
- * @param id Vector ID
109
- * @returns true if deleted, false if not found
110
- */
111
- delete(id: string): boolean;
112
- /**
113
- * Update vector metadata
114
- * @param id Vector ID
115
- * @param metadata New metadata
116
- */
117
- updateMetadata(id: string, metadata: Record<string, any>): void;
118
- /**
119
- * Get database statistics
120
- */
121
- stats(): DbStats;
122
- /**
123
- * Save database to disk
124
- * @param path Optional path (uses configured path if not provided)
125
- */
126
- save(path?: string): void;
127
- /**
128
- * Load database from disk
129
- * @param path Path to database file
130
- */
131
- load(path: string): void;
132
- /**
133
- * Clear all vectors from database
134
- */
135
- clear(): void;
136
- /**
137
- * Build HNSW index for faster search
138
- */
139
- buildIndex(): void;
140
- /**
141
- * Optimize database (rebuild indices, compact storage)
142
- */
143
- optimize(): void;
144
- }
145
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,yCAAyC;IACzC,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CACh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B,iBAAiB;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB;;;OAGG;IACH,KAAI,OAAO,EAAE,SAAS,GAAG,QAAQ,CAAC;IAElC;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAEjC;;;OAGG;IACH,WAAW,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAE1C;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,YAAY,EAAE,CAAC;IAE3C;;;;OAIG;IACH,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;IAEpC;;;;OAIG;IACH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC;IAE5B;;;;OAIG;IACH,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IAEhE;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC;IAEjB;;;OAGG;IACH,IAAI,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAE1B;;;OAGG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IAEd;;OAEG;IACH,UAAU,IAAI,IAAI,CAAC;IAEnB;;OAEG;IACH,QAAQ,IAAI,IAAI,CAAC;CAClB"}
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,211 +0,0 @@
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/');
@@ -1,85 +0,0 @@
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!"