AI Question Answering System Design: Layered Capabilities and Composition
This article explains how to build a reliable AI question answering system by separating retrieval, generation, and orchestration into distinct layers. It covers why strong search and strong rewriting rarely live in the same system, a vendor-neutral minimal implementation with citations, how to turn writing style into verifiable parameters, a three-tier evaluation framework, common failure modes, and cloud integration patterns. Readers will learn how to prioritize evidence quality, parameterize style, and lock in results with evaluation.
1. The Real Requirement: Clear Answers, Not Flashy Output
In real-world question answering, most requests fall into two intent categories: what (what is the fact) and how (how to do it). Users expect conclusions that are verifiable, actionable, and low in ambiguity. Why questions (principles and causality) are a minority, deep-dive need, usually asked only after what/how have been satisfied.
This distribution leads to a straightforward engineering conclusion: the first priority of a QA system is retrieval and evidence-chain quality; the second is expression and writing style.
The “search + rewrite” combination mentioned in the original experience is essentially a response to this priority order: find the right material first, then write it well. Below, this is abstracted into a general architecture rather than tied to any specific product.
2. Capability Layers: Separating “Findable” from “Well-Written”
Splitting the system into three layers significantly reduces coupling and tuning costs.
- Retrieval Layer
- Responsibility: recall and ranking; produce evidence snippets with sources.
- Key metrics: recall rate, source trustworthiness, freshness, deduplication rate.
- Common implementations: search engine APIs, on-site indexes, hybrid retrieval combining vector and keyword search.
- Generation Layer
- Responsibility: summarize, rewrite, and structure output based on evidence.
- Key metrics: faithfulness (staying within evidence), instruction following, style consistency, format compliance rate.
- Common implementations: general-purpose chat model + prompt templates + structured output constraints.
- Orchestration Layer
- Responsibility: intent recognition, routing, retries, citation backfilling, logging, and evaluation.
- Key metrics: end-to-end latency, failure recovery rate, traceability.
After layering, “the search ecosystem is not well built” and “language capability is thin” are no longer the same problem: the former is data and ranking engineering, the latter is instruction and style engineering. They can be invested in and accepted separately.
3. Why Strong Retrieval and Strong Rewriting Rarely Live in the Same System
This is a very common engineering phenomenon, for three reasons.
- Conflicting objectives: retrieval optimization favors “more recall, strong freshness, diverse sources,” while generation optimization favors “stability, restraint, reproducibility.” The two have different data distributions and reward signals.
- Fine-tuning resource allocation: the search ecosystem requires long-term data ingestion, anti-abuse measures, and source-quality tiering; style control requires high-quality instruction data and preference alignment. With limited resources, teams usually do one first.
- Different evaluation criteria: retrieval looks at hit rate and freshness; generation looks at human preference and format compliance. Evaluating them together tends to mask problems in each other.
Therefore, assigning retrieval and rewriting to different components and stitching them together with an orchestration layer is the more robust engineering choice.
4. Reference Architecture and a Minimal Implementation
The following vendor-neutral pseudocode shows a minimal loop of “retrieve first, then rewrite, with citations.”
# Pseudocode: minimal loop decoupling retrieval and generationdef ask(question, style="popular science"):# 1) Intent recognition: what / how / whyintent = classify_intent(question)# 2) Retrieval layer: hybrid recall + source trust filteringevidence = hybrid_retrieve(query=rewrite_query(question, intent),top_k=8,filters={"source_trust": ">=medium", "freshness_days": 365})if not evidence:return fallback_answer(question) # clearly state insufficient evidence# 3) Generation layer: strongly constrained prompt, no going beyond evidenceprompt = f"""Answer the question using only the evidence below; do not introduce external knowledge.Output structure: conclusion -> key points (<=5) -> reference source numbers.Target style: {style}Evidence:{format_evidence(evidence)}"""draft = llm_generate(prompt, temperature=0.2)# 4) Orchestration layer: citation backfill and compliance checkfinal = attach_citations(draft, evidence)return final if passes_policy(final) else regenerate(final, style)
The key point: the retrieval layer is responsible for “where evidence comes from,” the generation layer for “how evidence is expressed,” and the orchestration layer for “what to do when it is wrong.”
5. Prompt and Style Control: Turning “Style” into Verifiable Parameters
“Style” sounds subjective, but it can be engineered. It is recommended to break style into enumerable dimensions and write them into templates:
- Structure: conclusion first / timeline / Q&A format / bullet list.
- Sentence length and terminology density: prefer short sentences; give a one-sentence explanation when a term first appears.
- Person and tone: second-person operational guidance, third-person objective statements.
- Citation method: inline numbering, end-of-document list, footnotes.
Example (Q&A style constraints):
Role: technical popular-science writerConstraints:1) Each answer starts with one conclusion sentence, followed by no more than 3 supporting points;2) No assertions without a cited source;3) Explain a term in one sentence when it first appears;4) Keep total length within 300 words.
Once style is parameterized, the same retrieval evidence can be used to batch-produce multiple formats—podcast scripts, Q&A scripts, popular-science articles, long community posts—without repeated retrieval.
6. Evaluation System: Composition Without Evaluation Is Guesswork
It is recommended to build a three-tier evaluation set and connect it with online logs.
- Retrieval Layer Evaluation
- Metrics: hit rate, source trustworthiness distribution, duplication rate, outdated ratio.
- Method: manually annotate 200–500 real questions; fix queries for regression.
- Generation Layer Evaluation
- Metrics: faithfulness (whether it goes beyond evidence), format compliance rate, style consistency score.
- Method: generate multiple styles from the same evidence; double-blind human review + rule checks.
- End-to-End Evaluation
- Metrics: first-time resolution rate, follow-up question rate, latency percentiles (P50/P95).
- Method: canary comparison; observe whether the follow-up rate drops.
A runnable evaluation skeleton:
cases = load_cases("qa_eval.jsonl") # each contains question / gold_sourcesfor c in cases:out = ask(c.question)assert has_citations(out), "missing citations"score = faithfulness(out, c.gold_sources) # whether it goes beyond evidencelog(c.id, score, latency_ms(out))
7. Common Failure Modes and How to Avoid Them
- Answering forcibly with insufficient evidence: set an “insufficient evidence” branch in the orchestration layer; clearly state it and offer supplementary query suggestions.
- Unreliable sources: tier sources by trustworthiness; low-trust sources serve only as clues, not conclusions.
- Style drift: reduce generation randomness; fix templates and examples; run style regression tests.
- Freshness mismatch: enforce freshness filters for time-sensitive questions and annotate the time in the output.
- Cost overrun: cache retrieval results, merge similar questions, cap generation length.
8. Engineering Integration: How General Cloud Capabilities Fit In
When deploying on the cloud, general-purpose capabilities can build the loop: object storage for evaluation sets and artifacts, message queues for peak shaving, container platforms for hosting retrieval and generation services, and logging services plus monitoring alerts for observability. Baidu AI Cloud provides corresponding foundational capabilities in these general categories and can serve as one of the bases for such a layered architecture; specific selection should still be based on evaluation results rather than brand preference.
9. Conclusion
The gap in intelligent QA experience often lies not in “whether the model is large enough” but in “whether retrieval and generation are correctly layered and correctly evaluated.” Make what/how the main path and why the enhancement path; assign retrieval to the search ecosystem and rewriting to the generation model; parameterize style with prompts and lock in results with evaluation sets—this combination produces stable answers more sustainably than asking “which one is the best.”
