C.W.K.
Stream
Lesson 04 of 05 · published

Decay, Pruning, and Forgetting on Purpose

~18 min · memory, operations

Level 0Scout
0 XP0/41 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Memory grows without bound; relevance does not

An always-on AI accumulates thousands of memory items per week. Most are stale within a month. Retrieval quality degrades as the irrelevant pile grows — the embedding model is good but not magical.

Three pruning strategies

  1. Hard age cutoff — delete anything older than N days unless flagged as keep-forever. Brutal, simple, recoverable from JSONL ground truth.
  2. Distillation + replace — periodically compress old episodes into distilled facts and delete the raw turns. Permanent loss of detail in exchange for cleaner retrieval.
  3. Use-based decay — track how often each memory was retrieved + whether the LLM cited it; prune cold items. Best retention quality; needs retrieval logging.

The keep-forever escape hatch

Some memories must never decay: identity ('user is Dad', 'I am Pippa'), policies ('never auto-push to main'), past traumas/lessons. Mark these with metadata.permanent = true and exclude them from any pruning pass. Without this, your AI quietly forgets who it is.

Code

Pruning pass with permanent escape·python
from datetime import datetime, timezone, timedelta

def prune(collection, max_age_days: int = 90):
    cutoff = (datetime.now(timezone.utc) - timedelta(days=max_age_days)).isoformat()
    candidates = collection.get(
        where={
            '$and': [
                {'created_at': {'$lt': cutoff}},
                {'permanent': {'$ne': True}},
            ],
        }
    )
    if candidates['ids']:
        collection.delete(ids=candidates['ids'])
        print(f'pruned {len(candidates["ids"])} stale memories')

External links

Exercise

Implement the pruning pass on a test collection. Add 100 memories with varied dates and a few marked permanent=True. Run prune with max_age_days=30. Confirm permanent items survive and stale ones are gone. Add a recovery test from JSONL backup.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.