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

Episodic vs Semantic Memory

~20 min · memory, design

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

Borrow the terms from cognitive science

  • Episodic memory — specific past events with time and context. "Last Tuesday, Dad asked about pgvector indexes."
  • Semantic memory — generalized knowledge stripped of context. "Dad prefers HNSW over IVFFlat for incremental ingestion."

An AI memory system needs both, and they have different storage shapes:

  • Episodic → append-only log (JSONL, time-series), retrieved by recency and similarity
  • Semantic → distilled knowledge base, retrieved by similarity, periodically rewritten by the model itself

Two retrieval contracts

When the user asks a question, you usually need both: episodic to recover what was actually said, semantic to recover the model's distilled understanding. Two retrievers, two scoring functions, fused at the prompt assembly stage.

Code

Two retrievers, one prompt·python
def assemble_memory_context(question: str, k_episodic: int = 4, k_semantic: int = 4):
    episodic = episodic_collection.query(
        query_embeddings=[embed(question)],
        n_results=k_episodic,
    )
    semantic = semantic_collection.query(
        query_embeddings=[embed(question)],
        n_results=k_semantic,
    )
    return {
        'episodic_memories': episodic['documents'][0],
        'semantic_memories': semantic['documents'][0],
    }

External links

Exercise

Sketch your app's memory needs. List 5 user interactions: which are episodic (specific event) vs semantic (general fact)? Decide whether one store, two stores, or no store at all is the right shape — most apps need fewer stores than they think.

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.