Decoupled Retrieval and Rewriting for AI Q&A: A Practical Guide
This guide explains why a single model cannot reliably handle every AI Q&A request and how to split retrieval from rewriting into two independently evolving stages. It covers a five-layer architecture, the evidence data structures that connect both sides, retrieval techniques such as query expansion and freshness filtering, constrained rewriting with inline citations, capability trade-offs between retrieval-optimized and rewriting-optimized systems, a three-tier evaluation framework, common pitfalls, and a phased rollout plan. The pattern is product-agnostic and built for accurate, readable answers that improve over time.
1. Background: Why One Model Can No Longer Do Everything
When building a production Q&A system, a common mistake is treating “answering a question” as a one-shot generation task handled by a single model. In real business scenarios, user requests usually fall into two categories. The first is What + How: what something is and how to do it. These require answers that are clear, actionable, and traceable to their sources. The second is Why: causes, mechanisms, and trade-offs, which demand stronger reasoning and explanation. The two categories place different demands on the system, and forcing them through the same pipeline with the same model often forces a compromise between accuracy and readability.
A more robust engineering approach is separation of responsibilities: split “gathering material” from “writing the draft” into two stages that can evolve independently. The retrieval side is responsible for recalling trustworthy material and controlling freshness and source quality. The rewriting side handles structure, consistent tone, and style adaptation. The two are connected through a standardized intermediate data structure, which makes them separately measurable and separately optimizable, and makes it easy to swap implementations for different business scenarios.
2. Overall Architecture: A Layered Design for Retrieval and Rewriting
A reusable layered structure typically has five layers:
- Access layer: a unified session entry point that manages multi-turn context, intent recognition, and clarifying follow-up questions.
- Retrieval layer: query rewriting, recall, coarse ranking, fine ranking, deduplication, and freshness filtering.
- Evidence layer: normalizes matched content into “evidence snippets” with a source identifier, timestamp, and trust label.
- Rewriting layer: structured writing grounded in evidence, producing Q&A copy, explainer articles, podcast scripts, and other formats.
- Governance layer: logging, evaluation, monitoring and alerting, and a closed loop for human feedback.
The key design principle is that the rewriting layer must never invent facts. Every factual statement should trace back to a snippet ID in the evidence layer, so when a dispute arises you can quickly locate the source of the problem.
A sketch of the intermediate data structures (pseudocode):
@dataclassclass Evidence:eid: str # Snippet IDsource: str # Source type: official docs / authoritative media / community experiencepublished_at: str # Publication time, used for freshness filteringtrust: float # Trust score from 0 to 1text: str # Body of the snippet@dataclassclass AnswerDraft:query: strintent: str # what/how or whycitations: list[str] # Referenced Evidence.eid valuesbody: str
3. The Retrieval Side: What Sets the Ceiling for Answer Quality
Retrieval quality essentially determines the ceiling on answer quality. On the engineering side, you can reinforce it in four directions:
- Query rewriting: expand a colloquial question into multiple search queries that cover synonyms and broader or narrower concepts, improving recall.
- Source tiering: assign weights by source, prioritizing official documentation and authoritative organizations, with experience-based content used only as a supplement.
- Freshness filtering: enforce time constraints on volatile information such as prices, versions, and policies, and down-weight or drop outdated material.
- Snippet-level deduplication: prevent the same passage from being recalled repeatedly and crowding the context window.
A simplified weighted ranking approach:
def score(doc, query):relevance = bm25(doc, query) # Lexical relevancesemantic = cosine(embed(doc), embed(query)) # Semantic relevancefreshness = exp(-age_days(doc) / 30) # Freshness decayreturn 0.4 * relevance + 0.4 * semantic + 0.2 * freshness * doc.trust
It is worth stressing that building the retrieval ecosystem is a long-term effort involving corpus ingestion, update frequency, structured extraction, and quality spot checks. There is no shortcut where swapping in a new model makes everything automatically better.
4. The Rewriting Side: Turning Material into a Readable Deliverable
The core of the rewriting side is not “generating all over again” but reorganizing under constraints. Recommended practices include:
- Structure first: produce an outline (conclusion, evidence, steps, caveats) before filling in each section, which reduces drift in long-form output.
- Parameterized style: abstract the target format into parameters such as sentence length, terminology density, whether to keep the first person, and paragraph length.
- Inline citations: mark evidence IDs after key conclusions to make review easier.
- Consistency checks: double-check numbers, proper nouns, and dates to prevent distortion during rewriting.
A prompt skeleton example:
You are a technical writer. Answer using only the evidence snippets I provide.Requirements:1) State the conclusion first, then the evidence and the steps;2) After each factual conclusion, cite the source with [E-ID];3) When evidence is insufficient, state clearly that "no reliable evidence was found" and do not speculate;4) Target format: {style}, sentence length: {len}, terminology density: {density}.Evidence: {evidences}Question: {query}
5. Division of Capabilities: Retrieval-Optimized vs. Rewriting-Optimized
From an engineering perspective, different implementation paths have different strengths and can be abstracted into two capability profiles:
- Retrieval-optimized: strong in recall and source coverage, suited to scenarios that need one clear answer; the weakness is plain writing style and mediocre long-form organization.
- Rewriting-optimized: strong in language organization and style transfer, suited to turning material into podcast scripts, Q&A copy, or explainers; the weakness is that if it carries its own retrieval, recall and ecosystem coverage are often not solid enough.
There is also a class of implementations focused on AI coding tools that excel at code completion, repository-level understanding, and debugging suggestions, but open-ended conversation and content creation are not their main battlefield. Match the choice to the primary business need rather than looking for one tool to solve every problem.
6. Evaluation: Making Optimization Evidence-Based
A three-tier set of metrics is recommended:
- Retrieval layer: recall rate, hit rate@K, distribution of source trust, proportion of outdated material.
- Generation layer: factual consistency (whether claims are supported by evidence), citation coverage, structural completeness.
- Experience layer: task completion rate, average number of interaction turns, human edit distance (degree of difference before and after editing).
The evaluation set should cover four question types: factual, procedural, comparative, and open-ended. Keep enough samples in each category and run a regression after every pipeline change, so you avoid “fixing the writing and breaking the facts.”
7. Common Pitfalls and Engineering Advice
- Pitfall 1: letting the rewriting model improvise freely. The result is fluent but untrustworthy. The countermeasure is to enforce citations and a “no evidence, no answer” rule.
- Pitfall 2: ignoring freshness. The countermeasure is to set mandatory time windows on volatile fields.
- Pitfall 3: stuffing the context window. The countermeasure is to fine-rank before admitting content to the window, keeping evidence IDs rather than full text.
- Pitfall 4: no feedback loop. The countermeasure is to feed human revisions back as evaluation samples and as input for prompt optimization.
If you need to handle a large volume of documents and logs, you can combine general cloud capabilities, such as object storage for raw material, a message queue for peak shaving, a container platform to host retrieval and rewriting services, and logging and monitoring with alerting for observability. Baidu AI Cloud offers corresponding product forms in these general categories that can be combined as needed, but the architecture itself is independent of any specific vendor.
8. Rollout Path: From Minimum Viable to Continuous Optimization
- Phase 1 (1-2 weeks): get the minimum “retrieval-evidence-rewriting” pipeline working end to end, starting with factual Q&A.
- Phase 2: add source tiering, freshness filtering, and inline citations, and build the evaluation set.
- Phase 3: expand rewriting templates by format and connect the human feedback loop.
- Phase 4: optimize cost and latency, for example by caching frequent queries, using tiered recall, and calling large models on demand.
Conclusion
“Which one is better” is essentially the wrong question. The real question is how to make retrieval and rewriting each do their own job. Give material gathering to the retrieval side and composition to the rewriting side, weld the two together with evidence IDs, and add layered evaluation plus a feedback loop. Only then can you reliably produce answers that are both accurate and readable. This pattern does not depend on any specific product and is easier to evolve with the business over the long term.
