Skip to main content

VectorStorage

Trait VectorStorage 

Source
pub trait VectorStorage {
    // Required methods
    fn store_vector(
        &mut self,
        vector: &[f32],
        metadata: Option<Value>,
    ) -> Result<u64, HnswError>;
    fn store_vector_with_id(
        &mut self,
        id: u64,
        vector: Vec<f32>,
        metadata: Option<Value>,
    ) -> Result<(), HnswError>;
    fn get_vector(&self, id: u64) -> Result<Option<Vec<f32>>, HnswError>;
    fn get_vector_with_metadata(
        &self,
        id: u64,
    ) -> Result<Option<(Vec<f32>, Value)>, HnswError>;
    fn store_batch(&mut self, batch: VectorBatch) -> Result<Vec<u64>, HnswError>;
    fn delete_vector(&mut self, id: u64) -> Result<(), HnswError>;
    fn vector_count(&self) -> Result<usize, HnswError>;
    fn list_vectors(&self) -> Result<Vec<u64>, HnswError>;
    fn clear_vectors(&mut self) -> Result<(), HnswError>;
    fn get_statistics(&self) -> Result<VectorStorageStats, HnswError>;
}
Expand description

Vector storage backend abstraction

Provides unified interface for storing and retrieving vectors across different storage backends. Automatically adapts to the active backend type.

Required Methods§

Source

fn store_vector( &mut self, vector: &[f32], metadata: Option<Value>, ) -> Result<u64, HnswError>

Store a vector with optional metadata

§Arguments
  • vector - Vector data to store
  • metadata - Optional JSON metadata
§Returns

Vector ID for future retrieval

§Examples
use serde_json::json;

let vector = vec![1.0, 2.0, 3.0];
let metadata = Some(json!({"source": "test"}));

let vector_id = storage.store_vector(&vector, metadata)?;
Source

fn store_vector_with_id( &mut self, id: u64, vector: Vec<f32>, metadata: Option<Value>, ) -> Result<(), HnswError>

Store vector with explicit ID

§Arguments
  • id - Explicit vector ID
  • vector - Vector data
  • metadata - Optional metadata
§Returns

Ok(()) if successful

Source

fn get_vector(&self, id: u64) -> Result<Option<Vec<f32>>, HnswError>

Retrieve vector by ID

§Arguments
  • id - Vector ID to retrieve
§Returns

Vector data if found

Source

fn get_vector_with_metadata( &self, id: u64, ) -> Result<Option<(Vec<f32>, Value)>, HnswError>

Retrieve vector with metadata

§Arguments
  • id - Vector ID to retrieve
§Returns

Vector and metadata if found

Source

fn store_batch(&mut self, batch: VectorBatch) -> Result<Vec<u64>, HnswError>

Store multiple vectors in batch

§Arguments
  • batch - Batch of vectors to store
§Returns

Vector IDs for all stored vectors

Source

fn delete_vector(&mut self, id: u64) -> Result<(), HnswError>

Delete vector by ID

§Arguments
  • id - Vector ID to delete
§Returns

Ok(()) if deleted or didn’t exist

Source

fn vector_count(&self) -> Result<usize, HnswError>

Get vector count

§Returns

Total number of stored vectors

Source

fn list_vectors(&self) -> Result<Vec<u64>, HnswError>

List all vector IDs

§Returns

List of all stored vector IDs

Source

fn clear_vectors(&mut self) -> Result<(), HnswError>

Clear all vectors

§Returns

Ok(()) when cleared

Source

fn get_statistics(&self) -> Result<VectorStorageStats, HnswError>

Get storage statistics

§Returns

Storage statistics for monitoring

Implementors§