Agentic AI · Intermediate level

Intermediate level · Module 7: Short-Term and Long-Term Memory · Lesson 2 of 3

Long-Term Memory Stores

Learners store useful facts across sessions (preferences, previous findings) in SQLite, retrieve relevant memories by keyword or embedding search, and give users control over them.

In this lesson you will

  • Store and retrieve long-term memories
  • Decide what is worth remembering

Key concepts

memory recordmetadata (user, date, source)retrieval by relevancememory expiryuser control

The lesson

Long-term memory saves selected information between sessions: a user's preferred report format, findings from earlier research, or frequently asked facts. Store each memory with metadata: who it belongs to, when it was created, its source and an expiry date.

Before each task, retrieve only the few most relevant memories (by keyword or embedding similarity) and add them to the context. Retrieving everything wastes tokens and confuses the model.

Remember facts, not raw conversations, and let users see and delete what is stored about them.

Step by step

  1. Create a memories table with metadata and expiry.
  2. Write save_memory and recall(query, k=3) functions.
  3. Test that relevant memories improve a follow-up task.
  4. Add a function to list and delete a user's memories.

Practice activity

Add a long-term memory store with recall and user control to the project.

Expected result: Relevant memories improve follow-up tasks, and users can see and delete them.

Check your understanding

  1. Why store metadata with memories?

    Show answer

    To know whose they are, where they came from and when they expire.

  2. Why retrieve only a few memories?

    Show answer

    To save tokens and avoid confusing the model with irrelevant information.

Further learning

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.