Memory Intermediate
Memory is what transforms an AI NPC from a stateless chatbot into a believable character. When an NPC remembers that you helped them last week, mentions a conversation you had about dragons, or holds a grudge because you stole from their shop - the illusion of a living world becomes real.
Memory Types
| Type | Duration | Storage | Example |
|---|---|---|---|
| Working | Current conversation | LLM context window | What the player just said |
| Short-term | Current session | In-memory buffer | Events from the last hour |
| Long-term | Across sessions | Vector database | Key relationship milestones |
| Shared | Persistent | World state DB | Common knowledge, rumors |
Vector Database Integration
Store NPC memories as embeddings in a vector database (Pinecone, ChromaDB, or Qdrant). When building the LLM prompt, retrieve the most relevant memories using semantic similarity search against the current conversation context.
Memory Formation
Not every conversation turn should become a memory. Implement an importance scoring system:
- Emotional intensity (arguments, gifts, confessions) → high importance
- Quest-related events (completed tasks, broken promises) → high importance
- Small talk and greetings → low importance, summarize periodically
- World events witnessed by the NPC → medium importance
Episodic Recall
When an NPC retrieves a memory, present it naturally in dialogue: "Last time you were here, you mentioned looking for the Crystal of Shadows. Did you find it?" This creates continuity and makes players feel their actions matter.
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX