pub struct VectorStore { /* private fields */ }Expand description
In-memory flat vector store backed by a Vec<VectorEntry>.
The configured Distance controls both how vectors are stored
(similarity metrics pre-normalise; distance metrics store verbatim) and
how queries are scored.
Implementations§
Source§impl VectorStore
impl VectorStore
Sourcepub fn to_snapshot(&self) -> IndexSnapshot
pub fn to_snapshot(&self) -> IndexSnapshot
Produce an IndexSnapshot capturing the current store contents.
Sourcepub fn from_snapshot(snapshot: IndexSnapshot) -> Result<Self, RagError>
pub fn from_snapshot(snapshot: IndexSnapshot) -> Result<Self, RagError>
Build a VectorStore from a previously-produced snapshot.
Returns RagError::Persistence if the schema version is unknown,
and RagError::DimensionMismatch if any stored entry has a
vector whose length disagrees with the snapshot’s dim.
Sourcepub fn save_json(&self, path: impl AsRef<Path>) -> Result<(), RagError>
pub fn save_json(&self, path: impl AsRef<Path>) -> Result<(), RagError>
Serialise this store to path as pretty-printed JSON.
Sourcepub fn load_json(path: impl AsRef<Path>) -> Result<Self, RagError>
pub fn load_json(path: impl AsRef<Path>) -> Result<Self, RagError>
Deserialise a store previously written by VectorStore::save_json.
Returns RagError::Persistence on malformed JSON or unknown
schema version, and RagError::DimensionMismatch if any stored
entry’s vector length disagrees with the snapshot’s dim.
Source§impl VectorStore
impl VectorStore
Sourcepub fn new_with_distance(dim: usize, distance: Distance) -> Self
pub fn new_with_distance(dim: usize, distance: Distance) -> Self
Create an empty store with a specific Distance metric.
Sourcepub fn insert(
&mut self,
vector: Vec<f32>,
chunk: Chunk,
) -> Result<usize, RagError>
pub fn insert( &mut self, vector: Vec<f32>, chunk: Chunk, ) -> Result<usize, RagError>
Insert a vector+chunk pair into the store.
Behaviour depends on the store’s Distance:
- Similarity metrics (Cosine, DotProduct, Angular) L2-normalise the stored vector up-front so that scoring is cheap.
- True distance metrics (Euclidean, Hamming) preserve the vector verbatim.
Returns the assigned entry id. Errors:
RagError::DimensionMismatchfor wrong-size vectors.RagError::NonFiniteforNaN/±∞entries.
Sourcepub fn search(&self, query: &[f32], top_k: usize) -> Vec<SearchResult>
pub fn search(&self, query: &[f32], top_k: usize) -> Vec<SearchResult>
Return the top-top_k entries by score.
The query vector is normalised internally when the metric is a
similarity; it is not mutated. Results are returned in descending
score order (see SearchResult::score for polarity).
Sourcepub fn search_with_threshold(
&self,
query: &[f32],
top_k: usize,
min_score: f32,
) -> Vec<SearchResult>
pub fn search_with_threshold( &self, query: &[f32], top_k: usize, min_score: f32, ) -> Vec<SearchResult>
Like Self::search but discards results whose score is below
min_score.
Sourcepub fn search_filtered(
&self,
query: &[f32],
top_k: usize,
filter: &MetadataFilter,
) -> Result<Vec<SearchResult>, RagError>
pub fn search_filtered( &self, query: &[f32], top_k: usize, filter: &MetadataFilter, ) -> Result<Vec<SearchResult>, RagError>
Search filtered by a MetadataFilter.
Filter evaluation is post-scoring; the metric is evaluated against every entry, then results that fail the filter are discarded.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all entries from the store (preserves the configured dimension and distance metric).
Sourcepub fn memory_usage_bytes(&self) -> usize
pub fn memory_usage_bytes(&self) -> usize
Approximate heap memory used by the stored vectors and chunk texts. This is a lower-bound estimate: it counts vector bytes and chunk-text bytes but ignores allocator overhead and struct padding.