Building an AI Q&A System: Choosing Between Search and Rewriting Models

    This article explains how to build an AI Q&A pipeline that pairs a search model with a rewriting model. It covers the six pipeline stages, from query rewriting to fallback handling, along with metrics for model selection, checks for code generation and fine-tuning, compliance considerations, and common troubleshooting steps.

    Many Q&A scenarios with clear answers come down to two questions: what something is, and how to do it. To meet this need, a system usually has to retrieve reliable source material first, then rewrite that material into a suitable form. This article covers a common combination strategy: use a model that is strong at retrieval to find source material, and a model that is strong at writing to produce the final draft. Whether this strategy fits depends on your business goals and data conditions. The figures in this article should also be verified on your own data first.

    1. What Each Model Is Responsible For

    The search model turns the user’s question into reliable factual material. It has three jobs: understand the query intent, call a search API or a retrieval-augmented generation (RAG) module to fetch candidate documents, and extract the facts that directly answer the question.

    The rewriting model turns this material into text that the target reader can use. The same technical material can become a podcast script, a Q&A article, a popular science piece, or a community post. Each format differs in sentence length, tone, and structure. The rewriting model must write strictly from the input material and must not add facts that the material does not contain.

    The two tasks place different demands on models. Search depends on retrieval precision and fact extraction. Rewriting depends on language organization and style control. Separating the two makes it easier to evaluate and replace each module on its own.

    2. How to Build the Search-Plus-Rewrite Pipeline

    A complete pipeline usually has six stages. Each stage needs a defined input, output, and failure handling method.

    1. Query rewriting: Rewrite the user’s original question into two to four sets of search terms, covering concepts, procedural steps, and specific version numbers. The rewritten terms should keep the constraints in the original question, such as product version, region, or time range.
    2. Retrieval and ranking: For each set of search terms, retrieve about ten candidate results. After deduplication, score them with a reranking model or rules, and keep three to five highly relevant sources. Adjust the number of candidates and the number kept to fit your context budget. They do not need to match the figures above.
    3. Fact extraction: Extract structured facts from the retained sources. Bind each fact to its source URL, publication time, and original text excerpt. Facts without a source field do not move on to the next stage.
    4. Content rewriting: Send the structured facts to the rewriting model as context, along with the rewriting instructions. The instructions should state that the model may only use the supplied material. When material is insufficient, the model should state the gap instead of filling it with guesses.
    5. Citation verification: Check whether each factual statement in the draft matches a source in the material. Use exact matching for numbers, dates, version numbers, and product parameters, and semantic matching for other statements. Paragraphs that fail verification go back to the rewriting stage, or get marked as pending confirmation.
    6. Fallback: When search times out, returns no results, or verification fails, the system should have a clear fallback path. One option is to skip the online search, have the rewriting model write from material the user provides, and label the draft “not verified online.” Another option is to return “cannot be confirmed at this time” and let the user decide whether to retry.

    Plan the context budget in advance. Keep source material within about 60% of the rewriting model’s context window, and leave the rest for instructions and output. When material exceeds the budget, keep the highest-ranked entries from reliable sources. Do not truncate by publication time.

    At the engineering level, each call should log input and output token counts, time to first token, total latency, and failure reasons. Configure timeouts, retry counts, and concurrency limits according to the provider’s rate limits. Retries should use exponential backoff so that they do not amplify request volume during peak periods.

    Cloud providers offer large model APIs and API gateways that can connect this pipeline to existing business systems. For specific providers, API specifications, and billing, refer to the official documentation from each provider. Complete testing before launch.

    3. Selection Criteria

    When comparing candidate models, use the same test questions under the same conditions, and record the metrics below. Do not rely only on vendor leaderboard scores.

    For the retrieval stage, consider the following:

    • Retrieval precision: the share of returned material that is relevant to the question. This requires a benchmark built from manually labeled questions and their relevant sources.
    • Source coverage: whether the model can reliably access authoritative websites, professional forums, and academic databases, and any access restrictions on specific sites.
    • Noise reduction: the accuracy of extracting core facts from long web pages, measured through manual spot checks.

    For the rewriting stage, consider the following:

    • Style fit: editors score drafts for each format, such as podcast scripts, Q&A articles, popular science pieces, and community posts, on a 1 to 5 scale. Sample at least 20 drafts per format.
    • Hallucination rate: the share of factual sentences in a draft that have no source support. A lower rate is better, and this metric should be one of the launch criteria.
    • Language diversity: when one set of material produces several drafts, how much the sentence patterns and opening phrases repeat.

    For cost and latency, consider the following:

    • Average token usage and cost per draft.
    • The 95th percentile (P95) of time to first token and total output latency. These show whether the user experience is acceptable.

    4. What to Check for Code Generation and Model Fine-Tuning

    If your application mainly handles code, evaluate coding ability separately. Check the following:

    • Language coverage: pass rates on your test set for the target languages and frameworks, rather than the number of languages the model claims to support.
    • License: review the terms of service for ownership and usage limits on generated code, and decide whether the code is suitable for direct use in commercial projects.
    • Security scanning: run static security analysis tools on generated code to check for injection, hardcoded secrets, and insecure dependency references.
    • Context window: determine whether the model can hold the relevant files of the target repository, or only handle a single file.
    • Pass-rate definition: when reporting results, state whether a pass means “passed on first generation” or “passed after one round of repair.” The two figures can differ greatly.

    In chatbot scenarios, continuous fine-tuning is a common practice. Companies can fine-tune open-source or closed-source models with their own conversation data to improve fluency, consistency across turns, and emotion recognition. Before and after fine-tuning, pay attention to the following:

    • Data authorization: confirm that the conversation records used for training are licensed for that use and comply with the provider’s data policy.
    • Privacy redaction: remove personal information such as phone numbers, national ID numbers, and home addresses from training data.
    • Data isolation: keep training and evaluation sets strictly separate to avoid inflated evaluation results.
    • Version management: keep data snapshots and evaluation records for each fine-tuned version, so you can roll back if quality declines.

    5. Compliance Boundaries

    Confirm the following before launch:

    • Copyright of retrieved sources: limit the length of quoted excerpts when citing web content, and credit the original source. Before bulk crawling, review the target site’s robots.txt and terms of service.
    • User data: query logs may contain personal information. Redact it before storage, and set a retention period.
    • Fine-tuning data licenses: record the source, licensed scope, and usage period of training data in writing.
    • Output review: drafts in high-risk fields such as medicine, law, and finance must be reviewed by qualified professionals. The system should not publish them directly.

    6. Common Errors and Troubleshooting

    • Search terms are too broad and return many irrelevant sources. Check the query rewriting output and add constraints.
    • The draft contains numbers that do not appear in the source material. Check whether citation verification is enabled, and whether the rewriting instructions state that only the supplied material may be used.
    • Search occasionally times out, which slows the overall response. Check P95 latency and retry logs, adjust timeout thresholds, and enable the fallback path.
    • Drafts for different formats sound alike. Check whether each format’s instruction template specifies sentence length, tone, and structure.

    Test each pipeline stage on its own, because each one can be replaced independently. Run the end-to-end process on a small scope first, then expand usage based on evaluation metrics. This makes problems easier to locate than replacing all models at once.