CertSafari
    Databricks Certified Context Engineer Associate· Lessons

    Domain 4 · Lesson 26/45

    Diagnosing memory retrieval failures with precision, recall and traces

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

    9 min read
    2.25% of exam
    4 sources
    Published 3 Oct 2026
    Docs as of 30 Sep 2026

    What you will be able to do

    • Map over-retrieval to precision-style metrics and under-retrieval to recall-style metrics
    • State which retrieval metrics need ground truth and which do not
    • Use MLflow traces to find which retrieval step polluted or starved an agent's context
    • Choose the memory-search setting or retrieval technique that addresses the diagnosed failure

    1.Measure retrieval separately from the answer

    Over-retrieval and under-retrieval both live in the retrieval step, but they show up in the answer only indirectly. An agent might answer correctly today while dragging ten irrelevant memories into every turn. That works until one of them misleads it. Databricks' guidance is that it is very important to collect both response and retrieval metrics, because only measuring both lets you tell the components apart.

    There is a precondition: you need a reproducible evaluation system before you tune anything. A golden dataset, a synthetic evaluation set or ground-truth-free judges all qualify. Changing your memory search settings without measuring is guesswork, and it is easy to trade one failure for the other without noticing.

    Checkpoint 1 of 6· Check yourself

    A team plans to raise the memory search limit because users complain about forgotten preferences. They have no evaluation set. What does the Databricks retrieval-quality guidance say to do first?

    Sources12

    2.Precision catches pollution, recall catches gaps

    The two failure modes map onto the two classic retrieval metrics:

    - Precision asks what percentage of the retrieved items are relevant to the request. Low precision means irrelevant material is getting in. That is over-retrieval. - Recall asks what percentage of the known-relevant items were retrieved. Low recall means needed material is missing. That is under-retrieval.

    The cookbook example: two of three retrieved results were relevant, so precision was 0.66 (2/3). Those results covered two of four relevant documents, so recall was 0.5 (2/4). One retrieval can be mediocre on both.

    There is a practical difference between the two metrics. Computing precision does not require knowing all the relevant items, so an LLM judge can score it on live traffic. Computing recall requires ground truth that lists every relevant item. In MLflow 3 the built-in judges follow the same split. RetrievalRelevance checks whether retrieved context is relevant to the request and needs no ground truth. RetrievalSufficiency checks whether the context provides all the information needed and does need expectations.

    Which metric detects which retrieval failure, and what it needs
    Metric / judgeQuestion it answersFailure it exposesNeeds ground truth?
    chunk_relevance/precisionWhat % of the retrieved chunks are relevant to the request?Over-retrievalNo
    document_recallWhat % of the ground truth documents are represented in the retrieved chunks?Under-retrievalYes
    context_sufficiencyAre the retrieved chunks sufficient to produce the expected response?Under-retrievalYes
    total_token_countWhat's the total count of tokens for LLM generations?Cost side of over-retrievalNo

    Checkpoint 2 of 6· Match them up

    Match each built-in MLflow 3 judge to what it evaluates

    Tap a term, then the definition that fits it.

    Checkpoint 3 of 6· 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?

    Sources13

    3.Use traces to see what memory actually returned

    Metrics tell you that a failure exists. Traces show you where it happened. An MLflow trace records one complete execution of the agent, including every intermediate step (LLM calls, retriever lookups, tool invocations), along with latency and errors. Each of those steps is a span with its inputs and outputs. For a memory tool, the span shows the query the agent sent and the entries that came back.

    That is how you tell the failures apart in practice. A span that returned many entries unrelated to the request points to over-retrieval. A span that returned nothing, or returned entries that miss a fact you know is stored, points to under-retrieval. The search tool below returns the literal text No memory found. when nothing matches, and that is easy to spot in a span's outputs:

    A memory search tool. Its query and returned entries appear in the trace as a span.python
    @function_tool
        def search_memory(query: str) -> str:
            """Search long-term memory for relevant facts about the user."""
            results = memory_store.search(actor_id=actor_id, query=query, limit=10)
            return "\n\n".join(f"{r.memory.path}: {r.memory.content}" for r in results) or "No memory found."

    Missing history often appears only across turns. A fact from turn two that the agent forgets by turn eight is invisible when you score turns one at a time. Tagging traces with mlflow.trace.session groups the turns of one conversation, so you can evaluate the conversation end-to-end.

    Checkpoint 4 of 6· Check yourself

    An agent forgets a constraint the user gave early in a long conversation. Scoring individual turns shows nothing wrong. What helps you catch this?

    Sources4

    4.Match the fix to the diagnosis

    Once you know which failure you have, the levers follow from it. In managed memory, the first lever is the limit on each search. Lowering it trims pollution, and raising it closes gaps. Re-measure precision and recall after each change. The other levers are writing better description text on entries so BM25 search finds them, and scoping each search to the correct actor_id.

    If your agent also retrieves from AI Search indexes, the retrieval-quality guide offers techniques that improve one side without simply sacrificing the other:

    - Metadata filtering dramatically improves precision by eliminating irrelevant results, and it also improves recall within the filtered subset. - Reranking boosts precision by achieving high recall with fewer candidates. You retrieve broadly, then keep only the best results. - Hybrid search improves recall by catching both semantic and keyword matches.

    Which side to favour depends on the use case. When missing key context leads to wrong answers, weight recall. When the user needs the exact item at the top, weight precision.

    Checkpoint 5 of 6· Fill the gap

    Which parameter controls how many memory entries this search can return? It is the setting you lower to reduce over-retrieval and raise to reduce under-retrieval.

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

    Checkpoint 6 of 6· Exam question

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

    Sources2

    Exam traps

    Each one states something that sounds right. Open it to see what is actually true.

    1. 1.If the agent's final answers are correct, its memory retrieval does not need separate evaluation.Why is that wrong?

      Good responses can rest on faulty retrieval, so response metrics alone hide over- and under-retrieval. Collect retrieval metrics too.

      Covered in Measure retrieval separately from the answer

    2. 2.You need a fully labelled ground-truth set before you can detect any retrieval problem.Why is that wrong?

      Precision, the over-retrieval signal, can be judged without knowing all relevant items. Only recall-style metrics need complete ground truth.

      Covered in Precision catches pollution, recall catches gaps

    Sources

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

    1. 1.
      “A RAG application can respond poorly despite retrieving the correct context; it can also provide good responses based on faulty retrievals.”
      ↩︎ Measure retrieval separately from the answer
      “two out of the three retrieved results were relevant to the user's query, so the precision was 0.66 (2/3)”
      ↩︎ Precision catches pollution, recall catches gaps
      “Computing recall requires your ground-truth to contain all relevant items.”
      ↩︎ Precision catches pollution, recall catches gaps
      “It is very important to collect both response and retrieval metrics.”
      ↩︎ Exam trap 1
      “Computing precision does not require knowing all relevant items.”
      ↩︎ Exam trap 2
    2. 2.
      “If you don't have evaluation in place, stop here and set it up first.”
      ↩︎ Measure retrieval separately from the answer
      “Dramatically improves precision by eliminating irrelevant results.”
      ↩︎ Match the fix to the diagnosis
      “Boosts precision by achieving high recall with fewer candidates.”
      ↩︎ Match the fix to the diagnosis
      “Improves recall by catching both semantic and keyword matches.”
      ↩︎ Match the fix to the diagnosis
    3. 3.
      “Is the retrieved context directly relevant to the user's request?”
      ↩︎ Precision catches pollution, recall catches gaps
      “Does the context provide all necessary information to generate a response that includes the ground truth facts?”
      ↩︎ Checkpoint
    4. 4.
      “every intermediate step (LLM calls, retriever lookups, tool invocations), latency, and any errors”
      ↩︎ Use traces to see what memory actually returned
      “Session grouping lets you evaluate conversation quality end-to-end, not just turn by turn.”
      ↩︎ Use traces to see what memory actually returned

    Ready to test yourself?

    Practise Databricks Certified Context Engineer Associate in quiz mode.

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