Your dense retriever performs poorly on terse user queries against prose heavy docs. How does HyDE (Hypothetical Document Embeddings) help, and via what mechanism?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
HyDE asks an LLM to draft a fake answer, embeds that draft instead of the query, and retrieves against it, moving the search anchor into the document cluster.
Imagine searching a library by handing the librarian your question scribbled on a sticky note: 'best espresso machine?' The shelves are full of long, formal product reviews, and your terse note doesn't look anything like them, so the match is weak. Now imagine you first write a short fake review yourself ('This machine pulls rich shots with a stable temperature') even if the details are wrong. You hand THAT to the librarian instead. It looks like the real reviews on the shelf, so the librarian finds genuine matches fast. HyDE does exactly this: an LLM writes a hypothetical answer document, you embed that document instead of the bare query, and you search with it. The fake answer can contain errors; what matters is that it shares the shape and style of the real documents.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 min: state the query-doc mismatch, explain HyDE's embed-the-fake-answer mechanism, note accuracy irrelevance, then cover cost/latency and when fine-tuning or hybrid wins instead.
# HyDE: embed a hypothetical answer, not the raw query
query = "best espresso machine for small kitchens?"
hyp_doc = llm.generate(
f"Write a short passage that answers: {query}"
) # may hallucinate; that's fine
hyp_vec = embed(hyp_doc) # embed the synthetic DOC, not the query
chunks = index.search(hyp_vec, top_k=5)
# optional: average with the raw query vector to reduce variance
# anchor = 0.5 * hyp_vec + 0.5 * embed(query)| Technique | What gets embedded | Retrains? | Main cost |
|---|---|---|---|
| HyDE | LLM-generated hypothetical answer doc | No | Extra LLM call per query |
| Raw dense retrieval | The user's query text | No | Cheapest, weakest on style gap |
| Multi-query expansion | Several LLM rewrites of the query | No | Multiple searches per query |
| Fine-tuned embeddings | Query + docs in aligned space | Yes | Training data + GPU time |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Thinking HyDE retrains or fine-tunes the embedding model. It does neither; it's a zero-shot runtime trick that only changes which text gets embedded for retrieval.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.