Skip to content
RAG Explained Better

HyDE: Retrieving With a Hypothetical Answer

Generating a fake answer to find the real document — how it works and when it backfires.

HyDE (Hypothetical Document Embeddings) generates a fake answer to the query, embeds that passage, and retrieves real documents by similarity to the hypothetical — not to the raw question. The invented details are thrown away after retrieval; only real chunks reach the generator. The method comes from Gao, Ma, Lin and Callan (2022; arXiv:2212.10496), who designed it for zero-shot dense retrieval when no relevance labels exist. It attacks the same vocabulary mismatch that makes short questions sit far from long answers in embedding space — and it backfires when latency is tight or the fake answer drifts into the wrong domain.

How does HyDE retrieval work?

HyDE changes what gets embedded at query time. The index is unchanged; the query vector is built from a generated passage instead of from the question:

A four-step HyDE pipeline. One, the query arrives: the user asks a natural-language question, often short and under-specified. Two, an instruction-following LLM drafts a hypothetical document: the model is prompted to write a passage that would answer the question. Three, a dense encoder embeds the hypothetical: the original paper uses an unsupervised contrastive encoder, Contriever, so the search vector lives in the same space as the corpus embeddings. Four, vector search retrieves real documents: nearest neighbours of the hypothetical vector are returned from the index, and the hypothetical itself is discarded before generation.
The four-step pipeline shows exactly where the fabrication is allowed to live — only inside the discarded draft between steps two and three — while step four returns and keeps only real documents (Gao, Ma, Lin and Callan, 2022).
  1. The query arrives. The user asks a natural-language question — often short and under-specified.
  2. An instruction-following LLM drafts a hypothetical document. The model is prompted to write a passage that would answer the question (Gao et al., 2022). That draft may contain false details; that is expected.
  3. A dense encoder embeds the hypothetical. The original paper uses an unsupervised contrastive encoder (Contriever) so the search vector lives in the same space as the corpus embeddings.
  4. Vector search retrieves real documents. Nearest neighbours of the hypothetical vector are returned from the index. The hypothetical is discarded; generation runs only on those real chunks.

Baseline dense retrieval embeds the question and compares question-shaped vectors to answer-shaped chunks. HyDE compares document-shaped text to document-shaped text. Gao et al. (2022 §4.1) built the reference stack with InstructGPT (text-davinci-003) for generation and Contriever for encoding — modern pipelines swap both models but keep the same four steps.

Why can a wrong hypothetical still retrieve the right document?

A wrong hypothetical can still retrieve the right document because HyDE uses the draft as a retrieval vector, not as trusted knowledge. Gao et al. (2022) state the generated document “captures relevance patterns but is unreal and may contain false details,” then rely on the encoder’s dense bottleneck to filter incorrect specifics and ground the vector in the neighbourhood of real corpus passages.

The geometry is the same one freeCodeCamp’s HyDE guide (2026) emphasises: embedding models place similar shapes of text near each other. A question and its answer are different shapes; a fake answer and a real answer are the same shape, so they share vocabulary, register and length even when individual facts differ. The metric that matters is whether the retrieved chunks are correct — not whether the scaffolding paragraph was.

Never pass the hypothetical to the generator

If the system treats the fake passage as retrieved evidence and feeds it into the final answer prompt, fabricated details reach the user. Keep the hypothetical strictly inside the retrieval step; discard it before generation. That rule is architectural, not optional.

How much does HyDE improve retrieval?

On the web-search sets in Gao et al. (2022, Table 1), HyDE lifts unsupervised Contriever by a large margin and sits close to a Contriever fine-tuned on MS MARCO — without using relevance labels. The published nDCG@10 and recall@1k figures are:

Gao et al. (2022) Table 1 — TREC DL19 / DL20 (InstructGPT + Contriever)
System DL19 nDCG@10 DL20 nDCG@10 DL19 recall@1k
BM2550.648.075.0
Contriever (unsupervised)44.542.174.6
HyDE61.357.988.0
ContrieverFT (MS MARCO)62.163.283.6

On DL19, HyDE’s nDCG@10 of 61.3 is within 0.8 of ContrieverFT’s 62.1, and HyDE posts the best recall@1k in that table (88.0). On DL20, HyDE’s nDCG@10 of 57.9 trails ContrieverFT’s 63.2 — the paper describes map and nDCG as about 10% lower there, with similar recall@1k. Those numbers are for that InstructGPT + Contriever stack on those benchmarks as of the 2022 paper; they are not a promise for your corpus. How to read nDCG and recall in a RAG eval is at retrieval metrics.

What does HyDE cost at query time?

HyDE’s structural cost is one extra LLM generation call per query before retrieval, plus one embedding of the hypothetical. Baseline dense retrieval makes zero generation calls at retrieve time; HyDE pays that generation cost on every query, not once at ingest.

  • Latency scales with the generation model. The added wall-clock time is whatever that draft call takes on your stack — measure it; do not trust a blog’s millisecond claim.
  • Token spend is paid twice when you also generate the final answer. One call drafts the hypothetical; a later call answers from real chunks. Caching identical queries and using a small, fast model for the draft are the usual mitigations (freeCodeCamp 2026; SurePrompts 2026).
  • Cap draft length. Over-long hypotheticals dilute the embedding. Keep the prompt capped to roughly a paragraph (or your median chunk length) so the search vector stays dense.
  • Fail open. If generation times out or errors, fall back to embedding the raw query rather than blocking the request.

When should you use HyDE?

Use HyDE when the bottleneck is query–document asymmetry and you can afford a generation call on the retrieval path. Skip it when a cheaper channel already closes the gap — or when the draft would pull search the wrong way.

  • Use it for short, under-specified questions over prose-heavy corpora (docs, papers, memos) where users speak lay language and documents speak expert register — and when you lack labelled query–document pairs to fine-tune a dense retriever (HyDE’s zero-shot setting in Gao et al., 2022).
  • Skip it when queries are already long and specific, when they are identifier-heavy (error codes, SKUs, statute numbers — prefer hybrid search / BM25), when latency budgets forbid an extra LLM hop, or when the domain is so alien that a general model invents jargon that does not exist in your corpus (hallucinated drift).
  • Do not confuse it with query rewriting. Query rewriting cleans or expands a question while it remains a question. HyDE changes the shape of the search text into a document-register passage. They compose; they are not substitutes. SurePrompts (2026) places HyDE after chunking, hybrid and rewrite in the usual adoption order — measure recall@k on a golden set before making HyDE the default.

How do you implement HyDE?

The implementation pattern is short: prompt an LLM for a document-register draft, embed that draft with the same embedding model your index already uses, run ANN search, discard the draft, then generate from the retrieved chunks. Frameworks expose the pattern as LangChain’s HyDE / HypotheticalDocumentEmbedder path and LlamaIndex’s HyDEQueryTransform (verify the current import path as of July 2026 — APIs move). The vector store that holds the dense index — Weaviate, Qdrant, Milvus, and others — is interchangeable for the search step; HyDE changes what is embedded, not which database you use.

Runnable, pinned end-to-end code belongs with building the pipeline. Prove whether HyDE earns its latency on retrieval metrics for your own queries — the Gao table is the literature baseline, not your production score.

What is HyDE in RAG?

HyDE (Hypothetical Document Embeddings) asks an LLM to draft a fake answer to the user query, embeds that draft, and retrieves real documents by similarity to the hypothetical instead of to the raw question. The draft is discarded after retrieval; only real chunks reach the generator. The method was introduced by Gao, Ma, Lin and Callan (2022; arXiv:2212.10496).

How much does HyDE improve retrieval?

On Gao et al. (2022) Table 1, HyDE raises unsupervised Contriever nDCG@10 from 44.5 to 61.3 on TREC DL19 and from 42.1 to 57.9 on DL20, with DL19 recall@1k rising from 74.6 to 88.0. Those figures are for InstructGPT plus Contriever on those benchmarks — re-measure on your corpus before treating them as a production promise.

Does a wrong hypothetical break the final answer?

Not if the architecture is correct. HyDE uses the draft only as a search vector; Gao et al. (2022) note that false details are filtered by the encoder bottleneck as the vector is grounded to real corpus neighbours. The failure mode is leaking the hypothetical into the generation prompt — keep it out of the final context.

When should you skip HyDE?

Skip HyDE when queries are already long and specific, when they are identifier-heavy (prefer hybrid or BM25), when you cannot afford an extra LLM call on the retrieval path, or when a general model would invent domain jargon that does not exist in your corpus. Measure recall@k with and without HyDE on a golden set before making it default.

Is HyDE the same as query rewriting?

No. Query rewriting cleans or expands a question while it stays a question. HyDE changes the search text into a document-shaped passage so retrieval compares answer-to-answer. Depth on rewriting is at /retrieval/query-rewriting/; this page owns the HyDE mechanism.