Expand description
§DiskAnn (generic over anndists::Distance<f32>)
A minimal, on-disk, DiskANN-like library that:
- Builds a Vamana-style graph (greedy + α-pruning) in memory
- Writes vectors + fixed-degree adjacency to a single file
- Memory-maps the file for low-overhead reads
- Is generic over any
Distance<f32>fromanndists(L2, Cosine, Hamming, Dot, …) - Supports incremental updates (add/delete vectors without full rebuild)
§Example
use anndists::dist::{DistL2, DistCosine};
use diskann_rs::{DiskANN, DiskAnnParams};
// Build a new index from vectors, using L2 and default params
let vectors = vec![vec![0.0; 128]; 1000];
let index = DiskANN::<DistL2>::build_index_default(&vectors, DistL2{}, "index.db").unwrap();
// Or with custom params
let index2 = DiskANN::<DistCosine>::build_index_with_params(
&vectors,
DistCosine{},
"index_cos.db",
DiskAnnParams { max_degree: 48, ..Default::default() },
).unwrap();
// Search the index
let query = vec![0.0; 128];
let neighbors = index.search(&query, 10, 64);
// Open later (provide the same distance type)
let _reopened = DiskANN::<DistL2>::open_index_default_metric("index.db").unwrap();§Incremental Updates
use anndists::dist::DistL2;
use diskann_rs::IncrementalDiskANN;
// Build initial index
let vectors = vec![vec![0.0; 128]; 1000];
let mut index = IncrementalDiskANN::<DistL2>::build_default(&vectors, "index.db").unwrap();
// Add vectors without rebuilding
let new_ids = index.add_vectors(&[vec![1.0; 128]]).unwrap();
// Delete vectors (lazy tombstoning)
index.delete_vectors(&[0, 1, 2]).unwrap();
// Compact when needed
if index.should_compact() {
index.compact("index_v2.db").unwrap();
}§File Layout
[ metadata_len:u64 ][ metadata (bincode) ][ padding up to vectors_offset ] [ vectors (num * dim * f32) ][ adjacency (num * max_degree * u32) ]
vectors_offset is a fixed 1 MiB gap by default.
Re-exports§
pub use simd::SimdL2;pub use simd::SimdDot;pub use simd::SimdCosine;pub use simd::simd_info;pub use pq::ProductQuantizer;pub use pq::PQConfig;pub use pq::PQStats;
Modules§
Structs§
- DiskANN
- Main struct representing a DiskANN index (generic over distance)
- Disk
AnnParams - Optional bag of knobs if you want to override just a few.
- Filtered
DiskANN - DiskANN index with metadata filtering support
- Incremental
Config - Configuration for the incremental index behavior
- Incremental
DiskANN - An incremental DiskANN index supporting add/delete without full rebuild
- Incremental
Stats - Statistics about an incremental index
Enums§
- Disk
AnnError - Custom error type for DiskAnnRS operations
- Filter
- A single filter condition
Constants§
- DISKANN_
DEFAULT_ ALPHA - DISKANN_
DEFAULT_ BUILD_ BEAM - DISKANN_
DEFAULT_ MAX_ DEGREE - Defaults for in-memory DiskANN builds
Functions§
- delta_
local_ idx - Convert a delta global ID to local delta index
- is_
delta_ id - Check if an ID is from the delta layer