HyDE: Hypothetical Document Embeddings
~15 min read
Questions aren't semantically similar to their answers, which hurts naive retrieval. HyDE fixes this by having the LLM generate a hypothetical answer first, then embedding THAT to search — even though the hypothetical answer may contain hallucinated details.
HyDE: Hypothetical Document Embeddings is a Pro topic
Sign in, then upgrade to Pro or Power to unlock this topic and the full AI Engineering curriculum.
Key points
- •Root problem: questions and their answers aren't semantically similar, so directly embedding the question retrieves irrelevant context
- •HyDE's fix: generate a hypothetical answer first, embed THAT instead of the question, then retrieve using the hypothetical's embedding
- •The hypothetical answer can and often does contain hallucinated details — this doesn't badly hurt retrieval
- •The contriever embedding model acts like a near-lossless compressor, filtering hallucinated specifics while preserving semantic shape
- •Trade-off: HyDE improves retrieval quality but adds latency and cost from the extra LLM call needed before retrieval even starts