VectorStore

Struct VectorStore 

Source
pub struct VectorStore {
    pub vectors: Vec<Vector>,
    pub hnsw_index: Option<HNSWIndex>,
    pub id_to_index: FxHashMap<String, usize>,
    /* private fields */
}
Expand description

Vector store with HNSW indexing

Fields§

§vectors: Vec<Vector>

All vectors stored in memory (used for rescore when quantization enabled)

§hnsw_index: Option<HNSWIndex>

HNSW index for approximate nearest neighbor search

§id_to_index: FxHashMap<String, usize>

Map from string IDs to internal indices (public for Python bindings)

Implementations§

Source§

impl VectorStore

Source

pub fn new(dimensions: usize) -> Self

Create new vector store

Source

pub fn new_with_quantization(dimensions: usize, mode: QuantizationMode) -> Self

Create new vector store with quantization

Quantization is trained on the first batch of vectors inserted.

Source

pub fn new_with_params( dimensions: usize, m: usize, ef_construction: usize, ef_search: usize, distance_metric: Metric, ) -> Result<Self>

Create new vector store with custom HNSW parameters

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open a persistent vector store at the given path

Creates a new database if it doesn’t exist, or loads existing data. All operations (insert, set, delete) are automatically persisted.

§Arguments
  • path - Directory path for the database (e.g., “mydb.oadb”)
§Example
let mut store = VectorStore::open("mydb.oadb")?;
store.set("doc1".to_string(), vector, metadata)?;
// Data is automatically persisted
Source

pub fn open_with_dimensions( path: impl AsRef<Path>, dimensions: usize, ) -> Result<Self>

Open a persistent vector store with specified dimensions

Like open() but ensures dimensions are set for new databases.

Source

pub fn open_with_options( path: impl AsRef<Path>, options: &VectorStoreOptions, ) -> Result<Self>

Open a persistent vector store with custom options.

This is the internal implementation used by VectorStoreOptions::open().

Source

pub fn build_with_options(options: &VectorStoreOptions) -> Result<Self>

Build an in-memory vector store with custom options.

Source

pub fn insert(&mut self, vector: Vector) -> Result<usize>

Insert vector and return its ID

Source

pub fn insert_with_metadata( &mut self, id: String, vector: Vector, metadata: JsonValue, ) -> Result<usize>

Insert vector with string ID and metadata

This is the primary method for inserting vectors with metadata support. Returns error if ID already exists (use set for insert-or-update semantics).

Source

pub fn set( &mut self, id: String, vector: Vector, metadata: JsonValue, ) -> Result<usize>

Upsert vector (insert or update) with string ID and metadata

This is the recommended method for most use cases.

Source

pub fn set_batch( &mut self, batch: Vec<(String, Vector, JsonValue)>, ) -> Result<Vec<usize>>

Batch set vectors (insert or update multiple vectors at once)

This is the recommended method for bulk operations.

Enable text search on this store

Source

pub fn enable_text_search_with_config( &mut self, config: Option<TextSearchConfig>, ) -> Result<()>

Enable text search with custom configuration

Check if text search is enabled

Source

pub fn set_with_text( &mut self, id: String, vector: Vector, text: &str, metadata: JsonValue, ) -> Result<usize>

Upsert vector with text content for hybrid search

Source

pub fn set_batch_with_text( &mut self, batch: Vec<(String, Vector, String, JsonValue)>, ) -> Result<Vec<usize>>

Batch upsert vectors with text content for hybrid search

Search text index only (BM25 scoring)

Hybrid search combining vector similarity and BM25 text relevance

Source

pub fn hybrid_search_with_rrf_k( &mut self, query_vector: &Vector, query_text: &str, k: usize, alpha: Option<f32>, rrf_k: Option<usize>, ) -> Result<Vec<(String, f32, JsonValue)>>

Hybrid search with configurable RRF k constant

Source

pub fn hybrid_search_with_filter( &mut self, query_vector: &Vector, query_text: &str, k: usize, filter: &MetadataFilter, alpha: Option<f32>, ) -> Result<Vec<(String, f32, JsonValue)>>

Hybrid search with filter

Source

pub fn hybrid_search_with_filter_rrf_k( &mut self, query_vector: &Vector, query_text: &str, k: usize, filter: &MetadataFilter, alpha: Option<f32>, rrf_k: Option<usize>, ) -> Result<Vec<(String, f32, JsonValue)>>

Hybrid search with filter and configurable RRF k constant

Source

pub fn hybrid_search_with_subscores( &mut self, query_vector: &Vector, query_text: &str, k: usize, alpha: Option<f32>, rrf_k: Option<usize>, ) -> Result<Vec<(HybridResult, JsonValue)>>

Hybrid search returning separate keyword and semantic scores.

Returns HybridResult with keyword_score (BM25) and semantic_score (vector distance) for each result, enabling custom post-processing or debugging.

Source

pub fn hybrid_search_with_filter_subscores( &mut self, query_vector: &Vector, query_text: &str, k: usize, filter: &MetadataFilter, alpha: Option<f32>, rrf_k: Option<usize>, ) -> Result<Vec<(HybridResult, JsonValue)>>

Hybrid search with filter returning separate keyword and semantic scores.

Source

pub fn update( &mut self, id: &str, vector: Option<Vector>, metadata: Option<JsonValue>, ) -> Result<()>

Update existing vector by string ID

Source

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

Delete vector by string ID

This method:

  1. Marks the vector as deleted (soft delete)
  2. Repairs the HNSW graph using MN-RU algorithm to maintain recall quality
  3. Removes from text index if present
  4. Persists to WAL
Source

pub fn delete_batch(&mut self, ids: &[String]) -> Result<usize>

Delete multiple vectors by string IDs

Uses batch MN-RU graph repair for better efficiency than individual deletes.

Source

pub fn delete_by_filter(&mut self, filter: &MetadataFilter) -> Result<usize>

Delete vectors matching a metadata filter

Evaluates the filter against all vectors and deletes those that match. This is more efficient than manually iterating and calling delete_batch.

§Arguments
  • filter - MongoDB-style metadata filter
§Returns

Number of vectors deleted

Source

pub fn count_by_filter(&self, filter: &MetadataFilter) -> usize

Count vectors matching a metadata filter

Evaluates the filter against all vectors and returns the count of matches. More efficient than iterating and counting manually.

§Arguments
  • filter - MongoDB-style metadata filter
§Returns

Number of vectors matching the filter

Source

pub fn get(&self, id: &str) -> Option<(Vector, JsonValue)>

Get vector by string ID

Returns owned data since vectors may be loaded from disk for quantized stores.

Source

pub fn get_batch( &self, ids: &[impl AsRef<str>], ) -> Vec<Option<(Vector, JsonValue)>>

Get multiple vectors by string IDs

Returns a vector of results in the same order as input IDs. Missing/deleted IDs return None in their position.

Source

pub fn get_metadata_by_id(&self, id: &str) -> Option<&JsonValue>

Get metadata by string ID (without loading vector data)

Source

pub fn batch_insert(&mut self, vectors: Vec<Vector>) -> Result<Vec<usize>>

Insert batch of vectors in parallel

Source

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

Rebuild HNSW index from existing vectors

Source

pub fn merge_from(&mut self, other: &VectorStore) -> Result<usize>

Merge another VectorStore into this one using IGTM algorithm

Source

pub fn needs_index_rebuild(&self) -> bool

Check if index needs to be rebuilt

Source

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

Ensure HNSW index is ready for search

K-nearest neighbors search using HNSW

Source

pub fn knn_search_with_ef( &mut self, query: &Vector, k: usize, ef: Option<usize>, ) -> Result<Vec<(usize, f32)>>

K-nearest neighbors search with optional ef override

Source

pub fn knn_search_readonly( &self, query: &Vector, k: usize, ef: Option<usize>, ) -> Result<Vec<(usize, f32)>>

Read-only K-nearest neighbors search (for parallel execution)

Source

pub fn knn_search_ef( &self, query: &Vector, k: usize, ef: usize, ) -> Result<Vec<(usize, f32)>>

Fast K-nearest neighbors search with concrete ef value

Source

pub fn knn_search_with_filter( &mut self, query: &Vector, k: usize, filter: &MetadataFilter, ) -> Result<Vec<(usize, f32, JsonValue)>>

K-nearest neighbors search with metadata filtering

Source

pub fn knn_search_with_filter_ef( &mut self, query: &Vector, k: usize, filter: &MetadataFilter, ef: Option<usize>, ) -> Result<Vec<(usize, f32, JsonValue)>>

K-nearest neighbors search with metadata filtering and optional ef override

Source

pub fn knn_search_with_filter_ef_readonly( &self, query: &Vector, k: usize, filter: &MetadataFilter, ef: Option<usize>, ) -> Result<Vec<(usize, f32, JsonValue)>>

Read-only filtered search (for parallel execution)

Uses Roaring bitmap index for O(1) filter evaluation when possible, falls back to JSON-based filtering for complex filters.

Source

pub fn search( &mut self, query: &Vector, k: usize, filter: Option<&MetadataFilter>, ) -> Result<Vec<(usize, f32, JsonValue)>>

Search with optional filter (convenience method)

Source

pub fn search_with_ef( &mut self, query: &Vector, k: usize, filter: Option<&MetadataFilter>, ef: Option<usize>, ) -> Result<Vec<(usize, f32, JsonValue)>>

Search with optional filter and ef override

Source

pub fn search_with_options( &mut self, query: &Vector, k: usize, filter: Option<&MetadataFilter>, ef: Option<usize>, max_distance: Option<f32>, ) -> Result<Vec<(usize, f32, JsonValue)>>

Search with all options: filter, ef override, and max_distance

Source

pub fn search_with_ef_readonly( &self, query: &Vector, k: usize, filter: Option<&MetadataFilter>, ef: Option<usize>, ) -> Result<Vec<(usize, f32, JsonValue)>>

Read-only search with optional filter (for parallel execution)

Source

pub fn search_with_options_readonly( &self, query: &Vector, k: usize, filter: Option<&MetadataFilter>, ef: Option<usize>, max_distance: Option<f32>, ) -> Result<Vec<(usize, f32, JsonValue)>>

Read-only search with all options (for parallel execution)

Source

pub fn search_batch( &self, queries: &[Vector], k: usize, ef: Option<usize>, ) -> Vec<Result<Vec<(usize, f32)>>>

Parallel batch search for multiple queries

Source

pub fn search_batch_with_metadata( &self, queries: &[Vector], k: usize, ef: Option<usize>, ) -> Vec<Result<Vec<(usize, f32, JsonValue)>>>

Parallel batch search with metadata

Source

pub fn knn_search_brute_force( &self, query: &Vector, k: usize, ) -> Result<Vec<(usize, f32)>>

Brute-force K-NN search (fallback)

Source

pub fn optimize(&mut self) -> Result<usize>

Optimize index for cache-efficient search

Reorders graph nodes and vectors using BFS traversal to improve memory locality. Nodes that are frequently accessed together during search will be stored adjacently in memory, reducing cache misses and improving QPS.

Call this after loading/building the index and before querying for best results. Based on NeurIPS 2021 “Graph Reordering for Cache-Efficient Near Neighbor Search”.

Returns the number of nodes reordered, or 0 if index is empty/not initialized.

Source

pub fn len(&self) -> usize

Number of vectors stored (excluding deleted vectors)

Source

pub fn count(&self) -> usize

Count of vectors stored (excluding deleted vectors)

Alias for len() - preferred for database-style APIs.

Source

pub fn is_empty(&self) -> bool

Check if store is empty

Source

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

List all non-deleted IDs

Returns vector IDs without loading vector data. O(n) time, O(n) memory for strings only.

Source

pub fn items(&self) -> Vec<(String, Vec<f32>, JsonValue)>

Get all items as (id, vector, metadata) tuples

Returns all non-deleted items. O(n) time and memory.

Source

pub fn contains(&self, id: &str) -> bool

Check if an ID exists (not deleted)

Source

pub fn memory_usage(&self) -> usize

Memory usage estimate (bytes)

Source

pub fn bytes_per_vector(&self) -> f32

Bytes per vector (average)

Set HNSW ef_search parameter (runtime tuning)

Get HNSW ef_search parameter

Source

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

Flush all pending changes to disk

Commits vector/metadata changes and HNSW index to .omen storage.

Source

pub fn is_persistent(&self) -> bool

Check if this store has persistent storage enabled

Source

pub fn storage(&self) -> Option<&OmenFile>

Get reference to the .omen storage backend (if persistent)

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Fruit for T
where T: Send + Downcast,