Skip to main content

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.

Durability note: implementations may buffer writes. Call flush to obtain an explicit durability barrier.

§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

Durability note: batch writes may be buffered. Call flush after store_batch to force persistence guarantees.

§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.

This is the explicit durability barrier. Callers that require deterministic crash consistency must call this method.

§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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§