The embedded mode allows you to use VectorXLite as a direct dependency in your Rust application, providing high-performance vector search with zero network overhead.
Overview
The embedded library combines SQLite's reliability with HNSW-based vector search, enabling:
- Sub-millisecond similarity search on millions of vectors
- SQL-powered payload filtering for hybrid queries
- ACID transactions with atomic operations
- In-memory or file-backed storage options
Installation
Add to your Cargo.toml:
[]
= { = "../embedded/core" } # Or from crates.io: "1.2"
= "0.8"
= "0.31"
= { = "0.37", = ["load_extension"] }
Quick Start
use ;
use Pool;
use SqliteConnectionManager;
Core Concepts
Collections
A collection combines a vector index with a payload table.
Creating Collections
let config = default
.collection_name
.vector_dimension // Dimension of your embeddings
.distance // Similarity metric
.max_elements // Capacity
.payload_table_schema
.index_file_path // Optional: persist HNSW index
.build?;
Checking Collection Existence
Before creating or using a collection, you can check if it exists:
// Check if a collection exists
if db.collection_exists? else
// Prevent duplicate collection creation
let collection_name = "products";
if !db.collection_exists? else
Important Notes:
- Collection names are case-sensitive
- Empty collection names return an error
- This check is atomic and thread-safe
- Useful for idempotent initialization code
Distance Functions
| Function | Description | Use Case |
|---|---|---|
Cosine |
Cosine similarity (normalized) | Text embeddings, NLP models |
L2 |
Euclidean distance | Image features, spatial data |
IP |
Inner product (dot product) | Pre-normalized vectors |
Storage Modes
In-Memory (Development/Testing)
let manager = memory;
File-Backed (Production)
let manager = file;
let config = default
.collection_name
.index_file_path // Persistent HNSW index
.build?;
Advanced Usage
JSON Payloads
let config = default
.collection_name
.payload_table_schema
.build?;
// Insert
let point = builder
.collection_name
.id
.vector
.payload_insert_query
.build?;
// Query JSON fields
let search = builder
.collection_name
.vector
.payload_search_query
.build?;
Atomic Operations
// Atomic batch insert using transactions
let manager = file;
let pool = builder
.connection_customizer
.build?;
let db = new?;
// All inserts are atomic - either all succeed or all fail
for in vectors.iter.enumerate
Connection Pooling
use SqliteConnectionCustomizer;
// Default timeout: 15 seconds
let customizer = new;
// Custom timeout: 30 seconds
let customizer = with_busy_timeout;
let pool = builder
.max_size // Max concurrent connections
.connection_customizer
.build?;
Examples
Run the included examples:
# Run all examples
# Run specific example
Performance Tips
- Use file-backed storage for datasets larger than RAM
- Tune
max_elementsto your expected dataset size - Index payload columns that you frequently filter on:
(category); - Batch operations for better throughput
- Persistent HNSW index with
index_file_pathfor faster restarts
API Reference
Main Types
VectorXLite- Main database interfacecreate_collection(config)- Create a new collectioncollection_exists(name)- Check if a collection existsinsert(point)- Insert a vector with payloaddelete(point)- Delete a vector from a collectiondelete_collection(collection)- Delete an entire collectionsearch(query)- Search for similar vectors
CollectionConfigBuilder- Configure collectionsInsertPoint- Insert operationsSearchPoint- Search operationsDistanceFunction- Similarity metrics (Cosine, L2, IP)
Full documentation
See the main README for comprehensive API documentation.
Architecture
┌─────────────────────────────────────────┐
│ Your Application │
├─────────────────────────────────────────┤
│ VectorXLite API │
├──────────────────┬──────────────────────┤
│ HNSW Index │ SQLite │
│ (Vector Search) │ (Payload Storage) │
├──────────────────┴──────────────────────┤
│ Connection Pool (r2d2) │
└─────────────────────────────────────────┘
Use Cases
- RAG Applications - Embed documents for LLM context retrieval
- Semantic Search - Find similar content by meaning
- Recommendation Systems - Similar item suggestions
- Image Search - Visual similarity using CNN embeddings
- Anomaly Detection - Outlier detection in high-dimensional data
- Deduplication - Find near-duplicate content
Testing
Run the comprehensive test suite:
# Run all tests
# Run specific test file
Next Steps
- Standalone Mode: Need multi-language clients? See ../standalone/
- Distributed Mode: Need high availability? See ../distributed/
- Documentation: Full API docs at docs.rs/vector_xlite
License
MIT OR Apache-2.0