BeginnerCoder

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.

Want it another way?
Task

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.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with AI Agents Foundations

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.