liveBook · Manning

Hypothetical document

As explained in Retrieval Augmented Generation, The Foundational Ideas

A hypothetical document is a synthetic passage generated to provide a document-like semantic representation of a user's information need.

A short question may use different words from the documents that answer it. A hypothetical document is an LLM-generated, document-like passage that expresses what a relevant answer might discuss. In Hypothetical Document Embeddings (HyDE), the passage serves as a search representation, not as evidence or a final answer. section 7.0 section 7.1

The retrieval path is:

  • Generate a plausible passage from the user's query, using language likely to occur in relevant documents. section 7.2
  • Embed that passage instead of the original query and search the corpus for similar documents. Unlike query augmentation, HyDE replaces the query embedding for this search. section 7.2
  • Use retrieved corpus documents for factual grounding; discard the generated passage after retrieval. Its details may be false even when it points toward useful evidence. section 7.0 section 7.2

When vocabulary does not match

A patient asks why their chest hurts while climbing stairs, while relevant documents describe exertional substernal discomfort and myocardial ischemia. In a five-document comparison, BM25 retrieves neither relevant document in its top two, direct dense retrieval finds one, and retrieval using the imagined passage finds both. The passage helps by resembling the documents' register and vocabulary, not by proving a diagnosis. section 7.1

Listing 7.2 Three retrievers over the same corpus.
encoder = SentenceTransformer("all-MiniLM-L6-v2")
corpus_vecs = encoder.encode(corpus)
def dense_top2(text):  #A
    vec = encoder.encode(text)
    scores = util.dot_score(vec, corpus_vecs).numpy()[0]
    return np.argsort(scores)[::-1][:2]
 
bm25 = BM25Okapi([doc.split() for doc in corpus])
bm25_scores = bm25.get_scores(query.split())
bm25_top2 = np.argsort(bm25_scores)[::-1][:2]
runs = [("BM25", bm25_top2), ("Dense", dense_top2(query)),
        ("HyDE", dense_top2(hyde_doc))]  #B
for name, top in runs:
    recall = len(set(top) & set(relevant)) / len(relevant)
    print(f"{name:6s} R@2 {recall:.2f}   retrieved {list(top)}")
 

The retrieval comparison holds the corpus and encoder fixed while changing the search text from the query to the hypothetical document. section 7.1

This is useful when a query is sparse or colloquial and the corpus is specialized, as in medical retrieval. It can work without labeled relevance pairs, but a wrongly framed passage can retrieve the wrong material confidently. Generating several passages or combining the hypothetical and original query vectors can hedge against a bad generation; a reranker or groundedness check remains important. section 7.5 section 7.7

How Retrieval Augmented Generation, The Foundational Ideas covers it

How deep it goes
Explains generation, embedding substitution, corpus grounding, and failure mitigations, with a worked three-retriever comparison.
Examples
Compares BM25, dense retrieval, and HyDE on a chest-pain query and illustrates clinical-guideline retrieval for atrial fibrillation.
What it assumes
Builds on LLM generation and document embeddings; does not require labeled query–document relevance pairs.
What you can do after
Apply it via HyDE to search with a generated passage while grounding any final answer in retrieved documents.
How it connects
Connects to dense retrieval, query augmentation, zero-shot retrieval, reranking, and groundedness checks.

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.