# What Is HyDE?

> What HyDE is, how a made-up answer helps find real documents, its costs and limits, explained simply for your AI interview.

**In short:** HyDE, short for hypothetical document embeddings, has an AI model first write a made-up answer to the question, then searches with that answer instead of the raw question. Real documents that look like the answer come back, which helps when the question and the documents use different words.

AI and LLM interview question Q128, Retrieval-augmented generation (RAG). Advanced, occasional (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-hyde

## Say it in 30 seconds

HyDE stands for hypothetical document embeddings. When a question comes in, the model first writes a short made-up answer. The search then looks for real documents that match that made-up answer. The made-up text can have wrong details, but only real documents come back, so HyDE helps when people and documents use different words. It adds several model calls per question, because the paper samples several made-up answers and combines their vectors, so I measure it against plain search before I use it.

## Say it in 2 minutes

HyDE stands for hypothetical document embeddings. It comes from a 2022 paper by Luyu Gao and three co-authors. The idea starts from a gap: a customer's short question and the formal policy clause often use different words, so a plain search can miss the clause that answers it.

The steps are simple. First, a language model, the kind that follows written instructions, writes a made-up answer to the question. Second, an encoder turns that made-up answer into a vector, a list of numbers that stands for its meaning. Third, the app searches the stored document vectors for the nearest ones and returns those real documents. The made-up answer can contain false details, but the paper expects the encoder to filter out the wrong details, because it compresses the text into one vector.

The trade-offs are real. Every question costs several extra model calls before the search starts, so it adds delay and cost. The made-up answer is only as good as the model that writes it, and the paper found bigger models gave bigger gains. HyDE needs no training, which makes it useful at the start of a project. Once there are enough labelled questions, a trained retriever may do better.

In an interview, I would say it in one breath: write a made-up answer, search with it, return the real text, and measure it against plain search before using it in production.

## What is HyDE, in plain words?

HyDE is a way to search by meaning when the question and the documents use different words. Before it searches, an AI model writes a short, made-up answer to the question. The search then uses that made-up answer to find real documents that look like it.

Picture a claims handler at an insurer who gets a call: a customer's phone was smashed, and they ask whether it is covered. She doesn't flip through the policy from the first page. She first imagines the clause she expects to find, then looks for the clause that reads most like it. HyDE does the same for an AI app, with the model playing the handler.

The same thing happens in a real claims assistant. The customer types short, casual words, such as "Do I get money back if my phone gets smashed?", while the policy uses formal wording like accidental damage and waiting period. A plain search on the customer's words can miss the clause that answers them.

- **Embedding:** A list of numbers that stands for the meaning of a piece of text. Similar meanings get similar numbers.
- **Hypothetical document:** Made-up text that answers a question. It may be wrong, so it is only used to search.
- **Encoder:** The model that turns a piece of text into an embedding.
- **Vector search:** Finding the stored embeddings that sit closest to the question's embedding.
- **Corpus:** The stored documents that the search covers, such as a policy library.

## How does HyDE work, step by step?

The app runs four steps for each question. The chart shows them from left to right.

*Diagram, How HyDE finds the right clause: The customer's question goes to a model, which writes a made-up answer. An encoder turns that answer into a vector, and the search finds the closest stored documents. The real clause that comes back is the one the answer points to.*
1. The question goes to the model, which writes a made-up answer.
2. The made-up answer goes to the encoder, which turns it into numbers.
3. Those numbers are compared with the numbers of every stored document.
4. The closest real clause comes back. The made-up text stays inside the search.

1. **Ask the model for a made-up answer:** The prompt is simple, such as "write a document that answers the question". No training is needed for this step.
2. **Turn that answer into a vector:** An encoder turns the made-up text into a list of numbers that stands for its meaning. The paper used Contriever, a published encoder, for this.
3. **Search the stored document vectors:** The app finds the stored document vectors closest to the made-up answer's vector. Closeness is a score for how alike two lists of numbers are, called vector similarity.
4. **Return the real documents:** The made-up text is used only for the search. The real documents are what come back, so the answer can point to text a person can check.

> "Given a query, HyDE first zero-shot instructs an instruction-following language model (e.g. InstructGPT) to generate a hypothetical document." (The HyDE paper, 2022)
>
> "the generated document is not real, can contain factual errors but is like a relevant document" (The HyDE paper, on the made-up document)

## Why does a made-up answer help the search?

The made-up answer copies the shape and wording of a real answer, even when its facts are wrong. A search that compares meanings can then land near the documents that really answer the question. The paper expects the encoder to filter out the wrong details, because it compresses the text into one vector.

- **Raw question: Few shared words.** Only money and back match the refund note, so the search picks the refund rule and misses the damage clause.
- **HyDE's made-up answer: Words that match the clause.** Accidental damage, repaired, waiting period and screen all match the damage clause, which is the right one.

Here is a small version in plain Python. No real model runs in it, so the made-up answer is typed in by hand, and word overlap stands in for embeddings. The marked lines are the ones that matter.

```python
# A simplified HyDE step. The made-up answer is typed in, because no real model runs here.
# Word overlap stands in for embeddings, so the code runs with no libraries.
CHUNKS = {
    "damage": "Accidental damage, such as a cracked screen, is repaired after a 30-day waiting period.",
    "refunds": "Refunds: money is paid back only in the first 14 days of the plan.",
    "upgrades": "Upgrades to a newer model are not covered by the plan.",
}

def words(text):
    return set(text.lower().replace("?", "").replace(",", "").replace(".", "").replace(":", "").split())

def best(text):
    return max(CHUNKS, key=lambda name: len(words(text) & words(CHUNKS[name])))

question = "Do I get money back if my phone gets smashed?"
hypothetical = "A smashed phone screen is accidental damage. Accidental damage is repaired or replaced after the 30-day waiting period has passed."

print("raw question ->", best(question))
print("hypothetical ->", best(hypothetical))
```

Output:

```text
raw question -> refunds
hypothetical -> damage
```

The raw question shares only two words with the refund note and none with the damage clause, so it picks the wrong passage. The made-up answer shares ten words with the damage clause. A real system swaps word overlap for embeddings, which catch meaning rather than exact words.

## What are the trade-offs and limits?

HyDE is attractive because it needs no training. The paper says so directly, and it reports that a bigger generating model helped more:

> "No model is trained in HyDE: both the generative model and the contrastive encoder remain intact." (The HyDE paper, on training)
>
> "with larger models bringing larger improvements" (The HyDE paper, on model size)

The costs are simple to name. Each question needs several extra model calls, one per sampled made-up answer, which adds delay and cost to every search. The made-up answer is only as good as the model that writes it, and it can state false facts, so it must only steer the search and never become the answer.

Where it fits best is early in a project. The paper says HyDE is more powerful and irreplaceable when few relevance labels are present, meaning when nobody has yet marked which documents answer which questions. As a search log grows with labelled examples, a trained retriever can take over more of the work.

### How would you use HyDE in a claims assistant?

A mid-size insurer wants its assistant to answer policy questions from 40,000 pages of wording. In a test run with made-up numbers, plain search misses about one question in five. I would not switch everything to HyDE on day one. I would run it as a second search beside keyword search, merge the two lists, and keep the made-up answer out of the reply.

1. **Build a labelled test set:** About 200 real customer questions, each with the clause that answers it. The labels are the ground truth the search is judged on.
2. **Compare the three search lists:** Measure plain search, HyDE and the merged list on the same questions before choosing one.
3. **Watch cost and delay:** Each question adds several model calls. Set a budget per question and alert the team when the average rises.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: the model writes a made-up answer, and search uses it.
- [ ] Why it works: the made-up answer uses the wording of real documents.
- [ ] The trade-off: several extra model calls per question, and possibly wrong details.
- [ ] Why the encoder matters: it turns the text into a vector and filters detail.
- [ ] When to use it: few labelled questions, and a test against plain search.
- [ ] Honesty: the paper's results come from public benchmarks such as TREC DL and BEIR, so measure on yours.

**Common traps**

- Trap: "The model answers the question, then we return that answer." Better: The made-up answer only drives the search. The real documents are what come back, so the answer can cite them.
- Trap: "HyDE makes the search more accurate in every case." Better: The paper reports gains on public benchmarks, such as TREC DL and BEIR. Measure on your questions before you trust it.
- Trap: "Retrain the embedding model on our questions first." Better: HyDE needs no training. That is its appeal, so start there and add training only if the numbers ask for it.

## Can you spot the problem?

**Spot the problem:** Your team builds a HyDE step for an insurer's claims search. Which setup is the risky one?

A. The model writes a made-up answer, and the search uses its vector to find real clauses.
B. The made-up answer is shown to the customer as the policy wording.
C. Plain keyword search runs beside HyDE, and both lists are merged.
D. Each question's model call is logged, so cost can be tracked.

**Answer:** B. Showing the made-up text as policy wording presents a guess as fact, and HyDE's made-up text can contain false details. Only the real documents should go back to the customer.

**Quick check:** Why does HyDE search with a made-up answer instead of the raw question?

A. The made-up answer is always true, so it is safer to search with.
B. It uses the wording a real answer would use, which can match the right documents.
C. The model replaces the vector index.
D. It needs no encoder at all.

**Answer:** B. A made-up answer uses the wording a real answer would use, so its embedding can land near the right documents. It can be wrong in its facts, so it is never the source of the answer. HyDE still uses an encoder and a vector index.

## Can you answer these from memory?

**Flash cards**

- **What does HyDE stand for?** Hypothetical document embeddings.
- **What does the model write first?** A made-up answer to the question, which may contain false details.
- **What gets searched?** The made-up answer's embedding. Real documents come back.
- **Does HyDE need training?** No. The paper says no model is trained in HyDE.
- **What is the main cost?** Several extra model calls for every question, one per sampled made-up answer.
- **When was the paper submitted?** December 2022, by Gao, Ma, Lin and Callan.

## Likely follow-up questions

- Q127 What are query rewriting and expansion? https://designervenkat.online/interview/ai/what-are-query-rewriting-and-expansion
- Q123 What is hybrid search (BM25 + vectors)? https://designervenkat.online/interview/ai/what-is-hybrid-search
- Q126 Rerankers: cross-encoder vs bi-encoder? https://designervenkat.online/interview/ai/cross-encoder-vs-bi-encoder-rerankers
- Q131 Retrieval metrics: recall@k, MRR, nDCG? https://designervenkat.online/interview/ai/retrieval-metrics-recall-at-k-mrr-ndcg
- Q120 How does HNSW work? https://designervenkat.online/interview/ai/how-does-hnsw-work
- Q129 What is metadata filtering? https://designervenkat.online/interview/ai/what-is-metadata-filtering

## Learn it in depth

- [Embeddings for builders](https://designervenkat.online/learn/ai-engineering/embeddings)
- [Performing Similarity Search](https://designervenkat.online/learn/ai-engineering/performing-similarity-search)
