The indexing work in Chapter 2 produced an artifact with fixed tokens, retrieval units, vectors, and source identities. That artifact is ready to search when someone asks for a film “like Alien but for kids.” The request names one work as a reference and adds an audience constraint, yet neither part maps neatly onto the stored records. A plot can resemble Alien without sharing its words, and the corpus has no content-rating field that can enforce “for kids.”
This is the problem query understanding must handle before retrieval. The words in a query are evidence of a task, often incomplete because people use misspellings, aliases, remembered fragments, implicit constraints, and terms whose meaning depends on the domain. The system can correct, resolve, extract, or expand that language, but every transformation reaches the retrievers, rankers, and stages that follow. A useful interpretation exposes evidence the request left implicit. A poor one sends the pipeline after a different task.
The instrument below compares three queries as typed and after rewriting. For each version, it shows results from BM25, which matches indexed terms, and vector retrieval, which compares semantic representations. Diamond-marked titles are plausible answers to the original request. Select each case and ask whether the intervention is necessary, unnecessary, or interpretive, then watch whether it helps both retrieval methods or produces a mixed result.
The spelling case shows the clearest gain. The misspelled query gives BM25 only a generic term to match, and neither retriever finds Jaws. After correction, both place it first. The vague-memory query behaves differently: both methods already return Groundhog Day first, so rewriting adds complexity without repairing the result.
The Alien request is less settled. Rewriting it as “family friendly science fiction adventure with creatures” makes the interpretation explicit, but it does not improve both lists consistently or make every result family friendly. The rewrite has separated a broad preference from a hard constraint. It has not proved that the interpretation is correct, nor has it supplied evidence the corpus never stored. Query understanding needs evaluation because even a plausible rewrite can preserve one part of a request while weakening another.
One query can describe a range of acceptable results
Lexical and vector retrieval compare a representation of the query with representations of individual documents. That comparison works when similarity to one document is a useful approximation of the goal. It becomes weaker when the short request describes a range of acceptable results, as the Alien query does by asking for a resemblance rather than one known film.
Consider the query “iPhone” on a marketplace. A listing titled simply “iPhone” may resemble the query more closely than listings titled with a model, generation, storage size, or condition. That textual similarity does not establish that the listing is current, available, or appropriate for the shopper. The query provides too little evidence to identify one ideal document, and the set of useful results depends on behavior and context outside the text.
A broader intent becomes visible through repeated outcomes. For “iPhone,” the system can collect the models and accessories that people who issued the query went on to inspect or purchase, then weight those documents by the strength of each interaction. The resulting bag of documents represents the range and relative frequency of accepted outcomes, which lets the system model intent as a distribution over documents. A navigational query, where the user wants one known page or item, should produce a narrow distribution concentrated around that result. Category, recommendation, and preference-shaped queries usually spread their weight across more possibilities.
Roughly twenty engagements is a practical starting threshold for constructing a bag. With only a few observations, one unusual click can distort the representation. That number is a heuristic rather than a universal minimum, so a production system must validate it against local traffic and the biases in what users were shown.
Turn observed outcomes into a query representation
Once the system has enough observations, it can turn the bag into a representation that retrieval can use. Embed each document, give stronger interactions more weight, average the vectors, then normalize the result to unit length. The new vector points toward the region of embedding space that users chose to explore, allowing retrieval to search from that neighborhood instead of relying only on the few words they typed.
This is a form of relevance feedback drawn from behavior, though the behavior remains imperfect evidence. A purchase may count more than a click, but neither is a direct judgment, and users can only choose from the results they were shown. Pseudo-relevance feedback begins with weaker evidence by treating the first retrieved results as relevant and using them to form another query. Chapter 4 shows how that composition works.
The shape of the bag provides evidence of its own. A tight cluster suggests a specific intent. A wider spread means that several kinds of result have been accepted, leaving ranking more room to use context or popularity. Nearby centroids can also reveal different phrasings of the same intent, allowing the system to canonicalize those queries and pool their statistics.
The average works best for preferences expressed across a group of results. For “like Alien but for kids,” observed choices could represent the desired region of science fiction, adventure, and creature stories. They cannot guarantee that each film suits children. That hard constraint must remain explicit as the query moves through the system.
Preserve the request while extracting usable structure
Preserving a hard constraint beside a whole-query representation requires a choice about structure. The phrase “like Alien” carries a relationship that can weaken when reduced to separate terms, while “for kids” names a condition the system may need to filter. The useful question is which parts must remain together and which parts the pipeline can act on separately.
A reductionist approach parses “Apple iPhone 16 black” into brand, product, model, and color. A holistic approach keeps the full query together so relationships among those terms survive.
Substitutability shows what can be lost. An Android phone is a better substitute for an iPhone than a MacBook is, even though the MacBook shares the Apple brand. Yet “I want yellow things” has the opposite shape: shirts, mugs, and cars share no product category, so the color must be handled separately. Useful structure depends on the request rather than one parsing rule applied to every query.
A practical pipeline can combine the approaches. It keeps the whole-query representation, parses known entities and constraints, enriches them with domain evidence, then transforms the result into a retrieval request. Step through the phases in the instrument below and watch what each one adds without discarding the original relationship.
"something like Alien but for kids"
- The user names one known film.
- The user also states an audience constraint.
Fallback ruleIf parsing finds no useful structure, pass the original query forward unchanged.
As you move through the instrument, the family-friendly constraint becomes explicit but remains unresolved. The movie corpus has no content-rating field, so a more structured request still cannot enforce it. Parsing can resolve surface forms such as “Kubrick” and “Stanley Kubrick” to the same canonical entity through a curated entity library, but the evidence required to use any extracted structure must still exist.
When the index does support the structure, enrichment can connect it to a fixed operation. Semantic functions are small programs triggered by recognized terms whose behavior remains inspectable. Consider “top kimchi near Charlotte.” A lexical engine may find nothing when asked to match all four tokens because restaurant descriptions do not express location, cuisine, and quality in one text field. The pipeline instead maps “top” to a rating boost, “kimchi” to Korean cuisine and related terms, and “near Charlotte” to a geographic filter. The retriever stays the same, but receives a request expressed in evidence the index can use.
Let the index supply domain language
The structured request still needs the vocabulary of its domain. The related terms for “kimchi” do not have to come from a hand-written synonym list. Chapter 2 introduced the inverted index, which maps terms to documents. Add a forward index that maps each document back to its terms, and the system can move in both directions: from a query term to the documents that contain it, then outward to terms that occur unusually often in those documents.
The second hop matters because the documents surrounding a term reveal which other terms the corpus associates with that use. Together with categories attached to the documents, this term-to-document-to-term structure forms a semantic knowledge graph. Consider a community Q&A corpus with technical and travel categories. In the technical category, “server” leads toward docker, nginx, and ssh. In the travel category, the same token leads toward restaurant, tipping, and VPN. Conditioning the traversal on a category separates meanings that a global synonym list would mix together.
The surrounding phrase can change the evidence just as much as the category. “Airplane” points toward travel, while “airplane crash” points toward science fiction because crashes occur more often in fictional stories than in travel discussions within this corpus. The expansion follows how people use the terms together rather than a fixed definition assigned to either word.
SPLADE, which Chapter 4 introduces, offers a learned alternative. Without domain fine-tuning, its expansion for “lasagna” in a restaurant corpus includes fragments such as “la” and “zagna,” along with “hotel” and “festival.” The index traversal returns pasta, alfredo, and the Italian category instead. Fine-tuning may close that gap. The choice is therefore contextual: learned expansion can generalize beyond observed term links, while the index-based method requires no training and keeps every expansion traceable to stored evidence.
For “like Alien but for kids,” a conditioned traversal could add corpus-specific language around creature features, family adventure, or science fiction. Those expansions help express the resemblance in terms the index recognizes. They still cannot certify suitability for children because the artifact contains no evidence for that judgment.
Spend latency only on unresolved meaning
That remaining gap does not automatically justify the most expensive interpreter. Query understanding runs on the online path and shares its latency budget with retrieval and ranking.
The pipeline should begin with the least expensive method that can preserve the task. A deterministic parser can handle known aliases and structured fields, while a bounded index traversal can add domain terms. A language model becomes useful when the query remains ambiguous or requires an interpretation those methods cannot express. Applying that model to every query would add latency and cost even when the original text was already sufficient.
Hypothetical Document Embeddings (HyDE) show what selective model use can add when observed interactions are unavailable. A language model generates a hypothetical passage for the query, the system embeds that text, and vector retrieval finds real documents nearby. This can work well when one generated passage reasonably represents the target. It captures less of the variation in a broad or preference-shaped intent, where multiple observed outcomes can represent the acceptable result space more directly.
Semantic caching reduces repeated model work by storing an expensive interpretation under a representation of its intent rather than only the exact query string. A later phrasing can reuse that interpretation only when its context and hard constraints still agree. Otherwise, a semantically similar cache hit could quietly discard the very condition query understanding was meant to preserve.
The request now reaches retrieval with its original language intact, its whole-query meaning represented, supported entities and constraints made explicit, and domain expansions traced to the corpus. It also carries uncertainty that interpretation could not settle, including the missing evidence behind “for kids.” If the first candidates expose a mismatch, an agent can inspect them, revise the request, and search again; Chapter 8 develops that bounded loop.
Query understanding has made the request more specific without finding a document. Chapter 4 must now recover candidates that express the request in different language while preserving the exact terms and constraints that still matter.