Skip to main content

VectorStore

Struct VectorStore 

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

Vector store for managing embeddings

Implementations§

Source§

impl VectorStore

Source

pub fn new(config: VectorStoreConfig) -> Self

Create a new vector store

Source

pub fn with_dim(dim: usize) -> Self

Create with default config for given dimension

Source

pub fn len(&self) -> usize

Get the number of vectors

Source

pub fn is_empty(&self) -> bool

Check if empty

Source

pub fn put(&mut self, entry: VectorEntry) -> Result<()>

Insert a vector

Source

pub fn put_embedding( &mut self, id: impl Into<String>, embedding: impl Into<Embedding>, ) -> Result<()>

Insert a vector with just ID and embedding

Source

pub fn put_batch(&mut self, entries: Vec<VectorEntry>) -> Result<usize>

Batch insert

Source

pub fn search(&self, query: &Embedding, k: usize) -> Vec<SearchResult>

Search for similar vectors

Source

pub fn search_with_filter<F>( &self, query: &Embedding, k: usize, filter: F, ) -> Vec<SearchResult>
where F: Fn(&VectorEntry) -> bool,

Search with a filter on metadata

Source

pub fn search_namespace( &self, query: &Embedding, k: usize, namespace: &str, ) -> Vec<SearchResult>

Search by namespace

Source

pub fn get(&self, id: &str) -> Option<&VectorEntry>

Get a vector by ID

Source

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

Delete a vector

Source

pub fn ids(&self) -> Vec<&String>

Get all IDs

Source

pub fn similarity(&self, id1: &str, id2: &str) -> Option<f32>

Compute similarity between two vectors by ID

Source

pub fn upsert(&mut self, entry: VectorEntry) -> Result<bool>

Upsert: insert or update a vector

Source

pub fn clear(&mut self)

Clear all vectors from the store

Source

pub fn stats(&self) -> VectorStoreStats

Get store statistics

Source

pub fn find_similar(&self, id: &str, k: usize) -> Vec<SearchResult>

Find vectors similar to a given ID

Source

pub fn contains(&self, id: &str) -> bool

Check if a vector exists

Source

pub fn config(&self) -> &VectorStoreConfig

Get the configuration

Source

pub fn update_metadata( &mut self, id: &str, key: impl Into<String>, value: impl Into<Value>, ) -> bool

Update metadata for an existing vector

Source

pub fn get_namespace(&self, namespace: &str) -> Vec<&VectorEntry>

Get all vectors in a namespace

Source

pub fn count_namespace(&self, namespace: &str) -> usize

Count vectors in a namespace

Source

pub fn delete_namespace(&mut self, namespace: &str) -> usize

Delete all vectors in a namespace

Source

pub fn centroid(&self, namespace: Option<&str>) -> Option<Embedding>

Compute centroid of all vectors (or a subset by namespace)

Trait Implementations§

Source§

impl Debug for VectorStore

Source§

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

Formats the value using the given formatter. 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.