ruvector/examples/rust
2026-10-10 14:13:34 -07:00
..
advanced_features.rs docs: Organize examples/ with comprehensive READMEs 2025-11-29 14:05:04 +00:00
agenticdb_demo.rs docs: Organize examples/ with comprehensive READMEs 2025-11-29 14:05:04 +00:00
basic_usage.rs feat: Complete ALL Ruvector phases - production-ready vector database 2025-11-19 14:37:21 +00:00
batch_operations.rs feat: Complete ALL Ruvector phases - production-ready vector database 2025-11-19 14:37:21 +00:00
gnn_example.rs docs: Organize examples/ with comprehensive READMEs 2025-11-29 14:05:04 +00:00
rag_pipeline.rs feat(postgres): Add HNSW index and embedding functions support (#62) 2025-12-09 11:14:52 -05:00
README.md docs: align tutorials, simplify onboarding, and add animated navigation 2026-10-10 14:13:34 -07:00

RuVector Rust tutorial

Animated tutorial: install, write, reopen, verify

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 and run an application

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 storage

Replace 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 --release

The 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.

Verify persistence

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.

Explore the wider stack

Goal Guide
Graph relationships Graph examples
Graph partitioning MinCut examples
Contrastive training Training guide
Memory reconstruction MRAgent
Portable vector artifacts RVF examples

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.