Struct VectorLite

Source
pub struct VectorLite<const N: usize> { /* private fields */ }
Expand description

A lightweight lsh-based ann index.

Implementations§

Source§

impl<const N: usize> VectorLite<N>

Source

pub fn new(num_trees: usize, max_leaf_size: usize) -> Self

Create a new VectorLite index with the given number of trees and max leaf size. More trees means more accuracy but slower search and larger memory usage. Lower max_leaf_size means higher accuracy but larger memory usage.

Source

pub fn len(&self) -> usize

Get the number of vectors in the index.

Source

pub fn is_empty(&self) -> bool

Check if the index is empty.

Source

pub fn index(&self) -> &VectorLiteIndex<N>

Get the index.

Source

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

Serialize the index to a byte vector.

Source

pub fn from_bytes(bytes: &[u8]) -> Self

Deserialize the index from a byte vector.

Trait Implementations§

Source§

impl<const N: usize> ANNIndexOwned<N> for VectorLite<N>

Source§

fn insert_with_rng(&mut self, vector: Vector<N>, id: String, rng: &mut impl Rng)

Insert a vector into the index with a custom rng.
Source§

fn delete_by_id(&mut self, id: &str) -> bool

Delete a vector from the index by id. Returns true if the vector was deleted, false if it was not found.
Source§

fn get_by_id(&self, id: &str) -> Option<&Vector<N>>

Get a vector from the index by id.
Source§

fn search_with_metric( &self, query: &Vector<N>, top_k: usize, metric: ScoreMetric, ) -> Vec<(String, f32)>

Search for the top_k nearest neighbors of the query vector. Returns a array of (id, score) pairs, higher score means closer.
Source§

fn insert(&mut self, vector: Vector<N>, id: String)

Insert a vector into the index.
Source§

fn search(&self, query: &Vector<N>, top_k: usize) -> Vec<(String, f32)>

Search for the top_k nearest neighbors of the query vector. Returns a array of (id, score) pairs, higher score means closer.
Source§

impl<'__de, const N: usize, __Context> BorrowDecode<'__de, __Context> for VectorLite<N>

Source§

fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given BorrowDecode.
Source§

impl<const N: usize, __Context> Decode<__Context> for VectorLite<N>

Source§

fn decode<__D: Decoder<Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
Source§

impl<const N: usize> Encode for VectorLite<N>

Source§

fn encode<__E: Encoder>(&self, encoder: &mut __E) -> Result<(), EncodeError>

Encode a given type.

Auto Trait Implementations§

§

impl<const N: usize> Freeze for VectorLite<N>

§

impl<const N: usize> RefUnwindSafe for VectorLite<N>

§

impl<const N: usize> !Send for VectorLite<N>

§

impl<const N: usize> !Sync for VectorLite<N>

§

impl<const N: usize> Unpin for VectorLite<N>

§

impl<const N: usize> UnwindSafe for VectorLite<N>

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