A documentation search can miss the right page even when the answer is in the index. A short question and the document that answers it may use different language, causing the passage to be missed or ranked below loosely related results. Zero-shot retrieval tackles this without relevance-labeled examples or task-specific retriever fine-tuning. section 7.0
Hypothetical Document Embeddings (HyDE) turns the question into a document-like search target. An LLM writes a plausible answer passage; an unsupervised encoder embeds that passage; similarity search compares its vector with pre-indexed document vectors. The generated passage models relevance, not factual authority: it is discarded after retrieval, and the retrieved documents ground the final answer. section 7.0 section 7.3
Searching for deployment guidance
Suppose a new hire asks for deployment-pipeline best practices, but direct retrieval returns snippets about API keys and versioning rather than the central architecture document. HyDE instead generates a passage resembling the sought guidance and searches for documents similar to that passage. A plausible topic and terminology can help even if an invented detail in the passage is wrong; the encoder tends to preserve the broader relevance pattern. section 7.0 section 7.3
Listing 7.3 HyDE in LangChain.
from providers import get_chat_model, get_embeddings
from langchain_core.prompts import PromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_classic.chains.hyde.base import (
HypotheticalDocumentEmbedder)
llm = get_chat_model(temperature=0)
base_embeddings = get_embeddings()
prompt = PromptTemplate(
input_variables=["question"],
template=("Please write a passage to answer the question.\n"
"Question: {question}\nPassage:")
) #A
hyde_embedder = HypotheticalDocumentEmbedder(
llm_chain=prompt | llm | StrOutputParser(), #B
base_embeddings=base_embeddings,
)
query = "What are the best practices for a startup's user growth?"
hypothetical_doc_embedding = hyde_embedder.embed_query(query) #C
The LangChain example builds a passage-writing prompt, connects it to an LLM and base embeddings, then calls `embed_query` to produce the HyDE search vector. section 7.3
Table 7.1 HyDE zero-shot performance vs. baselines
|
Benchmark
|
BM25 (Lexical)
|
Contriever (Unsupervised Dense)
|
HyDE (Zero-Shot)
|
Contriever-FT (Supervised Dense)
|
|
TREC DL19
|
38.3
|
44.5
|
61.9
|
64.5
|
|
TREC DL20
|
35.8
|
43.1
|
60.1
|
62.1
|
|
BEIR (SciFact)
|
66.8
|
64.3
|
69.7
|
71.0
|
|
BEIR (FiQA)
|
26.9
|
30.5
|
38.8
|
48.1
|
The benchmark table compares HyDE with lexical, unsupervised dense and supervised dense baselines; it shows why a training-free approach is worth evaluating rather than assuming it matches supervised retrieval everywhere. section 7.3
Zero-shot does not mean cost-free or failure-proof. HyDE adds an LLM call per query, and a wrongly framed hypothetical answer can retrieve the wrong material confidently. Averaging several generated passages or combining the HyDE vector with the original query vector can hedge against a bad generation; a reranker or groundedness check remains useful downstream. For a new domain, the generation prompt can be adapted without retraining the retriever. section 7.3 section 7.7











