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.