Lossy compression produces a smaller representation by discarding information. In dense retrieval, an encoder squeezes prose into a fixed-size vector, preserving topical patterns while dropping surface details. section 7.3
Semantic filtering in retrieval
A hypothetical document may contain a wrong date or name, yet its vector can still support retrieval because the dense bottleneck filters detail-level errors. This protection fails when the generated text uses the wrong framing or subject area. section 7.3
The same tradeoff appears in familiar media formats and text embeddings:
- JPEG discards visual details people are unlikely to notice. section 7.3
- MP3 discards audio details people are unlikely to hear. section 7.3
- A text encoder maps a paragraph to a vector containing a few hundred to a thousand numbers. 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
Shows a HyDE pipeline that generates a hypothetical passage and embeds it for retrieval. section 7.3
