The --query-rewrite flag transforms user queries to improve RAG retrieval quality using the QueryRewriterAgent.
Quick Start
Basic Query Rewrite
Expected Output:
--rewrite-tools now accepts any name reachable by praisonai tools list โ the same resolver chain used by praisonai research --tools and --expand-tools. See Tool Resolution for the full chain.
Combine with Other Flags
How It Works
- Query Analysis: The QueryRewriterAgent analyzes your input
- Strategy Selection: Automatically selects the best rewrite strategy
- Query Transformation: Expands abbreviations, adds context, fixes typos
- Execution: The rewritten query is used for the task
Rewrite Strategies
Examples
Technical Query
Rewritten to: โWhat are the key differences between OpenAIโs GPT-4 and Anthropicโs Claude 3 language models in terms of capabilities, performance, and use cases?โ
Ambiguous Query
Rewritten to: โHow do I set up a Retrieval-Augmented Generation (RAG) system, including document ingestion, embedding generation, vector storage, and query processing?โ
Follow-up Query
Rewritten to: โWhat are the cost considerations and pricing models for implementing this solution?โ
Choosing the rewriterโs model
The CLIโs --query-rewrite step honours the standard cascade โ CLI flag wins, env vars next, gpt-4o-mini fallback last:
To keep a cheap rewriter regardless of the main model, pin it explicitly with OPENAI_MODEL_NAME=gpt-4o-mini while --llm drives the main agent โ but the recommended pattern is running the rewriter and main agent on the same model.
Programmatic Usage
The model= kwarg on QueryRewriterAgent is unchanged โ the cascade above applies only to the CLI path.
Best Practices
Use --query-rewrite for RAG and search optimization. For expanding task prompts, use --expand-prompt instead.
Query rewriting adds an additional LLM call. Use --metrics to monitor token usage.