Query Transformation and HyDE: Correcting Distribution Shift in Embedding Space
A query is question-shaped and a document is answer-shaped, so a bare query sits off the document manifold and its nearest documents are mediocre. HyDE writes a hypothetical answer, embeds that, and retrieves real documents near it — landing back inside the manifold. It is pseudo-relevance feedback with a generated rather than a retrieved centroid, and it trades query-document mismatch for one honest new cost: generation bias, which no amount of Monte-Carlo averaging removes.
From expanding the query to transforming it
The previous topic on pseudo-relevance feedback fixed a vocabulary mismatch. A query said “rate guidance”; the relevant filings said “outlook” and “forecast” and never the word “guidance,” so the bare query missed them — until Rocchio and RM3 expanded the query with terms harvested from the top-ranked feedback documents and bridged the gap. That mechanism lives in term space: it adds words.
Dense retrieval moves the whole problem onto the sphere. A dual encoder maps the query and the document into one shared embedding space and scores them by cosine similarity, so there is no vocabulary to bridge — only geometry. And the geometry has its own version of the mismatch, sharper and harder to see. A query is question-shaped: “What did the company guide for next quarter?” A document is answer-shaped: three sentences of a 10-K stating the number. The two encoders are trained to bring a matched pair close, but the distributions they induce on the sphere do not coincide — questions cluster in one region, answers in another. A bare query therefore lands slightly off the document manifold, and its nearest documents are mediocre: close enough to be plausible, not close enough to be right.
We make this precise on the finance geometry the dense-retrieval topic built. Its document manifold is a set of unit company prototypes — one passage per company, grouped into sectors. We reuse that manifold exactly, and we build our own queries, because the dense topic drew its queries -tight on their own company, so its recall@1 is already — the “too-easy corpus” that would hide the very gap we want to study.
Definition 1 (The query–document gap).
Let be the unit embedding of company ‘s document (its answer prototype) and let be a fixed unit offset axis — the “generic document-ness” direction, taken as the normalized corpus centroid. A bare query for company at distribution-shift angle is the great-circle interpolation from the answer direction toward the offset axis,
plus a small von Mises–Fisher spread. At the query sits on the manifold (it is the answer direction) and recall@1 is . As grows every query is pulled toward the same generic axis , so the queries lose their company specificity and the document nearest starts to win regardless of which company was asked about. Recall@1 falls. The gap is not noise — it is a systematic rotation of the query distribution away from the document distribution.
Panel A of the laboratory traces this. At the operating shift the bare query’s recall@1 has fallen to : most queries retrieve the wrong company’s filing. The two-dimensional projection shows why — the bare query (hollow square) sits apart from the document cloud, nearer the generic center than the gold answer.
Numbers are baked from query_transformation_hyde.py's viz_constants(); the document manifold is the dense-retrieval finance geometry (8 company prototypes, dim 32), and the queries are drawn off it. A synthetic von Mises–Fisher generator stands in for the LLM.
HyDE: retrieve where the answers live
HyDE’s move is disarmingly simple. Do not retrieve with the query. Instead ask a language model to write a hypothetical answer — a fake document that would answer the question if it existed — embed that, and retrieve real documents near its embedding. The hypothetical need not be factually correct; it only needs to land in the right neighborhood of the document manifold. A generated paragraph about a company’s revenue guidance, however invented its numbers, embeds like a 10-K passage, not like a question. It is answer-shaped by construction.
Proposition 1 (HyDE corrects the distribution shift (demonstrated)).
Model the generator as drawing a hypothetical document from a von Mises–Fisher distribution centered at the answer direction . Because lives on the document manifold near , retrieving with recovers the gold document — independently of the bare query’s distribution-shift angle . HyDE ignores where the query landed and synthesizes an on-manifold proxy in its place. On the finance geometry a faithful generator recovers recall@1 at every , against the bare query’s at — the flat green line above the collapsing red one in Panel A.
The collapse anchor pins the construction: a perfect hypothetical — infinitely concentrated, faithful — is exactly the gold document , so HyDE retrieval with it reproduces the gold document’s own retrieval byte-for-byte (top-1 is the answer, and the full ranking is identical). The notebook asserts this for every company.
That HyDE’s recall does not depend on is the whole point, and worth dwelling on. The bare query’s position in embedding space carries the distribution shift; HyDE discards that position and keeps only the query’s intent, which the generator re-expresses in the document distribution’s own dialect. Distribution shift cannot survive a step that re-samples from the target distribution.
Averaging hypotheticals: a Monte-Carlo estimator with a bias floor
One hypothetical is a noisy draw. HyDE in practice averages several — generate hypothetical documents, embed each, and retrieve with the normalized mean . This is precisely a Monte-Carlo estimator of the generation distribution’s center, and it inherits that estimator’s two-sided behavior.
Proposition 2 (Variance falls toward the 1/k rate (demonstrated)).
For a faithful generator, is a consistent estimator of the answer direction — the maximum-likelihood mean-direction estimate of the von Mises–Fisher samples. Its angular deficit falls monotonically in and approaches the Monte-Carlo rate asymptotically: each doubling of drives the deficit-halving ratio toward . On the finance geometry the deficit falls across , and as the estimate sharpens, recall@1 rises with from toward (Panel B, the green curve). Averaging denoises the hypothetical.
So far this only argues for sampling more. The honest result is the other side of the estimator.
Proposition 3 (Hallucination bias is irreducible (demonstrated)).
Suppose the generator hallucinates on a fraction of queries — for those, it writes a document about the wrong company, so its generation center is not but a wrong direction. Then is consistent for the wrong center: while stays bounded away from , and the query retrieves the wrong document no matter how large is. Recall therefore plateaus at a ceiling near : on the finance geometry the large- recall is , , at hallucination rates (Panel B, the dashed reference lines). Averaging reduces variance; it cannot reduce bias.
This is the load-bearing honesty of HyDE, and the cleanest way to state what it costs.
HyDE is the neural generalization of pseudo-relevance feedback
Step back and the shape is familiar. Rocchio’s relevance feedback moves a query toward the centroid of pseudo-relevant documents, ; RM3 does the language-model version. HyDE is the same update, lifted onto the sphere, with one substitution: the centroid is taken over generated hypotheticals instead of retrieved documents.
Proposition 4 (Generated feedback beats retrieved feedback on an off-manifold query (demonstrated)).
Write the embedding-space update , renormalized; is the bare query and is the pure pseudo-document (canonical HyDE). Two ways to form the centroid:
- HyDE — the mean of generated hypothetical embeddings. On an off-manifold query this centroid is clean (the generator is answer-shaped), so recall climbs from at to at and at — a little of the original query mixed in is even slightly better than the pure hypothetical.
- Real pseudo-relevance feedback — the mean of the bare query’s top-retrieved documents. Here the feedback is polluted: the off-manifold query retrieves the wrong documents, so its centroid points the wrong way and recall falls from to as grows.
Panel C shows the two curves diverging. The lesson is exactly when the neural generalization earns its keep: classical relevance feedback bootstraps from retrieved documents, so it inherits the bad query’s mistakes; HyDE bootstraps from a generator that never saw the corpus, so a bad query cannot poison it.
The ancestry is not just an analogy — the notebook imports the pseudo-relevance-feedback module and reruns its term-space RM3 and Rocchio, reproducing the prerequisite’s improve-then-drift curve (recall@4 with a little feedback, drifting back to when the feedback set over-expands). That is the inset in Panel C. HyDE inherits the improvement and, by generating rather than retrieving its feedback, sidesteps the drift that comes from feeding back the wrong documents.
Where this sits
HyDE is a query-side transform: it runs before retrieval, spending one generation call to move the query onto the document distribution. Read alongside its sibling on retrieval versus long context, the two are the same rate-distortion trade taken on opposite sides of the pipeline — long context spends read-time compute to lower answer distortion; HyDE spends generate-time compute to lower retrieval distortion. Both are governed by the same geometry of the finance manifold, and both are honest about the cost.
What HyDE leaves open is the quality of the thing it generates. Its whole risk is concentrated in whether the hypothetical is faithful to the question’s intent — a property we have so far only modeled with a hallucination rate . Turning that rate into a measured quantity, on real generated text rather than a synthetic von Mises–Fisher knob, is the next step.
Connections
- The dual encoder is the architecture whose shared embedding space the gap lives in; we reuse its finance document manifold (one vMF company prototype per passage) and its separable score, then build off-manifold queries the dense topic's own tight queries never exhibit. dense-retrieval-dual-encoders
- HyDE is the neural generalization of this topic: Rocchio/RM3 move the query toward the centroid of pseudo-relevant retrieved documents; HyDE moves it toward the centroid of generated ones. We import its term-space RM3/Rocchio to reproduce the improve-then-drift curve HyDE inherits. pseudo-relevance-feedback
- The hypothetical document is a von Mises–Fisher draw near the answer prototype, and averaging k of them is a mean-direction estimator — the sphere geometry and the sampler come straight from this topic. hypersphere-vmf-geometry
- Its sibling in the generation-grounding track asked how much context to read; this one asks what to retrieve in the first place. Both are distortion-versus-rate trades on the same finance geometry — HyDE buys recall by paying a generation call up front. retrieval-vs-long-context
References & Further Reading
- paper Precise Zero-Shot Dense Retrieval without Relevance Labels — Gao, Ma, Lin & Callan (2023) HyDE: generate a hypothetical answer document, embed it, and retrieve real documents near it — zero-shot dense retrieval with no relevance labels.
- paper Dense Passage Retrieval for Open-Domain Question Answering — Karpukhin, Oğuz, Min, Lewis, Wu, Edunov, Chen & Yih (2020) DPR, the dual encoder whose shared query/document embedding space is where the distribution-shift gap appears.
- paper Improving Retrieval Performance by Relevance Feedback — Salton & Buckley (1990) The definitive treatment of Rocchio relevance feedback in the vector space model — the q' = a·q + b·centroid update HyDE lifts into embedding space.
- paper Relevance-Based Language Models — Lavrenko & Croft (2001) RM1/RM3, the relevance-model view of pseudo-relevance feedback that the prerequisite implements and this topic imports.
- book Introduction to Information Retrieval — Manning, Raghavan & Schütze (2008) Chapter 9: relevance feedback and query expansion, the classical ancestor of query transformation.