cloudflare-rag  by RafalWilinski

Fullstack RAG app for "Chat with your PDFs" built on Cloudflare

created 11 months ago
566 stars

Top 57.7% on sourcepulse

GitHubView on GitHub
Project Summary

This project provides a full-stack Retrieval Augmented Generation (RAG) application, "Chat with your PDFs," built entirely on Cloudflare's serverless ecosystem. It targets developers and users seeking a self-contained, performant AI application deployable on a global edge network, leveraging Cloudflare's integrated services for a streamlined experience.

How It Works

The application implements a hybrid RAG approach, combining Full-Text Search (FTS) on Cloudflare D1 (using BM25) with vector search on Cloudflare Vectorize. User queries are expanded into multiple variations, which are then executed against both datastores. Results from D1 and Vectorize are merged using Reciprocal Rank Fusion (RRF) to produce a ranked list of relevant context, which is then passed to an LLM for response generation. This hybrid strategy aims to provide more accurate and comprehensive context than either FTS or vector search alone.

Quick Start & Requirements

  • Install dependencies: pnpm install (or npm install)
  • Deploy primitives: ./setup.sh
  • Configure wrangler.toml with D1 database ID and KV namespace ID.
  • Set API keys in .dev.vars (Cloudflare Account ID required; Groq, OpenAI, Anthropic optional, with fallback to Workers AI).
  • Run dev server: npm run dev
  • Deploy to Cloudflare Pages: npm run deploy
  • Requires Node.js, pnpm/npm, and wrangler CLI.

Highlighted Details

  • Hybrid RAG using D1 (BM25) and Vectorize (dense retrieval) with Reciprocal Rank Fusion.
  • Supports multiple LLM providers (OpenAI, Groq, Anthropic) via Cloudflare AI Gateway with fallbacks.
  • Server-Sent Events (SSE) for real-time streaming to the UI.
  • Per-IP rate limiting using Cloudflare KV.
  • Integrated OCR via unpdf within a Cloudflare Worker.
  • Utilizes Cloudflare's Smart Placement for optimal workload distribution.

Maintenance & Community

The project is maintained by RafalWilinski. Contact information for consulting is provided via Twitter and a personal website.

Licensing & Compatibility

Licensed under the MIT License. This permissive license allows for commercial use and integration into closed-source projects.

Limitations & Caveats

The project relies heavily on the Cloudflare ecosystem; deployment and operation are tied to Cloudflare services. Specific Cloudflare resource IDs (D1, KV) must be manually configured after initial setup.

Health Check
Last commit

11 months ago

Responsiveness

1 week

Pull Requests (30d)
0
Issues (30d)
0
Star History
26 stars in the last 90 days

Explore Similar Projects

Starred by John Resig John Resig(Author of jQuery; Chief Software Architect at Khan Academy), Georgios Konstantopoulos Georgios Konstantopoulos(CTO, General Partner at Paradigm), and
2 more.

mcp-server-cloudflare by cloudflare

0.5%
3k
MCP servers for LLM integration with Cloudflare services
created 8 months ago
updated 1 week ago
Feedback? Help us improve.