ruvector 0.1.100 → 0.2.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/bin/cli.js +820 -47
- package/package.json +28 -4
- package/HOOKS.md +0 -221
- package/PACKAGE_SUMMARY.md +0 -409
- package/examples/api-usage.js +0 -211
- package/examples/cli-demo.sh +0 -85
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ruvector",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "High-performance vector database for Node.js with automatic native/WASM fallback",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc && cp src/core/onnx/pkg/package.json dist/core/onnx/pkg/",
|
|
12
12
|
"prepublishOnly": "npm run build",
|
|
13
|
-
"test": "node test/integration.js"
|
|
13
|
+
"test": "node test/integration.js && node test/cli-commands.js"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
16
16
|
"vector",
|
|
@@ -41,7 +41,15 @@
|
|
|
41
41
|
"continual-learning",
|
|
42
42
|
"onnx",
|
|
43
43
|
"semantic-embeddings",
|
|
44
|
-
"minilm"
|
|
44
|
+
"minilm",
|
|
45
|
+
"brain",
|
|
46
|
+
"shared-intelligence",
|
|
47
|
+
"mcp",
|
|
48
|
+
"edge-computing",
|
|
49
|
+
"pi-brain",
|
|
50
|
+
"identity",
|
|
51
|
+
"pi-key",
|
|
52
|
+
"distributed-compute"
|
|
45
53
|
],
|
|
46
54
|
"author": "ruv.io Team <info@ruv.io> (https://ruv.io)",
|
|
47
55
|
"homepage": "https://ruv.io",
|
|
@@ -71,7 +79,23 @@
|
|
|
71
79
|
"@types/node": "^20.10.5",
|
|
72
80
|
"typescript": "^5.3.3"
|
|
73
81
|
},
|
|
82
|
+
"files": [
|
|
83
|
+
"bin/",
|
|
84
|
+
"dist/",
|
|
85
|
+
"README.md",
|
|
86
|
+
"LICENSE"
|
|
87
|
+
],
|
|
88
|
+
"peerDependencies": {
|
|
89
|
+
"@ruvector/pi-brain": ">=0.1.0",
|
|
90
|
+
"@ruvector/ruvllm": ">=2.0.0",
|
|
91
|
+
"@ruvector/router": ">=0.1.0"
|
|
92
|
+
},
|
|
93
|
+
"peerDependenciesMeta": {
|
|
94
|
+
"@ruvector/pi-brain": { "optional": true },
|
|
95
|
+
"@ruvector/ruvllm": { "optional": true },
|
|
96
|
+
"@ruvector/router": { "optional": true }
|
|
97
|
+
},
|
|
74
98
|
"engines": {
|
|
75
|
-
"node": ">=
|
|
99
|
+
"node": ">=18.0.0"
|
|
76
100
|
}
|
|
77
101
|
}
|
package/HOOKS.md
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
# RuVector Hooks for Claude Code
|
|
2
|
-
|
|
3
|
-
Self-learning intelligence hooks that enhance Claude Code with Q-learning, vector memory, and automatic agent routing.
|
|
4
|
-
|
|
5
|
-
## Quick Start
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
# Full setup: hooks + pretrain + optimized agents
|
|
9
|
-
npx ruvector hooks init --pretrain --build-agents quality
|
|
10
|
-
|
|
11
|
-
# Or step by step:
|
|
12
|
-
npx ruvector hooks init # Setup hooks
|
|
13
|
-
npx ruvector hooks pretrain # Analyze repository
|
|
14
|
-
npx ruvector hooks build-agents # Generate agent configs
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
## What It Does
|
|
18
|
-
|
|
19
|
-
RuVector hooks integrate with Claude Code to provide:
|
|
20
|
-
|
|
21
|
-
| Feature | Description |
|
|
22
|
-
|---------|-------------|
|
|
23
|
-
| **Agent Routing** | Suggests the best agent for each file type based on learned patterns |
|
|
24
|
-
| **Co-edit Patterns** | Predicts "likely next files" from git history |
|
|
25
|
-
| **Vector Memory** | Semantic recall of project context |
|
|
26
|
-
| **Command Analysis** | Risk assessment for bash commands |
|
|
27
|
-
| **Self-Learning** | Q-learning improves suggestions over time |
|
|
28
|
-
|
|
29
|
-
## Commands
|
|
30
|
-
|
|
31
|
-
### Initialization
|
|
32
|
-
|
|
33
|
-
```bash
|
|
34
|
-
# Full configuration
|
|
35
|
-
npx ruvector hooks init
|
|
36
|
-
|
|
37
|
-
# With pretrain and agent building
|
|
38
|
-
npx ruvector hooks init --pretrain --build-agents security
|
|
39
|
-
|
|
40
|
-
# Minimal (basic hooks only)
|
|
41
|
-
npx ruvector hooks init --minimal
|
|
42
|
-
|
|
43
|
-
# Options
|
|
44
|
-
--force # Overwrite existing settings
|
|
45
|
-
--minimal # Basic hooks only
|
|
46
|
-
--pretrain # Run pretrain after init
|
|
47
|
-
--build-agents # Generate optimized agents (quality|speed|security|testing|fullstack)
|
|
48
|
-
--no-claude-md # Skip CLAUDE.md creation
|
|
49
|
-
--no-permissions # Skip permissions config
|
|
50
|
-
--no-env # Skip environment variables
|
|
51
|
-
--no-gitignore # Skip .gitignore update
|
|
52
|
-
--no-mcp # Skip MCP server config
|
|
53
|
-
--no-statusline # Skip status line config
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Pretrain
|
|
57
|
-
|
|
58
|
-
Analyze your repository to bootstrap intelligence:
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
npx ruvector hooks pretrain
|
|
62
|
-
|
|
63
|
-
# Options
|
|
64
|
-
--depth <n> # Git history depth (default: 100)
|
|
65
|
-
--verbose # Show detailed progress
|
|
66
|
-
--skip-git # Skip git history analysis
|
|
67
|
-
--skip-files # Skip file structure analysis
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
**What it learns:**
|
|
71
|
-
- File type → Agent mapping (`.rs` → rust-developer)
|
|
72
|
-
- Co-edit patterns from git history
|
|
73
|
-
- Directory → Agent mapping
|
|
74
|
-
- Project context memories
|
|
75
|
-
|
|
76
|
-
### Build Agents
|
|
77
|
-
|
|
78
|
-
Generate optimized `.claude/agents/` configurations:
|
|
79
|
-
|
|
80
|
-
```bash
|
|
81
|
-
npx ruvector hooks build-agents --focus quality
|
|
82
|
-
|
|
83
|
-
# Focus modes
|
|
84
|
-
--focus quality # Code quality, best practices (default)
|
|
85
|
-
--focus speed # Rapid development, prototyping
|
|
86
|
-
--focus security # OWASP, input validation, encryption
|
|
87
|
-
--focus testing # TDD, comprehensive coverage
|
|
88
|
-
--focus fullstack # Balanced frontend/backend/database
|
|
89
|
-
|
|
90
|
-
# Options
|
|
91
|
-
--output <dir> # Output directory (default: .claude/agents)
|
|
92
|
-
--format <fmt> # yaml, json, or md (default: yaml)
|
|
93
|
-
--include-prompts # Include system prompts in agent configs
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### Verification & Diagnostics
|
|
97
|
-
|
|
98
|
-
```bash
|
|
99
|
-
# Check if hooks are working
|
|
100
|
-
npx ruvector hooks verify
|
|
101
|
-
|
|
102
|
-
# Diagnose and fix issues
|
|
103
|
-
npx ruvector hooks doctor
|
|
104
|
-
npx ruvector hooks doctor --fix
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
### Data Management
|
|
108
|
-
|
|
109
|
-
```bash
|
|
110
|
-
# View statistics
|
|
111
|
-
npx ruvector hooks stats
|
|
112
|
-
|
|
113
|
-
# Export intelligence data
|
|
114
|
-
npx ruvector hooks export -o backup.json
|
|
115
|
-
npx ruvector hooks export --include-all
|
|
116
|
-
|
|
117
|
-
# Import intelligence data
|
|
118
|
-
npx ruvector hooks import backup.json
|
|
119
|
-
npx ruvector hooks import backup.json --merge
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### Memory Operations
|
|
123
|
-
|
|
124
|
-
```bash
|
|
125
|
-
# Store context in vector memory
|
|
126
|
-
npx ruvector hooks remember "API uses JWT auth" -t project
|
|
127
|
-
|
|
128
|
-
# Semantic search memory
|
|
129
|
-
npx ruvector hooks recall "authentication"
|
|
130
|
-
|
|
131
|
-
# Route a task to best agent
|
|
132
|
-
npx ruvector hooks route "implement user login"
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
## Hook Events
|
|
136
|
-
|
|
137
|
-
| Event | Trigger | RuVector Action |
|
|
138
|
-
|-------|---------|-----------------|
|
|
139
|
-
| **PreToolUse** | Before Edit/Write/Bash | Agent routing, file analysis, command risk |
|
|
140
|
-
| **PostToolUse** | After Edit/Write/Bash | Q-learning update, pattern recording |
|
|
141
|
-
| **SessionStart** | Conversation begins | Load intelligence, display stats |
|
|
142
|
-
| **Stop** | Conversation ends | Save learning data |
|
|
143
|
-
| **UserPromptSubmit** | User sends message | Context suggestions |
|
|
144
|
-
| **PreCompact** | Before context compaction | Preserve important context |
|
|
145
|
-
| **Notification** | Any notification | Track events for learning |
|
|
146
|
-
|
|
147
|
-
## Generated Files
|
|
148
|
-
|
|
149
|
-
After running `hooks init`:
|
|
150
|
-
|
|
151
|
-
```
|
|
152
|
-
your-project/
|
|
153
|
-
├── .claude/
|
|
154
|
-
│ ├── settings.json # Hooks configuration
|
|
155
|
-
│ ├── statusline.sh # Status bar script
|
|
156
|
-
│ └── agents/ # Generated agents (with --build-agents)
|
|
157
|
-
│ ├── rust-specialist.yaml
|
|
158
|
-
│ ├── typescript-specialist.yaml
|
|
159
|
-
│ ├── test-architect.yaml
|
|
160
|
-
│ └── project-coordinator.yaml
|
|
161
|
-
├── .ruvector/
|
|
162
|
-
│ └── intelligence.json # Learning data
|
|
163
|
-
├── CLAUDE.md # Project documentation
|
|
164
|
-
└── .gitignore # Updated with .ruvector/
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
## Environment Variables
|
|
168
|
-
|
|
169
|
-
| Variable | Default | Description |
|
|
170
|
-
|----------|---------|-------------|
|
|
171
|
-
| `RUVECTOR_INTELLIGENCE_ENABLED` | `true` | Enable/disable intelligence |
|
|
172
|
-
| `RUVECTOR_LEARNING_RATE` | `0.1` | Q-learning rate (0.0-1.0) |
|
|
173
|
-
| `RUVECTOR_MEMORY_BACKEND` | `rvlite` | Memory storage backend |
|
|
174
|
-
| `INTELLIGENCE_MODE` | `treatment` | A/B testing mode |
|
|
175
|
-
|
|
176
|
-
## Example Output
|
|
177
|
-
|
|
178
|
-
### Agent Routing
|
|
179
|
-
```
|
|
180
|
-
🧠 Intelligence Analysis:
|
|
181
|
-
📁 src/api/routes.ts
|
|
182
|
-
🤖 Recommended: typescript-developer (85% confidence)
|
|
183
|
-
→ learned from 127 .ts files in repo
|
|
184
|
-
📎 Likely next files:
|
|
185
|
-
- src/api/handlers.ts (12 co-edits)
|
|
186
|
-
- src/types/api.ts (8 co-edits)
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
### Command Analysis
|
|
190
|
-
```
|
|
191
|
-
🧠 Command Analysis:
|
|
192
|
-
📦 Category: rust
|
|
193
|
-
🏷️ Type: test
|
|
194
|
-
✅ Risk: LOW
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
## Best Practices
|
|
198
|
-
|
|
199
|
-
1. **Run pretrain on existing repos** — Bootstrap intelligence before starting work
|
|
200
|
-
2. **Use focus modes** — Match agent generation to your current task
|
|
201
|
-
3. **Export before major changes** — Backup learning data
|
|
202
|
-
4. **Let it learn** — Intelligence improves with each edit
|
|
203
|
-
|
|
204
|
-
## Troubleshooting
|
|
205
|
-
|
|
206
|
-
```bash
|
|
207
|
-
# Check setup
|
|
208
|
-
npx ruvector hooks verify
|
|
209
|
-
|
|
210
|
-
# Fix common issues
|
|
211
|
-
npx ruvector hooks doctor --fix
|
|
212
|
-
|
|
213
|
-
# Reset and reinitialize
|
|
214
|
-
npx ruvector hooks init --force --pretrain
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
## Links
|
|
218
|
-
|
|
219
|
-
- [RuVector GitHub](https://github.com/ruvnet/ruvector)
|
|
220
|
-
- [npm Package](https://www.npmjs.com/package/ruvector)
|
|
221
|
-
- [Claude Code Documentation](https://docs.anthropic.com/claude-code)
|
package/PACKAGE_SUMMARY.md
DELETED
|
@@ -1,409 +0,0 @@
|
|
|
1
|
-
# ruvector Package Summary
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
The main `ruvector` package provides a unified interface for high-performance vector database operations in Node.js, with automatic platform detection and smart fallback between native (Rust) and WASM implementations.
|
|
6
|
-
|
|
7
|
-
## Package Structure
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
/workspaces/ruvector/npm/packages/ruvector/
|
|
11
|
-
├── src/ # TypeScript source
|
|
12
|
-
│ ├── index.ts # Smart loader with platform detection
|
|
13
|
-
│ └── types.ts # TypeScript type definitions
|
|
14
|
-
├── dist/ # Compiled JavaScript and types
|
|
15
|
-
│ ├── index.js # Main entry point
|
|
16
|
-
│ ├── index.d.ts # Type definitions
|
|
17
|
-
│ ├── types.js # Compiled types
|
|
18
|
-
│ └── types.d.ts # Type definitions
|
|
19
|
-
├── bin/
|
|
20
|
-
│ └── cli.js # CLI tool
|
|
21
|
-
├── test/
|
|
22
|
-
│ ├── mock-implementation.js # Mock VectorDB for testing
|
|
23
|
-
│ ├── standalone-test.js # Package structure tests
|
|
24
|
-
│ └── integration.js # Integration tests
|
|
25
|
-
├── examples/
|
|
26
|
-
│ ├── api-usage.js # API usage examples
|
|
27
|
-
│ └── cli-demo.sh # CLI demonstration
|
|
28
|
-
├── package.json # NPM package configuration
|
|
29
|
-
├── tsconfig.json # TypeScript configuration
|
|
30
|
-
└── README.md # Package documentation
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Key Features
|
|
34
|
-
|
|
35
|
-
### 1. Smart Platform Detection
|
|
36
|
-
|
|
37
|
-
The package automatically detects and loads the best available implementation:
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
// Tries to load in this order:
|
|
41
|
-
// 1. @ruvector/core (native Rust, fastest)
|
|
42
|
-
// 2. @ruvector/wasm (WebAssembly, universal fallback)
|
|
43
|
-
|
|
44
|
-
import { VectorDB, getImplementationType, isNative, isWasm } from 'ruvector';
|
|
45
|
-
|
|
46
|
-
console.log(getImplementationType()); // 'native' or 'wasm'
|
|
47
|
-
console.log(isNative()); // true if using native
|
|
48
|
-
console.log(isWasm()); // true if using WASM
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
### 2. Complete TypeScript Support
|
|
52
|
-
|
|
53
|
-
Full type definitions for all APIs:
|
|
54
|
-
|
|
55
|
-
```typescript
|
|
56
|
-
interface VectorEntry {
|
|
57
|
-
id: string;
|
|
58
|
-
vector: number[];
|
|
59
|
-
metadata?: Record<string, any>;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
interface SearchQuery {
|
|
63
|
-
vector: number[];
|
|
64
|
-
k?: number;
|
|
65
|
-
filter?: Record<string, any>;
|
|
66
|
-
threshold?: number;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
interface SearchResult {
|
|
70
|
-
id: string;
|
|
71
|
-
score: number;
|
|
72
|
-
vector: number[];
|
|
73
|
-
metadata?: Record<string, any>;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
interface DbOptions {
|
|
77
|
-
dimension: number;
|
|
78
|
-
metric?: 'cosine' | 'euclidean' | 'dot';
|
|
79
|
-
path?: string;
|
|
80
|
-
autoPersist?: boolean;
|
|
81
|
-
hnsw?: {
|
|
82
|
-
m?: number;
|
|
83
|
-
efConstruction?: number;
|
|
84
|
-
efSearch?: number;
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### 3. VectorDB API
|
|
90
|
-
|
|
91
|
-
Comprehensive vector database operations:
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
const db = new VectorDB({
|
|
95
|
-
dimension: 384,
|
|
96
|
-
metric: 'cosine'
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
// Insert operations
|
|
100
|
-
db.insert({ id: 'doc1', vector: [...], metadata: {...} });
|
|
101
|
-
db.insertBatch([...entries]);
|
|
102
|
-
|
|
103
|
-
// Search operations
|
|
104
|
-
const results = db.search({
|
|
105
|
-
vector: [...],
|
|
106
|
-
k: 10,
|
|
107
|
-
threshold: 0.7
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// CRUD operations
|
|
111
|
-
const entry = db.get('doc1');
|
|
112
|
-
db.updateMetadata('doc1', { updated: true });
|
|
113
|
-
db.delete('doc1');
|
|
114
|
-
|
|
115
|
-
// Database management
|
|
116
|
-
const stats = db.stats();
|
|
117
|
-
db.save('./mydb.vec');
|
|
118
|
-
db.load('./mydb.vec');
|
|
119
|
-
db.buildIndex();
|
|
120
|
-
db.optimize();
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### 4. CLI Tools
|
|
124
|
-
|
|
125
|
-
Command-line interface for database operations:
|
|
126
|
-
|
|
127
|
-
```bash
|
|
128
|
-
# Create database
|
|
129
|
-
ruvector create mydb.vec --dimension 384 --metric cosine
|
|
130
|
-
|
|
131
|
-
# Insert vectors
|
|
132
|
-
ruvector insert mydb.vec vectors.json --batch-size 1000
|
|
133
|
-
|
|
134
|
-
# Search
|
|
135
|
-
ruvector search mydb.vec --vector "[0.1,0.2,...]" --top-k 10
|
|
136
|
-
|
|
137
|
-
# Statistics
|
|
138
|
-
ruvector stats mydb.vec
|
|
139
|
-
|
|
140
|
-
# Benchmark
|
|
141
|
-
ruvector benchmark --num-vectors 10000 --num-queries 1000
|
|
142
|
-
|
|
143
|
-
# Info
|
|
144
|
-
ruvector info
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
## API Reference
|
|
148
|
-
|
|
149
|
-
### Constructor
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
new VectorDB(options: DbOptions): VectorDB
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
### Methods
|
|
156
|
-
|
|
157
|
-
- `insert(entry: VectorEntry): void` - Insert single vector
|
|
158
|
-
- `insertBatch(entries: VectorEntry[]): void` - Batch insert
|
|
159
|
-
- `search(query: SearchQuery): SearchResult[]` - Search similar vectors
|
|
160
|
-
- `get(id: string): VectorEntry | null` - Get by ID
|
|
161
|
-
- `delete(id: string): boolean` - Delete vector
|
|
162
|
-
- `updateMetadata(id: string, metadata: Record<string, any>): void` - Update metadata
|
|
163
|
-
- `stats(): DbStats` - Get database statistics
|
|
164
|
-
- `save(path?: string): void` - Save to disk
|
|
165
|
-
- `load(path: string): void` - Load from disk
|
|
166
|
-
- `clear(): void` - Clear all vectors
|
|
167
|
-
- `buildIndex(): void` - Build HNSW index
|
|
168
|
-
- `optimize(): void` - Optimize database
|
|
169
|
-
|
|
170
|
-
### Utility Functions
|
|
171
|
-
|
|
172
|
-
- `getImplementationType(): 'native' | 'wasm'` - Get current implementation
|
|
173
|
-
- `isNative(): boolean` - Check if using native
|
|
174
|
-
- `isWasm(): boolean` - Check if using WASM
|
|
175
|
-
- `getVersion(): { version: string, implementation: string }` - Get version info
|
|
176
|
-
|
|
177
|
-
## Dependencies
|
|
178
|
-
|
|
179
|
-
### Production Dependencies
|
|
180
|
-
|
|
181
|
-
- `commander` (^11.1.0) - CLI framework
|
|
182
|
-
- `chalk` (^4.1.2) - Terminal styling
|
|
183
|
-
- `ora` (^5.4.1) - Spinners and progress
|
|
184
|
-
|
|
185
|
-
### Optional Dependencies
|
|
186
|
-
|
|
187
|
-
- `@ruvector/core` (^0.1.1) - Native Rust bindings (when available)
|
|
188
|
-
- `@ruvector/wasm` (^0.1.1) - WebAssembly module (fallback)
|
|
189
|
-
|
|
190
|
-
### Dev Dependencies
|
|
191
|
-
|
|
192
|
-
- `typescript` (^5.3.3) - TypeScript compiler
|
|
193
|
-
- `@types/node` (^20.10.5) - Node.js type definitions
|
|
194
|
-
|
|
195
|
-
## Package.json Configuration
|
|
196
|
-
|
|
197
|
-
```json
|
|
198
|
-
{
|
|
199
|
-
"name": "ruvector",
|
|
200
|
-
"version": "0.1.1",
|
|
201
|
-
"main": "dist/index.js",
|
|
202
|
-
"types": "dist/index.d.ts",
|
|
203
|
-
"bin": {
|
|
204
|
-
"ruvector": "./bin/cli.js"
|
|
205
|
-
},
|
|
206
|
-
"scripts": {
|
|
207
|
-
"build": "tsc",
|
|
208
|
-
"test": "node test/standalone-test.js"
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
## Build Process
|
|
214
|
-
|
|
215
|
-
```bash
|
|
216
|
-
# Install dependencies
|
|
217
|
-
npm install
|
|
218
|
-
|
|
219
|
-
# Build TypeScript
|
|
220
|
-
npm run build
|
|
221
|
-
|
|
222
|
-
# Run tests
|
|
223
|
-
npm test
|
|
224
|
-
|
|
225
|
-
# Package for NPM
|
|
226
|
-
npm pack
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
## Testing
|
|
230
|
-
|
|
231
|
-
The package includes comprehensive tests:
|
|
232
|
-
|
|
233
|
-
### 1. Standalone Test (`test/standalone-test.js`)
|
|
234
|
-
|
|
235
|
-
Tests package structure and API using mock implementation:
|
|
236
|
-
- Package structure validation
|
|
237
|
-
- TypeScript type definitions
|
|
238
|
-
- VectorDB API functionality
|
|
239
|
-
- CLI structure
|
|
240
|
-
- Smart loader logic
|
|
241
|
-
|
|
242
|
-
### 2. Integration Test (`test/integration.js`)
|
|
243
|
-
|
|
244
|
-
Tests integration with real implementations when available.
|
|
245
|
-
|
|
246
|
-
### 3. Mock Implementation (`test/mock-implementation.js`)
|
|
247
|
-
|
|
248
|
-
JavaScript-based VectorDB implementation for testing and demonstration purposes.
|
|
249
|
-
|
|
250
|
-
## Examples
|
|
251
|
-
|
|
252
|
-
### API Usage (`examples/api-usage.js`)
|
|
253
|
-
|
|
254
|
-
Demonstrates:
|
|
255
|
-
- Basic CRUD operations
|
|
256
|
-
- Batch operations
|
|
257
|
-
- Semantic search
|
|
258
|
-
- Different distance metrics
|
|
259
|
-
- Performance benchmarking
|
|
260
|
-
- Persistence
|
|
261
|
-
|
|
262
|
-
### CLI Demo (`examples/cli-demo.sh`)
|
|
263
|
-
|
|
264
|
-
Bash script demonstrating CLI tools.
|
|
265
|
-
|
|
266
|
-
## Usage Examples
|
|
267
|
-
|
|
268
|
-
### Simple Vector Search
|
|
269
|
-
|
|
270
|
-
```javascript
|
|
271
|
-
const { VectorDB } = require('ruvector');
|
|
272
|
-
|
|
273
|
-
const db = new VectorDB({ dimension: 3 });
|
|
274
|
-
|
|
275
|
-
db.insertBatch([
|
|
276
|
-
{ id: 'cat', vector: [0.9, 0.1, 0.1], metadata: { animal: 'cat' } },
|
|
277
|
-
{ id: 'dog', vector: [0.1, 0.9, 0.1], metadata: { animal: 'dog' } },
|
|
278
|
-
{ id: 'tiger', vector: [0.8, 0.2, 0.15], metadata: { animal: 'tiger' } }
|
|
279
|
-
]);
|
|
280
|
-
|
|
281
|
-
const results = db.search({
|
|
282
|
-
vector: [0.9, 0.1, 0.1],
|
|
283
|
-
k: 2
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
console.log(results);
|
|
287
|
-
// [
|
|
288
|
-
// { id: 'cat', score: 1.0, ... },
|
|
289
|
-
// { id: 'tiger', score: 0.97, ... }
|
|
290
|
-
// ]
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
### Semantic Document Search
|
|
294
|
-
|
|
295
|
-
```javascript
|
|
296
|
-
const db = new VectorDB({ dimension: 768, metric: 'cosine' });
|
|
297
|
-
|
|
298
|
-
// Insert documents with embeddings (from your embedding model)
|
|
299
|
-
db.insertBatch([
|
|
300
|
-
{ id: 'doc1', vector: embedding1, metadata: { title: 'AI Guide' } },
|
|
301
|
-
{ id: 'doc2', vector: embedding2, metadata: { title: 'Web Dev' } }
|
|
302
|
-
]);
|
|
303
|
-
|
|
304
|
-
// Search with query embedding
|
|
305
|
-
const results = db.search({
|
|
306
|
-
vector: queryEmbedding,
|
|
307
|
-
k: 10,
|
|
308
|
-
threshold: 0.7
|
|
309
|
-
});
|
|
310
|
-
```
|
|
311
|
-
|
|
312
|
-
### Persistence
|
|
313
|
-
|
|
314
|
-
```javascript
|
|
315
|
-
const db = new VectorDB({
|
|
316
|
-
dimension: 384,
|
|
317
|
-
path: './vectors.db',
|
|
318
|
-
autoPersist: true
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
// Changes automatically saved
|
|
322
|
-
db.insert({ id: 'doc1', vector: [...] });
|
|
323
|
-
|
|
324
|
-
// Or manual save
|
|
325
|
-
db.save('./backup.db');
|
|
326
|
-
|
|
327
|
-
// Load from disk
|
|
328
|
-
db.load('./vectors.db');
|
|
329
|
-
```
|
|
330
|
-
|
|
331
|
-
## Performance Characteristics
|
|
332
|
-
|
|
333
|
-
### Mock Implementation (JavaScript)
|
|
334
|
-
- Insert: ~1M vectors/sec (batch)
|
|
335
|
-
- Search: ~400 queries/sec (1000 vectors, k=10)
|
|
336
|
-
|
|
337
|
-
### Native Implementation (Rust)
|
|
338
|
-
- Insert: ~10M+ vectors/sec (batch)
|
|
339
|
-
- Search: ~100K+ queries/sec with HNSW index
|
|
340
|
-
- 150x faster than pgvector
|
|
341
|
-
|
|
342
|
-
### WASM Implementation
|
|
343
|
-
- Insert: ~1M+ vectors/sec (batch)
|
|
344
|
-
- Search: ~10K+ queries/sec with HNSW index
|
|
345
|
-
- ~10x faster than pure JavaScript
|
|
346
|
-
|
|
347
|
-
## Integration with Other Packages
|
|
348
|
-
|
|
349
|
-
This package serves as the main interface and coordinates between:
|
|
350
|
-
|
|
351
|
-
1. **@ruvector/core** - Native Rust bindings (napi-rs)
|
|
352
|
-
- Platform-specific native modules
|
|
353
|
-
- Maximum performance
|
|
354
|
-
- Optional dependency
|
|
355
|
-
|
|
356
|
-
2. **@ruvector/wasm** - WebAssembly module
|
|
357
|
-
- Universal compatibility
|
|
358
|
-
- Near-native performance
|
|
359
|
-
- Fallback implementation
|
|
360
|
-
|
|
361
|
-
## Error Handling
|
|
362
|
-
|
|
363
|
-
The package provides clear error messages when implementations are unavailable:
|
|
364
|
-
|
|
365
|
-
```
|
|
366
|
-
Failed to load ruvector: Neither native nor WASM implementation available.
|
|
367
|
-
Native error: Cannot find module '@ruvector/core'
|
|
368
|
-
WASM error: Cannot find module '@ruvector/wasm'
|
|
369
|
-
```
|
|
370
|
-
|
|
371
|
-
## Environment Variables
|
|
372
|
-
|
|
373
|
-
- `RUVECTOR_DEBUG=1` - Enable debug logging for implementation loading
|
|
374
|
-
|
|
375
|
-
## Next Steps
|
|
376
|
-
|
|
377
|
-
To complete the package ecosystem:
|
|
378
|
-
|
|
379
|
-
1. **Create @ruvector/core**
|
|
380
|
-
- napi-rs bindings to Rust code
|
|
381
|
-
- Platform-specific builds (Linux, macOS, Windows)
|
|
382
|
-
- Native module packaging
|
|
383
|
-
|
|
384
|
-
2. **Create @ruvector/wasm**
|
|
385
|
-
- wasm-pack build from Rust code
|
|
386
|
-
- WebAssembly module
|
|
387
|
-
- Universal compatibility layer
|
|
388
|
-
|
|
389
|
-
3. **Update Dependencies**
|
|
390
|
-
- Add @ruvector/core as optionalDependency
|
|
391
|
-
- Add @ruvector/wasm as dependency
|
|
392
|
-
- Configure proper fallback chain
|
|
393
|
-
|
|
394
|
-
4. **Publishing**
|
|
395
|
-
- Publish all three packages to npm
|
|
396
|
-
- Set up CI/CD for builds
|
|
397
|
-
- Create platform-specific releases
|
|
398
|
-
|
|
399
|
-
## Version
|
|
400
|
-
|
|
401
|
-
Current version: **0.1.1**
|
|
402
|
-
|
|
403
|
-
## License
|
|
404
|
-
|
|
405
|
-
MIT
|
|
406
|
-
|
|
407
|
-
## Repository
|
|
408
|
-
|
|
409
|
-
https://github.com/ruvnet/ruvector
|