Skip to main content

MmapVectorStore

Struct MmapVectorStore 

Source
pub struct MmapVectorStore { /* private fields */ }
Expand description

Memory-mapped vector store for ultra-high-throughput writes.

This implementation uses memory-mapped I/O to achieve 500K-1M vectors/sec write throughput by eliminating syscall overhead.

§Key Features

  • Direct memory writes: No write() syscalls, just memcpy
  • Pre-allocated storage: File is pre-sized to avoid remapping
  • Checkpoint-based durability: msync() called periodically, not per-write
  • HNSW index: Same O(log N) search as regular VectorStore

§Trade-offs

  • Higher memory usage (file is memory-mapped)
  • Checkpoint-bounded durability (may lose recent writes on crash)
  • Requires pre-allocation (must estimate capacity)

Implementations§

Source§

impl MmapVectorStore

Source

pub fn new<P: AsRef<Path>>(path: P, config: MmapVectorConfig) -> Result<Self>

Creates or opens a memory-mapped vector store.

§Arguments
  • path - Path to the mmap file
  • config - Configuration for the store
§Errors
  • SynaError::InvalidDimensions - If dimensions are not in range 64-8192
  • SynaError::Io - If file operations fail
Source

pub fn insert(&mut self, key: &str, vector: &[f32]) -> Result<()>

Inserts a vector with the given key.

This is an ultra-fast operation because it writes directly to memory without any syscalls. The data is persisted via periodic checkpoints.

§Arguments
  • key - Unique identifier for the vector
  • vector - The vector data (must match configured dimensions)
§Errors
  • SynaError::DimensionMismatch - If vector length doesn’t match
  • SynaError::Io - If the mmap region is full
Source

pub fn insert_batch( &mut self, keys: &[&str], vectors: &[&[f32]], ) -> Result<usize>

Inserts multiple vectors in a batch (maximum throughput).

This is the fastest way to load vectors, achieving 500K-1M vectors/sec.

§Arguments
  • keys - Slice of key strings
  • vectors - Slice of vector slices
§Returns

Number of vectors successfully inserted.

Source

pub fn get(&self, key: &str) -> Result<Option<Vec<f32>>>

Retrieves a vector by key.

Source

pub fn get_slice(&self, key: &str) -> Option<&[f32]>

Gets a vector as a slice reference (zero-copy).

§Safety

The returned slice is valid only as long as the MmapVectorStore exists and no grow operations occur.

Source

pub fn search(&self, query: &[f32], k: usize) -> Result<Vec<MmapSearchResult>>

Searches for the k nearest neighbors.

Source

pub fn build_index(&mut self) -> Result<()>

Builds the HNSW index from all stored vectors.

Source

pub fn checkpoint(&mut self) -> Result<()>

Checkpoints the store to disk (flushes mmap and saves index).

Source

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

Flushes any pending changes to disk.

Source

pub fn len(&self) -> usize

Returns the number of vectors stored.

Source

pub fn is_empty(&self) -> bool

Returns true if the store is empty.

Source

pub fn dimensions(&self) -> u16

Returns the configured dimensions.

Source

pub fn metric(&self) -> DistanceMetric

Returns the configured distance metric.

Source

pub fn has_index(&self) -> bool

Returns whether an HNSW index is built.

Source

pub fn is_dirty(&self) -> bool

Returns whether the index has unsaved changes.

Source

pub fn keys(&self) -> Vec<String>

Returns all keys in the store.

Trait Implementations§

Source§

impl Drop for MmapVectorStore

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

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, 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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V