SkillByAIOpen interactive version →

Lesson 15 / 25

Long-Term Memory: Store and Retrieve

Facts that should persist across sessions belong in storage, not in the prompt.

Write, retrieve, forget

Long-term memory means saving useful facts (user preferences, project details, past decisions) outside the model and retrieving only the relevant ones into future contexts, like retrieval over your own notes. Design it deliberately: what is worth saving, who can see it, how it is updated when facts change, and how users can view and delete it. Saved memories are user data: apply privacy rules, avoid storing secrets, and remember that a wrong memory will keep reappearing until it is corrected.

A memory record design

Structured fields make memories easy to retrieve, update and delete.

{
  "user_id": "u_42",
  "fact": "prefers answers in bullet points",
  "source": "stated by user on 2026-09-12",
  "scope": "all chats",
  "updated_at": "2026-09-12",
  "expires": null
}
# retrieve: top-k memories for this user relevant to the request
# update: replace when the user changes a preference
# delete: user-visible "forget this" control

Let users see and delete memory

A visible memory list with delete buttons builds trust and fixes wrong memories quickly.

Quick check: What should happen to long-term memories over time?

  • They should be updatable and deletable, with privacy rules applied
  • They should never change
  • They should all be sent on every call
  • They should include passwords for convenience
Answer

They should be updatable and deletable, with privacy rules applied — Memory is user data with a lifecycle.