HyDE
Hypothetical document embeddings
Asks a language model to write a fake answer to the question, embeds that fake answer, and uses it as the vector query to find real passages.
In DocSlurpIllustrated explainer
On this page
The problem: questions look like other questions
Vector search embeds your question and returns the passages whose vectors point the same way. That works only if a question and its answer embed close together, and often they don’t. A question is short, interrogative and full of the asker’s words: “How fast can my assistant get the Learjet to London?” The answer is declarative and full of the author’s words: “Once the travel desk confirms a request, the aircraft is wheels-up for Farnborough within three hours.”
Embedding models put text that reads alike close together. So the question’s nearest neighbors are often other questions: a FAQ heading, a launch review line saying “the team kept asking how fast the jet could get to London”, a ticket. The page that actually answers can rank below all of them.
The trick: search with a fake answer
HyDE (hypothetical document embeddings, Gao et al., 2022) changes what gets embedded:
- Ask a language model to write a short passage that would answer the question. It doesn’t need to know the real answer; it needs to sound like a document.
- Embed that passage instead of the question.
- Run normal vector search with that embedding.
- Return real passages from your corpus. The fake answer is thrown away.
The model might write: “The Learjet can fly to London once the travel desk books it, within 8 hours.” The number is wrong (the guide says three hours), and that doesn’t matter. The draft talks about the jet, bookings, the travel desk and hours in the declarative style of a travel guide, so its embedding lands among travel-guide passages, right next to the real answer.
Work it through
Two dimensions, illustrative numbers. Each vector is already unit length, so cosine similarity is just the dot product.
| Vector | Coordinates |
|---|---|
| q, the question | (0.42, 0.91) |
| h, the fake answer | (0.88, 0.47) |
F, travel-desk-guide.pdf p.3, the real answer |
(0.92, 0.39) |
X, launch-review.pdf p.9, “the team kept asking how fast…” |
(0.30, 0.95) |
| F (answer) | X (question-like) | |
|---|---|---|
| q · | 0.42 × 0.92 + 0.91 × 0.39 = 0.74 | 0.42 × 0.30 + 0.91 × 0.95 = 0.99 |
| h · | 0.88 × 0.92 + 0.47 × 0.39 = 0.99 | 0.88 × 0.30 + 0.47 × 0.95 = 0.71 |
Searching with the question ranks the launch review line first (0.99) and the answer second (0.74). Searching with the fake answer flips them: the real answer scores 0.99. The fake answer was wrong about the facts and right about the neighborhood.
The rule: the hypothesis is a probe, never evidence
The draft exists only to produce a vector. It must never be shown as an answer, quoted or cited. In the figure it is crossed out at the citation step: what the user sees is the real travel desk page, with its real “three hours”. If a system leaks the hypothesis into the answer, it has turned a retrieval trick into a hallucination machine.
Where it breaks
- A wrong premise steers the search. If the model misunderstands the question, its draft points at the wrong neighborhood, and the search confidently retrieves passages about the wrong thing. Questions about your own internal names are risky: the model has never heard of “Bravo” and will guess.
- It adds a model call before every search. Latency goes up by one generation, and each query costs tokens. For short, keyword-like queries the gain is usually small.
- It helps vector search only. Keyword search gains nothing from a fluent paragraph, and feeding it the hypothesis would match the draft’s invented details. Keep the original words for the keyword side of hybrid search.
- The paper’s setting is zero-shot. HyDE was proposed for dense retrievers trained without relevance labels. Embedding models fine-tuned on question-answer pairs already pull questions toward answers, so the gap HyDE closes may be smaller. Measure it on your own queries.
When to use it
Try HyDE when users ask full natural-language questions over documents written in a different register: policy manuals, research papers, travel guides. Skip it for lookups of codes, names and titles, where the question already contains the words the answer uses.
In DocSlurp, HyDE is off by default and turned on per request (hyde: true) or per project. It asks for a 2 to 3 sentence neutral passage, treats the query as untrusted input in the prompt, and falls back to the plain query if the model call fails or returns nothing. The hypothesis replaces the query only for the vector branch; keyword search and reranking still use your original words, and the citations always come from retrieved passages.
In DocSlurp
In DocSlurp
Off by default; turn it on with hyde: true or the project default useHyDE. hydeExpand asks for a 2 to 3 sentence passage (at most 150 output tokens) and falls back to the original query on any failure (core/server/src/search/hyde.ts). Only the vector branch uses the hypothesis; keyword search and reranking keep your words.