ContentsRAG from Scratch to TRECAdisak Sukul · Iowa State University

Start here

Part 1 · Foundations

Part 2 · Finding the evidence

Part 3 · Writing the answer

Part 4 · Judging RAG

Part 5 · TREC and the 2026 tracks

Part 6 · Case studies: our submissions

Part 7 · Beyond text: video

Part 8 · Streams and advanced RAG

Back matter

Part 2 · Finding the evidence · Chapter 7

Asking the question better

In one sentence: the words a person uses to ask are seldom the best words to search with, so we rewrite the question into one or several search queries before we search.

Why you should care

A search engine sees only the query. If the query is a long, chatty paragraph, keyword search is pulled toward its filler words. If the query is three words, it may miss half of what the person wanted. Query rewriting is the cheapest step in a RAG pipeline to change, and it changes everything after it.

Words you need

Information need
What the person really wants to know. The query is only one attempt to say it.
Query rewriting
Turning the person's words into a query that searches better. Also called query reformulation.
Query variant
One of several different queries written for the same information need.
Multi-query
Searching with several variants and merging the results.
Query expansion
Adding words to a query, for example synonyms.
Decomposition
Splitting a question with several parts into one query per part.
HyDE
Hypothetical document embeddings. A language model writes a made-up answer, and the search uses that answer as the query.
Deterministic
Giving the same output every time for the same input. A rule is deterministic. A language model usually is not.

Core The idea

In TREC RAG 2026 the question is a narrative: a paragraph in which a person explains what they want to know and why. Here is one we made up in the same style.

Our town's river bridge was closed last spring after inspectors found cracks. I want to understand how engineers decide whether an old bridge can be repaired or must be replaced. What does each option cost, and how long does a repair last?

This is a good statement of an information need and a poor keyword query. It has several parts: how the decision is made, what it costs, how long a repair lasts. It also has words that will match the wrong documents, such as “town”, “spring” and “last”.

There are four families of rewrites.

FamilyWhat it doesGood forRisk
ShortenKeep only the important words, or one sentenceKeyword search on long questionsDropping the one word that mattered
ExpandAdd synonyms and related wordsVocabulary mismatchDrifting off topic
DecomposeOne query for each part of the questionQuestions with several partsMore searches, more off-target documents
Imagine the answerA language model writes a possible answer and you search with it (HyDE)Dense search, where an answer looks more like a document than a question doesThe made-up answer can be wrong and lead the search the wrong way

You do not have to pick one. Write several variants, search with each, and fuse the lists (Chapter 8). A document that several variants find is a safer bet than one that a single variant finds.

Rules or a language model?

A rewrite can be made by a simple rule, such as “take the first sentence”, or by a language model. Rules are free, instant and the same every time. A language model writes better queries and costs money, takes time, and may give a different rewrite on each run. A different rewrite means different documents and a different score, which makes experiments harder to repeat. Start with rules. Add a model when you can measure that it helps.

Watch and read

For the two videos we confirmed that the link opens and the title and channel match. We have not watched them through.

How we did it at TREC 2026

For every retrieval run in the RAG track we made seven variants of each narrative, all by rule. No language model wrote any query. This table shows what our code produces for the made-up narrative above.

VariantRuleQuery for the bridge narrative
fullThe whole narrativeAll three sentences
firstsentFirst sentenceOur town's river bridge was closed last spring after inspectors found cracks.
first2sentFirst two sentencesThe first sentence plus “I want to understand how engineers decide …”
lastsentLast sentenceWhat does each option cost, and how long does a repair last?
firstlastFirst and last sentenceThe two sentences above, joined
kw15Drop common words and repeats, keep the 15 longest wordsinspectors engineers repaired replaced whether bridge closed spring cracks decide option repair river after found
kw8The same, 8 longest wordsinspectors engineers repaired replaced whether bridge closed spring

Each variant went to BM25. The seven lists were fused with RRF. The run isu-bm25-rrf7 is exactly this and nothing more.

Why rules? Two reasons. First, the queries are the same every time we build a run, so two of our runs never differ because of a query. Second, we wanted one run with no language model in it at all, as a floor.

In RAGTIME the topic already comes in parts: a title and a longer problem statement. We sent both as separate queries (Chapter 11). In Change Detection one group of runs expands the question with words from example documents once those documents have arrived in the stream (Chapter 39).

What surprised us

Our keyword rule keeps the longest words, not the most important ones. Look at kw8 in the table. It kept “whether” and “spring” and dropped “cracks”, “repair” and “cost”. The rule assumes that long words carry the topic. That is often true and sometimes badly wrong. The variant lastsent has the opposite problem here: “What does each option cost, and how long does a repair last?” does not contain the word “bridge”. Each variant alone is weak. We relied on fusion to cover for them, and we never measured each variant alone on the official judgments, so we cannot say which ones helped and which ones only added off-target documents. That would be a good student project.

Try it

  1. Write a narrative of three sentences about something you want to know. Produce the seven variants by hand with our rules.
  2. Which variant would you search with if you could use only one? Which one is clearly bad?
  3. Ask a language model for three search queries for the same narrative. Compare them with the rule-based ones. Ask again. Did you get the same three?
  4. Improve the keyword rule. One idea: rank words by how rare they are in the collection, which is the IDF from Chapter 5, and not by their length.

Check yourself

  1. Why is a narrative a poor keyword query?
  2. Name the four families of rewrites.
  3. Give one advantage of rule-based rewrites and one of rewrites by a language model.
  4. What is the risk of HyDE?
  5. Why does searching with several weak variants and fusing them often beat one variant?
Answers
  1. It is long, has several parts, and holds filler words that match off-target documents.
  2. Shorten, expand, decompose, and imagine the answer.
  3. Rules: free, fast and the same every time. A language model: better wording, and it can add words the person did not use.
  4. The made-up answer may be wrong, and the search then finds documents that agree with the mistake.
  5. The variants fail in different ways. A document found by several of them is more likely to be on topic.

Go deeper

  • Pseudo-relevance feedback. Search once, assume the top documents are relevant, take words from them, and search again. RM3 is the classic method. It needs no language model.
  • Generated expansions. Methods such as query2doc add a passage written by a language model to the query. They help keyword search too, because the passage holds the vocabulary of an answer.
  • Step-back and decomposition prompts. A model can be asked for a more general question first, or for the sub-questions. Each one is a new search.
  • Query performance prediction. Can you tell, before judging, that a variant is bad? Signals include how rare its words are and how much its results agree with the other variants.
  • Repeatability. If a model writes your queries, save every query to a file and treat the file as data. Our rule-based variants need no such file, since the code makes the same queries again.
  • Project idea. Take our seven rules and one public test collection. Score each variant alone, then every way of leaving one out of the fusion. Which variant can you remove at no cost?