The Debug Session Nobody Wants
A customer reports that your AI assistant gave them information about a feature that was deprecated three versions ago. The output looks confident. Reasonable. Wrong.
What happened?
You pull up the chat logs. You look at the answer. It reads fine. You ask the model the same question again. This time it answers correctly — pulling from the current version. You run it a third time. Back to the old answer.
This is the moment every engineer working on RAG systems hits a wall. The visibility stops at the output. What got retrieved? What documents were ranked highest? Why was that old version considered more relevant than the current one? None of these answers are visible. The answer is wrong, but the path to wrongness is invisible.
This is the core problem that retrieval observability solves.
"I can see what the AI outputs. I can't see what it retrieved. That's the problem."
And the follow-up is worse:
"Same question. Different answer on replay. That's not an accuracy problem — that's a non-determinism problem."
Without visibility into the retrieval chain, debugging becomes guesswork. Is the model hallucinating? Is the retrieval system broken? Is the knowledge base stale? Or is the query being rewritten in unpredictable ways? Without a trace, you're blind.
What Is Retrieval Observability?
Retrieval observability means seeing the complete chain of decisions made during information retrieval — before the language model ever generates a response.
Specifically: visibility into what query variations were tried, which documents or knowledge nodes were ranked highest, why they were ranked that way, and what confidence the retrieval system assigned to each choice.
In traditional database debugging, you don't just see the output of a query — you see the query plan, the indexes hit, the execution time, the rows scanned. That's why database engineers can diagnose problems efficiently. The information retrieval layer of an AI system deserves the same level of inspection.
Without retrieval observability, the system is a black box: query goes in, answer comes out. You have no visibility into the middle — and that's where most AI errors live.
Why Output Monitoring Isn't Enough
Consider the standard approach to AI quality: test the final answer. Is it correct? Does it match expected output? Does it sound coherent?
This is observability of the last step only. It's equivalent to debugging a complex SQL query by only reading the UI result set. You can see that the result is wrong, but without seeing the query that ran, the indexes used, or the filter conditions, you can't fix it.
Most output-only monitoring tells you that something failed. Retrieval observability tells you where it failed.
Consider this failure scenario:
An AI system is supposed to answer questions about API documentation. The latest version is in the knowledge base. A user asks: "Does your API support OAuth 2.0?"
The system answers: "No, we only support API key authentication." This is wrong.
Output monitoring shows: Answer is factually incorrect.
Retrieval observability shows: The retrieval system ranked a document from version 2.1 (which predates OAuth support) higher than the current version 3.2. The confidence score was 0.92, which is why the model trusted it.
These are completely different diagnoses requiring completely different fixes:
- Output monitoring: "The answer is wrong. Ask the model to be more careful."
- Retrieval observability: "The ranking function is prioritizing older documents. Adjust recency weighting or implement version-aware chunking."
Without the trace, the former is all you get.
The Non-Determinism Problem
Ask an RAG system the same question twice. Get a different answer.
This happens more often than most engineers realize. Same query, same knowledge base, different results. The model might be drawing from different retrieved documents. The retrieval system might be returning results in a different order due to vector similarity tie-breaking. The prompt might have been rewritten differently on the second run.
Non-determinism makes debugging impossible. If a user reports a wrong answer and the team tries to reproduce it, they might get the correct answer on the first retry. Is it fixed? No. Run it again. Wrong answer reappears.
This is a nightmare for production systems. Compliance requires audit trails. Customers require consistency. Support tickets require reproducibility.
The reasons most RAG systems are non-deterministic:
- Floating-point similarity scores don't sort identically across runs if scores are close
- Lazy query rewriting that varies based on model temperature or sampling
- Uncontrolled retrieval ranking that treats tied relevance scores as equivalent
Retrieval observability solves this by making every step explicit and reproducible. If the system can show the reasoning trace for a given query, it can be replayed. Same question, same trace, same answer, every time.
This is deterministic replay — and it's essential for enterprise AI.
The 4-Phase Reasoning Trace
A complete retrieval trace captures four critical phases:
Phase 1: Query Rewrite
The original user query often isn't the best question to ask the knowledge base. "does the api support webhooks" gets rewritten to "API webhook integration support." The trace should show the original query, the rewritten query, and the reason for the rewrite.
If answers are inconsistent, sometimes the issue is inconsistent query rewriting.
Phase 2: Sub-Queries
Complex questions often need multiple retrieval passes. "What does your API support and what are the limits?" spawns two sub-queries: "API supported features" and "API rate limits and quotas."
The trace should show which sub-queries were generated and why. If a sub-query is missing, that's a knowledge gap. If it returns no results, that's a coverage problem.
Phase 3: Node Selection + Reason
For each sub-query, which knowledge nodes were retrieved and why?
Retrieval Trace Sub-query: “API webhook support” 1. docs/webhooks.md Score: 0.94 Semantic match on “webhook” and “event-driven” 2. docs/integrations.md Score: 0.71 Term match on “webhook” only 3. docs/api-v2.md Score: 0.58 Semantic match on “API” and “async”
If the wrong node is ranked first, this is where you spot it.
Phase 4: Confidence Score
After all nodes are retrieved and ranked, the system should assign a confidence score: how confident is this retrieval result going to produce a correct answer?
Signal Meaning High confidence + wrong answer Problem is in the model layer Low confidence + any answer Problem is in the retrieval layer
Without this score, there's no way to distinguish retrieval failures from model failures.
Deterministic Replay: Auditing AI Answers
Suppose a compliance officer asks: "Show me how your AI system arrived at this customer answer."
With retrieval observability and deterministic replay, the answer is: "Run this exact query. Here's the trace. Here are the retrieved documents. Here's the reasoning chain. Run it. Same answer. Every time."
This is auditable AI.
Non-deterministic systems can't do this. They can show what happened but can't prove it would happen again. That's unacceptable for regulated industries.
Deterministic replay requires: seeding random number generators, freezing query rewriting logic, locking retrieval ranking, and recording the full reasoning trace.
The payoff: a complete audit trail. Same query, same trace, same answer, same documents retrieved, same confidence score.
What Good Retrieval Traces Reveal
Scenario 1: Stale document retrieved
The trace shows: the older doc scored 0.89, the current one scored 0.84. Recency weighting isn't implemented. Fix: add version-aware retrieval.
Scenario 2: Wrong section of the right document
The trace shows: the right document was retrieved, but the wrong chunk was ranked first. Fix: improve chunk boundaries or add section-level metadata.
Scenario 3: Low confidence + hallucination
The trace shows: confidence 0.31, minimal match, no direct answer found. The model answered anyway. Fix: add confidence thresholds — if confidence < 0.5, return "I don't know" instead of letting the model guess.
Scenario 4: Conflicting knowledge nodes
The trace shows: on run 1, doc A (score 0.92) was retrieved first. On run 2, doc B (score 0.91) was retrieved first. The docs contradict each other and the retrieval order is determined by a float tie-break. Fix: break ties deterministically and flag conflicting sources.
Each of these scenarios is invisible without a retrieval trace. Output monitoring shows only that something went wrong. The trace shows what went wrong and where.
Adding Retrieval Observability to a LangChain Pipeline
Most LangChain RAG pipelines look like this:
query → retriever.invoke() → documents → llm.invoke() → answer
What's missing: visibility into what retriever.invoke() actually returned and why.
To add retrieval observability:
- Wrap the retriever with logging — capture retrieved documents, relevance scores, and metadata.
- Make query rewriting explicit — log both the original and rewritten queries with the rewrite reason.
- Add a ranking step — assign confidence scores and capture why documents were ranked in a given order.
- Record the trace — serialize the full retrieval trace (phases 1–4) before passing documents to the LLM.
- Implement deterministic seeding — set random seeds at the start of each trace so decisions are reproducible.

The trace object is what enables debugging and replay. For a production-ready implementation with full retrieval tracing, see how Brainfish's knowledge layer provides built-in observability →
Further Reading
- What We Learned from Analyzing 1M Support Interactions — Real-world retrieval patterns from 1 million support interactions, including what causes wrong answers
- Answering the Tough Questions About Brainfish — How Brainfish approaches retrieval tracing and observability under the hood
- Compliance-Grade AI: How High-Governance Teams Pilot Without Risk — Why deterministic replay and audit trails matter in regulated industries
- Why Brainfish — The case for AI-native knowledge infrastructure with full retrieval observability built in