CertSafari
    Databricks Certified Context Engineer Associate· Lessons

    Domain 4 · Lesson 26/45

    Over-retrieval and under-retrieval in agent memory

    Diagnose risks of over-retrieval (context pollution) and under-retrieval (missing relevant history) in a memory system.

    15 min read
    2.25% of exam
    9 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Explain context pollution (over-retrieval) and missing history (under-retrieval) in an agent memory system, and tell the two apart from an agent's behaviour
    • Trace each failure to the retrieval setting behind it, such as the result limit, actor_id scope, the match criterion, a recall call that never happened, or a fact that was never saved
    • Measure memory retrieval apart from the answer using precision, recall and MLflow judges, and pick the fix each result points to

    Key concept

    Precision and recall for memory retrieval — Score the memories that a recall step returns separately from the final answer. Precision is the share of returned memories that are relevant, so low precision means pollution. Recall is the share of relevant memories that came back, so low recall means missing history. The two failures need opposite fixes.

    1.Two ways memory retrieval goes wrong

    An agent with long-term memory doesn't see its whole memory store on each turn. It sees only what a recall step returns. In Databricks agent memory, memories are durable facts, preferences and decisions about a subject. The agent fetches them with a natural-language search. Each search is scoped to one actor_id, ranks entries by a full-text BM25 relevance score, and stops at limit.

    A single recall call. The actor_id sets the scope, the query sets the ranking, and limit caps how many entries reach the context.python
    results = memory_store.search(actor_id="user-123", query="communication preferences", limit=10)

    That one call can fail in two opposite directions. It can return too much: entries that loosely match the query but have nothing to do with the question. Or it can return too little: the entry with the fact the agent needs is in the store but never comes back. Either way the answer suffers, because the model can only reason over the context it was handed.

    From the outside, both failures look the same: a wrong or off-target answer. Underneath, they come from different settings and need opposite fixes. Tightening retrieval cures one and worsens the other. So diagnosis starts by measuring retrieval on its own. Precision asks how much of what came back was relevant. Recall asks how much of what was relevant came back.

    Checkpoint 1 of 7· Fill the gap

    An agent's context fills up with loosely matching memories that have nothing to do with the question (over-retrieval). In this recall call, which parameter caps how many memory entries reach the context?

    results = memory_store.search(actor_id="user-123", query="communication preferences",  ? =10)

    Sources123

    2.Over-retrieval: context pollution

    Context pollution is worse output caused by irrelevant memories crowding the context next to the relevant ones. It is a quality failure, not a fault in the store. The store is up, every write landed, and search returned results. It just returned too many of the wrong ones. Recalled-but-irrelevant history then shapes the answer, which makes over-retrieval a concrete source of Context confusion, where content unrelated to the task steers the response. Polluted context doesn't make the model hesitate. It leads to confident, wrong answers.

    Pollution usually traces back to one of three settings. The first is the retrieval count. How many entries come back is a tunable retrieval parameter, and every entry past the relevant ones lowers precision. The second is scope. Every list and search covers exactly one actor_id. If the agent uses a shared key, such as a team or project ID, one user's recall competes with everything the whole group has saved. The third is how the store ages. An agent that saves memories one conversation at a time slowly collects overlapping and conflicting entries, so a single search can return a stale version of a fact alongside the current one. A memory pipeline is the process that counters this: it runs after the fact, reads an actor's past conversations from a session store, and distills them into consolidated memory entries.

    Sources of over-retrieval in a memory store and the change that raises precision
    CauseWhat the agent doesChange that raises precision
    limit set far above the number of relevant entriesMentions old or unrelated facts alongside the right oneLower limit so that fewer, better-ranked entries come back
    actor_id set to a shared team or project keyApplies another user's preferences to this userSet actor_id to the verified end-user identity when memory should be private
    Overlapping and conflicting entries built up over many conversationsMixes a superseded decision with the current oneRun a memory pipeline that merges overlapping entries, with instructions to skip one-off content

    Some fixes act at write time instead of read time. Pipeline instructions can tell distillation what to skip, such as one-off troubleshooting steps, so those entries never exist to pollute a later search. If memories are served from an AI Search index instead of the memory store, metadata filters and the built-in reranker also raise precision. Filters drop out-of-scope entries before ranking, and the reranker keeps high recall from a smaller candidate set.

    Checkpoint 2 of 7· Check yourself

    Users report that a support agent answers one person using a teammate's preferred contact channel and timezone. The memory store is healthy and search returns results. What is the most likely cause?

    Checkpoint 3 of 7· Exam question

    In the context of an agent memory system, what does the term 'context pollution' refer to?

    Sources43156

    3.Under-retrieval: missing relevant history

    Under-retrieval means relevant history never reaches the model, so the agent answers as if earlier facts had never been established. It asks again for a preference the user already gave, or it contradicts a decision made three conversations ago. Long-term memory exists so that a fact surfaces whenever it matters, no matter which conversation produced it. Under-retrieval breaks exactly that promise. With the key context missing, the model doesn't stop. It fills the gap, and that is where hallucinations come from.

    The most basic cause is a recall call that never happened. When memory is wrapped as tools, the model chooses when to search, guided only by its system prompt. If that prompt doesn't make clear when recall is worth doing, the agent answers from the current session alone. This is the risk of Fixed session replay vs agent-driven memory recall from the agent-driven side: the memory exists, but the trace has no search span.

    A second cause is a match criterion that is too narrow. Here the recall call runs, but the relevant entry is screened out. A similarity cutoff is a setting of vector (AI Search) retrieval, such as score_threshold, which excludes results scoring below it. The BM25 memory-store search takes no such cutoff, so this case applies to memories served from an AI Search index. Take an aggressive cutoff that only admits near-exact matches. It drops a memory saying "prefers email over phone" when the query is "how should we contact this customer": same fact, different words. That is a recall problem. The fix is to relax the cutoff or broaden the matching strategy. Adding storage, regenerating embeddings or freeing context-window space won't help, because none of those changes which entries pass the filter. The memory store ranks by full-text BM25, so wording matters. The description field on each entry improves retrieval, so write descriptions in the terms future questions will use. When memories live in an AI Search index, hybrid search catches keyword matches as well as semantic ones.

    For memories retrieved through AI Search, switching to hybrid search adds keyword matching on top of vector similarity.python
    # Enable hybrid search
    results = index.similarity_search(
        query_text="error code E404",
        query_type="HYBRID"  # Combines vector and keyword search
    )

    Two causes sit outside the search call. A fact that was never written can't be recalled. An agent that saves memories mid-conversation has only that conversation in view and misses facts it didn't think to save. A memory pipeline reads all of an actor's conversations afterwards and captures what the agent missed. The other cause is the wrong partition. If actor_id is built from the wrong identity, or quietly falls back to a shared key, the search runs against a partition that doesn't hold this user's entries. If your scheme depends on an end-user identity, reject requests that arrive without one.

    Checkpoint 4 of 7· Check yourself

    A memory search runs against an AI Search index with a strict similarity cutoff. The trace shows the search span, but the entry "prefers email over phone" never comes back for the query "how should we contact this customer". Which change addresses this?

    Checkpoint 5 of 7· Exam question

    A team sets an aggressive similarity-score cutoff on their memory retriever so that only near-exact matches are returned. Afterward, users notice the agent frequently fails to recall clearly relevant past preferences that were phrased differently than the current query. What is happening, and what should the team do?

    Sources26175

    4.Measuring memory retrieval separately from the answer

    Answer quality alone can't tell pollution from missing history. A response can be poor even when retrieval returned the right context, and it can be good even when retrieval was faulty. Scoring only the final answer hides which half broke. So measure the recall step on its own, then the response.

    Precision and recall split the recall step cleanly. Suppose a search returns three memories, two of them relevant, and four relevant memories exist in total. Precision is 2/3 (0.66) and recall is 2/4 (0.5). The two metrics need different labels. You can judge precision by looking only at what came back. Recall needs ground truth that lists every relevant memory, because you can't count what's missing without knowing what should have been there.

    Agent Evaluation metrics and the memory failure each one flags
    MetricNeeds ground truth?A low score points to
    chunk_relevance/precisionNoOver-retrieval: irrelevant memories polluting the context
    document_recallYesUnder-retrieval: relevant memories missing from what came back
    context_sufficiencyYesUnder-retrieval: what came back isn't enough to produce the expected response
    groundednessNoThe response isn't supported by the retrieved context (hallucination)

    These are the same MLflow retrieval judges as failure-mode signals used for document retrieval, read with a memory lens. Low relevance means pollution and low sufficiency means missing history. For a single bad answer, open the trace and inspect the recall span, as in Did retrieval fail, or generation?. If the right memory is in the span and the answer ignored it, generation failed. If the span is crowded with unrelated entries, retrieval over-fetched. If the needed memory is absent, or there's no recall span at all, retrieval under-fetched.

    Use the same approach to judge a configuration change. Say a new limit, cutoff or scope arrives and hallucinations rise. Run mlflow.genai.evaluate() with relevance and groundedness scorers over captured traces or an evaluation set, once for the old configuration and once for the new. If relevance fell, the change caused pollution. If relevance held but sufficiency fell, it caused missing history. Look at the relative change between the two runs more than the absolute scores. Skimming a few transcripts, or shipping to everyone and waiting for complaints, gives you no metric to compare.

    Checkpoint 6 of 7· Match them up

    Your memory evaluation run comes back with one Agent Evaluation metric scoring low. Match each metric to the failure that a low score points to.

    Tap a term, then the definition that fits it.

    Checkpoint 7 of 7· Exam question

    A team suspects that a recent change to their memory retrieval configuration is causing more hallucinated answers, but they are not sure whether the cause is too much irrelevant context or too little relevant context. What is the best way to empirically diagnose this using their existing tooling?

    Sources896

    Sources

    (9)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Search returns the most relevant entries ranked by a full-text (BM25) relevance score.”
      ↩︎ Two ways memory retrieval goes wrong
      “Every list and search is scoped to a single actor_id”
      ↩︎ Over-retrieval: context pollution
      “wrap the client operations as tools and instruct the agent on when to use them in its system prompt”
      ↩︎ Under-retrieval: missing relevant history
      “description improves retrieval”
      ↩︎ Under-retrieval: missing relevant history
      “If your strategy depends on an end-user identity, reject requests that don't carry one rather than falling back to a shared actor_id.”
      ↩︎ Under-retrieval: missing relevant history
      “Set actor_id to a fixed key you choose, such as a team, project, or organization ID. Everyone reads and writes the same memories.”
      ↩︎ Checkpoint
    2. 2.
      “Agent memory stores durable facts, preferences, and decisions that an agent recalls in later, separate conversations, retrieved by semantic search.”
      ↩︎ Two ways memory retrieval goes wrong
      “The agent recalls them whenever they are relevant, regardless of which conversation surfaced them.”
      ↩︎ Under-retrieval: missing relevant history
    3. 3.
      “It's difficult to generate high-quality RAG output if the context provided to the LLM is missing important information or contains superfluous information.”
      ↩︎ Two ways memory retrieval goes wrong
      “The retrieval parameters (for example, the number of chunks or documents retrieved).”
      ↩︎ Over-retrieval: context pollution
      “It's difficult to generate high-quality RAG output if the context provided to the LLM is missing important information or contains superfluous information.”
      ↩︎ Key concept
    4. 4.
      “When the harness pulls in the wrong information from memory or search systems, the model may confidently generate incorrect answers.”
      ↩︎ Over-retrieval: context pollution
      “When the harness pulls in the wrong information from memory or search systems, the model may confidently generate incorrect answers.”
      ↩︎ Exam trap 1
    5. 5.
      “A memory pipeline builds long-term memory from your agent's past conversations.”
      ↩︎ Over-retrieval: context pollution
      “Over many conversations, its memory collects overlapping and conflicting entries, and facts that the agent didn't think to save don't reach memory.”
      ↩︎ Over-retrieval: context pollution
      “The content to skip, such as one-off troubleshooting steps.”
      ↩︎ Over-retrieval: context pollution
      “with all of an actor's conversations and existing memory in view, so it can capture what the agent missed and keep memory consolidated.”
      ↩︎ Under-retrieval: missing relevant history
    6. 6.
      “Boosts precision by achieving high recall with fewer candidates.”
      ↩︎ Over-retrieval: context pollution
      “RAG agents: Missing key context leads to incorrect answers or hallucinations.”
      ↩︎ Under-retrieval: missing relevant history
      “Improves recall by catching both semantic and keyword matches.”
      ↩︎ Under-retrieval: missing relevant history
      “Focus on relative improvements as you test different strategies, not absolute scores.”
      ↩︎ Measuring memory retrieval separately from the answer
      “Optimizing without measurement is guesswork.”
      ↩︎ Measuring memory retrieval separately from the answer
      “Improves recall by catching both semantic and keyword matches.”
      ↩︎ Exam trap 2
    7. 7.
      “Minimum similarity score threshold for filtering results. Results with scores below this threshold are excluded.”
      ↩︎ Under-retrieval: missing relevant history
    8. 8.
      “A RAG application can respond poorly despite retrieving the correct context; it can also provide good responses based on faulty retrievals.”
      ↩︎ Measuring memory retrieval separately from the answer
      “Computing recall requires your ground-truth to contain all relevant items.”
      ↩︎ Measuring memory retrieval separately from the answer
      “Are the retrieved chunks sufficiency to produce the expected response?”
      ↩︎ Measuring memory retrieval separately from the answer
      “A RAG application can respond poorly despite retrieving the correct context; it can also provide good responses based on faulty retrievals.”
      ↩︎ Exam trap 3
      “Precision is the proportion of retrieved documents that are actually relevant to the user's request.”
      ↩︎ Prediction
      “Retrieval | document_recall | What % of the ground truth documents are represented in the retrieved chunks? | Deterministic | Yes”
      ↩︎ Checkpoint
    9. 9.
      “mlflow.genai.evaluate() - Evaluation harness to orchestrate offline evaluation with scorers and datasets”
      ↩︎ Measuring memory retrieval separately from the answer

    Ready to test yourself?

    Practise Databricks Certified Context Engineer Associate in quiz mode.

    Spotted a mistake, or was something unclear? Tell us.