Skip to main content

Right Retrieval, Wrong Answer: Root-Causing and Guarding the RAG Generation Stage

· 4 min read
Jack Ning
Maintainer of Bytedesk

The most frustrating moment in a RAG system is not "nothing retrieved" but the correct answer was retrieved and the model still got it wrong. The logs show it plainly: the right policy chunk ranked first going into the context, yet the model's answer mixed everything up. Blaming "the model is weak" is the laziest conclusion — how context is organized, how the prompt is written, and how chunks are ordered can each be the real culprit.

This is the seventh post in an experience-sharing series for AI customer service product managers and developers, drawn from hands-on practice as an AI product manager at a Southeast Asian cross-border e-commerce platform. In this post I want to share how to localize the problem across retrieval relevance, context completeness, prompt design, and model generation when RAG has already retrieved the relevant knowledge but the model still generates a wrong answer — and how to design the citation verification, refusal, and human handoff mechanisms.

Illustration: Attribution and fallback when retrieval is right but generation is wrong

Three Key Points in Root-Causing the Generation Stage​

  • End-to-end root-cause analysis: which link to check first, how to check it — a systematic elimination process, not tuning by luck.
  • Prompt engineering and generation constraints: how to "frame" the model within the evidence using prompts and output structure.
  • Trustworthiness safeguards: citation verification, refusal, and human handoff — the last line of defense for answer credibility.

The Overall Design​

For any bad case, I follow a fixed order:

  • Retrieval relevance: manually annotate whether the correct knowledge entered top-K and at what rank. Present but ranked low → a reranking problem; high relevance score but actually irrelevant content → an embedding or chunking problem.
  • Context completeness: check whether key conditions of the correct chunk (exception clauses, applicability scope) were truncated by chunking or pushed out of the context window by other chunks → remedies: adjust chunk granularity, control top-K count, optimize chunk ordering (key chunks first).
  • Prompt design: check whether the system prompt explicitly says "answer only from the given knowledge, cite sources, refuse when evidence is insufficient"; run ablation experiments across prompt versions and let data decide.
  • Model generation: when all above are fine, A/B test a stronger model; sample the same input multiple times to see whether outputs are unstable (temperature too high) — that is a model capability or decoding issue.

2. Citation verification: make answers checkable​

  • Require key conclusions in the answer to carry knowledge chunk IDs;
  • Before release, run a verifier that checks whether cited chunks actually exist and actually support the conclusion (an NLI model or rules for consistency);
  • Answers that fail verification do not go out — better to trigger the refusal flow than let a "fabricated citation" reach the user.

3. Refusal and human handoff: design the fallback explicitly​

  • Set confidence thresholds: when the top retrieval score is below threshold, chunks contradict each other, or the model self-assesses insufficient evidence, trigger a clarifying question or a "cannot confirm right now, connecting you to a human" response.
  • Questions involving money or compliance, emotionally escalated users, or sessions with more than N consecutive refusals → automatic handoff to a human.
  • When handing off, carry the retrieved knowledge and dialogue context so the agent takes over with full visibility, minimizing the user's cost of repeating themselves.

How This Maps to Weiyu​

The Weiyu open-source customer service system (GitHub: https://github.com/bytedesk/bytedesk , website: https://www.weiyuai.cn ) provides ready-made paths for these safeguards in human-AI collaboration: the AI agent answers from knowledge-base retrieval and switches seamlessly to human agents when confidence is low or handoff rules trigger, with full conversation context passed along so users need not repeat themselves; agents can review conversation records for QA, locating specific "AI answered wrong" cases; sessions involving money or after-sales disputes can be routed to dedicated teams via skill groups. The open-source architecture also makes it easy to add custom quality gates like citation verification at the generation layer.

Key Takeaways​

  • Fixed diagnostic order: retrieval relevance → context completeness → prompt design → model generation; eliminate link by link instead of tuning blindly.
  • Context organization is often overlooked: key conditions truncated or pushed out of the window are a top cause of "retrieved right, answered wrong."
  • Citation verification makes answers checkable: fabricated citations never ship.
  • Refusal is not failure — it is a responsible fallback; consecutive refusals should escalate to humans.
  • Hand off with context: agents take over faster, and users do not repeat themselves.