Zenaique

When does query expansion help context assembly, and when does it just inflate noise?

Flashcard·Medium·4.0 · 0·~30s·Asked atAccentureDatadogInduced Ai
Attempt it
TL;DR

Expansion paraphrases the query into a small fan and unions the results to lift recall on short under-specified queries; the cost is broader noise unless reranking and trimming clean up after the union.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine you ask a librarian for help with one search term and they only check that one term. If the book uses different words, they miss it. Query expansion is asking the librarian to also try two or three closely related phrases just in case. You will find more relevant books, but you will also find some only loosely related ones. The fix is to look at the whole pile and let a better filter pick the actual best ones. Expansion alone is half a solution. Expansion plus a strong second-pass filter is the full move.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Query expansion is a recall lever that costs precision. Whether it improves your retrieval depends on whether the failures you are seeing are recall failures (the right chunk is in the corpus but not in the top-k) or precision failures (the top-k contains the right chunk but the model picks badly). Expansion helps the former and hurts the latter.

This card walks through what expansion does, the mandatory downstream that recovers precision, and the variants, HyDE, step-back prompting, multi-query, that share the same shape.

What query expansion does and when it helps

A user's query is one point in embedding space. Top-k retrieval returns the chunks closest to that point. If the user's vocabulary differs from the corpus's, the embedding lands in a slightly different region than the relevant chunks, and the top-k misses them.

Query expansion sidesteps this by generating 2 to 5 paraphrases of the original query. Each paraphrase has a different embedding, close to the original but probing slightly different regions of the vector space. The system retrieves against each, unions the result sets, and feeds the combined pool into the rest of the pipeline.

When this works

Three indicators that expansion will help:

  • Short queries. Two or three tokens carry less signal than a sentence; expansion adds back the missing context by paraphrasing.
  • Vocabulary mismatch. Users and corpus authors use different terminology. Expansion probes synonyms and rewordings.
  • Recall-limited evals. Inspection shows the right chunk is in the corpus but plain top-k frequently misses it.

When all three hold, expansion can lift recall meaningfully, gains of 5-15 percentage points on recall-at-5 are typical on short-query corpora.

The precision cost and the mandatory downstream
Variants worth knowing in 2026
When expansion is the wrong tool
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
python
def expand_query(original: str, n: int = 3) -> list[str]:
    prompt = (
        f"Generate {n} different ways to phrase this query, each a single line, "
        f"covering different vocabulary the corpus might use. Original: {original}"
    )
    paraphrases = llm.complete(prompt).strip().split("\n")
    return [original] + paraphrases[:n]

def retrieve_with_expansion(user_query: str, k1: int = 20) -> list[Chunk]:
    queries = expand_query(user_query, n=3)
    # union and dedupe across all retrievals
    seen: dict[str, Chunk] = {}
    for q in queries:
        for c in vector_db.search(q, top_k=k1):
            seen.setdefault(c.id, c)
    # rerank against the ORIGINAL query, not the paraphrases
    candidates = list(seen.values())
    return reranker.rerank(user_query, candidates, top_n=5)

Real products, models, and research that use this idea.

  • LangChain's MultiQueryRetriever (2026) wraps the expansion and union pattern as a single retriever class with configurable fan-out.
  • LlamaIndex's MultiStepQueryEngine and HyDEQueryTransform expose expansion variants as composable pipeline stages.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow is HyDE different from query expansion?
A

Expansion paraphrases the query and retrieves against each; HyDE generates a hypothetical answer and retrieves against the answer's embedding. Different probes, same goal.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Running expansion without a reranker after the union. The expanded result set is broader and the original problem (the right chunk is buried) is now the new problem (too many loosely relevant chunks).

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Explain what query expansion does in one sentence

  • Name the recall gain and the precision cost

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Pick the most effective intervention when an agent's context grows by 8KB every iteration
MCQ·Medium