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

TypeDurationStorageExample
WorkingCurrent conversationLLM context windowWhat the player just said
Short-termCurrent sessionIn-memory bufferEvents from the last hour
Long-termAcross sessionsVector databaseKey relationship milestones
SharedPersistentWorld state DBCommon 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
Summarization Chain: Periodically run a summarization pass that compresses older memories into concise summaries. "Player visited the shop 12 times in March and always bought healing potions" is more useful than 12 individual visit logs.

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.