pub struct VectorIndex { /* private fields */ }Expand description
Wrapper around HNSW index
Implementations§
Source§impl VectorIndex
impl VectorIndex
Sourcepub fn new(dimensions: usize, metric: DistanceMetric) -> VectorIndex
pub fn new(dimensions: usize, metric: DistanceMetric) -> VectorIndex
Create a new vector index
Sourcepub fn add(
&mut self,
node_id: NodeId,
vector: &Vec<f32>,
) -> Result<(), VectorError>
pub fn add( &mut self, node_id: NodeId, vector: &Vec<f32>, ) -> Result<(), VectorError>
Add a vector to the index
Sourcepub fn search(
&self,
query: &[f32],
k: usize,
) -> Result<Vec<(NodeId, f32)>, VectorError>
pub fn search( &self, query: &[f32], k: usize, ) -> Result<Vec<(NodeId, f32)>, VectorError>
Search for nearest neighbors
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Get dimensions
Sourcepub fn metric(&self) -> DistanceMetric
pub fn metric(&self) -> DistanceMetric
Get metric
Sourcepub fn dump(&self, path: &Path) -> Result<(), VectorError>
pub fn dump(&self, path: &Path) -> Result<(), VectorError>
Save index to disk by serializing stored vectors via bincode. On load, vectors are re-inserted into a fresh HNSW index.
Sourcepub fn load(
path: &Path,
dimensions: usize,
metric: DistanceMetric,
) -> Result<VectorIndex, VectorError>
pub fn load( path: &Path, dimensions: usize, metric: DistanceMetric, ) -> Result<VectorIndex, VectorError>
Load index from disk: deserialize stored vectors and re-insert into HNSW.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for VectorIndex
impl !RefUnwindSafe for VectorIndex
impl Send for VectorIndex
impl Sync for VectorIndex
impl Unpin for VectorIndex
impl UnsafeUnpin for VectorIndex
impl !UnwindSafe for VectorIndex
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more