Skip to Content

8. Memory

Persist exchanges and retrieve relevant ones on each new turn. Inject above retrieved chunks, below the system prompt. Unbounded history increases noise — retrieval must be selective.

!!! warning “Memory is retrieval” Treat memory like retrieval: if you wouldn’t blindly pass all documents to the model, don’t blindly pass all prior turns either. A wrong or low-quality exchange stored as memory will contaminate future turns.

Memory Types

TypeWhat it isStorage
Working memoryThe current conversation’s context windowFinite and expensive
Episodic memoryStored past conversations, retrieved by relevanceThis is what you build in this module
Semantic memoryLong-term facts about the user or domainOften a simple key-value store, not vector search

Multi-Turn UX

Summarise older turns rather than dropping them. A good conversation summary preserves decisions and facts while discarding filler. Context window management is a design problem, not just an engineering one.

Resources

Anthropic memory patterns · pgvector · Pinecone