Workflow
- Receive user query
- Optionally gather context via tools
- Apply rewriting strategy (BASIC, HyDE, STEP_BACK, SUB_QUERIES, MULTI_QUERY)
- Return optimized query/queries
Setup
Run — Python
Run — CLI
Run — agents.yaml
Serve API
Rewriting Strategies
BASIC
Expand abbreviations, fix typos, add context to short queries.
HYDE
Generate hypothetical document for better semantic matching.
STEP_BACK
Generate higher-level concept questions for complex queries.
SUB_QUERIES
Decompose multi-part questions into focused sub-queries.
MULTI_QUERY
Generate multiple paraphrased versions for ensemble retrieval.
CONTEXTUAL
Resolve references using conversation history.
Basic Rewriting
Expands abbreviations, fixes typos, and adds context to short keyword queries.HyDE (Hypothetical Document Embeddings)
Generates a hypothetical document that would answer the query, improving semantic matching.Step-Back Prompting
Generates broader, higher-level questions to retrieve background context.Sub-Query Decomposition
Breaks complex multi-part questions into focused sub-queries.Multi-Query Generation
Generates multiple paraphrased versions for ensemble retrieval.Contextual Rewriting
Uses conversation history to resolve pronouns and references.Auto Strategy Detection
Automatically selects the best strategy based on query characteristics.Custom Abbreviations
Add domain-specific abbreviations for better expansion.Response Structure
Using Tools for Context
The Query Rewriter Agent can use tools (e.g., search) to gather context before rewriting. The agent decides when to use tools based on the query.Custom Tools
CLI Usage
Query rewriting is available via CLI and works with any command.With Any Prompt
With Deep Research
Custom Tools File
Configuration Options
Integration with RAG
Monitor / Verify
Features Demonstrated
| Feature | Implementation |
|---|---|
| Workflow | Single-step query optimization |
| Observability | --verbose flag |
| Tools | Optional search tools for context |
| Structured Output | RewriteResult with metadata |
Next Steps
- RAG for document retrieval
- Knowledge Base for document ingestion
- Memory for persistent context

