Retrieval and RAGQuery understanding and retrieval designStaff
How should query rewriting preserve negation when retrieving eligibility rules and exceptions?
By Amit Kumar3 min readWorked answer includedReviewed 28 Sept 2026
The question
Interview question
A user asks which contractors are not eligible for a travel allowance. Rewriting removes not, retrieval misses the exclusions and the answer describes eligible employees. Explain how to preserve the requested logical condition, retrieve both governing rules and exceptions, and distinguish a supported ineligible population from people whose eligibility is simply unknown.
Draft your approach first
Take a few minutes before you read the answer. Name the constraint that matters most, the failure you are designing for and how you would know it worked.
Reveal the worked answerWorked answer
The rewrite dropped a logical operator in the user's question. “Not eligible” is the target set, not a decorative word to remove for cleaner search. A dense retriever may still find semantically close eligibility text, and an LLM can turn that into a fluent answer about the opposite group. Research on domain-specific query rewriting argues that rewriting needs to reason about the information need rather than just transform surface text. That paper is not a claim about this particular policy corpus. The local evidence is the original query, rewrite, candidate list and answer.
For a hypothetical policy, suppose contractor travel is allowed only with project approval, except that agency contractors are excluded. A query for “not eligible” needs that exclusion and the approval condition. A document saying how eligible employees submit claims does not establish either. The final explanation should name which exclusion applies and what attributes are needed, rather than treating all contractors without a retrieved eligibility passage as excluded.
I would preserve an intent representation alongside any expanded query: entity contractor, benefit travel allowance, requested class excluded, effective date and jurisdiction if supplied. Run exact lexical searches for exception and exclusion language, plus semantic candidates. Do not translate natural-language “not” directly into a broad Boolean NOT eligible filter without checking the document structure. The relevant exception may appear in a paragraph that also contains the word “eligible,” and a Boolean exclusion could remove it. Use retrieval to find the governing rule and exceptions, then apply the rule to named people only if their attributes are available and authorized.
Negation also exposes the difference between a rule question and a population query. To list individual ineligible contractors, the system needs an authorized, sufficiently complete contractor population and the attributes required by the rule. Missing approval data might mean no recorded approval, or a failed connector, depending on the source contract. Absence from a top-k search result does not decide that predicate. If only policy text is available, explain the exclusion rule and ask for the relevant person or structured population lookup.
Evaluate the rewrite as a separate stage. Compare original and rewritten queries against a small set of contrast pairs: “eligible” versus “not eligible,” “before” versus “after,” “with approval” versus “without approval,” and policy versions. Inspect first-stage recall for the exception source, then whether reranking and answer synthesis keep the exclusion. If the source does not enumerate all contractors, answer the rule rather than fabricate a list of people.
The interviewer may argue that the final generator still sees the original user question. It does, but it cannot cite an exception the retriever never supplied, and can easily rationalize the wrong broad policy. The query rewrite removed a version number. Why did RAG still look healthy? covers a version number lost in a rewrite. The retriever found the exception. Why did the reranker put it last? covers an exception that retrieval found but reranking demoted. This one loses the negation before retrieval and points the whole evidence search at the wrong population.
Preserve the original query beside each rewrite and log which intent fields changed. A test should fail when polarity changes even if topical similarity improves. Use the original query or a constrained expansion when the rewrite cannot retain the condition confidently. This trades some retrieval convenience for traceable intent. The generator should receive both the supported exclusion evidence and any missing population attributes so it can distinguish an answer from an unsupported list.
Related questions
Keep practising retrieval and rag
Follow another question in this area, or search the complete library.
Get my essays on AI engineering and distributed systems by email. Subscribe to ArchCrux