Cost-Effective RAG with Intelligent Routing and Reflection on Cloudflare
说明与用途
作者描述了在 Cloudflare Workers 上构建一个成本效益高的 RAG 系统,使用智能查询路由(SQL/BM25/Vector)将嵌入成本降低 71%。该系统包含用于知识合成的反思层,并通过 MCP 与 Claude 集成。
问题
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.
结果
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.
工作流
- 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.
证据
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.
- 记录日期: 2026-09-08T04:52:41.240Z