Expand description
B4 (v0.22.4): two-tier semantic memory — a unified MemoryStore abstraction
(namespaced key-value + semantic recall) with a short-/long-term split and
weighted-decay ranking.
§Why a second memory abstraction
crate::BaseMemory manages conversation history (messages injected into the
next prompt). The types in this module manage knowledge: durable facts about the
user / task extracted from completed turns, addressable by namespace (e.g. one per
user or session) and retrievable by meaning rather than by recency in a transcript.
§The two tiers
ShortTermMemoryis the in-thread working tier: bounded per namespace (capacity, FIFO eviction), exact key-value lookups plus semantic search purely by similarity. Nothing is persisted; a dropped store is a forgotten store.LongTermMemoryis unbounded and ranks candidates the way generative-agent systems do:score = w_similarity · sim + w_recency · 2^(−age/half_life) + w_importance · importance(DecayWeights). Frequently re-accessed memories stay fresh; old, unimportant ones naturally sink — nothing is deleted on the read path.TwoTierMemorywires the two together: writes land in the short tier;consolidatepromotes entries that clear thePromotionPolicy(high importance or enough re-accesses). Recall searches both tiers with one uniform weighted formula and de-duplicates by key (short tier wins on collision).
§Semantics without a mandatory embedding dependency
SemanticScorer is a pluggable trait; the always-available LexicalScorer
ranks by cosine over term-frequency vectors (Unicode-aware tokenization), so the
whole abstraction and its tests run offline with zero extra dependencies. An
embedding-backed scorer can be supplied with with_scorer without touching the
stores.
All time-dependent logic takes an injected clock, so decay/consolidation tests are pure — no sleeps.
Structs§
- Decay
Weights - Weights and half-life of the long-term ranking formula.
- Lexical
Scorer - Dependency-free scorer: cosine similarity over Unicode word term-frequency vectors.
- Long
Term Memory - Unbounded long-term memory with weighted-decay ranking.
- Memory
Hit - A recall result.
- Memory
Item - A storable unit of knowledge.
- Memory
Query - A semantic recall query against one namespace.
- Promotion
Policy - Policy deciding which short-term entries consolidate into long-term memory.
- Short
Term Memory - Bounded in-thread working memory (one FIFO queue per namespace).
- Stored
Memory - A memory with its lifecycle bookkeeping.
- TwoTier
Memory - Two-tier memory: bounded short-term working store + decayed long-term store.
Enums§
- Memory
Tier - Which tier a recall hit came from.
Traits§
- Memory
Extractor - Turns a completed conversation turn into durable memories.
- Memory
Store - Namespaced key-value store with semantic recall.
- Semantic
Scorer - Pluggable semantic similarity between two texts.
Type Aliases§
- Clock
- Injectable wall clock (defaults to
SystemTime::now).