liveBook · Manning

Zero-shot learning

As explained in Retrieval Augmented Generation, The Foundational Ideas

Zero-shot retrieval is retrieval performed without relevance-labeled examples or task-specific fine-tuning of the retriever.

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

How Retrieval Augmented Generation, The Foundational Ideas covers it

How deep it goes
Works through HyDE’s generate–embed–search procedure and an implementation sketch, while leaving broader pipeline integration beyond the simplified code.
Examples
Uses a missed deployment document, a LangChain embedding example and benchmark comparisons with BM25, Contriever and supervised dense retrieval.
What it assumes
Introduces zero-shot prompting as instruction-only prompting and builds retrieval from an off-the-shelf LLM and unsupervised encoder.
What you can do after
Apply it via LangChain’s HypotheticalDocumentEmbedder and evaluate its retrieval gains against the extra LLM call and wrong-framing risk.
How it connects
Connects dense retrieval to hypothetical document embeddings, unsupervised contrastive encoders, query expansion, reranking and groundedness checks.

Also explained in

Compare how 12 books explain zero-shot learning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Retrieval Augmented Generation, The Foundational Ideas. The section links point to the parts of the book it draws on.