A Practical Guide to Decoupling Retrieval and Rewriting in AI Q&A Systems

    This article explains why AI question-answering systems should separate retrieval from rewriting, and how to build such a pipeline. It covers a capability breakdown across retrieval, language generation, and code tasks, a four-stage architecture, key retrieval design choices such as multi-path recall and source tiering, rewriting strategies with fact constraints, and consistency checks with evaluation metrics for both sides. Readers will find pseudocode, prompt skeletons, common pitfalls, and selection advice for open-domain Q&A, content production, and coding assistance.

    1. The Problem: Users Want “What” and “How”

    In real AI Q&A scenarios, most users do not need the full reasoning chain behind a conclusion. They want a clear answer (what) and an actionable path (how). This shapes the value of two capabilities: finding reliable sources in open corpora and returning high-confidence answers, and organizing the raw material into text that readers will actually read and understand.

    Letting one model handle both end to end creates engineering risk. When retrieval quality is unstable, fluent language hides factual gaps; when style requirements change, the retrieval strategy has to be retuned as well. A safer design splits the system into two independently evolving stages: retrieval and rewriting.

    2. Capability Layers: Retrieval, Generation, and Coding

    From an engineering perspective, conversational AI capabilities fall into three rough layers.

    • Retrieval and knowledge acquisition: determines the factual basis of an answer; depends on corpus coverage, source credibility ranking, freshness indexing, and query rewriting.
    • Language organization and style control: determines readability and style fit, including long-form structure, terminology density, and tone consistency.
    • Structured and code generation: performs well in coding assistance, configuration generation, and scripting, emphasizing syntactic correctness and context consistency.

    A common mistake is expecting one model to be best at all three layers. A more realistic view: different models and technical approaches have different strengths. Some are more mature in open-domain Q&A and source coverage, some are more stable in rewriting and style transfer, and some are stronger on code tasks. The key is not to pick an all-around champion but to split by layer and combine.

    The recommended production shape is a four-stage pipeline: query understanding → retrieval and recall → material pruning and evidence scoring → stylized rewriting and verification.

    1. User question
    2. ↓
    3. [1] Query understanding: normalization, coreference resolution, sub-question decomposition
    4. ↓
    5. [2] Retrieval and recall: multi-path recall + source credibility tiers + freshness filtering
    6. ↓
    7. [3] Evidence processing: deduplication, snippet pruning, conflict detection, confidence scoring
    8. ↓
    9. [4] Style rewriting: generation in the target style + factual consistency check
    10. ↓
    11. Final answer (with source attribution)

    This structure yields three direct benefits: the retrieval side can be swapped and tuned independently without touching generation; the rewriting side can switch styles quickly through prompts and examples; and when a factual error appears, the problem can be traced to a specific stage.

    4. Key Design Choices for Retrieval

    The ceiling on retrieval quality is set by the corpus ecosystem. Engineering work can focus on:

    1. Multi-path recall: run keyword search and semantic vector search in parallel. The former handles proper nouns and exact matches; the latter handles content with similar intent but different wording.
    2. Source tiering: assign different weights to authoritative institutions, official documentation, academic and industry material, and ordinary community content, so low-credibility sources do not dominate the answer.
    3. Freshness control: force a time filter for pricing, version, and policy questions, and state the information date in the answer.
    4. Query rewriting: expand a colloquial question into multiple search expressions covering synonyms and broader or narrower concepts.

    Illustrative pseudocode:

    1. def retrieve(query, top_k=8):
    2. sub_qs = decompose(query) # sub-question decomposition
    3. cand = []
    4. for q in sub_qs:
    5. cand += keyword_search(q, top_k) # exact-match path
    6. cand += vector_search(q, top_k) # semantic recall path
    7. cand = dedup(cand)
    8. cand = [c for c in cand if c.trust >= TRUST_TH and within_ttl(c)]
    9. return rerank(cand, query)[:top_k] # cross-encoder reranking

    5. Key Design Choices for Rewriting

    The goal of rewriting is to re-express content without changing facts. Reusable strategies include:

    • Style templates: explainers emphasize analogies and layered progression; Q&A pieces emphasize a question-answer rhythm; podcast scripts emphasize spoken pauses and transitions; community long-form posts emphasize subheadings and key points up front.
    • Fact-constraint prompts: require using only the provided material, state explicitly when information is missing (“no reliable source found”), and prohibit speculative completion.
    • Structure constraints: limit paragraph length, number of key points, and how often terms are explained, reducing output that looks complete but carries little information.

    Prompt skeleton example:

    1. Write using only the material I provide; do not introduce outside facts.
    2. Target style: {style}
    3. Reader profile: {audience}
    4. Output structure: conclusion first → 3-5 key points → action recommendations → source attribution
    5. If the material is insufficient to support a conclusion, state "insufficient material".

    6. Consistency Checks and Evaluation Metrics

    A decoupled architecture needs verification, otherwise the rewriting stage can introduce factual drift. Two sets of metrics are recommended:

    • Retrieval side: hit rate, share of credible sources, freshness pass rate, answer coverage (whether a clear what/how was found).
    • Generation side: factual consistency (whether conclusions are supported by the material), style compliance, redundancy, readability score.

    A lightweight verification step can perform a reverse check: map each conclusion in the generated answer back to a material snippet, and delete or downgrade sentences that cannot be mapped to “pending confirmation”.

    7. Common Pitfalls and Selection Advice

    • Pitfall 1: judging only by fluency. High fluency with missing sources is the most typical hidden risk.
    • Pitfall 2: using one model for both retrieval and style control, so tuning interferes with itself.
    • Pitfall 3: ignoring the difference between coding and conversational tasks and measuring both with the same evaluation standard.
    • Selection advice: first determine whether the business is open-domain Q&A, content production, or coding assistance, then choose per layer. For cost-sensitive scenarios, a tiered setup with a small model for retrieval reranking and a large model for final rewriting works well. If an organization already has general cloud capabilities, object storage can hold material, a message queue can decouple tasks, and logging and monitoring services can track quality.

    8. Conclusion

    “Which one is better” is essentially the wrong question; the real question is “what capability does each stage need”. Splitting retrieval from rewriting, assigning the most suitable approach to each, and stitching them together with consistency checks delivers clear answers with stable style. The same approach applies to similar systems built on general cloud products at Baidu AI Cloud.