VectorStorage

Trait VectorStorage 

Source
pub trait VectorStorage: Send + Sync {
    // Required methods
    fn store(&mut self, id: u64, vector: &[f32]) -> Result<()>;
    fn store_batch(&mut self, vectors: &[(u64, &[f32])]) -> Result<usize>;
    fn retrieve(&self, id: u64) -> Result<Option<Vec<f32>>>;
    fn delete(&mut self, id: u64) -> Result<()>;
    fn flush(&mut self) -> Result<()>;
    fn len(&self) -> usize;
    fn ids(&self) -> Vec<u64>;

    // Provided method
    fn is_empty(&self) -> bool { ... }
}
Expand description

Trait defining storage operations for vectors.

Required Methods§

Source

fn store(&mut self, id: u64, vector: &[f32]) -> Result<()>

Stores a vector with the given ID.

§Errors

Returns an error if the write operation fails.

Source

fn store_batch(&mut self, vectors: &[(u64, &[f32])]) -> Result<usize>

Stores multiple vectors in a single batch operation.

This is optimized for bulk imports:

  • Single WAL write for the entire batch
  • Contiguous memory writes
  • Single fsync at the end
§Errors

Returns an error if the write operation fails.

Source

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

Retrieves a vector by ID.

§Errors

Returns an error if the read operation fails.

Source

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

Deletes a vector by ID.

§Errors

Returns an error if the delete operation fails.

Source

fn flush(&mut self) -> Result<()>

Flushes pending writes to disk.

§Errors

Returns an error if the flush operation fails.

Source

fn len(&self) -> usize

Returns the number of vectors stored.

Source

fn ids(&self) -> Vec<u64>

Returns all stored IDs.

Provided Methods§

Source

fn is_empty(&self) -> bool

Returns true if the storage is empty.

Implementors§