pub struct GuardedMemory { /* private fields */ }Expand description
Wraps any Arc<dyn Memory> and adds dedup + sensitivity filtering on
write. recall is pass-through.
Implementations§
Source§impl GuardedMemory
impl GuardedMemory
Sourcepub fn new(inner: Arc<dyn Memory>) -> Self
pub fn new(inner: Arc<dyn Memory>) -> Self
Wrap inner with the default sensitivity patterns (credit-card-like
13-19 digit runs, emails, common monetary patterns) and a dedup
threshold of 0.6 Jaccard token overlap.
Sourcepub fn without_default_sensitivity(self) -> Self
pub fn without_default_sensitivity(self) -> Self
Drop the default sensitivity patterns — useful for tests or when callers know they’re storing already-redacted content.
Sourcepub fn with_sensitivity_pattern(
self,
pat: impl AsRef<str>,
) -> Result<Self, Error>
pub fn with_sensitivity_pattern( self, pat: impl AsRef<str>, ) -> Result<Self, Error>
Add an extra regex pattern. If the entry content matches ANY pattern, the write is dropped.
Sourcepub fn with_blocked_substring(self, s: impl Into<String>) -> Self
pub fn with_blocked_substring(self, s: impl Into<String>) -> Self
Add a literal substring to the block-list (case-insensitive contains).
Cheaper than a regex; use for app-specific terms that should never
hit memory (e.g. "password", "内部秘钥").
Sourcepub fn with_dedup_threshold(self, t: f32) -> Self
pub fn with_dedup_threshold(self, t: f32) -> Self
Override the Jaccard token-overlap threshold above which an entry is considered a duplicate of an existing one. Range [0.0, 1.0]; default 0.6. Set to 1.0 to require exact match, 0.0 to disable dedup.
Sourcepub fn with_dedup_recall_k(self, k: usize) -> Self
pub fn with_dedup_recall_k(self, k: usize) -> Self
How many candidates to fetch from recall for dedup comparison.
Default 5. Increase if your store gets large and recall miss rate
is high; decrease for tiny stores.
Trait Implementations§
Source§impl Memory for GuardedMemory
impl Memory for GuardedMemory
Source§fn recall<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn recall<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str,
k: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<MemoryEntry>, MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
k entries most relevant to query, ordered by
descending relevance. The query is typically the current task
description; backends choose how to score (keyword, embedding, BM25…).
Returning an empty Vec is fine and must not be treated as an error.Source§fn write<'life0, 'async_trait>(
&'life0 self,
entry: MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn write<'life0, 'async_trait>(
&'life0 self,
entry: MemoryEntry,
) -> Pin<Box<dyn Future<Output = Result<(), MemoryError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
entry. The backend assigns the id field; callers may
leave it empty. Implementations must be safe to call concurrently
from multiple tasks.