pub struct LsmIndex { /* private fields */ }Expand description
LSM-tiered streaming vector index.
Provides O(1) amortized inserts with multi-level search across independently-built HNSW graphs.
Implementations§
Source§impl LsmIndex
impl LsmIndex
Sourcepub fn insert(&mut self, doc_id: u32, vector: Vec<f32>) -> Result<()>
pub fn insert(&mut self, doc_id: u32, vector: Vec<f32>) -> Result<()>
Insert a vector.
Appends to L0. When L0 exceeds buffer_capacity, triggers compaction.
Sourcepub fn insert_slice(&mut self, doc_id: u32, vector: &[f32]) -> Result<()>
pub fn insert_slice(&mut self, doc_id: u32, vector: &[f32]) -> Result<()>
Insert from a borrowed slice.
Sourcepub fn search(&self, query: &[f32], k: usize) -> Result<Vec<(u32, f32)>>
pub fn search(&self, query: &[f32], k: usize) -> Result<Vec<(u32, f32)>>
Search across all levels, merging results.
Searches each level independently, filters tombstones, and merges by
distance. Cost: O(L * search_per_level) where L = number of levels.
Sourcepub fn compact(&mut self) -> Result<()>
pub fn compact(&mut self) -> Result<()>
Trigger compaction: merge L0 into L1, and cascade if needed.
Compaction builds an HNSW graph from the merged vectors and replaces the target level. Tombstoned vectors are excluded during the merge.
Sourcepub fn num_levels(&self) -> usize
pub fn num_levels(&self) -> usize
Number of levels (including L0).
Sourcepub fn level_sizes(&self) -> Vec<usize>
pub fn level_sizes(&self) -> Vec<usize>
Number of vectors at each level.
Sourcepub fn force_merge_all(&mut self) -> Result<()>
pub fn force_merge_all(&mut self) -> Result<()>
Force-compact all levels into a single bottom level.
Useful for read-heavy workloads: eliminates multi-level search overhead. Expensive: rebuilds the entire graph.