ruvector-cli 2.0.4

CLI and MCP server for Ruvector
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
# Ruvector CLI and MCP Server

High-performance command-line interface and Model Context Protocol (MCP) server for Ruvector vector database.

## Table of Contents

- [Installation]#installation
- [CLI Usage]#cli-usage
- [MCP Server]#mcp-server
- [Configuration]#configuration
- [Examples]#examples
- [Shell Completions]#shell-completions

## Installation

```bash
# Build from source
cargo build --release -p ruvector-cli

# Install binaries
cargo install --path crates/ruvector-cli

# The following binaries will be available:
# - ruvector (CLI tool)
# - ruvector-mcp (MCP server)
```

## CLI Usage

### Create a Database

```bash
# Create with specific dimensions
ruvector create --path ./my-vectors.db --dimensions 384

# Use default location (./ruvector.db)
ruvector create --dimensions 1536
```

### Insert Vectors

```bash
# From JSON file
ruvector insert --db ./my-vectors.db --input vectors.json --format json

# From CSV file
ruvector insert --db ./my-vectors.db --input vectors.csv --format csv

# From NumPy file
ruvector insert --db ./my-vectors.db --input embeddings.npy --format npy

# Hide progress bar
ruvector insert --db ./my-vectors.db --input vectors.json --no-progress
```

#### Input Format Examples

**JSON format:**
```json
[
  {
    "id": "doc1",
    "vector": [0.1, 0.2, 0.3, ...],
    "metadata": {
      "title": "Document 1",
      "category": "science"
    }
  },
  {
    "id": "doc2",
    "vector": [0.4, 0.5, 0.6, ...],
    "metadata": {
      "title": "Document 2",
      "category": "tech"
    }
  }
]
```

**CSV format:**
```csv
id,vector,metadata
doc1,"[0.1, 0.2, 0.3]","{\"title\": \"Document 1\"}"
doc2,"[0.4, 0.5, 0.6]","{\"title\": \"Document 2\"}"
```

### Search Vectors

```bash
# Search with JSON array
ruvector search --db ./my-vectors.db --query "[0.1, 0.2, 0.3]" --top-k 10

# Search with comma-separated values
ruvector search --db ./my-vectors.db --query "0.1, 0.2, 0.3" -k 5

# Show full vectors in results
ruvector search --db ./my-vectors.db --query "[0.1, 0.2, 0.3]" --show-vectors
```

### Database Info

```bash
# Show database statistics
ruvector info --db ./my-vectors.db
```

Output example:
```
Database Statistics
  Vectors: 10000
  Dimensions: 384
  Distance Metric: Cosine

HNSW Configuration:
  M: 32
  ef_construction: 200
  ef_search: 100
```

### Benchmark Performance

```bash
# Run 1000 queries
ruvector benchmark --db ./my-vectors.db --queries 1000

# Custom number of queries
ruvector benchmark --db ./my-vectors.db -n 5000
```

Output example:
```
Running benchmark...
  Queries: 1000
  Dimensions: 384

Benchmark Results:
  Total time: 2.45s
  Queries per second: 408
  Average latency: 2.45ms
```

### Export Database

```bash
# Export to JSON
ruvector export --db ./my-vectors.db --output backup.json --format json

# Export to CSV
ruvector export --db ./my-vectors.db --output backup.csv --format csv
```

### Import from Other Databases

```bash
# Import from FAISS (coming soon)
ruvector import --db ./my-vectors.db --source faiss --source-path index.faiss

# Import from Pinecone (coming soon)
ruvector import --db ./my-vectors.db --source pinecone --source-path config.json
```

### Global Options

```bash
# Use custom config file
ruvector --config ./custom-config.toml info --db ./my-vectors.db

# Enable debug mode
ruvector --debug search --db ./my-vectors.db --query "[0.1, 0.2, 0.3]"

# Disable colors
ruvector --no-color info --db ./my-vectors.db
```

## MCP Server

The Ruvector MCP server provides programmatic access via the Model Context Protocol.

### Start Server

```bash
# STDIO transport (for local communication)
ruvector-mcp --transport stdio

# SSE transport (for HTTP streaming)
ruvector-mcp --transport sse --host 127.0.0.1 --port 3000

# With custom config
ruvector-mcp --config ./mcp-config.toml --transport sse

# Debug mode
ruvector-mcp --debug --transport stdio
```

### MCP Tools

The server exposes the following tools:

#### 1. vector_db_create

Create a new vector database.

**Parameters:**
- `path` (string, required): Database file path
- `dimensions` (integer, required): Vector dimensions
- `distance_metric` (string, optional): Distance metric (euclidean, cosine, dotproduct, manhattan)

**Example:**
```json
{
  "name": "vector_db_create",
  "arguments": {
    "path": "./my-db.db",
    "dimensions": 384,
    "distance_metric": "cosine"
  }
}
```

#### 2. vector_db_insert

Insert vectors into database.

**Parameters:**
- `db_path` (string, required): Database path
- `vectors` (array, required): Array of vector objects

**Example:**
```json
{
  "name": "vector_db_insert",
  "arguments": {
    "db_path": "./my-db.db",
    "vectors": [
      {
        "id": "vec1",
        "vector": [0.1, 0.2, 0.3],
        "metadata": {"label": "test"}
      }
    ]
  }
}
```

#### 3. vector_db_search

Search for similar vectors.

**Parameters:**
- `db_path` (string, required): Database path
- `query` (array, required): Query vector
- `k` (integer, optional, default: 10): Number of results
- `filter` (object, optional): Metadata filters

**Example:**
```json
{
  "name": "vector_db_search",
  "arguments": {
    "db_path": "./my-db.db",
    "query": [0.1, 0.2, 0.3],
    "k": 5
  }
}
```

#### 4. vector_db_stats

Get database statistics.

**Parameters:**
- `db_path` (string, required): Database path

**Example:**
```json
{
  "name": "vector_db_stats",
  "arguments": {
    "db_path": "./my-db.db"
  }
}
```

#### 5. vector_db_backup

Backup database to file.

**Parameters:**
- `db_path` (string, required): Database path
- `backup_path` (string, required): Backup file path

**Example:**
```json
{
  "name": "vector_db_backup",
  "arguments": {
    "db_path": "./my-db.db",
    "backup_path": "./backup.db"
  }
}
```

### MCP Resources

The server provides access to database resources via URIs:

- `database://local/default`: Default database resource

### MCP Prompts

Available prompt templates:

- `semantic-search`: Generate semantic search queries

## Configuration

Ruvector can be configured via TOML files, environment variables, or CLI arguments.

### Configuration File

Create a `ruvector.toml` file:

```toml
[database]
storage_path = "./ruvector.db"
dimensions = 384
distance_metric = "Cosine"

[database.hnsw]
m = 32
ef_construction = 200
ef_search = 100
max_elements = 10000000

[cli]
progress = true
colors = true
batch_size = 1000

[mcp]
host = "127.0.0.1"
port = 3000
cors = true
```

### Environment Variables

```bash
export RUVECTOR_STORAGE_PATH="./my-db.db"
export RUVECTOR_DIMENSIONS=384
export RUVECTOR_DISTANCE_METRIC="cosine"
export RUVECTOR_MCP_HOST="0.0.0.0"
export RUVECTOR_MCP_PORT=8080
```

### Configuration Precedence

1. CLI arguments (highest priority)
2. Environment variables
3. Configuration file
4. Default values (lowest priority)

### Default Config Locations

Ruvector looks for config files in these locations:

1. `./ruvector.toml`
2. `./.ruvector.toml`
3. `~/.config/ruvector/config.toml`
4. `/etc/ruvector/config.toml`

## Examples

### Building a Semantic Search Engine

```bash
# 1. Create database
ruvector create --path ./search.db --dimensions 384

# 2. Generate embeddings (external script)
python generate_embeddings.py --input documents/ --output embeddings.json

# 3. Insert embeddings
ruvector insert --db ./search.db --input embeddings.json

# 4. Search
ruvector search --db ./search.db --query "[0.1, 0.2, ...]" -k 10
```

### Batch Processing Pipeline

```bash
#!/bin/bash

DB="./vectors.db"
DIMS=768

# Create database
ruvector create --path $DB --dimensions $DIMS

# Process batches
for file in data/batch_*.json; do
  echo "Processing $file..."
  ruvector insert --db $DB --input $file --no-progress
done

# Verify
ruvector info --db $DB

# Benchmark
ruvector benchmark --db $DB --queries 1000
```

### Using with Claude Code

```bash
# Start MCP server
ruvector-mcp --transport stdio

# Claude Code can now use vector database tools
# Example prompt: "Create a vector database and insert embeddings from my documents"
```

## Shell Completions

Generate shell completions for better CLI experience:

```bash
# Bash
ruvector --generate-completions bash > ~/.local/share/bash-completion/completions/ruvector

# Zsh
ruvector --generate-completions zsh > ~/.zsh/completions/_ruvector

# Fish
ruvector --generate-completions fish > ~/.config/fish/completions/ruvector.fish
```

## Error Handling

Ruvector provides helpful error messages:

```bash
# Missing required argument
$ ruvector create
Error: Missing required argument: --dimensions

# Invalid vector dimensions
$ ruvector insert --db test.db --input vectors.json
Error: Vector dimension mismatch. Expected: 384, Got: 768
Suggestion: Ensure all vectors have the correct dimensionality

# Database not found
$ ruvector info --db nonexistent.db
Error: Failed to open database: No such file or directory
Suggestion: Create the database first with: ruvector create --path nonexistent.db --dimensions <dims>

# Use --debug for full stack traces
$ ruvector --debug info --db nonexistent.db
```

## Performance Tips

1. **Batch Inserts**: Insert vectors in batches for better performance
2. **HNSW Tuning**: Adjust `ef_construction` and `ef_search` based on your accuracy/speed requirements
3. **Quantization**: Enable quantization for memory-constrained environments
4. **Dimensions**: Use appropriate dimensions for your use case (384 for smaller models, 1536 for larger)
5. **Distance Metric**: Choose based on your embeddings:
   - Cosine: Normalized embeddings (most common)
   - Euclidean: Absolute distances
   - Dot Product: When magnitude matters

## Troubleshooting

### Build Issues

```bash
# Ensure Rust is up to date
rustup update

# Clean build
cargo clean && cargo build --release -p ruvector-cli
```

### Runtime Issues

```bash
# Enable debug logging
RUST_LOG=debug ruvector info --db test.db

# Check database integrity
ruvector info --db test.db

# Backup before operations
cp test.db test.db.backup
```

## Contributing

See the main Ruvector repository for contribution guidelines.

## License

MIT License - see LICENSE file for details.