What you will be able to do
- Explain how query rewriting and filter extraction turn a user query into a retrieval query that captures intent
- State the downstream changes each technique needs before it works
- Design a multi-step query understanding component (intent classification, entity extraction, rewriting) and weigh its latency cost
- Know when to have the agent ask a clarification question instead of guessing intent
1.Query rewriting: restating what the user meant
In a Databricks RAG chain, user intent is resolved in query understanding, the step at the start of the chain that turns the raw user query into the retrieval query. Retrieval sees nothing except that query. This page covers the techniques that go into this step.
The first is query rewriting: "Query rewriting involves translating a user query into one or more queries that better represent the original intent." Its stated purpose is to make it more likely that retrieval finds the most relevant documents. It helps most with complex or ambiguous queries, or with queries whose wording doesn't match the terminology in the documents. Databricks gives three examples:
- Paraphrasing conversation history in a multi-turn chat. A follow-up like "what about the other one?" is meaningless to a vector search on its own. The rewrite folds in the earlier turns so the retrieval query stands alone. - Correcting spelling mistakes in the user's query. - Replacing words or phrases with synonyms to capture a broader range of relevant documents.
A rewrite can also produce several queries from one request, which suits a question that really asks two things.
Databricks attaches a constraint to rewriting that's easy to overlook: "Query rewriting must be done in conjunction with changes to the retrieval component". A rewrite is only useful if the retriever is set up to make use of it. If the rewritten query is written in terminology or a form that the index and retrieval strategy don't handle well, rewriting can just move the mismatch to a different place. Treat query understanding and retrieval as one unit that you tune together.
Checkpoint 1 of 5· Exam question
In a multi-turn support chat, a user first asks about their laptop warranty, then asks 'What about the other one?' The agent retrieves accurate warranty terms, but for the wrong device because it did not identify which device 'the other one' refers to. What change to the pipeline best prevents this failure?
Correct answer: C — Resolve the referent of 'the other one' against prior conversation state during the reasoning step, before retrieval is triggered
- A. Wrong. Hybrid search changes how documents are matched but does not resolve which device the ambiguous pronoun refers to.
- B. Wrong. Longer retention keeps history available, but the pipeline still needs to actually resolve the referent using that history before retrieving; retention alone does not fix the mismatch.
- C. Correct. Ambiguous references like 'the other one' are an intent-resolution problem. Resolving the referent from conversation state during reasoning, before the retrieval call is issued, ensures the right device's warranty terms are fetched.
- D. Wrong. Appending a disclaimer after an already-wrong answer was generated does not stop the wrong document from being retrieved and used.
- E. Wrong. Few-shot examples influence phrasing and formatting, not the agent's ability to resolve which device an ambiguous follow-up refers to.
Checkpoint 2 of 5· Check yourself
In a multi-turn support chat, follow-up questions retrieve generic documents while first-turn questions work well. Which query understanding technique addresses this most directly?
Databricks lists paraphrasing conversation history in a multi-turn chat as a query rewriting example. It puts the missing context from earlier turns into the retrieval query before retrieval runs. The other options act on retrieval output or on the response.
“Paraphrasing conversation history in a multi-turn chat”Source: docs.databricks.com
Sources1
2.Filter extraction: turning stated criteria into retrieval parameters
Some intent is better expressed as constraints than as reworded text. If a user asks for "reports from 2023" or about a specific product, a semantic search over the whole corpus may return content that's similar but from the wrong year or for the wrong product. That's the accurate-but-mismatched pattern again. Filter extraction handles this. It "involves identifying and extracting these filters from the query and passing them to the retrieval step as additional parameters." Databricks' examples are time periods ("articles from the last 6 months"), products, services or categories ("laptops"), and geographic entities such as city names or country codes.
Filter extraction has more dependencies than rewriting. It requires changes to both the metadata extraction data pipeline and the retriever chain. The metadata step has to make sure the relevant fields exist on every document or chunk, and "the retrieval step should be implemented to accept and apply extracted filters." Extracting "2023" from the query is pointless if no chunk has a year field, or if the retriever ignores the parameter.
| Aspect | Query rewriting | Filter extraction |
|---|---|---|
| What it produces | One or more reformulated retrieval queries | Filter parameters passed to the retrieval step |
| Typical examples | Paraphrasing multi-turn history, fixing spelling, adding synonyms | Time periods, products or categories, geographic entities |
| Problem it fixes | Ambiguous queries, or wording that doesn't match document terminology | Results drawn from the wrong subset of the data |
| Other components that must change | The retrieval component | The metadata extraction data pipeline and the retriever chain |
Checkpoint 3 of 5· Match them up
Match each query understanding output to the user request it best fits
Tap a term, then the definition that fits it.
Rewriting reformulates the text of the query (synonyms, paraphrased history). Filter extraction turns explicit criteria such as dates or products into parameters that narrow retrieval to a subset of the data.
“Filter extraction involves identifying and extracting these filters from the query and passing them to the retrieval step as additional parameters.”Source: docs.databricks.com
Sources1
3.Multi-step intent resolution and clarification
Another design decision is whether query understanding should be one LLM call or several. A single, carefully written prompt is efficient. Databricks notes that splitting complex logic across several calls often gives better results, and calls this a general rule of thumb whenever many complex steps would otherwise go into one prompt. For example, "you might use one LLM call to classify the query intent, another to extract relevant entities, and a third to rewrite the query". The tradeoff is stated directly: "Although this approach may add some latency to the overall process, it can allow for more fine-grained control". It can also improve the quality of what gets retrieved.
For a customer support bot, the multi-step component looks like this:
1. Intent classification. An LLM assigns the query to predefined categories such as product information, troubleshooting or account management. 2. Entity extraction. "Based on the identified intent, use another LLM call to extract relevant entities from the query", for example product names, reported errors or account numbers. 3. Query rewriting. "Use the extracted intent and entities to rewrite the original query into a more specific and targeted format", for example a query that names the deployment target and the exact error.
Checkpoint 4 of 5· Put it in order
Order the steps of the multi-step query understanding component Databricks describes for a customer support bot
- 1.Classify the query into a predefined intent category
- 2.Extract entities relevant to that intent, such as product names or error messages
- 3.Pass the rewritten query to retrieval
- 4.Rewrite the query into a specific, targeted retrieval query using the intent and entities
Each step depends on the one before it. Entity extraction is based on the identified intent, rewriting uses both the intent and the entities, and the result becomes the retrieval query.
“Use the extracted intent and entities to rewrite the original query into a more specific and targeted format”Source: docs.databricks.com
Sometimes intent can't be inferred because the user simply hasn't given the key detail. Databricks' Genie Agent guidance handles this with an explicit clarification rule. For example, when a user asks for a sales breakdown without a time range, sales channel or KPIs, the agent "must ask a clarification question first to gather necessary information." The instruction should name the trigger condition, the missing details, the required action, and an example question to ask. It's still intent resolution that happens before retrieval and answering. The difference is that the agent gets the missing piece from the user instead of guessing.
Checkpoint 5 of 5· Exam question
A common agent pipeline pattern proceeds through the stages: reason and plan, find information, reason again, then act and respond. At which stage should the agent establish what the user is actually asking for?
Correct answer: A — Reason and plan, the first stage, before any retrieval call is made
- A. Correct. The initial reasoning/planning stage is where the agent interprets the user's request and decides what to look up. Intent must be established here so that the subsequent retrieval call targets the right information.
- B. Wrong. By the time retrieval executes, the query being retrieved on has already been formed; establishing intent this late means retrieval may already target the wrong thing.
- C. Wrong. This stage applies business logic to already-retrieved information; if intent was not resolved earlier, the wrong information may already have been fetched.
- D. Wrong. This is the final output stage; resolving intent this late is too late to influence what was retrieved.
Exam traps
Each one states something that sounds right. Open it to see what is actually true.
1.Adding a query rewriting step by itself is enough to fix mismatched retrieval.Why is that wrong?
Databricks says rewriting must be paired with changes to the retrieval component. A rewrite the retriever isn't set up to use can just move the mismatch elsewhere.
2.Filter extraction only needs a change to the query understanding prompt.Why is that wrong?
The data pipeline also has to provide the matching metadata fields on each chunk, and the retriever has to accept and apply the filters.
Covered in Filter extraction: turning stated criteria into retrieval parameters
3.A single LLM call is always the better design for query understanding because it adds no latency.Why is that wrong?
Separate calls for intent classification, entity extraction and rewriting add latency but give finer control and can improve what gets retrieved. It's a tradeoff to weigh, not a fixed rule.
Sources
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Query rewriting involves translating a user query into one or more queries that better represent the original intent.”
↩︎ Query rewriting: restating what the user meant“Query rewriting must be done in conjunction with changes to the retrieval component”
↩︎ Query rewriting: restating what the user meant“the retrieval step should be implemented to accept and apply extracted filters”
↩︎ Filter extraction: turning stated criteria into retrieval parameters“Extracting specific time periods mentioned in the query”
↩︎ Filter extraction: turning stated criteria into retrieval parameters“you might use one LLM call to classify the query intent, another to extract relevant entities, and a third to rewrite the query”
↩︎ Multi-step intent resolution and clarification“Based on the identified intent, use another LLM call to extract relevant entities from the query”
↩︎ Multi-step intent resolution and clarification“Query rewriting must be done in conjunction with changes to the retrieval component”
↩︎ Exam trap 1“The metadata extraction step should ensure that the relevant metadata fields are available for each document/chunk”
↩︎ Exam trap 2“Although this approach may add some latency to the overall process, it can allow for more fine-grained control”
↩︎ Exam trap 3“Paraphrasing conversation history in a multi-turn chat”
↩︎ Checkpoint“Filter extraction involves identifying and extracting these filters from the query and passing them to the retrieval step as additional parameters.”
↩︎ Checkpoint“Use the extracted intent and entities to rewrite the original query into a more specific and targeted format”
↩︎ Checkpoint - 2.
“you must ask a clarification question first to gather necessary information”
↩︎ Multi-step intent resolution and clarification