Episodic vs. Semantic Memory: What to Remember

Episodic vs. Semantic Memory: What to Remember

Master the distinction between episodic (event-based) and semantic (fact-based) memory in AI agents and how to store them in a vector database.

Episodic vs. Semantic Memory: What to Remember

In human psychology, memory is not a single bucket. We have different systems for remembering "What we did" vs. "What we know." AI agents use these same concepts to manage their vector storage effectively.

In this lesson, we break down Episodic and Semantic memory and learn how to implement them in a vector database schema.


1. Episodic Memory: The Personal Log

Episodic Memory is the record of specific events or experiences. For an agent, this is usually the "Who said what" of a conversation.

  • Example: "At 2 PM, User John asked for a price audit on Project X."
  • Storage Strategy: High granularity. Usually stored with a session ID and a precise timestamp.
  • Retrieval Goal: To re-establish the "Vibe" or "Thread" of a specific past conversation.

2. Semantic Memory: The Knowledge Base

Semantic Memory is the storage of generalized facts, concepts, and rules that are independent of a specific event.

  • Example: "The price of Gold is $2,000/oz" or "User John prefers dark mode."
  • Storage Strategy: Lower granularity, higher stability. These memories are often deduplicated and updated rather than simply appended.
  • Retrieval Goal: To provide the agent with the "Rules of Engagement" or "Background Truths" for a task.

3. Comparison Table

FeatureEpisodic MemorySemantic Memory
ContentEvents, Chat Logs, ObservationsFacts, Preferences, Rules
TimingTime-bound (Sequential)Timeless (Axiomatic)
Vector DB UseRetrieve similar "Situations"Retrieve relevant "Facts"
Metadatasession_id, timestamp, user_moodcategory, confidence_score, data_source

4. Implementation: Memory Type Tagging

In your vector database, you should use Metadata Filtering to differentiate between these two modes.

Python Code: Multi-Memory Routing

def add_memory(collection, content, m_type="episodic", metadata=None):
    if metadata is None:
        metadata = {}
    
    metadata["memory_type"] = m_type
    
    collection.add(
        documents=[content],
        metadatas=[metadata],
        ids=[f"{m_type}_{datetime.now().timestamp()}"]
    )

# Retrieving only Facts (Semantic)
results = collection.query(
    query_texts=["What does the user like?"],
    where={"memory_type": "semantic"}, # FILTERING!
    n_results=2
)

5. The "Consolidation" Process

A advanced agent will perform Memory Consolidation:

  1. Take a day's worth of Episodic logs.
  2. Use an LLM to "Summarize" them into new Semantic facts.
  3. Update the Semantic memory and delete (or archive) the bulky Episodic logs.

This is the secret to a high-density, low-cost long-term memory.


6. Summary and Key Takeaways

  1. Episodic = The Story (Events).
  2. Semantic = The Wiki (Truths).
  3. Metadata Filters are essential for querying the right kind of memory for the right task.
  4. Consolidation prevents "Memory Bloat" by move specific events into general knowledge.

In the next lesson, we’ll look at Agent Recall and Planning—how the agent actually uses this retrieved data to solve complex problems.


Congratulations on completing Module 12 Lesson 2! You now know how to categorize the AI mind.

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn