pub struct HotStore {
pub capacity: usize,
/* private fields */
}Expand description
Bounded FIFO short-term memory.
When the store is full and a new entry is pushed, the oldest entry is silently evicted. This mirrors the limited capacity of a control register.
§Examples
use lmm_agent::cognition::memory::{HotStore, MemoryEntry};
let mut store = HotStore::new(2);
store.push(MemoryEntry::new("a".into(), 0.5, 0));
store.push(MemoryEntry::new("b".into(), 0.9, 1));
store.push(MemoryEntry::new("c".into(), 0.7, 2)); // evicts "a"
assert_eq!(store.len(), 2);
assert_eq!(store.entries()[0].content, "b");Fields§
§capacity: usizeMaximum number of entries that can be held simultaneously.
Implementations§
Source§impl HotStore
impl HotStore
Sourcepub fn push(&mut self, entry: MemoryEntry)
pub fn push(&mut self, entry: MemoryEntry)
Appends a new entry, evicting the oldest when at capacity.
Sourcepub fn entries(&self) -> &VecDeque<MemoryEntry>
pub fn entries(&self) -> &VecDeque<MemoryEntry>
Returns an ordered slice of all current entries (oldest → newest).
Sourcepub fn relevant(&self, query: &str, top_n: usize) -> Vec<&MemoryEntry>
pub fn relevant(&self, query: &str, top_n: usize) -> Vec<&MemoryEntry>
Returns the top-n entries most relevant to query using token-overlap scoring.
§Examples
use lmm_agent::cognition::memory::{HotStore, MemoryEntry};
let mut store = HotStore::new(10);
store.push(MemoryEntry::new("Rust ownership model".into(), 0.8, 0));
store.push(MemoryEntry::new("Python garbage collector".into(), 0.6, 1));
let top = store.relevant("Rust memory", 1);
assert_eq!(top[0].content, "Rust ownership model");Sourcepub fn drain_to_cold(&mut self, cold: &mut ColdStore, threshold: f64)
pub fn drain_to_cold(&mut self, cold: &mut ColdStore, threshold: f64)
Moves entries whose score meets or exceeds threshold into cold.
Promoted entries are removed from the hot store; entries below threshold are retained.
§Examples
use lmm_agent::cognition::memory::{HotStore, ColdStore, MemoryEntry};
let mut hot = HotStore::new(5);
hot.push(MemoryEntry::new("high value".into(), 0.9, 0));
hot.push(MemoryEntry::new("low value".into(), 0.2, 1));
let mut cold = ColdStore::default();
hot.drain_to_cold(&mut cold, 0.7);
assert_eq!(cold.len(), 1);
assert_eq!(hot.len(), 1);Trait Implementations§
Auto Trait Implementations§
impl Freeze for HotStore
impl RefUnwindSafe for HotStore
impl Send for HotStore
impl Sync for HotStore
impl Unpin for HotStore
impl UnsafeUnpin for HotStore
impl UnwindSafe for HotStore
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