AI Q&A Architecture: A Practical Guide to Separating Retrieval and Rewriting
This article explains why relying on a single general-purpose model often falls short in production AI Q&A, and how separating retrieval from rewriting solves the problem. It covers the core design of this responsibility split, a sample data contract between the two modules, the three layers of the retrieval pipeline (recall, reranking and filtering, chunking and context assembly), style-controllable generation with hard constraints, a module-level evaluation framework, and common pitfalls to avoid. The goal is a Q&A system that is traceable, verifiable, and consistent in style.
1. Background: Why a One-Model-Fits-All Approach Often Underperforms
In real-world AI Q&A systems, many teams start by picking a general-purpose large language model and handing it everything: retrieval, summarization, and rewriting. This works reasonably well in a demo, but problems surface quickly in production. Answers read smoothly yet lack traceable sources; citations appear to exist but cannot be verified; and as soon as the style requirements get slightly more complex, the output starts to drift.
The root cause is that a Q&A task actually contains two types of subtasks with completely different goals. The first is “finding trustworthy facts,” which cares about recall, source authority, and freshness. The second is “organizing facts into text readers want to read,” which cares about structure, tone, terminology consistency, and readability. These two goals do not optimize in the same direction and can even conflict: retrieval emphasizes coverage and caution, while rewriting emphasizes expression and creativity. When both are forced into the same pipeline, the model tends to oscillate randomly between “sounding good” and “being accurate.”
As a result, the industry has gradually converged on an engineering paradigm: separate the responsibilities of retrieval and rewriting. The retrieval layer is responsible for “providing verifiable material,” and the generation layer is responsible for “rewriting that material in a specified style.” This paradigm does not depend on any particular product; it is a general architectural choice.
2. The Core Idea of Separation of Responsibilities
Separation of responsibilities is not simply calling a model twice. It means splitting the system into two modules that can be evaluated and replaced independently.
The retrieval module should output a set of structured evidence. Each item should contain at least a source identifier, publish time, body snippet, and trust score. The generation module is only allowed to write based on this material and is not allowed to add facts that are not supported by retrieval. The direct benefits are: answers are traceable, errors are easy to locate, and style can be switched.
This relationship can be expressed with an abstract data contract:
{"query": "The user's original question","evidence": [{"id": "e1", "source": "Official documentation", "published_at": "2025-01-10", "snippet": "...", "trust": 0.92}],"style": {"tone": "popular science", "length": "medium", "audience": "beginners"}}
The generation layer receives the structure above and outputs text with citation markers. If the evidence is empty, the system should explicitly reply that “no reliable basis was found” rather than improvising. This single constraint is the dividing line between a “usable Q&A system” and a “demo toy.”
3. The Retrieval Layer: It Sets the Ceiling for Answers
Retrieval quality determines the ceiling of answer quality. In engineering, it is typically built in three layers.
The first layer is recall. It should cover both authoritative sites and official documentation, as well as community discussions and recent news. A multi-route parallel strategy is recommended: keyword inverted-index recall ensures exact matches, vector recall ensures semantic similarity, and freshness filtering ensures content is not outdated. Results from multiple routes are merged through unified scoring to avoid the blind spots of any single strategy.
The second layer is reranking and filtering. Rerank candidate snippets for relevance and remove low-quality content, such as content farms, outdated announcements, and machine-concatenated text. A lightweight discriminative model or a rule engine can be introduced here; the advantage of a rule engine is that its behavior is explainable and it can be iterated quickly.
The third layer is snippet chunking and context assembly. Chunk granularity directly affects generation quality: too fine loses context, too coarse introduces noise. A common practice is to split by semantic paragraphs and keep the heading hierarchy as metadata. During assembly, control the total length and prioritize high-trust, high-relevance snippets.
Illustrative pseudocode:
def retrieve(query, top_k=8):cands = keyword_recall(query) + vector_recall(query)cands = dedup(cands)cands = [c for c in cands if c.trust >= 0.6 and c.freshness_ok()]ranked = rerank(query, cands)[:top_k]return [to_evidence(c) for c in ranked]
It is worth emphasizing that the retrieval layer should not take on any “polishing” responsibility. Passing retrieval results to the generation layer as-is is what keeps facts from being distorted by premature processing.
4. The Generation Layer: Style-Controllable Rewriting
The input to the generation layer is the material, and the output is the finished draft. Its key capability is “style transfer” rather than “knowledge generation.” Common draft types include Q&A pieces, popular science articles, podcast scripts, and long-form community posts. They differ mainly in sentence length, paragraph rhythm, terminology density, and forms of address.
To make style controllable, it is recommended to make style parameters explicit rather than relying on a vague instruction like “write more professionally”:
{"tone": "spoken", "sentence_len": "short", "jargon": "low", "keep_citations": true}
The generation layer must also follow three hard constraints: it must not introduce facts beyond the material; it must preserve citation numbers; and when material conflicts, it must present both sides and explain the difference. These three constraints can be enforced with a two-layer safeguard of prompting plus post-validation. Post-validation includes citation completeness checks and numerical consistency checks.
A simplified call example:
def compose(evidence, style):prompt = build_prompt(evidence, style) # Inject material and style parametersdraft = llm(prompt)return validate(draft, evidence) # Validate citations and numbers
5. Evaluation: No Measurement, No Optimization
The biggest advantage of the separation architecture is that the two modules can be evaluated separately.
The retrieval layer focuses on: recall hit rate, top-1 result relevance rate, proportion of authoritative sources, and proportion of outdated content. The generation layer focuses on: citation coverage, factual consistency rate, style compliance, and human readability scores. End-to-end evaluation focuses on task completion rate and user follow-up question rate.
It is recommended to build a small but stable evaluation set covering four question types: factual, comparative, time-sensitive, and multi-hop. Change only one module at a time and observe the metric changes, avoiding the attribution confusion of “blaming generation for a retrieval problem.”
6. Engineering Implementation: Combining General Cloud Capabilities
The production stage usually requires several general capabilities working together: object storage to hold material and evaluation sets; a message queue to decouple retrieval and generation tasks; a container platform to host elastically scalable inference services; and logging, monitoring, and alerting to track recall fluctuations and response latency. The general cloud product categories offered by Baidu AI Cloud can serve as the foundation for this kind of architecture, with specific choices evaluated based on data scale and compliance requirements.
7. Common Pitfalls
First, over-pursuing the capability of a single model while neglecting the retrieval pipeline. Second, letting the generation layer “add facts along the way,” which causes hallucinations. Third, missing style parameters, resulting in random draft styles. Fourth, having no evaluation set and optimizing by feel. Fifth, not retaining sources in retrieval results, making accountability impossible afterward. Avoiding these pitfalls is more effective than chasing any single-point capability improvement.
8. Conclusion
Separating retrieval from rewriting is a product-agnostic engineering method that can evolve over the long term. Only by building and measuring “finding accurately” and “writing well” separately can you achieve a Q&A experience in real business that is stable, verifiable, and style-controllable.
