MMOOZZGG.com

Glossary

What are hypothetical document embeddings (HyDE)

In short

HyDE (hypothetical document embeddings) is a search technique in which the model first writes a sample answer to the question, and the system then looks for documents similar to that answer, not to the question itself.

Search and RAG · hypothetical document embeddings

MMOOZZGG.com editorsChecked: 2 min read

For a child

You are looking for a beach photo in an album but do not remember where it is. So you draw on a sheet of paper roughly what you remember: sand, waves, an umbrella. Then you leaf through the album and look for a picture like your drawing. The drawing may be inaccurate, but it helps you find the real photo. HyDE does the same with texts.

In plain words

A short question and a long paragraph of a document are written differently, so search by meaning does not always bring them together. HyDE solves this with a workaround. First, the AI writes an invented answer to the question that looks like a page from a manual. It may contain errors, and that is fine. Then this text is turned into numbers, and the system looks for real documents in the base that are close to it. What it finds looks like an answer in form and words. For example, for the question how to connect a cash register to the accounting software, the model writes a paragraph in the style of instructions, and the search finds the real sections of the manual.

For business

The technique is useful when you have no labeled examples of a question and the right document and no time to fine-tune search: it works with ready-made models. It is designed for short questions to long formal documents. The cost: each search needs a call to a generative model first, so the answer gets more expensive and slower. There is a risk in narrow topics: if the model knows the subject poorly, the invented answer leads the search astray, and with wrong terms it finds the wrong documents. The invented text is not shown to the user; it is only for search. Whether this extra delay is worth it is checked on a set of real requests before the assistant goes live.

For a specialist

HyDE (hypothetical document embeddings) was proposed by Gao, Ma, Lin and Callan (2022) for dense retrieval without labeled relevance pairs (zero-shot dense retrieval). The pipeline has two steps. An instruction-following generative model (InstructGPT in the paper) writes a hypothetical document for the query: it may contain factual errors but carries the relevance pattern. Then an encoder trained without supervision in a contrastive way (Contriever in the paper) encodes this document, and search runs by the closeness of its vector to the corpus vectors. As the authors intend, the dense bottleneck of the encoder filters out the extra details of the invented text. By their data, HyDE clearly outperforms Contriever and is comparable to fine-tuned retrievers on web search, question answering, fact checking and several languages. In the paper, N hypothetical documents are generated and their vectors averaged, in one variant together with the vector of the query itself. The technique belongs to query optimization before retrieval, next to query rewriting and query expansion.

Example

A client writes: the register cannot see the accounting app. The model writes a paragraph in the style of instructions about setting up the data exchange between the register and the accounting software, and the search finds the right section of the manual, even though the client’s words are not in it.

Related terms

Questions and answers

Why does HyDE work if the invented answer may be wrong? For search, what matters is not the accuracy of the facts but the form and vocabulary of the text. The invented answer resembles real documents in style and terms, so its vector lands closer to them than the vector of a short question.
When should you not use HyDE? When the model knows the topic poorly and invents the wrong terms, and when every fraction of a second matters. Each search needs an extra call to a generative model.

Sources

Where companies use it

Not sure whether your company needs this?

AI solutions map
Contact us