# The queries in the evaluation set are twice as long as what users say

Date: 2026-11-26
Category: Technology
Tags: Evaluation, Query Rewriting, RAG
Summary: After query rewriting goes live, the offline evaluation set and real inputs are often no longer from the same distribution. This article explains how to distinguish three types of misalignment, the approach of stratified resampling by rewrite trigger rate, and when you can skip redoing it.

The query in an evaluation set and the query a user actually types into the search box are often not the same thing.

After a round of query rewriting (normalizing colloquialisms, coreferences, and typos into searchable expressions), this gap can grow large enough to invalidate your metrics. A common phenomenon: rewriting lifts nDCG by a few points on the offline set, but the online dashboard doesn't move, or even moves in the opposite direction. Most people's first instinct is to go back and tune the rewriting model. I prefer to check something else first: is the evaluation set still aligned with production?

## Evaluation sets are written; user queries are spoken

The source of an evaluation set basically determines its shape. Document titles, FAQs, customer service tickets, and question lists compiled by operations staff share one thing in common: they are all written sentences that have already been processed by a human. Document titles are written by editors, FAQs are revised by operations, and tickets are typed by users and then edited after the fact.

Queries users type on the spot are not like this. They are short, missing subjects, full of coreferences and typos, mix Chinese and English, and are peppered with colloquial words. A common scenario: a user searches "能换绑吗" (can I rebind?) in the app, not "修改绑定手机号的操作步骤" (steps to change the bound phone number); they search "咋退" (how to refund?), not "如何申请退款" (how to apply for a refund). It's also common for users to hit enter before selecting characters in the pinyin input method.

In terms of magnitude, the median Chinese character count of online queries in single-turn search scenarios is often between single digits and the low teens; for evaluation sets constructed from document titles and FAQs, the median often doubles. This isn't a stylistic difference—it directly changes retrieval behavior. Short queries rely on semantic matching and error correction; long queries rely on keyword coverage and phrase matching. The same system has completely different failure modes on the two types of input.

If the evaluation set is all long queries, the recall and nDCG you measure only reflect system performance on long queries. After launch, users don't talk that way, so the metrics naturally don't line up.

## The rewriting layer tears this seam wide open

Query rewriting usually does several things: filling in coreferences in multi-turn conversations (turning "它多少钱" into "iPhone 15 多少钱"), converting colloquial speech to written form, correcting errors, completing entities, and expanding synonyms. Once it goes live, the online pipeline becomes: raw query enters the rewriting layer, the rewriting layer outputs the retrieval query, which then goes into generation.

The problem is: which pipeline was run during evaluation?

The first approach: the evaluation set stores raw queries, and the evaluation script runs the full pipeline. This is closest to production. But the annotated answers are usually written against the raw query. If rewriting fills "它" with the wrong entity, the retrieval results won't match the annotations, and you can't tell whether the rewriting was wrong, the retrieval was wrong, or the annotation itself was ambiguous.

The second approach: the evaluation set stores rewritten queries, and evaluation only runs retrieval and generation. This is equivalent to feeding ideal rewriting results into retrieval, completely shielding the errors of online rewriting. The metrics will look good—so good that they have no reference value.

The third approach: the evaluation set stores raw queries, and the evaluation script also skips rewriting. What you're testing is not the production pipeline at all.

Of the three, the second is the most insidious. Because the queries in the evaluation set look more "standard," no one reviewing it would suspect a problem.

The figure below answers: where in the pipeline the evaluation set might be attached, and what gets measured when it's attached in the wrong place.

```mermaid
flowchart LR
    subgraph ONLINE["线上链路"]
        direction LR
        A1[用户原始query] --> A2[改写层] --> A3[检索] --> A4[生成]
    end
    subgraph EVAL["评测链路"]
        direction LR
        B1[评测集query] --> B2{跑不跑改写}
        B2 -->|跑| B3[端到端]
        B2 -->|不跑| B4[只测检索]
    end
```

## Three kinds of misalignment—first figure out which one

Not all alignment problems require resampling. First classify the misalignment, because the actions are completely different.

| Misalignment type | Typical symptom | How to check |
| --- | --- | --- |
| Distribution misalignment | Evaluation set queries are longer, more written, and have fewer typos | Compare median lengths and colloquial-word ratios on both sides |
| Pipeline misalignment | The evaluation script doesn't call the rewriting layer, or uses a fixed rewriting cache | Check whether the evaluation script entry point is the same as production |
| Annotation misalignment | Rewriting changed the correct answer, but annotations weren't updated | Sample a few dozen and check whether the target is consistent before and after rewriting |

Distribution misalignment is the most common and the easiest to overlook, because it doesn't throw errors—it just slowly drains the meaning out of your metrics. Checking it is cheap: plot a histogram of query lengths for online logs and the evaluation set, and compare medians and P90.

Pipeline misalignment is easy to check, but often no one checks it. The evaluation script may have been written months ago, before the rewriting layer existed; rewriting was added later, the evaluation script wasn't updated, and it has been running that way ever since.

Annotation misalignment is the most troublesome. The typical case is coreference resolution: in the original sentence "它支持无线充电吗" (does it support wireless charging?), "它" refers to product A in the preceding context, but the rewriting layer fills in product B, while the annotated answer is still written for A. Such samples will be judged wrong in end-to-end evaluation, but the error is neither in retrieval nor in generation. Sample a batch of rewritten samples and have a human look at them, and you can estimate the proportion of such mislabeled cases. If the proportion is high, fix the annotations first—don't rush to change the model.

## Resample stratified by rewriting trigger rate—don't redo everything

Once you've confirmed distribution misalignment, the action is not to tear down the evaluation set and start over. The more cost-effective approach is to resample from online logs, stratified by rewriting trigger rate.

Four specific rules:

1. Sample from online query logs; don't go back to documents and FAQs to reconstruct.
2. Stratify by whether rewriting was triggered, and allocate the two strata according to their actual online proportions—don't sample half and half.
3. Keep the original query and the rewritten query as pairs, and annotate against the rewritten target.
4. Report metrics by stratum: look at the subset where rewriting was triggered separately, and the subset where it wasn't separately.

Rule 4 is often skipped. If you report them mixed together, the gains from rewriting get diluted by the large number of untriggered samples, and the errors introduced by rewriting get averaged away, leaving you with a number no one can explain.

```yaml
sampling:
  source: online_query_log
  window_days: 14
  strata:
    rewrite_hit:
      condition: rewrite_applied == true
      share: 0.35  # 示意值，按线上日志实际占比填
    rewrite_miss:
      condition: rewrite_applied == false
      share: 0.65
  keep_pairs: true
  label_on: rewritten
```

Size the sample at the level of a few hundred, not several thousand at once. The subset where rewriting was triggered is the focus; cover the three high-frequency scenarios of multi-turn coreference, colloquial input, and typos, and make sure each sample can be traced back to the original query so problems can be replayed.

## When you can skip resampling

There are two cases where I would hold off on resampling and observe for a while first.

First, rewriting only does normalization—for example, full-width/half-width conversion, case unification, trimming leading and trailing spaces, traditional/simplified conversion—without changing semantics or filling in entities. In this case, the semantic distribution of the evaluation set and online queries isn't skewed, provided the evaluation script runs the same normalization before retrieval. Many "metrics dropped after rewriting" incidents are actually because the evaluation script didn't do normalization, or did a different one.

Second, the rewriting trigger rate is extremely low. In single-turn entity search, users basically type model numbers, product names, and people's names; error correction and expansion rarely trigger, so the evaluation set distribution won't be skewed by rewriting.

Conversely, multi-turn customer service and assistant-type products don't fit either case. In these scenarios, the share of queries with coreferences can reach double-digit percentages, colloquial input is the norm, and the rewriting trigger rate is high—the evaluation set must be resampled. Applying the experience of single-turn search to multi-turn conversation is the most common misjudgment in this class of alignment problems.

You don't need to guess whether the trigger rate is high or low: add a flag in the logs for whether rewriting took effect, and you'll see the distribution within a week. This instrumentation is cheap, and the payoff is that all subsequent evaluation discussions have evidence behind them.

## Where this cost should be booked

The main cost of resampling is annotation. Checking one query plus its rewritten target takes roughly a few minutes; a few hundred samples is a few person-days of work. That sounds like a lot, but compared with a launch decision made on inflated metrics, it's not a high price. Inflated metrics don't cause trouble immediately—they come back two or three months later in the form of "why doesn't online performance match the reports?"

I usually prefer a two-track setup: a full regression set covering the main business scenarios, run frequently; and a rewrite-specific set of a few hundred cases, run only when the rewrite layer changes. The specific set doesn't aim for full coverage—it aims for every case being able to explain why it's there.

Start with one small thing: print the query length distribution from recent online traffic side by side with that of the eval set. If the medians differ by more than 2x, don't stare at nDCG yet—go look at the eval set.
