pub struct TwoTierMemory { /* private fields */ }Expand description
Two-tier memory: bounded short-term working store + decayed long-term store.
- Writes (
put) always land in the short tier. getchecks the short tier first, then the long tier.searchscores both tiers with the long-term weighted formula (so cross-tier ordering is on one scale), de-duplicating by key with the short tier preferred.consolidatepromotes qualifying short-term entries into long-term memory and removes them from the short tier.
Implementations§
Source§impl TwoTierMemory
impl TwoTierMemory
Sourcepub fn new(short_capacity: usize) -> Self
pub fn new(short_capacity: usize) -> Self
Creates a two-tier store with default capacity/weights/scorer/policy.
Sourcepub fn with_policy(self, policy: PromotionPolicy) -> Self
pub fn with_policy(self, policy: PromotionPolicy) -> Self
Replaces the promotion policy.
Sourcepub fn short_term(&self) -> Arc<ShortTermMemory> ⓘ
pub fn short_term(&self) -> Arc<ShortTermMemory> ⓘ
The short-term tier (direct access for seeding/tests).
Sourcepub fn long_term(&self) -> Arc<LongTermMemory> ⓘ
pub fn long_term(&self) -> Arc<LongTermMemory> ⓘ
The long-term tier (direct access for seeding/tests).
Sourcepub fn set_policy(&self, policy: PromotionPolicy)
pub fn set_policy(&self, policy: PromotionPolicy)
Replaces the promotion policy at runtime.
Sourcepub async fn consolidate_namespace(
&self,
namespace: &str,
) -> Result<Vec<String>, MemoryError>
pub async fn consolidate_namespace( &self, namespace: &str, ) -> Result<Vec<String>, MemoryError>
Promotes qualifying short-term entries of one namespace into long-term memory, removing promoted entries from the short tier. Returns the promoted keys.
Sourcepub async fn consolidate(&self) -> Result<Vec<String>, MemoryError>
pub async fn consolidate(&self) -> Result<Vec<String>, MemoryError>
Promotes qualifying entries across every short-term namespace.
Trait Implementations§
Source§impl Debug for TwoTierMemory
impl Debug for TwoTierMemory
Source§impl MemoryStore for TwoTierMemory
impl MemoryStore for TwoTierMemory
Source§fn put<'life0, 'life1, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
item: MemoryItem,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn put<'life0, 'life1, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
item: MemoryItem,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Writes/updates an item in the namespace. Re-putting an existing key refreshes
its content and access time.
Source§fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<MemoryItem>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<Option<MemoryItem>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Exact key lookup (
None when absent). Counts as an access.Source§fn search<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
query: &'life1 MemoryQuery<'life2>,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryHit>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn search<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
query: &'life1 MemoryQuery<'life2>,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryHit>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Semantic recall, best score first, capped at
query.k.Source§fn forget<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<bool, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn forget<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
key: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<bool, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Removes one entry; returns whether it existed.
Source§fn clear_namespace<'life0, 'life1, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<usize, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn clear_namespace<'life0, 'life1, 'async_trait>(
&'life0 self,
namespace: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<usize, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Drops every entry in the namespace; returns the number removed.
Auto Trait Implementations§
impl !Freeze for TwoTierMemory
impl !RefUnwindSafe for TwoTierMemory
impl !UnwindSafe for TwoTierMemory
impl Send for TwoTierMemory
impl Sync for TwoTierMemory
impl Unpin for TwoTierMemory
impl UnsafeUnpin for TwoTierMemory
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