Building an Efficient AI Q&A Workflow: Technical Practices for Retrieval-Augmented Generation
This article explains how to build an efficient AI question-answering workflow by splitting it into a retrieval stage and a generation stage instead of relying on a single model. It covers a four-layer architecture, retrieval optimizations such as query rewriting and source trust filtering, the separation of answer synthesis from style rewriting, a three-layer evaluation loop, and how to assemble the pipeline from general cloud service categories, along with common pitfalls and selection advice.
1. Background: Why a Single Model Cannot Cover Every Requirement
When teams start building intelligent applications, many of them initially treat “intelligent Q&A” as a single model call: the user submits a question and the model returns an answer directly. Once the business is actually running, however, a single model usually struggles to satisfy two conflicting demands at the same time.
The first demand is factual accuracy. Users typically expect a clear conclusion — what something is and how to do it — rather than a long chain of reasoning. This requires strong retrieval capability, broad source coverage, and the ability to judge how trustworthy a source is.
The second demand is expression quality. Once the material is in hand, what users really need is a draft written in a specific style: a podcast script, a Q&A-style piece, an explainer article, or a long community post. This depends far more on language organization, structural arrangement, and style control.
Forcing both capabilities into one model commonly produces one of two outcomes: weak retrieval leads to factual drift, or thin stylistic ability produces drafts that are hard to use. The more engineering-friendly approach is therefore to split the flow into a two-stage pipeline: retrieval augmentation + generation and rewriting.
2. Overall Architecture: Decoupling Retrieval from Generation
The recommended baseline architecture can be abstracted into four layers:
- Access layer: session management, multi-turn context maintenance, permissions, and rate limiting.
- Retrieval layer: query rewriting, multi-path recall, source filtering, and chunk reranking.
- Generation layer: answer synthesis and style rewriting, each using a different prompting strategy.
- Governance layer: logging, evaluation, monitoring and alerting, and cost attribution.
A sketch of the orchestration logic (pseudocode, expressing flow structure only):
def answer_pipeline(query, session):ctx = session.load_recent(turns=5)q = rewrite_query(query, ctx) # Query rewriting, resolving referencesdocs = hybrid_recall(q, top_k=20) # Multi-path recalldocs = filter_by_trust(docs) # Source trust filteringpacks = rerank_and_pack(q, docs, budget=6) # Rerank and trim to the context budgetdraft = llm_answer(q, packs, style="neutral")final = llm_rewrite(draft, style=session.target_style)log_and_score(q, packs, draft, final)return final
Decoupling delivers three core benefits: retrieval quality can be measured independently; rewriting styles become pluggable and replaceable; and when any layer misbehaves, the problem can be traced to a specific stage instead of being blamed vaguely on “the model isn’t good enough.”
3. The Retrieval Layer: What Sets the Floor for Answer Quality
Retrieval quality essentially determines the factual floor of an answer. In practice, there are five directions worth optimizing.
Query rewriting. Multi-turn conversations contain many references and ellipses. The semantics need to be completed before retrieval, otherwise recall will drift noticeably.
Multi-path recall and hybrid ranking. Running keyword matching and semantic vector matching in parallel and then ranking them together covers both exact hits on proper nouns and semantic generalization.
Source trust tiers. Apply whitelists and domain-authority tiers to sources. Low-trust sources should only supplement background and must not serve as the basis for conclusions.
Chunk-level reranking and redundancy removal. Split long documents into chunks, rerank them, and control the token budget that enters the context so key information is not diluted.
Traceable citations. Key conclusions in an answer should be bound to source chunk IDs, which makes verification easy for users and makes attribution easier for later evaluation.
It is worth stressing that building the retrieval ecosystem is not something a model can do automatically. It depends on index coverage, crawl and update frequency, and accumulated domain corpora — which is the root cause of why many general-purpose models perform inconsistently on factual Q&A.
4. The Generation Layer: Separating Answer Synthesis from Style Rewriting
The generation layer should be split into two actions.
The goal of the answer synthesis stage is to be “correct and restrained”: answer strictly on the basis of the retrieved chunks, and when the chunks are insufficient, state the information gap explicitly rather than filling it in freely. A constrained prompt structure like this works well:
Answer using only the numbered chunks below.If the chunks are insufficient to support a conclusion, output "insufficient information" and list what is missing.Output structure: conclusion -> key evidence (with IDs) -> applicable boundaries.Chunks: [1] ... [2] ...
The goal of the rewriting stage is style fit. The same material can be mapped to different formats: a podcast script needs short sentences and rhythm; a Q&A piece needs an explicit question-and-answer structure; an explainer needs analogies and layers that progress from simple to advanced; a long community post needs layered arguments backed by evidence. In engineering terms, style should be externalized as configuration rather than hard-coded in the prompt, so styles can be switched quickly and compared through A/B testing.
5. Closing the Evaluation Loop: No Measurement, No Optimization
Three layers of evaluation are recommended:
- Retrieval metrics: recall hit rate, chunk relevance, share of trusted sources.
- Generation metrics: factual consistency, conclusion clarity, citation completeness.
- Style metrics: sentence-length distribution, structure compliance rate, human preference scores.
Also keep a manual sampling channel, and automatically feed low-scoring online sessions back into the evaluation set to form a continuous iteration loop.
6. Engineering Implementation: Combining General Cloud Capabilities
Implementation does not require any proprietary interface; the full chain can be assembled from general cloud product categories: object storage for corpora and evaluation sets; a message queue for peak shaving and driving asynchronous index updates; a container platform to host retrieval and inference services with elastic scaling; logging, monitoring, and alerting for trace tracking and anomaly detection; and key and permission management to consolidate access control. Baidu AI Cloud offers corresponding capabilities in these general categories, so it can be integrated smoothly into an existing architecture.
7. Common Pitfalls and Selection Advice
Pitfall 1: Over-trusting the general capability of a single model. Factual accuracy and stylistic expression should be optimized separately.
Pitfall 2: Ignoring the retrieval ecosystem. When index coverage is insufficient, switching models yields limited gains.
Pitfall 3: Hard-coding style into the prompt. This leads to high iteration cost and makes gradual rollout impossible.
Pitfall 4: Going live without evaluation. Without measurement, optimization can only rely on subjective impressions.
For selection, start by using a small evaluation set to compare the three capabilities — retrieval, synthesis, and rewriting — side by side, then decide how each stage should be implemented. For factual Q&A, prioritize retrieval and citations; for content-production scenarios, prioritize rewriting and style configuration.
