SparseVectorStore

Struct SparseVectorStore 

Source
pub struct SparseVectorStore<E: StorageEngine> { /* private fields */ }
Expand description

A store for sparse vector embeddings.

SparseVectorStore provides CRUD operations for sparse embeddings organized into named embedding spaces. Sparse embeddings only store non-zero values, making them efficient for high-dimensional vectors with few active elements.

Implementations§

Source§

impl<E: StorageEngine> SparseVectorStore<E>

Source

pub const fn new(engine: E) -> Self

Create a new sparse vector store with the given storage engine.

Source

pub fn create_space( &self, space: &SparseEmbeddingSpace, ) -> Result<(), VectorError>

Create a new sparse embedding space.

§Errors

Returns an error if the space already exists or if the storage operation fails.

Source

pub fn get_space( &self, name: &EmbeddingName, ) -> Result<SparseEmbeddingSpace, VectorError>

Get a sparse embedding space by name.

§Errors

Returns an error if the space doesn’t exist or if the storage operation fails.

Source

pub fn delete_space(&self, name: &EmbeddingName) -> Result<(), VectorError>

Delete a sparse embedding space and all its embeddings.

§Errors

Returns an error if the space doesn’t exist or if the storage operation fails.

Source

pub fn list_spaces(&self) -> Result<Vec<SparseEmbeddingSpace>, VectorError>

List all sparse embedding spaces.

§Errors

Returns an error if the storage operation fails.

Source

pub fn put( &self, entity_id: EntityId, space_name: &EmbeddingName, embedding: &SparseEmbedding, ) -> Result<(), VectorError>

Store a sparse embedding for an entity in a space.

§Errors

Returns an error if:

  • The embedding space doesn’t exist
  • Any index exceeds the space’s max dimension
  • The storage operation fails
Source

pub fn get( &self, entity_id: EntityId, space_name: &EmbeddingName, ) -> Result<SparseEmbedding, VectorError>

Get a sparse embedding for an entity from a space.

§Errors

Returns an error if:

  • The embedding space doesn’t exist
  • The embedding doesn’t exist for this entity
  • The storage operation fails
Source

pub fn delete( &self, entity_id: EntityId, space_name: &EmbeddingName, ) -> Result<bool, VectorError>

Delete a sparse embedding for an entity from a space.

§Returns

Returns Ok(true) if the embedding was deleted, Ok(false) if it didn’t exist.

§Errors

Returns an error if the storage operation fails.

Source

pub fn exists( &self, entity_id: EntityId, space_name: &EmbeddingName, ) -> Result<bool, VectorError>

Check if a sparse embedding exists for an entity in a space.

§Errors

Returns an error if the storage operation fails.

Source

pub fn list_entities( &self, space_name: &EmbeddingName, ) -> Result<Vec<EntityId>, VectorError>

List all entity IDs that have sparse embeddings in a space.

§Errors

Returns an error if the storage operation fails.

Source

pub fn count(&self, space_name: &EmbeddingName) -> Result<usize, VectorError>

Count the number of sparse embeddings in a space.

§Errors

Returns an error if the storage operation fails.

Source

pub fn get_many( &self, entity_ids: &[EntityId], space_name: &EmbeddingName, ) -> Result<Vec<(EntityId, Option<SparseEmbedding>)>, VectorError>

Get multiple sparse embeddings at once.

Returns a vector of (EntityId, Option<SparseEmbedding>) tuples.

§Errors

Returns an error if the storage operation fails.

Source

pub fn put_many( &self, embeddings: &[(EntityId, SparseEmbedding)], space_name: &EmbeddingName, ) -> Result<(), VectorError>

Store multiple sparse embeddings at once.

§Errors

Returns an error if the embedding space doesn’t exist, any index is out of bounds, or the storage operation fails.

Source

pub fn delete_entity(&self, entity_id: EntityId) -> Result<usize, VectorError>

Delete all sparse embeddings for an entity across all spaces.

§Errors

Returns an error if the storage operation fails.

Auto Trait Implementations§

§

impl<E> Freeze for SparseVectorStore<E>
where E: Freeze,

§

impl<E> RefUnwindSafe for SparseVectorStore<E>
where E: RefUnwindSafe,

§

impl<E> Send for SparseVectorStore<E>

§

impl<E> Sync for SparseVectorStore<E>

§

impl<E> Unpin for SparseVectorStore<E>
where E: Unpin,

§

impl<E> UnwindSafe for SparseVectorStore<E>
where E: UnwindSafe,

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more