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, justmemcpy - 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
impl MmapVectorStore
Sourcepub fn insert(&mut self, key: &str, vector: &[f32]) -> Result<()>
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 vectorvector- The vector data (must match configured dimensions)
§Errors
SynaError::DimensionMismatch- If vector length doesn’t matchSynaError::Io- If the mmap region is full
Sourcepub fn get_slice(&self, key: &str) -> Option<&[f32]>
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.
Sourcepub fn search(&self, query: &[f32], k: usize) -> Result<Vec<MmapSearchResult>>
pub fn search(&self, query: &[f32], k: usize) -> Result<Vec<MmapSearchResult>>
Searches for the k nearest neighbors.
Sourcepub fn build_index(&mut self) -> Result<()>
pub fn build_index(&mut self) -> Result<()>
Builds the HNSW index from all stored vectors.
Sourcepub fn checkpoint(&mut self) -> Result<()>
pub fn checkpoint(&mut self) -> Result<()>
Checkpoints the store to disk (flushes mmap and saves index).
Sourcepub fn dimensions(&self) -> u16
pub fn dimensions(&self) -> u16
Returns the configured dimensions.
Sourcepub fn metric(&self) -> DistanceMetric
pub fn metric(&self) -> DistanceMetric
Returns the configured distance metric.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for MmapVectorStore
impl RefUnwindSafe for MmapVectorStore
impl Send for MmapVectorStore
impl Sync for MmapVectorStore
impl Unpin for MmapVectorStore
impl UnwindSafe for MmapVectorStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more