Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Agent Memory  ›  Capstone Project

Long-Term Memory — Retrieval and Forgetting

RAG and Vector Databases 15 minLong-term memory stores notes as embeddings so the most relevant can be retrieved by meaning and added to the context, while expiry, recency weighting and consolidation keep stale memories from crowding out current ones.

Long-Term Memory — Retrieval and Forgetting

After a year, Tripmate holds hundreds of notes about Asha's trips. When she asks, "What was that quiet hotel near the station in Udaipur?", it cannot paste all of them into the context. It must find the few that matter — and, over time, let go of the ones that no longer do.

The rule

Store by meaning, retrieve the few that matter, and let stale memories fade.

Embeddings make searching by meaning possible. An embedding model turns a piece of text into a long list of numbers — a vector — so that texts with similar meanings get vectors that are close together. "Quiet hotel near Udaipur station" lands near "calm guesthouse, 5 minutes' walk from Udaipur Junction", even though they share few words.

A vector database (or a vector index inside an ordinary database) stores those vectors and quickly finds the ones nearest to a query.

Retrieval-augmented generation (RAG) puts this to work in three steps:

  1. Retrieve — embed the question and fetch the most similar stored notes.
  2. Augment — add those notes to the context.
  3. Generate — the model answers using them, ideally saying which note it relied on.
question → embed → nearest 3 notes → [notes + question] → model → answer

Forgetting keeps long-term memory healthy. Common strategies:

  • Expiry — some memories get an end date (a price quote is stale in a week).
  • Recency weighting — older memories score lower when ranking results.
  • Consolidation — many old episodes are replaced by one summary.
  • Deletion on request — when a user asks to be forgotten, the data goes.

The shortcut

Rank memories by "relevant and still true", not relevance alone. A simple recipe multiplies the similarity score by a recency weight, so an old note must be a much better match to beat a fresh one.

Which Udaipur note does Tripmate retrieve?Step 1 of 4
  1. The candidates

    Note A (last month): similarity 0.80, recency weight 1.0. Note B (two years ago): similarity 0.90, recency weight 0.5.

The trap is trusting retrieval blindly. The nearest note is not always a correct one, and a stale note can contradict a newer fact. Keep dates on memories, prefer newer facts when they clash, and let the model say when nothing relevant was found.

Drills

Answer fast — trust the rule.

quick drill

What does an embedding represent?

quick drill

What are the three steps of retrieval-augmented generation, in order?

quick drill

Note C has similarity 0.70 and recency weight 1.0; Note D has similarity 0.95 and recency weight 0.6. Using similarity × recency, which ranks higher?

quick drill

A saved fare quote from last month keeps being used as current. Which forgetting strategy fits best?

Remember

  • Embeddings store meaning as vectors; RAG retrieves the nearest notes, adds them, then generates.
  • Shortcut: rank by "relevant and still true" — similarity weighted by recency.
  • Trap: trusting the nearest match blindly; keep dates and prefer newer facts.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainRetrieve and forget

Explain how Tripmate would answer "Which hotel did I like in Udaipur?" using embeddings and retrieval-augmented generation, and describe one forgetting strategy that would stop an outdated note from giving the wrong answer.