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>
impl<E: StorageEngine> SparseVectorStore<E>
Sourcepub const fn new(engine: E) -> Self
pub const fn new(engine: E) -> Self
Create a new sparse vector store with the given storage engine.
Sourcepub fn create_space(
&self,
space: &SparseEmbeddingSpace,
) -> Result<(), VectorError>
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.
Sourcepub fn get_space(
&self,
name: &EmbeddingName,
) -> Result<SparseEmbeddingSpace, VectorError>
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.
Sourcepub fn delete_space(&self, name: &EmbeddingName) -> Result<(), VectorError>
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.
Sourcepub fn list_spaces(&self) -> Result<Vec<SparseEmbeddingSpace>, VectorError>
pub fn list_spaces(&self) -> Result<Vec<SparseEmbeddingSpace>, VectorError>
Sourcepub fn put(
&self,
entity_id: EntityId,
space_name: &EmbeddingName,
embedding: &SparseEmbedding,
) -> Result<(), VectorError>
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
Sourcepub fn get(
&self,
entity_id: EntityId,
space_name: &EmbeddingName,
) -> Result<SparseEmbedding, VectorError>
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
Sourcepub fn delete(
&self,
entity_id: EntityId,
space_name: &EmbeddingName,
) -> Result<bool, VectorError>
pub fn delete( &self, entity_id: EntityId, space_name: &EmbeddingName, ) -> Result<bool, VectorError>
Sourcepub fn exists(
&self,
entity_id: EntityId,
space_name: &EmbeddingName,
) -> Result<bool, VectorError>
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.
Sourcepub fn list_entities(
&self,
space_name: &EmbeddingName,
) -> Result<Vec<EntityId>, VectorError>
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.
Sourcepub fn count(&self, space_name: &EmbeddingName) -> Result<usize, VectorError>
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.
Sourcepub fn get_many(
&self,
entity_ids: &[EntityId],
space_name: &EmbeddingName,
) -> Result<Vec<(EntityId, Option<SparseEmbedding>)>, VectorError>
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.
Sourcepub fn put_many(
&self,
embeddings: &[(EntityId, SparseEmbedding)],
space_name: &EmbeddingName,
) -> Result<(), VectorError>
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.
Sourcepub fn delete_entity(&self, entity_id: EntityId) -> Result<usize, VectorError>
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.