Skip to main content
The --query-rewrite flag transforms user queries to improve RAG retrieval quality using the QueryRewriterAgent.

Quick Start

Query Rewrite Demo

Usage

Basic Query Rewrite

Expected Output:

With Search Tools

--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

  1. Query Analysis: The QueryRewriterAgent analyzes your input
  2. Strategy Selection: Automatically selects the best rewrite strategy
  3. Query Transformation: Expands abbreviations, adds context, fixes typos
  4. 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.