Expand description
§Nitrite Vector — HNSW ANN index & RAG store for Nitrite
This crate adds an approximate-nearest-neighbour (ANN) vector index to the
Nitrite embedded database, backed by a hand-rolled, persistent
HNSW (Hierarchical Navigable Small World) graph, plus a thin
RagStore convenience layer for retrieval-augmented-generation workloads.
Embeddings are provided by the caller (bring-your-own vectors); this crate does not generate embeddings.
§Quick start (raw collection API)
ⓘ
use nitrite::nitrite::Nitrite;
use nitrite::common::PersistentCollection;
use nitrite_vector::{VectorModule, VectorIndexConfig, vector_index_options, vector_field};
use nitrite_vector::distance::Metric;
let db = Nitrite::builder()
.load_module(VectorModule::new(VectorIndexConfig::new(3, Metric::Cosine)))
.open_or_create(None, None)?;
let collection = db.collection("docs")?;
collection.create_index(vec!["embedding"], &vector_index_options())?;
// ... insert documents whose `embedding` field is a numeric array ...
let filter = vector_field("embedding").nearest(vec![0.1, 0.2, 0.3], 5).build();
let results = collection.find(filter)?;§RAG store
ⓘ
use nitrite_vector::RagStore;
use nitrite_vector::distance::Metric;
// `Metric::Cosine` must match the metric configured on the VectorModule.
let store = RagStore::create(&db, "kb", Metric::Cosine)?;
store.add("hello world", embedding, doc!{ "source": "wiki" })?;
let hits = store.search(query_vector, 5).run()?;§Security note
Vectors are stored in plaintext by both backends (embeddings are
generally invertible back to content — treat them as the data itself). The
DiskANN backend writes its files next to the database, outside whatever the
storage adapter provides, and therefore requires a persistent db_path.
Re-exports§
pub use diskann::DiskAnnConfig;pub use diskann::DiskAnnIndex;pub use distance::Metric;pub use filter::value_to_vector;pub use filter::vector_to_value;pub use filter::VectorNearestFilter;pub use filter::VECTOR_INDEX;pub use fluent::vector_field;pub use fluent::VectorFluentFilter;pub use fluent::VectorNearestBuilder;pub use indexer::VectorIndexer;pub use module::VectorModule;pub use module::VectorModuleBuilder;pub use precision::Precision;pub use rag::RagStore;pub use rag::SearchHit;pub use rag::SearchQuery;pub use vector_index::derive_vector_map_name;pub use vector_index::HnswBackend;pub use vector_index::IndexBackend;pub use vector_index::VectorIndex;pub use vector_index::VectorIndexConfig;
Modules§
- diskann
- Disk-resident DiskANN backend: a single-layer Vamana graph plus full vectors
stored on disk in a memory-mapped flat file (
flat_store), with product-quantized codes resident in RAM for fast approximate traversal and exact re-ranking from the on-disk vectors. - distance
- Distance metrics for vector similarity search.
- filter
- Vector search filter.
- fluent
- Fluent API for building vector search filters.
- hnsw
- In-memory HNSW (Hierarchical Navigable Small World) graph.
- indexer
- The vector indexer: implements Nitrite’s
NitriteIndexerProviderso an HNSW index can be created, maintained, and queried through the standard collection API. - module
- Nitrite module that registers the vector indexer, plus a fluent builder that surfaces every configurable knob.
- node
- Serializable records for the HNSW graph.
- precision
- User-selectable stored-vector precision.
- rag
- A thin retrieval-augmented-generation (RAG) store over a Nitrite collection.
- vector_
index - Durable HNSW index: bridges the in-memory
Hnswgraph with a NitriteNitriteMapso the graph survives restarts and participates in the store’s atomicity.
Functions§
- vector_
index_ options - Creates
IndexOptionsfor a vector index.