query-transformation-strategies
Skill8 starsChanged 7 months agoMITView on GitHub
Use query rewriting, step-back prompting, and sub-query decomposition to improve retrieval quality and comprehensiveness.
In this repository39 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rag-skillsSkill
- choosing-a-chunking-frameworkSkill
- contextual-chunk-headersSkill
- hierarchical-chunkingSkill
- semantic-chunkingSkill
- chunkingSkill
- sliding-window-chunkingSkill
- rag-for-code-documentationSkill
- rag-for-multimodal-contentSkill
- data-type-handlingSkill
- index-versioning-and-reindexingSkill
- production-rag-deploymentSkill
- deploymentSkill
- generation-evaluation-metricsSkill
- rag-evaluation-frameworksSkill
- retrieval-evaluation-metricsSkill
- evaluation-metricsSkill
- optimize-retrieval-latencySkill
- performance-optimizationSkill
- agentic-rag-routingSkill
- multi-agent-rag-orchestrationSkill
- rag-agentsSkill
- adaptive-retrievalSkill
- context-enrichment-windowSkill
- crag-corrective-ragSkill
- explainable-retrievalSkill
- graph-ragSkill
- hybrid-search-bm25-denseSkill
- hyde-hypothetical-document-embeddingsSkill
- hype-hypothetical-prompt-embeddingsSkill
- multi-pass-retrieval-with-rerankingSkill
- raptor-hierarchical-retrievalSkill
- self-ragSkill
- retrieval-strategiesSkill
- choosing-vector-db-by-datatypeSkill
- qdrant-for-production-ragSkill
- qdrant-setup-ragSkill
- vector-databasesSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 34
Use an LLM to reformulate the original query into a more detailed, specific version.
- Distinctive: line 66
Use reciprocal rank fusion (RRF) or weighted scoring to combine results from different query variants.
- Distinctive: line 73
When documents use different terminology than users
- Distinctive: line 75
When single-query retrieval produces incomplete or irrelevant results
- Distinctive: line 79
When latency must be minimized (query transformation adds LLM calls)
- Distinctive: line 80
When query-document alignment is already excellent
- Distinctive: line 82
When using datasets where queries are already well-formulated
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Overview
Query transformation strategies modify or expand user queries before retrieval to bridge the gap between natural language queries and document representations. These techniques improve retrieval relevance by generating multiple query variants, each targeting different aspects of the information need.
Problem Statement
Direct query-to-document matching has inherent limitations:
- Ambiguity: Natural language queries often contain unclear terms or multiple interpretations
- Style Mismatch: User queries differ in structure and vocabulary from indexed documents
- Incomplete Information: Single queries may not capture all relevant aspects of complex information needs
- Context Insensitivity: Direct queries don't account for broader context or domain knowledge
Key Concepts
- Query Rewriting: Reformulating queries to be more specific and detailed
- Step-back Prompting: Generating broader, more general queries for context retrieval
- Sub-query Decomposition: Breaking complex queries into simpler, component questions
- Query Expansion: Adding related terms and concepts to the original query
- Multi-Query Retrieval: Executing multiple query variants and combining results
Implementation Guide
Step 1: Implement Query Rewriting
Use an LLM to reformulate the original query into a more detailed, specific version.
Why: Enhanced queries include relevant terminology, proper context, and specific aspects that the original query might miss. This improves matching with technical documents and domain-specific content.
Instruct the LLM to expand queries with relevant domain terminology, clarify ambiguous terms, and add context that would appear in target documents.
Step 2: Implement Step-back Prompting
Generate a broader, more general version of the query to retrieve foundational context.
Why: Step-back queries provide background information and fundamental concepts that help ground more specific answers. This is especially valuable for technical topics where understanding basics is essential.
Generate step-back queries that capture higher-level concepts, general principles, or background knowledge related to the specific query.
Step 3: Implement Sub-query Decomposition
Break down complex queries into 2-4 simpler sub-questions covering different aspects.
Why: Sub-query decomposition ensures comprehensive coverage of multi-faceted questions. Each sub-query targets a different aspect, allowing retrieval of diverse information that together provide a complete answer.
Direct the LLM to identify component questions that, when answered together, comprehensively address the original query.
Step 4: Build Multi-Query Retrieval Pipeline
Execute multiple query variants and combine their retrieval results.
Why: Multi-query retrieval increases recall by retrieving documents matched by different query formulations. Combining results ensures broader coverage and higher likelihood of finding relevant information.
Retrieve documents for each query variant, then deduplicate results and re-rank by relevance to the original query.
Step 5: Implement Result Fusion Strategy
Combine results from different query transformations using scoring and deduplication.
Why: Result fusion prevents redundant information and prioritizes the most relevant documents across all query variants. A weighted scoring approach balances specificity with comprehensiveness.
Use reciprocal rank fusion (RRF) or weighted scoring to combine results from different query variants.
For implementation patterns, see LangChain routing workflows, LlamaIndex Query Transform Cookbook, and the Step-back prompting paper.
When to Use This Skill
- Building RAG systems where query ambiguity is common
- Handling complex, multi-faceted user questions
- When documents use different terminology than users
- For domains requiring both specific details and broad context
- When single-query retrieval produces incomplete or irrelevant results
When NOT to Use This Skill
- For very simple, direct queries (single-step retrieval is faster)
- When latency must be minimized (query transformation adds LLM calls)
- When query-document alignment is already excellent
- For real-time systems with strict latency budgets
- When using datasets where queries are already well-formulated
Related Skills
- HyDE - Different query expansion approach
- Fusion Retrieval - Combining multiple retrieval signals
- Adaptive Retrieval - Dynamic query processing
Metrics & Success Criteria
- Retrieval Recall: Increased recall for complex queries by 15-25%
- Query Coverage: Multiple query variants cover different aspects of information need
- Result Quality: More comprehensive and relevant document sets
- Latency: End-to-end latency increase < 500ms for typical queries
- Cost Efficiency: LLM calls balanced against relevance improvements
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

