Cost-Effective RAG with Intelligent Routing and Reflection on Cloudflare
Description and use
The author describes building a cost-effective RAG system on Cloudflare Workers using intelligent query routing (SQL/BM25/Vector) to reduce embedding costs by 71%. The system includes a reflection layer for knowledge synthesis and integrates with Claude via MCP.
Problem
Standard RAG tutorials often result in expensive production deployments by embedding every query and lacking context-specific retrieval, while LLMs fail to answer questions about internal, non-public knowledge.
Outcome
Implemented a hybrid RAG system with intelligent routing that cuts embedding costs by 71% and adds a reflection layer for better knowledge synthesis, deployed entirely on Cloudflare's free tier infrastructure.
Workflow
- Clone the vectorize-mcp-worker repository.
- Install dependencies using npm.
- Create a 1024d Vectorize index using wrangler.
- Create a D1 SQLite database using wrangler.
- Configure wrangler.toml with database IDs and deploy the schema.
- Deploy the worker using wrangler deploy.
- Set the API_KEY secret.
- Configure Claude Desktop with the MCP server URL and API key.
- Use the exposed tools (search, ingest, etc.) via Claude Desktop.
Evidence
In testing, that cuts average embedding cost by 71% compared to running everything through vectors.
Rough cost at 1,000 queries/day with intelligent routing: ~$0.11/month.
- Record date: 2026-09-08T04:52:41.240Z