Skip to content

Why Your RAG App Returns the Wrong Paragraph: A Five-Step Debugging Checklist

9 min reading

Compare selected and larger permitted context by locating lost evidence, checking paired outcomes, and declaring resource assumptions.

Page details

Blog 11 · Vikram Samal

Edition date: · 9 min read

20px

Edition dates place posts in a retrospective weekly reading sequence.

Last edited:

Sources · Technology essay

Editorial correction:

An earlier revision claimed an author-run experiment and performance comparisons without supporting evidence. Those claims have been removed. Numerical examples in this revision are explicitly hypothetical.

TL;DR
  • Inspect source freshness and chunk integrity before changing the generator.
  • Measure whether the expected passage survives retrieval and prompt assembly.
  • Use lexical matching for exact identifiers and evaluate hybrid ranking on actual questions.

The answer quotes thirty days.
The current policy says fourteen.
Find where the current paragraph disappeared.

Hypothetical scenario. Act 2, the price change. Priya asks about a return deadline. Northwind’s assistant confidently quotes an older thirty-day rule even though the current policy allows fourteen days. Dev proposes a larger model; Priya asks whether that model would receive the same stale paragraph.

What travels from a document to an answer

Retrieval-augmented generation, or RAG, gives a language model selected source material while it answers. Documents are parsed into readable content, split into chunks, embedded into vectors and stored in an index. At question time, a retrieval service selects candidates and optionally reranks them before assembling a prompt for generation.

An embedding is a numerical representation used to compare texts. Vector similarity helps find related language even when the question and source use different words. A lexical search uses words or identifiers more directly. Neither ranking method decides whether a policy is current, applicable to this customer or authorized for this employee.

The generator writes from the prompt it actually receives. The source repository, the search result list and the final prompt are therefore three separate inspection points. Debugging an answer means following the expected passage through those points, then checking whether the answer used it accurately. Changing the generator is useful only after locating a failure it can influence.

Current sourceIntact chunkTop-k resultActual prompt
Inspect the evidence at successive boundaries before attributing a wrong answer to generation.

First inspect the indexed revision

Start with one wrong answer and identify the exact source paragraph that should support a correct one. Record its document identity, revision and effective date. Compare those with the indexed record. A successful file upload does not demonstrate that parsing, embedding and index publication have completed or that an older revision has been removed.

For Northwind, the fourteen-day policy needs to exist as the active source before ranking can find it. Inspect deletion and replacement behavior as well as additions. Microsoft’s changed-and-deleted-blob documentation explains that deletion detection requires an explicit policy and configuration. That supports a concrete operational question: what causes an obsolete chunk to stop appearing in search results?

Keep document freshness distinct from model freshness. A model upgrade cannot repair a pipeline that never indexed the new policy. Conversely, a current document does not prove a current answer cache. The retrieval trace should identify the evidence revision actually selected, so Priya can distinguish stale ingestion from a stale derived answer.

Then read the chunk as the model sees it

Locate the expected passage in the parsed output and its stored chunk. Check table headers, list nesting, units and qualifiers. A sentence saying “within fourteen days” has a different meaning if the preceding heading limits it to unopened goods. A chunk that drops that heading changes the evidence before retrieval has even started.

Overlap is a tool for preserving nearby context across boundaries. It also duplicates text and can fill the candidate list with nearly identical passages. Inspect whether the question needs one coherent section, two neighboring sections or an entire table. Changing chunk size should follow that need rather than a universal token count copied from another corpus.

A useful diagnostic temporarily supplies the intact expected passage directly to the generator. If the answer then becomes correct, the earlier evidence path deserves attention. If it remains wrong, inspect the instruction, competing passages and acceptance rule. This intervention narrows the fault; it is not a substitute for testing the full retrieval pipeline afterward.

Third measure whether the passage ranks

Hypothetical worked example: Priya assembles 50 questions, each with one known supporting paragraph. Dev checks the top 5 returned chunks for each question. The supporting paragraph appears for 31 questions. Recall@5 in this single-relevant-passage example is 31 / 50 = 0.62 = 62%. The other 50 − 31 = 19 questions lack their required paragraph at that stage.

This measurement identifies a retrieval bottleneck; it does not establish the generator’s accuracy on the 31 supported questions. For questions with several relevant passages, define recall over the relevant set rather than silently preserving the simpler denominator. Track permission and policy-version slices too: an average can conceal poor results for the most consequential questions.

Exact product identifiers deserve special attention. An SKU is often a literal lookup target rather than a semantic concept. Hybrid search combines lexical and vector candidate rankings. Microsoft’s reciprocal-rank-fusion documentation describes combining ranked lists through reciprocal ranks, avoiding a direct comparison between unlike raw scoring scales. Measure whether that combination improves Northwind’s labeled questions before making it the default.

Fourth inspect prompt assembly and position

A search result can be correct and still disappear before generation. Prompt assembly can truncate long passages, insert too many duplicates or spend the context allowance on conversation history. Capture the selected chunk identities and the assembled evidence order. Compare them with the result list instead of inferring prompt contents from the retrieval service’s success response.

Position deserves a controlled test. Move the same verified paragraph while keeping the question and other evidence fixed, then evaluate whether the answer changes. That checks this application’s use of context directly. OpenAI’s prompt-caching guide describes reuse of matching prompt prefixes; cheaper repeated input still occupies a place in the prompt and does not make buried evidence automatically usable.

Give the prompt an explicit evidence structure: document title, effective revision, passage and citation handle. This helps both the model and the reviewer distinguish conflicting policies. The application should choose the applicable revision upstream where possible. Asking the model to adjudicate an arbitrary pile of obsolete and current chunks adds an avoidable source-selection problem.

Fifth check whether generation follows the evidence

Once the intended passage reaches the prompt intact, compare the answer with its actual conditions. Did it preserve the fourteen-day limit, the qualifying product category and the exception process? A valid citation marker is only a reference; inspect whether the cited passage supports the specific claim next to it. Fluent paraphrase can still broaden an exception into a general rule.

OpenAI’s evaluation guidance recommends task-specific evaluations and checks against human judgments. Northwind’s answer rubric separates source selection, factual support and actionable wording. That keeps a correct citation from compensating for a wrong deadline, and keeps an awkward but correct explanation from being counted as an evidence failure.

If conflicting passages remain, a useful response identifies the conflict or routes the question for review. Guessing which rule sounds most plausible creates an answer that the pipeline cannot justify. A refusal to decide is an allowed outcome when the underlying source state is genuinely unresolved; it should not hide a fixable indexing defect indefinitely.

In the wild: repairing context before retrieval

Anthropic’s Contextual Retrieval write-up describes adding chunk-specific context before embedding and lexical indexing. Its experiments reported reduced retrieval failures for its evaluated settings. The mechanism addresses a concrete loss: an isolated sentence can omit the document-level information needed to understand what it describes. Northwind would evaluate that mechanism against its own policy questions rather than import the reported improvement as a forecast.

The additional context is derived text. Keep the original paragraph available and distinguish its wording from the generated annotation. A misleading annotation can make the wrong passage rank more strongly. The source revision and annotation procedure therefore belong in the indexing record, so a quality regression can be traced to the transformation that introduced it.

The checklist establishes an order for investigation, not a claim that every defect has one cause. A stale paragraph and a poor chunk boundary can coexist. Fix the earliest confirmed failure, rerun the original question and then repeat the small evaluation set. Record downstream changes instead of declaring victory because one hand-selected answer improved.

Limits: a labeled question set samples a workload and does not certify every future query. Approximate search, policy ambiguity and changing permissions introduce separate failure modes. Use this procedure to collect discriminating evidence; increase the sample and inspect new error categories as the assistant’s responsibilities expand.

For Northwind, the immediate decision is to trace the fourteen-day paragraph through ingestion, chunking, ranking, prompt assembly and generation. Priya owns the correct policy interpretation. Dev owns evidence delivery. A model replacement becomes a candidate only when the observed failure is in the part of the chain that replacement can change.

Check yourself: rag decisions

The correct paragraph is absent from all candidates. Should the first experiment change the model?

No. Check freshness, parsing and retrieval first. A generator cannot reliably cite a paragraph that was never supplied.

The paragraph ranks first, but the prompt omits it. Which metric missed the failure?

Retrieval recall alone missed prompt assembly. Inspect the actual evidence passed to generation and its truncation policy.

A keyword query finds an exact SKU that vectors miss. What should change?

Evaluate lexical or hybrid retrieval for the identifier slice. Preserve the labeled examples so the improvement can be checked beyond one query.

Next read: Vector Search Is Not Access Control: How RAG Leaks Documents and How to Stop It.

Source: Changed and deleted blobs — Inspect Primary Source ↗
VS
Vikram Samal

Notes on generative AI and system design.