pub struct MemoryCache {
pub chunks: Vec<String>,
pub embeddings: Vec<Vec<f32>>,
pub source_channels: Vec<String>,
pub timestamps: Vec<f64>,
pub session_ids: Vec<String>,
pub tags: Vec<String>,
pub tombstones: Vec<u8>,
pub embedding_dim: usize,
pub norms: Vec<f32>,
pub activation_weights: Vec<f32>,
}Expand description
In-memory cache for the /memory group data.
Fields§
§chunks: Vec<String>§embeddings: Vec<Vec<f32>>§source_channels: Vec<String>§timestamps: Vec<f64>§session_ids: Vec<String>§tombstones: Vec<u8>§embedding_dim: usize§norms: Vec<f32>Pre-computed L2 norms for each embedding.
activation_weights: Vec<f32>Hebbian activation weights (default 1.0 per entry).
Implementations§
Source§impl MemoryCache
impl MemoryCache
pub fn new(embedding_dim: usize) -> Self
pub fn is_empty(&self) -> bool
Sourcepub fn count_active(&self) -> usize
pub fn count_active(&self) -> usize
Number of active (non-tombstoned) entries.
Sourcepub fn push(
&mut self,
chunk: String,
embedding: Vec<f32>,
source_channel: String,
timestamp: f64,
session_id: String,
tags: String,
) -> usize
pub fn push( &mut self, chunk: String, embedding: Vec<f32>, source_channel: String, timestamp: f64, session_id: String, tags: String, ) -> usize
Push a new entry, returns its index.
Sourcepub fn mark_deleted(&mut self, id: usize) -> bool
pub fn mark_deleted(&mut self, id: usize) -> bool
Mark an entry as deleted (tombstoned).
Sourcepub fn tombstone_fraction(&self) -> f32
pub fn tombstone_fraction(&self) -> f32
Fraction of entries that are tombstoned.
Sourcepub fn compact(&mut self) -> (usize, Vec<Option<usize>>)
pub fn compact(&mut self) -> (usize, Vec<Option<usize>>)
Remove all tombstoned entries, returns number removed. Also returns a mapping from old indices to new indices (None if removed). Recomputes norms for remaining entries.
Sourcepub fn flat_embeddings(&self) -> Vec<f32>
pub fn flat_embeddings(&self) -> Vec<f32>
Flatten all embeddings into a single Vec
Trait Implementations§
Source§impl Clone for MemoryCache
impl Clone for MemoryCache
Source§fn clone(&self) -> MemoryCache
fn clone(&self) -> MemoryCache
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for MemoryCache
impl RefUnwindSafe for MemoryCache
impl Send for MemoryCache
impl Sync for MemoryCache
impl Unpin for MemoryCache
impl UnsafeUnpin for MemoryCache
impl UnwindSafe for MemoryCache
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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