Lesson 19 — Long-term memory: keyword retrieval
Remembering across conversations
Long-term memory is a store of notes kept outside the conversation (in a file or a database). Before answering, the agent retrieves the few notes that match the question and puts them into the prompt. This is called retrieval, and it is the core of RAG (retrieval-augmented generation).
Real systems usually compare embeddings — lists of numbers that capture meaning — stored in a vector database. We use a simpler, "vector-free" version that works the same way: score each note by how many words it shares with the question, then keep the top results.
A stop word is a very common word ("the", "is", "what") that matches everything, so we ignore it. set_a & set_b gives the items in both sets.
Why it matters: retrieval lets an agent "remember" thousands of facts while sending only the 2–3 relevant ones to the model.
Write score(query, note): how many words (not in STOP) appear in both. Use words(), & and -.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based AI Agents Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for AI Agents Foundations books — check the publication year so the examples match current versions.
Search Amazon →