Starter Kit - Ships with your template. You own it - modify freely.
Overview
AutoRAG is Cloudflare’s completely managed RAG (Retrieval-Augmented Generation) service that provides zero-configuration document retrieval with automatic R2 bucket integration. Unlike the built-in RAG agent which requires manual vector operations, AutoRAG handles everything automatically:- Automatic document ingestion from R2 buckets
- Automatic chunking with configurable size and overlap
- Automatic embedding generation via Workers AI
- Automatic indexing in Vectorize
- Continuous monitoring and updates
- Multi-format support: PDFs, images, text, HTML, CSV, and more
AutoRAG vs Built-in RAG
Choose AutoRAG when:
- You want zero-config RAG
- Documents are in R2 buckets
- You need automatic updates
- Simplicity is priority
- You need custom vector operations
- You want fine-grained control
- Documents come from multiple sources
- You need custom chunking logic
Prerequisites
Before using the AutoRAG agent, you must set up an AutoRAG instance in the Cloudflare dashboard:- Go to Cloudflare Dashboard → Workers & Pages → AutoRAG
- Create a new AutoRAG instance
- Connect it to your R2 bucket
- Configure chunking settings (optional)
- Add the instance to your
wrangler.toml:
Quick Start
Basic Usage (Answer Mode)
Search-Only Mode
Input Schema
Example Input
Output Schema
The output format depends on themode configuration:
Answer Mode (mode: answer)
Results Mode (mode: results)
Configuration
Required Configuration
Optional Configuration
Mode Options
answer mode:
- Returns AI-generated response grounded in documents
- Best for end-user Q&A
- Includes source citations
- Uses LLM to synthesize answer
results mode:
- Returns raw search results without generation
- Best for custom processing
- Includes context string for LLM pipelines
- No LLM cost for retrieval
Configuration Example
Examples
Example 1: AI-Generated Answer
Get an AI-generated answer grounded in your documents.Example 2: Raw Search Results
Get raw search results for custom processing.Example 3: Query Rewriting
Enable query rewriting for better retrieval with conversational queries.Example 4: Dynamic Top-K
Override the number of results at runtime.Example 5: RAG Pipeline with Custom Response
Combine AutoRAG results with custom LLM processing.Example 6: Fallback Chain
Try AutoRAG first, fall back to web search if no results.Best Practices
1. Choose the Right Mode
- Use
answermode for end-user Q&A - Use
resultsmode when building custom pipelines - Use
resultsmode to save LLM costs if you don’t need generation
2. Optimize Top-K
- Start with
topK: 5for most use cases - Increase to 10-20 for comprehensive searches
- Decrease to 1-3 for precise answers
- Remember: More results = higher latency + cost
3. Enable Query Rewriting Strategically
- Enable for conversational queries (“how do I…”, “what is…”)
- Disable for precise searches (product IDs, exact terms)
- Adds slight latency but improves recall
4. Monitor Source Quality
5. Cache Results
AutoRAG queries can be expensive. Cache when possible:Troubleshooting
No Results Returned
Problem:count: 0 in output
Solutions:
- Check if R2 bucket has documents
- Verify AutoRAG instance is processing documents
- Try broader query terms
- Enable
rewriteQuery: true
Low Relevance Scores
Problem:score < 0.5 for all results
Solutions:
- Improve document quality and formatting
- Adjust chunking settings in Cloudflare dashboard
- Rephrase query to match document language
- Increase
topKto get more candidates
Instance Not Found
Problem: “AutoRAG instance not found” Solutions:- Verify instance name in
wrangler.toml - Check binding name matches config
- Ensure AutoRAG instance is deployed
Slow Queries
Problem: High latency on queries Solutions:- Reduce
topKvalue - Disable
rewriteQueryif not needed - Use
mode: resultsinstead ofanswer - Add caching for common queries
Related Resources
Built-in RAG Agent
Manual RAG with full vector control
Starter Kit Overview
All starter kit agents

