Multi-query and Self-query Retrieval
Use multi-query retrieval for complex questions and self-query retrieval to turn conditions into filters safely.
One question, several searches
Some questions are really several questions in one. "Compare the leave rules for students and staff, and tell me who approves extra days" needs the student leave policy, the staff leave policy and the approval rules, which may sit in three different documents. A single search with the whole sentence often finds one of them well and misses the others.
Other questions contain conditions that belong in a filter rather than in the search text: "circulars from the exam cell after October about re-evaluation". Searching for those words by meaning does not reliably enforce "from the exam cell" or "after October".
Two techniques handle these cases by letting a language model plan the search: multi-query retrieval and self-query retrieval.
Multi-query retrieval
Multi-query retrieval asks a language model to write several different search queries for the same question, runs each one, and merges the results. The queries can cover different parts of a complex question (this is also called query decomposition), or different phrasings of the same need, so that results are less sensitive to wording.
For "Compare the leave rules for students and staff, and who approves extra days?", the model might generate:
- student medical leave limit per semester
- staff and faculty medical leave entitlement
- approval authority for leave beyond the limit
Each query is searched separately, and the results are combined, usually by removing duplicates or with Reciprocal Rank Fusion. The combined set is far more likely to contain everything the answer needs.
One complex question becomes several focused searches. Their results are merged into one set of sources.
The program below shows the merging step: three generated queries, three result lists, and one combined list with duplicates removed and ranks fused.
Expected output:
single best list covers: ['Regulations §4.1', 'Regulations §4.3', 'Attendance §2']
merged top 4: ['Regulations §4.1', 'HR Policy §7', 'Regulations §4.2', 'Regulations §4.3']
The scoring line is Reciprocal Rank Fusion: a page earns 1 / (60 + rank) from every list it appears in. scores.get(doc, 0) starts a page at 0 the first time it is seen, so a page found by several of the generated queries adds up points from each and rises in the merged list.
The single query found only student rules. The merged list covers student rules, staff rules and the approval rule.
Self-query retrieval
Self-query retrieval asks a language model to split the question into two parts: a search text (what to look for by meaning) and metadata filters (conditions on fields like department, date, type or language). The model is told which metadata fields exist and what values they can take, and it outputs a structured query.
For "circulars from the exam cell after October about re-evaluation", it might produce:
{
"search": "re-evaluation",
"filters": {"doc_type": "circular", "department": "exam cell", "date_after": "2026-10-01"}
}
The system then runs a filtered vector search: only exam-cell circulars after 1 October are considered, and among those, the ones closest to "re-evaluation" are returned. Self-query retrieval turns natural-language conditions into exact database filters, which embeddings alone cannot enforce.
Compare the two approaches below.
Costs and safeguards
Both techniques add a language model call before retrieval, and multi-query multiplies the number of searches. Use them where they pay off: multi-query for complex, multi-part questions; self-query for collections with rich metadata where users naturally mention dates, departments or types.
Self-query needs one safeguard in particular: never let the model's filters override security. The model might output a filter like access = staff because the question mentioned staff. Permission filters must always come from the logged-in user's role, applied by the system, and combined with whatever the model suggests, never replaced by it.