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.
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)In Databricks agent memory, search ranks entries by BM25 relevance. It stops at limit, so limit sets how many entries can crowd into the context. actor_id only sets the scope, and query sets the ranking.
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.
| Cause | What the agent does | Change that raises precision |
|---|---|---|
| limit set far above the number of relevant entries | Mentions old or unrelated facts alongside the right one | Lower limit so that fewer, better-ranked entries come back |
| actor_id set to a shared team or project key | Applies another user's preferences to this user | Set actor_id to the verified end-user identity when memory should be private |
| Overlapping and conflicting entries built up over many conversations | Mixes a superseded decision with the current one | Run 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?
Every search is scoped to one actor_id. With a shared team key, one user's recall competes with everything the group saved, which pollutes the context with other people's preferences. Pollution is a quality failure, not a store fault, and the fix is to set actor_id to the verified end-user identity.
“Set actor_id to a fixed key you choose, such as a team, project, or organization ID. Everyone reads and writes the same memories.”Source: docs.databricks.com
Checkpoint 3 of 7· Exam question
In the context of an agent memory system, what does the term 'context pollution' refer to?
Correct answer: A — Degraded output quality caused by irrelevant retrieved memories crowding out the relevant ones in context
- A. Correct: context pollution describes the over-retrieval symptom where too much irrelevant or low-value memory content is included, diluting the relevant signal and degrading response quality.
- B. Incorrect: this describes a security/tampering issue, not the quality-dilution effect that context pollution refers to.
- C. Incorrect: this describes an availability failure, not the retrieval-quality issue captured by 'context pollution'.
- D. Incorrect: this describes a data-integrity or write-path issue, unrelated to the concept of irrelevant content diluting retrieved context.
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.
# 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?
The search ran, but a near-exact cutoff screened out an entry with the same meaning in different words. That is a recall problem, so you need to relax the cutoff or broaden matching. Tightening the cutoff lowers recall further. Regenerating embeddings or freeing context space doesn't change which entries pass the filter.
“Improves recall by catching both semantic and keyword matches.”Source: docs.databricks.com
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?
Correct answer: A — The strict threshold is causing under-retrieval by excluding relevant but loosely worded memories; relax the threshold or broaden the matching strategy
- A. Correct: an overly strict similarity cutoff filters out relevant memories that are phrased differently but semantically related, producing under-retrieval. Relaxing the threshold or using a broader matching approach (e.g., hybrid search) restores recall.
- B. Incorrect: the symptom described is missing relevant memories, not noise from excess irrelevant matches, so this is not over-retrieval, and tightening the threshold further would only exclude more relevant results.
- C. Incorrect: nothing in the scenario points to storage capacity as the cause; the described failure is a matching/threshold issue, not a capacity issue.
- D. Incorrect: while embedding quality can affect matching, the scenario specifically describes a threshold that excludes valid matches, which is a configuration issue independent of embedding model version.
- E. Incorrect: a full context window would cause truncation of retrieved or instructional content generally, not a pattern where semantically relevant-but-differently-phrased memories are specifically excluded by score.
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.
| Metric | Needs ground truth? | A low score points to |
|---|---|---|
| chunk_relevance/precision | No | Over-retrieval: irrelevant memories polluting the context |
| document_recall | Yes | Under-retrieval: relevant memories missing from what came back |
| context_sufficiency | Yes | Under-retrieval: what came back isn't enough to produce the expected response |
| groundedness | No | The 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.
Precision is judged only on what came back, so a low score means pollution. document_recall and context_sufficiency need ground truth and flag missing history. Groundedness scores the response against the retrieved context, so it flags hallucination rather than a retrieval fault.
“Retrieval | document_recall | What % of the ground truth documents are represented in the retrieved chunks? | Deterministic | Yes”Source: docs.databricks.com
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?
Correct answer: A — Run MLflow evaluation with relevance and groundedness scorers over captured traces to compare the old and new retrieval configurations
- A. Correct: MLflow tracing captures what was retrieved and generated, and evaluation with relevance/groundedness scorers (LLM judges) lets the team measure, on real traces, whether the new configuration retrieves more noise (over-retrieval) or misses needed context (under-retrieval) compared to the prior configuration.
- B. Incorrect: manual, unstructured spot-checking is subjective, does not scale, and does not produce comparable metrics between the two configurations.
- C. Incorrect: shipping an unvalidated change to all production traffic and waiting for complaints is risky and reactive; it does not systematically diagnose the root cause before impacting users.
- D. Incorrect: verbose logs without structured traces or scorer-based evaluation provide raw detail but no comparative, quantified measurement of retrieval quality.
- E. Incorrect: rebuilding the index assumes the problem is data corruption rather than diagnosing whether the actual cause is retrieval breadth (over- or under-retrieval), and it discards data without evidence it is needed.
Sources
(9)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 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.
“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.
“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.https://www.databricks.com/blog/ai-harnessSecondary source
“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.
“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.
“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.
“Minimum similarity score threshold for filtering results. Results with scores below this threshold are excluded.”
↩︎ Under-retrieval: missing relevant history - 8.https://docs.databricks.com/aws/en/agents/tutorials/ai-cookbook/evaluate-assess-performanceOfficial docs
“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.
“mlflow.genai.evaluate() - Evaluation harness to orchestrate offline evaluation with scorers and datasets”
↩︎ Measuring memory retrieval separately from the answer