Expand description
§VectorLite
A high-performance, in-memory vector database optimized for AI agent workloads with HTTP API and thread-safe concurrency.
§Overview
VectorLite is designed for single-instance, low-latency vector operations in AI agent environments. It prioritizes sub-millisecond search performance over distributed scalability, making it ideal for:
- AI Agent Sessions: Session-scoped vector storage with fast retrieval
- Real-time Search: Sub-millisecond response requirements
- Prototype Development: Rapid iteration without infrastructure complexity
- Single-tenant Applications: No multi-tenancy isolation requirements
§Key Features
- In-memory storage for zero-latency access patterns
- Native Rust ML models using Candle framework with pluggable architecture
- Thread-safe concurrency with RwLock per collection and atomic ID generation
- HNSW indexing for approximate nearest neighbor search with configurable accuracy
- HTTP API for easy integration with AI agents and other services
§Quick Start
use vectorlite::{VectorLiteClient, EmbeddingGenerator, IndexType, SimilarityMetric};
// Create client with embedding function
let mut client = VectorLiteClient::new(Box::new(EmbeddingGenerator::new()?));
// Create collection
client.create_collection("documents", IndexType::HNSW)?;
// Add text (auto-generates embedding and ID)
let id = client.add_text_to_collection("documents", "Hello world")?;
// Search
let results = client.search_text_in_collection(
"documents",
"hello",
5,
SimilarityMetric::Cosine
)?;§Index Types
§FlatIndex
- Complexity: O(n) search, O(1) insert
- Memory: Linear with dataset size
- Use Case: Small datasets (< 10K vectors) or exact search requirements
§HNSWIndex
- Complexity: O(log n) search, O(log n) insert
- Memory: ~2-3x vector size due to graph structure
- Use Case: Large datasets with approximate search tolerance
§Similarity Metrics
- Cosine: Default for normalized embeddings, scale-invariant
- Euclidean: Geometric distance, sensitive to vector magnitude
- Manhattan: L1 norm, robust to outliers
- Dot Product: Raw similarity, requires consistent vector scaling
§HTTP Server
use vectorlite::{VectorLiteClient, EmbeddingGenerator, start_server};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = VectorLiteClient::new(Box::new(EmbeddingGenerator::new()?));
start_server(client, "127.0.0.1", 3001).await?;
Ok(())
}§Configuration Profiles
# Balanced (default)
cargo build
# Memory-constrained environments
cargo build --features memory-optimized
# High-precision search
cargo build --features high-accuracyRe-exports§
pub use index::flat::FlatIndex;pub use index::hnsw::HNSWIndex;pub use embeddings::EmbeddingGenerator;pub use embeddings::EmbeddingFunction;pub use client::VectorLiteClient;pub use client::Collection;pub use client::Settings;pub use client::IndexType;pub use server::create_app;pub use server::start_server;pub use persistence::PersistenceError;pub use persistence::save_collection_to_file;pub use persistence::load_collection_from_file;
Modules§
- client
- Client Module
- embeddings
- Embeddings Module
- index
- Index Module
- persistence
- Persistence Module
- server
- HTTP Server Module
Structs§
- Search
Result - Search result containing a vector ID and similarity score
- Vector
- Represents a vector with an ID and floating-point values
Enums§
- Similarity
Metric - Similarity metrics for vector comparison
- Vector
Index Wrapper - Wrapper enum for different vector index implementations
Constants§
- DEFAULT_
VECTOR_ DIMENSION - Default vector dimension for embedding models
Traits§
- Vector
Index - Trait for vector indexing implementations
Functions§
- cosine_
similarity - Calculate cosine similarity between two vectors
- dot_
product - Calculate dot product between two vectors
- euclidean_
similarity - Calculate Euclidean similarity between two vectors
- manhattan_
similarity - Calculate Manhattan similarity between two vectors