Skip to main content

VectorIndex

Struct VectorIndex 

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

Persistent vector index backed by HNSW. Open with VectorIndex::open or create with VectorIndex::build.

Implementations§

Source§

impl VectorIndex

Source

pub fn build( path: impl AsRef<Path>, entries: Vec<(String, Vec<f32>)>, m: usize, ef_construct: usize, ) -> Result<Self, DBError>

Build a new index from entries, write it to path, and return it.

m (graph connectivity) and ef_construct (build-time beam width) control quality/speed. Typical values: m=16, ef_construct=200.

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, DBError>

Open a previously built index from path.

Source

pub fn save(&self) -> Result<(), DBError>

Write this index to disk, overwriting any existing files atomically.

Source

pub fn search(&self, query: &[f32], top_k: usize) -> Vec<(String, f32)>

Search for the top_k nearest neighbours to query.

Returns (id, score) pairs sorted by descending score (higher = closer).

Source

pub fn search_with_ef( &self, query: &[f32], top_k: usize, ef_search: usize, ) -> Vec<(String, f32)>

Like [search] but with an explicit ef_search beam width.

Source

pub fn len(&self) -> usize

Number of vectors in the index.

Source

pub fn is_empty(&self) -> bool

Source

pub fn id_at(&self, i: usize) -> Option<&str>

Return the ID of the vector at internal index position i, if any.

Source

pub fn position_of(&self, id: &str) -> Option<u64>

Return the internal index position for a document ID, if present.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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