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
impl LshIndex
Sourcepub fn builder() -> LshIndexBuilder
pub fn builder() -> LshIndexBuilder
Start building an index with the builder pattern.
Sourcepub fn new(config: IndexConfig) -> Result<Self>
pub fn new(config: IndexConfig) -> Result<Self>
Create an index directly from an IndexConfig.
Sourcepub fn insert(&self, id: usize, vector: &[f32]) -> Result<()>
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.
Sourcepub fn insert_auto(&self, vector: &[f32]) -> Result<usize>
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.
Sourcepub fn insert_batch(&self, vectors: &[(usize, &[f32])]) -> Result<()>
pub fn insert_batch(&self, vectors: &[(usize, &[f32])]) -> Result<()>
Insert multiple vectors at once. Aborts on first error.
Sourcepub fn query(&self, vector: &[f32], k: usize) -> Result<Vec<QueryResult>>
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).
Sourcepub fn stats(&self) -> IndexStats
pub fn stats(&self) -> IndexStats
Compute aggregate statistics about the index.
Sourcepub fn metrics(&self) -> Option<MetricsSnapshot>
pub fn metrics(&self) -> Option<MetricsSnapshot>
Snapshot of runtime metrics (None if metrics were not enabled).
Sourcepub fn reset_metrics(&self)
pub fn reset_metrics(&self)
Reset metrics counters.
Sourcepub fn config(&self) -> IndexConfig
pub fn config(&self) -> IndexConfig
Return a clone of the current configuration.