Package com.tnsai.memory.strategy
Class TieredMemoryStore
java.lang.Object
com.tnsai.memory.strategy.TieredMemoryStore
4-tier memory store with Ebbinghaus-inspired decay and promotion.
Tiers: Working → Episodic → Semantic → Procedural
- Working: raw, high token cost, fast decay
- Episodic: compressed sessions, moderate decay
- Semantic: consolidated facts, slow decay
- Procedural: extracted workflows, near-permanent
Memories gain strength on access (spacing effect) and lose strength over time (decay). Strong memories promote upward; weak memories are evicted.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordResult of a consolidation cycle. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a new memory at the Working tier.add(String id, String content, MemoryTier tier) Adds a memory at a specific tier (for loading persisted state).voidclear()Clears all memories.Runs the consolidation cycle: decay → promote → evict.detectContradictions(double threshold) Detects contradictions: entries with similar content but from different sessions.Retrieves a memory by ID and records an access (reinforces strength).getActive(int topK) Retrieves only active (non-stale, non-superseded) memories.getByTier(MemoryTier tier) Retrieves all memories at a given tier, sorted by strength descending.getTopK(int k) Retrieves the top-K strongest memories across all tiers.booleanRemoves a memory by ID.intsize()Returns total entry count.Adds a new memory that supersedes an existing one.Returns entry count per tier.traceProvenance(String entryId) Traces provenance: returns the version chain for an entry.
-
Constructor Details
-
TieredMemoryStore
public TieredMemoryStore()
-
-
Method Details
-
add
Adds a new memory at the Working tier. -
add
Adds a memory at a specific tier (for loading persisted state). -
get
Retrieves a memory by ID and records an access (reinforces strength). -
getByTier
Retrieves all memories at a given tier, sorted by strength descending. -
getTopK
Retrieves the top-K strongest memories across all tiers. -
consolidate
Runs the consolidation cycle: decay → promote → evict.- Returns:
- summary of actions taken
-
supersede
Adds a new memory that supersedes an existing one. The old entry is marked superseded, its strength halved, and flagged stale. Related entries (same source session) are cascading-stale flagged.- Parameters:
id- new entry IDcontent- new contentoldId- ID of the entry being superseded- Returns:
- the new entry
-
detectContradictions
Detects contradictions: entries with similar content but from different sessions. Uses Jaccard similarity on word sets. Returns pairs of contradicting entry IDs.- Parameters:
threshold- Jaccard similarity threshold (0.0-1.0, default 0.7)- Returns:
- list of contradicting pairs [olderId, newerId]
-
getActive
Retrieves only active (non-stale, non-superseded) memories. -
traceProvenance
Traces provenance: returns the version chain for an entry. Follows supersedes links backward to the original. -
remove
Removes a memory by ID. -
size
public int size()Returns total entry count. -
tierCounts
Returns entry count per tier. -
clear
public void clear()Clears all memories.
-