Skip to main content

VectorIndex

Struct VectorIndex 

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

Immutable deterministic HNSW candidate index.

Implementations§

Source§

impl VectorIndex

Source

pub fn search_batch( &self, queries: &[&[f32]], count: usize, ) -> Result<Vec<Vec<SearchHit>>, SearchError>

Searches independent queries using bounded scoped workers. Each worker reuses its visited-set and heaps across queries.

§Errors

Returns the first query error in input order or a worker-panic error.

Source

pub fn search_batch_with_policy( &self, queries: &[&[f32]], count: usize, policy: SearchPolicy, ) -> Result<Vec<Vec<SearchHit>>, SearchError>

Searches independent queries with a shared per-query recall policy.

§Errors

Returns the first query error in input order or a worker-panic error.

Source§

impl VectorIndex

Source

pub fn build( config: IndexConfig, vectors: &[(u64, &[f32])], ) -> Result<Self, SearchError>

Builds independently seeded HNSW replicas over validated normalized vectors.

Input order does not affect the resulting graph when keys, vectors, config, and seed are unchanged.

§Errors

Returns typed configuration, vector, capacity, allocation, or worker failures.

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub const fn dimensions(&self) -> usize

Source

pub fn config(&self) -> &IndexConfig

Source

pub fn keys(&self) -> impl ExactSizeIterator<Item = u64> + '_

Iterates stable caller-provided keys in ascending order.

Source

pub fn vector(&self, key: u64) -> Option<&[f32]>

Returns the normalized vector stored for key.

Source

pub fn estimated_memory_bytes(&self) -> usize

Returns an allocation-based estimate of resident vector and graph storage. It excludes allocator metadata and temporary query scratch.

Source§

impl VectorIndex

Source

pub fn search( &self, query: &[f32], count: usize, ) -> Result<Vec<SearchHit>, SearchError>

Returns approximate top-K hits ordered by exact distance and key.

§Errors

Returns a typed error for an invalid query or scratch allocation.

Source

pub fn search_with_policy( &self, query: &[f32], count: usize, policy: SearchPolicy, ) -> Result<Vec<SearchHit>, SearchError>

Returns approximate top-K hits with a per-query recall policy.

This separates graph expansion from deterministic routing recovery so callers can raise recall without rebuilding the index.

§Errors

Returns a typed error for an invalid policy, query, or scratch allocation.

Source

pub fn search_exact( &self, query: &[f32], count: usize, ) -> Result<Vec<SearchHit>, SearchError>

Returns exact top-K results over the same normalized vectors.

This is intended as a correctness and recall oracle.

§Errors

Returns a typed error for an invalid query.

Source

pub fn search_exact_filtered<F>( &self, query: &[f32], count: usize, filter: F, ) -> Result<Vec<SearchHit>, SearchError>
where F: Fn(u64) -> bool,

Returns exact top-K results accepted by filter.

§Errors

Returns a typed error for an invalid query.

Source

pub fn search_filtered<F>( &self, query: &[f32], count: usize, filter: F, ) -> Result<Vec<SearchHit>, SearchError>
where F: Fn(u64) -> bool,

Searches HNSW candidates accepted by filter, with an exact fallback when selective filters do not yield enough approximate candidates.

§Errors

Returns a typed error for an invalid query or scratch allocation.

Source

pub fn search_filtered_with_policy<F>( &self, query: &[f32], count: usize, filter: F, policy: FilterSearchPolicy, ) -> Result<Vec<SearchHit>, SearchError>
where F: Fn(u64) -> bool,

Searches with the predicate applied during graph traversal.

Traversal avoids a full scan and may return fewer than count hits. ExactFallback preserves completeness when the graph cannot find enough accepted candidates.

§Errors

Returns a typed error for an invalid query or scratch allocation.

Source§

impl VectorIndex

Source

pub fn save(&self, path: impl AsRef<Path>) -> Result<(), SearchError>

Persists normalized vectors, routing data, and every HNSW replica.

The snapshot is written through a temporary sibling and flushed before replacement.

§Errors

Returns a typed storage, allocation, or capacity error.

Source

pub fn load(path: impl AsRef<Path>) -> Result<Self, SearchError>

Loads a persisted index into owned memory without rebuilding HNSW.

§Errors

Returns a typed storage, version, integrity, allocation, or config error.

Source

pub fn to_bytes(&self) -> Result<Vec<u8>, SearchError>

Serializes the canonical snapshot into an owned byte buffer.

§Errors

Returns a typed storage, allocation, or capacity error.

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, SearchError>

Restores an owned index directly from a canonical snapshot buffer.

§Errors

Returns a typed version, integrity, allocation, or config error.

Source

pub fn write_to<W: Write + Seek>( &self, writer: &mut W, ) -> Result<(), SearchError>

Writes a canonical snapshot to a seekable stream.

The caller should provide an empty or truncated stream.

§Errors

Returns a typed stream, allocation, or capacity error.

Source

pub fn read_from<R: Read>(reader: &mut R) -> Result<Self, SearchError>

Reads a complete canonical snapshot from a stream.

§Errors

Returns a typed stream, version, integrity, allocation, or config error.

Source

pub fn read_metadata( path: impl AsRef<Path>, ) -> Result<SnapshotMetadata, SearchError>

Reads snapshot metadata without decoding vectors or graphs.

§Errors

Returns a typed storage, version, or header error.

Trait Implementations§

Source§

impl Debug for VectorIndex

Source§

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

Formats the value using the given formatter. Read more
Source§

impl SearchShard for VectorIndex

Source§

fn dimensions(&self) -> usize

Source§

fn search_shard( &self, query: &[f32], count: usize, ) -> Result<Vec<SearchHit>, SearchError>

Searches this shard. 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.