# Query Rewriting and Expansion # Book: Retrieval From First Principles # Chapter URL: https://programmer.ie/books/retrieval/17-chapter/ # Prose fingerprint (sha256, normalized): 634bfcb3f23154931941808be80d9e05fe20138df36a0c2c0bacd83b17a8d0a4 # Snapshot generated at build time by Hugo. This is the complete rendered prose # of the chapter; it is not a transcript of the source file. The request says purge scratch buffer. The useful handbook passage uses different words: it describes a temporary cache and gives the command for clearing it. The original lexical query misses that required evidence. Appending temporary cache from the development glossary gives the same lexical scorer terms it can match. Nothing about the source or the ranking algorithm has changed; only the search expression has. But a successful vocabulary bridge is not a licence to expand every short expression. In the fictional collection, DR window may mean device recovery or disaster recovery. Substituting the latter would turn an unresolved request into a specific one without evidence that the user intended that sense. The same operation that helps one query can distort another. Understanding Queries and Routing chose which search mechanism to invoke while leaving the user’s words intact. This chapter holds the mechanism lexical and changes the expression sent to it. The design problem is not merely whether added terms retrieve something; it is whether the transformation remains accountable to the original information need. Name the operation rather than calling everything a rewrite These operations should not share one undifferentiated label. Normalisation alters a representation, for example by collapsing whitespace. Synonym or glossary expansion adds terms meant to express the same concept. A rewrite rephrases the request as a whole. Acronym expansion or entity disambiguation commits to a particular meaning or referent. Multi-query retrieval keeps several expressions and combines their results. Each operation can change recall or ranking, but the risk of silently changing the need is not the same. Operation What changes Where the risk sits Normalisation The representation only, such as whitespace or case Low risk to meaning; losing or altering an identifier is still a defect Glossary or synonym expansion Terms added to the searched expression Added terms may express a different concept than the request Rewrite The expression as a whole The reworded request can drop a constraint or a literal identifier Acronym expansion or entity disambiguation A meaning or a referent is committed to Picks one sense or one entity; DR window and the two Rowan organisations are the chapter’s examples Multi-query retrieval Several expressions are searched and their ranks fused Costs an additional call, and can change the order of evidence that was already found Only the first row is a pure representation change. The remaining four can alter which evidence is reachable, so each needs its own record, its own comparison and its own declared limits. The authors’ textbook treatment of query expansion distinguishes vocabulary and thesaurus expansion from feedback based on retrieved documents. Pseudo-relevance feedback takes leading results as a provisional source of useful terms. If those results are merely topical rather than sufficient, feedback can reinforce the mistake and shift later retrieval further from the need. Our executable glossary uses fixed author-written terms, not retrieved-document feedback. A language model is not required to expose the fundamental choice. A deterministic glossary can connect two expressions of the same concept, and a deterministic forced-sense rule can make an unjustified commitment just as clearly. Both outcomes are inspectable without attributing linguistic understanding to the code. Generation changes the mechanism but does not remove the distinction. Query2doc generates a pseudo-document from the request and combines it with the original query for search. HyDE instead encodes a hypothetical document and uses its vector to retrieve real documents. Document expansion by query prediction shifts generation to indexing, adding predicted query terms to a document’s searchable representation. The three approaches differ in what is generated, when the cost is paid and which stored representation must be invalidated after a change. In none of these approaches does generated wording become evidence about the world. A hypothetical document may be inaccurate yet still lead a search toward useful vocabulary or a nearby vector. That search benefit does not validate its claims. The returned evidence must still resolve to a real source representation, with the generated feature kept separate from the cited text. Our target-derived glossary is not an experiment on Query2doc, HyDE or document expansion. Keep a transformation record The reformulation interface starts from a plan containing the unchanged original request. Its output records the transformed query, transformation type, terms added, their source, the rationale, unresolved uncertainty, and the source allowance and budgets inherited from the caller. Both the original expression and the one actually searched remain available for replay and inspection. For example: original: purge scratch buffer ZX-68 added terms: temporary cache source: author-written, target-derived development glossary new query: purge scratch buffer ZX-68 temporary cache The implementation requires literal identifiers to survive exactly. It cannot drop ZX-68 in pursuit of a smoother sentence or silently replace it with a similar code. It also cannot enlarge the source allowance set by the trusted caller. Those checks prevent two concrete classes of drift, but they do not establish that every added word preserves the user’s intent. A structurally valid rewrite can still express the wrong sense. The glossary also connects regain access to credential-recovery vocabulary and leave a building to evacuation vocabulary. It is target-derived: the author chose exact terms appearing in the passages these queries were intended to find. Freezing those choices before the final comparison prevents post-result editing of this particular glossary; it does not make the choices independent of the targets. The final worlds also reuse the source designs documented in Understanding Queries and Routing. What is established is narrower and more useful than a general claim for rewriting. The code records a transformation, preserves exact identifiers, adds chosen vocabulary within a fixed budget and measures the evidence selected afterward. Because the vocabulary was selected with knowledge of the targets, the comparison does not test whether an independently designed expander would find appropriate terms for unfamiliar needs. When a phrase is ambiguous, the accepted transformation preserves that ambiguity and records it. A separately labelled unsafe teaching control instead forces DR to mean disaster recovery. Comparing the two exposes exactly where a rewrite stops offering search vocabulary and starts asserting an interpretation the request did not authorise. Hold the search allowance still The original and expanded lexical queries are compared under the same allowance: one search, at most six candidates, four selected units and a 900-character evidence-body cap. They use the same source-anchored needs and the same currently eligible corpus. This isolates the effect of changing the expression for the stated outcome measures; it does not equalise every underlying computation. Multi-query retrieval changes more than the words. When a glossary rule applies, it sends the original and expanded expressions through separate searches at depth three each, then fuses their ranks. That is two logical calls and no more than six returned generator rows before union. When no expansion applies, it uses only the original search. The final evidence-body and unit caps remain unchanged. Two depth-three lists are not interchangeable with one depth-six expanded-query list. A relevant item ranked fourth on one expression can disappear before fusion, while an item high in both lists can gain position through agreement. The additional call therefore buys a different candidate and ordering policy, as well as extra work; neither benefit is guaranteed. Inspect gains and ordering losses together On the twenty constructed final requests, sixteen have non-empty target bundles: Lexical query policy Complete target bundles Mean selected characters Mean calls Original 4/16 141.85 1.0 Expanded expression 7/16 153.40 1.0 Original plus expansion 7/16 149.90 1.2 Only four of the twenty requests activate the glossary: evacuation, credential recovery, cache clearing and identifier-bearing cache clearing. The first three account for every additional covered bundle; the identifier-bearing cache request was already covered without expansion. The other sixteen search expressions remain unchanged. Thus the absence of a bundle regression in this sample is a narrowly constrained finding, not evidence that expansion is generally safe: the rules rarely fire, and their added terms were chosen from target passages. The mirrored development coverage likewise rises from 4/11 to 7/11, but the development and final worlds are not independent designs, as Chapter 16 explains. The multi-query method also demonstrates a loss that bundle coverage alone conceals. For each of the three newly covered needs, expansion alone places a required anchor first; fusion places that anchor second. The complete bundle is still covered, but its first-anchor reciprocal rank falls from one to one half. Averaged over all sixteen target needs, first-anchor reciprocal rank falls from approximately .5208 for expansion alone to .4271 for multi-query fusion. Under these declared list depths and fusion settings, the extra search supplies neither an additional complete bundle nor earlier required evidence in the cases it was meant to help. It is a result about this fixed multi-query policy, not about every way to fuse rewritten queries. The settings were not altered after the observed loss. Do not score ambiguity as a successful rewrite For DR window, both the original and safe-expanded lexical searches surface device-recovery and disaster-recovery material. The unsafe control adds more results after forcing a disaster-recovery interpretation. By contrast, the accepted routing policy leaves the meaning unresolved. Finding more material for one possible sense is not the same as resolving which sense the user intended. Because the request lacks disambiguating information, this case has no accepted evidence bundle and its relevance metric is undefined. Additional disaster-recovery hits cannot be scored as a gain. Nor do the traces prove that disaster recovery was not the user’s intended meaning. What the unsafe control demonstrably does wrong is commit to that meaning without evidence; it does not demonstrate a downstream false answer. The same issue appears with entities. The public catalogue contains two organisations named Rowan. A rewrite that turns the shared display name into one canonical entity identifier has chosen an organisation, not merely improved spelling or search vocabulary. Unless other evidence disambiguates the request, the transformation must keep both possibilities open. Preserve the data boundary A retrieved note can contain tempting search terms, misleading assertions or hostile instructions. All remain source data. None may enlarge the allowed sources, reset the call budget or become a user instruction merely because it appeared in a result. This implementation uses a frozen author-written glossary; it does not execute retrieved content or promote that content into control logic. No LLM rewriter, pseudo-relevance-feedback loop, general intent-preservation test or downstream answer evaluation was run. The three glossary gains show what target-derived vocabulary can recover in this construction. They cannot justify unsupported assertions, broad expansion or confident acronym and entity choices. Those would require separately designed tests with new needs and explicit drift judgements. Rewriting can change which passages are found; it cannot by itself join facts scattered across them. The contact request still requires both a project assignment and a registry relationship. Decomposition and Multi-Hop Retrieval keeps the original need visible while conducting bounded searches for those linked obligations. The next question is not whether each subquery finds something plausible, but whether the retrieved evidence establishes the required connection. References and further reading Background and extensions for this chapter: Wang, Yang and Wei (2023). Query2doc: Query Expansion with Large Language Models. EMNLP. Extends a query using generated pseudo-documents while retaining the original request. Gao et al. (2023). Precise Zero-Shot Dense Retrieval without Relevance Labels. ACL. Uses a hypothetical document to guide dense retrieval of real sources. Nogueira et al. (2019). Document Expansion by Query Prediction. arXiv preprint, v2. Provides the contrasting operation of expanding documents with predicted queries. Related chapters Evidence and Verification. Explains why a transformed query or generated assertion still needs evidence.