Designing an Intelligent Q&A System Through Coordinated Retrieval and Rewriting

    This article explains how to design an intelligent question-answering system that separates content retrieval from answer generation. It covers query understanding, hybrid retrieval, reranking, source trust filtering, controlled rewriting, consistency checks, layered architecture, evaluation, monitoring, and common implementation pitfalls. The goal is to produce answers that are accurate, verifiable, and adapted to the needs of different audiences.

    1. Problem Background

    Intelligent question-answering applications typically need to accomplish two tasks: find reliable source material and organize that material into an answer that meets the user’s needs. These tasks have different objectives and different failure modes.

    When retrieval fails, the system may answer using outdated or incorrect information. When generation fails, the source material may be accurate, but the answer can still use the wrong tone, miss important conditions, or deviate from the user’s intent. If both tasks are handled inside a single black box, diagnosing problems becomes difficult.

    From the user’s perspective, many scenarios focus on two questions: “What is it?” and “How do I do it?” These requests require clear conclusions and actionable steps, while requiring relatively little elaboration of the reasoning process. Longer reasoning chains are more useful when users need causal explanations or a comparison of multiple options.

    When designing the system, first determine which type of scenario the target use case represents. Then decide how deeply to retrieve information and how much detail the generated answer should contain.

    2. Retrieval: Ensuring Source Quality

    Retrieval is the foundation of the entire pipeline. A typical process includes four steps:

    1. Query understanding: Convert the user’s conversational question into one or more search queries, while filling in constraints such as time, region, and product version.
    2. Candidate retrieval: Retrieve candidate documents from the index. A common approach is to run keyword search and vector search in parallel, then merge the results to combine exact matches with semantically similar content.
    3. Reranking: Use a more precise relevance model to score candidate documents individually and retain the highest-scoring results.
    4. Source filtering: Remove low-trust content based on rules involving site type, publication date, author information, and other factors. Record the source of every item so it can be verified later.

    Three metrics are particularly useful for evaluating retrieval:

    • Recall measures whether the correct source material was retrieved.
    • Precision measures the proportion of retrieved results that are relevant.
    • Source credibility requires manual annotation or rule-based scoring.

    All three are important. Optimizing only for recall introduces excessive noise, while optimizing only for precision can cause the system to miss critical evidence.

    3. Generation: Rewriting Source Material for the Target Format

    Once the source material has been selected, the generation module organizes it into a readable answer. A rewriting task needs to satisfy three types of constraints:

    • Content constraints: The answer may use only facts found in the retrieved material. It must not add numbers, dates, or conclusions that are not supported by the sources.
    • Structural constraints: The output should match the scenario, such as a Q&A response, tutorial, educational article, or structured summary. The template can also define the number of paragraphs and heading levels.
    • Style constraints: The system should specify the tone, terminology density, and target reader level. For beginners, reduce abbreviations and add analogies. For engineers, preserve interface names and parameter names.

    In practice, style requirements are often written as an independent template and passed separately from the source material. This allows the writing style to be changed without modifying the retrieval logic and makes it easier to compare different templates through testing.

    Another frequently overlooked risk is information loss during rewriting. When text is compressed, qualifiers such as “applies only to a specific version” or “is triggered only under certain conditions” are especially likely to be removed. These qualifiers should be listed as mandatory elements in the template and checked after generation.

    4. Example of a Layered Architecture

    Separating retrieval and generation into independent modules allows each layer to be iterated independently. The following pseudocode illustrates a common call sequence:

    1. function answer(question, style):
    2. queries = rewrite_query(question)
    3. candidates = []
    4. for q in queries:
    5. candidates += retrieve(q, top_k=20)
    6. docs = rerank(question, candidates)
    7. docs = filter_by_trust(docs, min_score=threshold)
    8. if docs is empty:
    9. return "No reliable supporting evidence was found. Please narrow the scope of the question."
    10. draft = generate(question, docs, template=style)
    11. if not check_consistency(draft, docs):
    12. draft = generate(question, docs, template=style, strict=True)
    13. return draft

    Retrieval and generation are coupled only through the filtered document list. The generation module does not access the index directly. As a result, the retrieval strategy and writing-style template can be changed independently.

    The consistency-checking module compares the answer with the source material, checking numbers, dates, and entity names. If inconsistencies are found, the system regenerates the answer with stricter constraints. If the answer remains inconsistent after retrying, the system should return the original source material or notify the user rather than output unverified information.

    5. Evaluation and Quality Assurance

    Before and after deployment, consider establishing four types of checks:

    • Offline evaluation: Build a test set containing questions, standard source material, and reference answers. Run regression tests after every change and compare changes across the relevant metrics.
    • Factual consistency: Split each answer into independent conclusion statements and determine whether each statement is supported by the source material. Track the proportion of unsupported conclusions.
    • Style compliance: Use rules to check prohibited terms, paragraph length, and heading hierarchy so that the output follows the template.
    • Online monitoring: Track the no-result rate, follow-up question rate, and proportion of negative feedback. These metrics directly reveal retrieval gaps and generation errors and can guide subsequent iterations.

    6. Common Pitfalls

    1. Treating the generation model as a search engine. A model’s internal knowledge has a cutoff date and cannot reliably provide verifiable sources. For time-sensitive information, the system must use retrieval to obtain up-to-date material.
    2. Relying too heavily on a single source. A single data source may have limited coverage and produce one-sided conclusions. Key facts should be cross-checked across multiple sources.
    3. Ignoring information loss during rewriting. Compression and rewriting can remove important qualifiers. Use templates to require their retention and measure this type of loss separately during evaluation.
    4. Using the same parameters for every task. Code generation, summary rewriting, and factual Q&A have different requirements for output length, randomness, and formatting strictness. Configure these settings according to the task type.

    7. Practical Recommendations

    When building this type of system, start with a fixed set of questions. Validate retrieval recall and source quality before connecting the generation module.

    Change only one part of the pipeline at a time so that the cause of any performance change can be identified. After both retrieval and generation are stable, gradually expand the range of supported questions and introduce online monitoring.