Skip to main content

LshIndex

Struct LshIndex 

Source
pub struct LshIndex { /* private fields */ }
Expand description

A locality-sensitive hashing index for approximate nearest-neighbor search.

Thread-safe: concurrent reads (queries) proceed in parallel; writes (inserts, removes) acquire exclusive access via parking_lot::RwLock.

Implementations§

Source§

impl LshIndex

Source

pub fn builder() -> LshIndexBuilder

Start building an index with the builder pattern.

Source

pub fn new(config: IndexConfig) -> Result<Self>

Create an index directly from an IndexConfig.

Source

pub fn insert(&self, id: usize, vector: &[f32]) -> Result<()>

Insert a vector with the given ID.

If a vector with this ID already exists it is silently replaced.

Source

pub fn insert_auto(&self, vector: &[f32]) -> Result<usize>

Insert a vector and receive an auto-assigned ID.

The ID is assigned atomically under the write lock, so concurrent calls will never produce duplicate IDs.

Source

pub fn insert_batch(&self, vectors: &[(usize, &[f32])]) -> Result<()>

Insert multiple vectors at once. Aborts on first error.

Source

pub fn query(&self, vector: &[f32], k: usize) -> Result<Vec<QueryResult>>

Find the k approximate nearest neighbors for vector.

Returns results sorted by ascending distance (closest first).

Source

pub fn remove(&self, id: usize) -> Result<()>

Remove a vector by ID.

Source

pub fn contains(&self, id: usize) -> bool

Check whether a vector ID is present.

Source

pub fn len(&self) -> usize

Number of stored vectors.

Source

pub fn is_empty(&self) -> bool

True when the index holds no vectors.

Source

pub fn stats(&self) -> IndexStats

Compute aggregate statistics about the index.

Source

pub fn metrics(&self) -> Option<MetricsSnapshot>

Snapshot of runtime metrics (None if metrics were not enabled).

Source

pub fn reset_metrics(&self)

Reset metrics counters.

Source

pub fn clear(&self)

Remove all vectors from the index (projections are preserved).

Source

pub fn config(&self) -> IndexConfig

Return a clone of the current configuration.

Trait Implementations§

Source§

impl Debug for LshIndex

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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