Function Signature
Purpose
Uses the LLM to remove conversational noise (greetings, filler phrases) while preserving the core question and all important terms. This step should run beforeexpand/2 and decompose/2 to clean up the input before further transformations.
Parameters
The agent context from the pipeline
Options for the rewrite step
Options
Custom rewriter module or function (default:
Arcana.Agent.Rewriter.LLM)- Module: Must implement
rewrite/2callback - Function: Signature
fn question, opts -> {:ok, rewritten} | {:error, reason} end
Custom prompt function
fn question -> prompt_string endOnly used by the default LLM rewriter.Override the LLM function for this step
Context Updates
The cleaned search query. Set to
nil if rewriting fails.Examples
Basic Usage
Custom Rewriter Module
Inline Rewriter Function
With Custom Prompt
Query Transformation Chain
The rewritten query becomes part of the transformation chain:expanded_query → rewritten_query → question
Examples of Rewrites
| Original | Rewritten |
|---|---|
| ”Hey, tell me about Elixir" | "about Elixir" |
| "Can you please explain processes?" | "explain processes" |
| "I’d like to know how GenServer works" | "how GenServer works" |
| "What’s the deal with supervision trees?" | "supervision trees” |
Custom Rewriter Behaviour
Telemetry Event
Emits[:arcana, :agent, :rewrite] with metadata:
When to Use
Userewrite/2 when:
- Users input conversational queries with noise
- You want to normalize queries before expansion
- Your system handles natural language input (chatbots, voice interfaces)
Best Practices
- Place early in pipeline - Before expand/decompose for best results
- Preserve technical terms - Don’t remove domain-specific vocabulary
- Keep question intent - Don’t change the meaning, just remove noise
- Handle edge cases - Already-clean queries should pass through unchanged
See Also
- expand/2 - Add synonyms and related terms
- decompose/2 - Break into sub-questions