pub struct NeuralMemoryStore { /* private fields */ }Expand description
In-memory store for neural embeddings with index-based retrieval.
Uses a VecDeque for O(1) front eviction instead of Vec::remove(0) which is O(n).
Implementations§
Source§impl NeuralMemoryStore
impl NeuralMemoryStore
Sourcepub fn store(&mut self, embedding: NeuralEmbedding) -> Result<usize>
pub fn store(&mut self, embedding: NeuralEmbedding) -> Result<usize>
Store an embedding, returning its physical index within the deque.
If the store is at capacity, the oldest embedding is evicted. Returns an error if the embedding dimension is inconsistent with previously stored embeddings.
Sourcepub fn get(&self, id: usize) -> Option<&NeuralEmbedding>
pub fn get(&self, id: usize) -> Option<&NeuralEmbedding>
Get an embedding by its index.
Sourcepub fn query_nearest(
&self,
query: &NeuralEmbedding,
k: usize,
) -> Vec<(usize, f64)>
pub fn query_nearest( &self, query: &NeuralEmbedding, k: usize, ) -> Vec<(usize, f64)>
Find the k nearest neighbors using brute-force Euclidean distance.
Returns pairs of (index, distance), sorted by ascending distance.
Sourcepub fn query_by_state(&self, state: CognitiveState) -> Vec<&NeuralEmbedding>
pub fn query_by_state(&self, state: CognitiveState) -> Vec<&NeuralEmbedding>
Query all embeddings matching a given cognitive state.
Sourcepub fn query_by_subject(&self, subject_id: &str) -> Vec<&NeuralEmbedding>
pub fn query_by_subject(&self, subject_id: &str) -> Vec<&NeuralEmbedding>
Query all embeddings for a given subject.
Sourcepub fn query_time_range(&self, start: f64, end: f64) -> Vec<&NeuralEmbedding>
pub fn query_time_range(&self, start: f64, end: f64) -> Vec<&NeuralEmbedding>
Query embeddings within a timestamp range [start, end].
Sourcepub fn embeddings_iter(&self) -> impl Iterator<Item = &NeuralEmbedding>
pub fn embeddings_iter(&self) -> impl Iterator<Item = &NeuralEmbedding>
Access all embeddings (for serialization).
Returns the two slices of the VecDeque as a pair. For contiguous access,
callers can use make_contiguous() on a mutable reference, or iterate.
Sourcepub fn embeddings(&self) -> Vec<&NeuralEmbedding>
pub fn embeddings(&self) -> Vec<&NeuralEmbedding>
Access all embeddings as a slice pair (VecDeque may be non-contiguous).
Trait Implementations§
Source§impl Clone for NeuralMemoryStore
impl Clone for NeuralMemoryStore
Source§fn clone(&self) -> NeuralMemoryStore
fn clone(&self) -> NeuralMemoryStore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more