Lesson 1112 lessons

Adding Memory with Firestore

Beyond conversation history

"Memory" means the AI recalls facts across separate sessions — not just within one conversation. This requires extracting and storing durable facts (user preferences, past decisions) separately from raw message history.

A simple memory schema

Store a user_memory/{uid} document with fields like preferences, keyFacts[], lastUpdated. After each conversation, optionally ask Claude to extract new durable facts and merge them into this document.

Injecting memory into new sessions

At the start of a new conversation, fetch the user's memory document and include a summary in the system prompt ("Known facts about this user: ..."). This gives continuity without resending full old conversations.

Key Takeaways

  • Memory means recalling facts across sessions, not just within one conversation.
  • Store durable facts separately from raw message history.
  • Optionally use Claude itself to extract new facts to remember.
  • Inject a memory summary into the system prompt for new sessions.

Build a basic memory store

Create a `user_memory/{uid}` Firestore document, manually seed it with 2-3 facts, and modify your system prompt to include those facts at the start of every new conversation.

Building a Chat UI Component