All examples · Core crate · API reference
Use the ruvector-core crate for embedded vector search. You need a Rust toolchain and platform build tools.
Create a small application with the persistent storage feature. This example uses exact search and disables the default optional features.
cargo new ruvector-memory
cd ruvector-memory
cargo add ruvector-core --no-default-features --features storageReplace src/main.rs with:
use ruvector_core::{DbOptions, SearchQuery, VectorDB, VectorEntry};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let db = VectorDB::new(DbOptions {
dimensions: 3,
storage_path: "./agent-memory.db".into(),
hnsw_config: None,
quantization: None,
..Default::default()
})?;
db.insert(VectorEntry {
id: Some("example-1".into()),
vector: vec![1.0, 0.0, 0.0],
metadata: None,
})?;
let hits = db.search(SearchQuery {
vector: vec![1.0, 0.0, 0.0],
k: 1,
filter: None,
ef_search: None,
})?;
assert_eq!(hits[0].id, "example-1");
println!("Nearest memory: {} (score: {})", hits[0].id, hits[0].score);
Ok(())
}cargo run --releaseThe fixed vector demonstrates insertion and retrieval; supply embeddings for semantic search. Keep Cargo.lock for reproducible dependency resolution. Rust API reference · Current core types · Storage and search implementation.
After the first successful run, remove only the db.insert(...)?; statement and run cargo run --release again from the same directory. The existing assertion should still find example-1. This checks recovery without reinserting the record.
Repository example files can target different crates and feature sets. Use each owning crate's Cargo configuration rather than assuming every file is a root workspace --example target.
