Skip to main content

LsmIndex

Struct LsmIndex 

Source
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

Source

pub fn new(config: LsmConfig) -> Self

Create a new LSM-tiered index.

Source

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.

Source

pub fn insert_slice(&mut self, doc_id: u32, vector: &[f32]) -> Result<()>

Insert from a borrowed slice.

Source

pub fn delete(&mut self, doc_id: u32)

Mark a vector for deletion.

Source

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.

Source

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.

Source

pub fn len(&self) -> usize

Number of active (non-tombstoned) vectors across all levels.

Source

pub fn is_empty(&self) -> bool

Whether the index has no active vectors.

Source

pub fn num_levels(&self) -> usize

Number of levels (including L0).

Source

pub fn level_sizes(&self) -> Vec<usize>

Number of vectors at each level.

Source

pub fn stats(&self) -> LsmStats

Statistics.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V