Skip to main content
Built-in - Framework-level agent. Configure only - cannot modify source.

Overview

The RAG agent provides manual Retrieval-Augmented Generation using Cloudflare AI for embeddings and Cloudflare Vectorize for vector storage. This is a low-level agent for building custom RAG pipelines where you control indexing and search operations.
For fully managed RAG with automatic document processing, see AutoRAG in the Starter Kit.
Key Features:
  • Manual control over indexing and search operations
  • Cloudflare AI embeddings using @cf/baai/bge-base-en-v1.5 (default)
  • Automatic chunking with semantic, fixed, or recursive strategies
  • Optional reranking with cross-encoder models for better relevance
  • Multi-tenant isolation via namespaces
  • Batch processing for efficient large-scale indexing (100 texts per embedding batch, 1000 vectors per upsert)

Required Bindings

Add these to your wrangler.toml:
Create the Vectorize index:
The default embedding model @cf/baai/bge-base-en-v1.5 produces 768-dimensional vectors. Match your index dimensions accordingly.

Operations

The RAG agent supports two primary operations:

1. Index Operation

Index documents into the vector store with automatic chunking and embedding.
Configuration:
Output:

2. Search Operation

Search the vector store using semantic similarity.
Configuration:
Output:

Complete RAG Pipeline

Build a complete question-answering system with manual RAG:

Advanced Patterns

Combine vector search with keyword search for better results:

Multi-Query RAG

Generate multiple search queries for better coverage:

Filtered Search with Metadata

Use metadata filters to narrow search scope:

Incremental Indexing

Index documents in batches with custom chunking:

Best Practices

1. Chunk Documents Intelligently

2. Add Rich Metadata

3. Use Namespaces for Isolation

4. Enable Reranking for Quality

5. Cache Search Results

Common Use Cases

Documentation Q&A

Customer Support Assistant

Content Recommendations

Performance Tips

Limit topK for Speed
Use Metadata Filters
Partition with Namespaces
Cache Aggressively

Limitations

  • Max document size: 8000 tokens per chunk
  • Max topK: 100 results
  • Metadata size: 10KB per document
  • Namespace limit: 1000 per account
  • Embedding model: Currently limited to Cloudflare AI models

Manual RAG vs AutoRAG

For most use cases, consider starting with AutoRAG and migrate to manual RAG when you need fine-grained control.

Next Steps

AutoRAG

Managed RAG with automatic document processing

HITL Agent

Human-in-the-Loop for RAG verification

Built-in Overview

All framework-level agents