Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Vector Stores

LangChainRust provides a unified VectorStore trait with 10+ backends for storing and retrieving document embeddings.

Supported Backends

StoreStructFeature GateAuth
InMemoryInMemoryVectorStorealwaysNone
FileFileVectorStorealwaysNone
ChromaDBChromaDBVectorStorealwayshttp://localhost:8000
PineconePineconeStorealwaysAPI key + host
LanceDBLanceDBVectorStorealwaysOptional API key
Neo4jNeo4jVectorStorealwaysbolt:// + password
QdrantQdrantVectorStoreqdrant-integrationhttp://localhost:6334
PGVectorpgvector (helpers)pgvector-storagesqlx connection
RedisRedisDocumentStoreredis-storageRedis URL
SQLiteSQLiteDocumentStoresqlite-storageFile path
MongoDBMongoChunkedDocumentStoremongodb-persistenceMongoDB URI

VectorStore Trait

#![allow(unused)]
fn main() {
#[async_trait]
pub trait VectorStore: Send + Sync {
    async fn add_documents(&self, documents: Vec<Document>, embeddings: Vec<Vec<f32>>) -> Result<Vec<String>, VectorStoreError>;
    async fn similarity_search(&self, query_embedding: &[f32], k: usize) -> Result<Vec<SearchResult>, VectorStoreError>;
    async fn get_document(&self, id: &str) -> Result<Option<Document>, VectorStoreError>;
    async fn get_embedding(&self, id: &str) -> Result<Option<Vec<f32>>, VectorStoreError>;
    async fn delete_document(&self, id: &str) -> Result<(), VectorStoreError>;
    async fn count(&self) -> usize;
    async fn clear(&self) -> Result<(), VectorStoreError>;
}
}

InMemory & File

#![allow(unused)]
fn main() {
use langchainrust::{InMemoryVectorStore, FileVectorStore, Document};

// In-memory (no persistence)
let store = InMemoryVectorStore::new();
let ids = store.add_documents(docs, embeddings).await?;
let results = store.similarity_search(&query_vec, 5).await?;

// File-backed (JSON persistence)
let store = FileVectorStore::new(PathBuf::from("./vectors.json"), 1536)?;
}

ChromaDB & Qdrant

#![allow(unused)]
fn main() {
use langchainrust::{ChromaDBVectorStore, ChromaDBConfig};

// ChromaDB
let store = ChromaDBVectorStore::new(ChromaDBConfig::new(
    "http://localhost:8000", "my_collection", 1536,
))?;

// Qdrant (feature: qdrant-integration)
use langchainrust::{QdrantVectorStore, QdrantConfig, QdrantDistance};
let store = QdrantVectorStore::new(QdrantConfig::new("http://localhost:6334", "my_collection")
    .with_vector_size(1536)
    .with_distance(QdrantDistance::Cosine))?;
}

Document & Builder Pattern

#![allow(unused)]
fn main() {
use langchainrust::{Document, VectorStoreBuilder, VectorStoreType};

let doc = Document::new("Hello, world!")
    .with_metadata("source", "test")
    .with_id("doc-1");

// Builder pattern
let store = VectorStoreBuilder::in_memory().build().await?;
let store = VectorStoreBuilder::file_backed("./vectors.json", 1536).build().await?;
}

See also