Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk6 min

Building a RAG Chatbot on Cloudflare Workers with Vectorize, D1, and Workflows

A RAG chatbot on Cloudflare pairs Workers AI embeddings with Vectorize search and D1 source records, with Workflows or Queues handling ingestion. Here is how the pieces fit and what to decide before production.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A retrieval-augmented generation (RAG) chatbot on Cloudflare splits its work across four services. Workers receives requests and coordinates the calls. Workers AI creates embeddings and writes the answer. Vectorize stores and searches those embeddings. D1 keeps the original text that each match points back to. Workflows, or Queues, handle the ingestion pipeline that loads documents into that system. Cloudflare’s tutorial “Build a Retrieval Augmented Generation (RAG) AI” shows this arrangement end to end, but it is a working example, not evidence of how well the design performs on quality, latency, or cost. Cloudflare’s service limits, model availability, and AI Search behavior change over time, so check the current documentation before you deploy anything, as of October 2026.

Which service does what

The clearest way to build this system is to assign each service one responsibility and keep it there. Mixing them makes the pipeline hard to debug, because a wrong answer could come from the embedding step, the search step, or the prompt, and you need to know which.

As an Amazon Associate I earn from qualifying purchases.

Component Responsibility in a RAG chatbot What it should not be asked to do
Cloudflare Workers Receives chat and ingestion requests and calls the other services in order Store documents or vectors
Workers AI Produces embeddings for documents and questions, and generates the final answer Hold your source corpus
Cloudflare Vectorize Stores embedding vectors and returns the IDs of the closest matches Store the original source text
Cloudflare D1 Stores source records, and optionally chat sessions and conversation history Perform vector similarity search
Cloudflare Workflows or Queues Coordinate multi-step ingestion, from insertion through embedding to indexing Serve live chat requests

Vectorize indexes meaning, and D1 keeps the words. A vector database holds numerical representations of text, not the text itself, so the system needs a stable link between each vector and the D1 row it came from. In the tutorial, that link is the D1 record ID, which is used as the vector identifier when the vector is written.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How a question is answered

At query time, the Worker runs these steps in order:

#1 Best Overall
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
  • Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized
  1. Receive the user’s question in a route handler.
  2. Convert the question into an embedding with the same model that was used for the documents. Vectors from different models are not comparable.
  3. Query Vectorize with that embedding and collect the IDs of the nearest matches.
  4. Use those IDs to look up the matching text in D1.
  5. Build a prompt that contains the user’s question and the retrieved text, then send it to a text-generation model through Workers AI.
  6. Return the generated answer to the client.

Retrieval only supplies candidate context. It does not guarantee that the model will answer correctly. The prompt should tell the model to rely on the retrieved text and to say when that text does not contain the answer, and you should test that behavior on questions your documents cannot answer. The tutorial demonstrates the mechanics of this pattern; it does not measure how often the output is right.

How documents get into the index

Ingestion is the part that differs most between a prototype and a production system. The tutorial accepts text, inserts a record into D1, generates an embedding with Workers AI, and upserts that vector into Vectorize using the D1 record ID. Cloudflare’s separate reference architecture describes a queue-based version of the same job, in which a Worker accepts documents, places them on a queue, and a consumer processes them in batches.

Pattern 1: a Workflow-based sequence

The tutorial models ingestion as Workflow steps: one step writes the D1 row, one generates the embedding, and one upserts the vector. Each step is a checkpoint, so a failed step can be retried without repeating the earlier ones. This keeps the code close to the sequence you can read in the tutorial, which makes it a sensible starting point for a small corpus.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
  • Includes Raspberry Pi 5 16GB with 2.4Ghz 64-bit quad-core CPU (16GB RAM)
  • Includes 128GB Micro SD Card pre-loaded with 64-bit Raspberry Pi OS, USB MicroSD Card Reader
  • CanaKit Turbine Black Case for the Raspberry Pi 5
  • CanaKit Low Noise Bearing System Fan
  • Mega Heat Sink - Black Anodized

Pattern 2: a queue with batching and retries

The reference architecture uses a queue as a backlog. The producer Worker accepts documents quickly and returns, and the consumer takes messages in batches, embeds them, writes to Vectorize and D1, and then acknowledges or retries the messages. This suits large or bursty ingestion, where you want the request path to stay fast and the processing rate to be controlled separately.

Consideration Workflow-based sequence Queue with batched consumer
Source in Cloudflare documentation Tutorial “Build a Retrieval Augmented Generation (RAG) AI” Reference architecture “Retrieval Augmented Generation (RAG)”
Best fit Small corpora, simple ingestion, and a single clear sequence of steps Large or bursty document loads that need a backlog
Retry handling Per step, as the tutorial’s Workflow is structured Per message, with acknowledgment and retry
Batch processing Not described in the tutorial Batches are a documented part of the design
Operational complexity Lower: one orchestration path Higher: producer, consumer, and queue configuration to maintain
Throughput figures Not stated in the cited pages Not stated in the cited pages

Neither pattern is mandatory. Choose based on how many documents you expect to load, how often they change, and how much you care about retrying a failed batch without reprocessing everything.

Index settings must match the embedding model

The tutorial uses the embedding model @cf/baai/bge-base-en-v1.5 and creates a Vectorize index with 768 dimensions and a cosine metric. Those values are the tutorial’s configuration, not a universal recommendation. The Vectorize documentation states that dimensions and distance metric are fixed when the index is created.

Rank #3
CanaKit Raspberry Pi 5 Essentials Starter Kit (4GB RAM)
  • CanaKit Raspberry Pi 5 Essentials Starter Kit

In practice, this means you should confirm the model’s output dimension before you create the index, and create the index with the matching value and metric. If you later switch embedding models, you cannot change the existing index in place; you create a new index and re-embed the whole corpus into it. Plan that re-indexing path before you commit to a model, because it affects how you store the original text and how easily you can rebuild the vectors.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Chat state and conversation history

Cloudflare’s guidance on AI application patterns describes D1 as a place to keep session state and conversation history alongside the inference logic. That is a reasonable home for chat history, since it is relational and sits next to your source records.

The tutorial itself does not go this far. It is a simple RAG walkthrough, and it does not define a memory design, a retention period, or how conversations are isolated between users or tenants. Before you put real users on the system, decide these things yourself:

Rank #4
SANOOV Raspberry Pi 5 4GB Kit, 4GB RAM Single Board Computer with Active Cooler and ABS Case, Complete Raspberry Pi 5 Starter Kit for IoT Robotics Retro Gaming
  • All-in-One Complete Kit: This SANOOV RPi 5 bundle comes with Raspberry Pi 5 4GB RAM single board, active cooler, durable ABS case and screwdriver. No extra parts needed, ready to use right out of the box for beginners and hobbyists
  • Powerful Single Board Computer: Equipped with 4GB RAM and high-performance processor, delivers fast running speed for 4K playback, AI projects, programming and daily computing tasks. SANOOV for raspberry pi 5 4GB is equipped with broadcom 64 quad-core Arm Cortex A76 processor with gigabit ethernet and upgraded with IEEE 802.11ac Wi-Fi, Bluetooth 5.0 dual-band 2.4Ghz and 5Ghz and Power Over Ethernet (POE). Upgrading delivers 2-3 x speed vs Pi 4, redefining the experience
  • Efficient Active Cooler: Effectively lowers operating temperature and prevents performance throttling. Runs quietly even under long-time heavy load, ensures stable operation all day long. SANOOV RPi 5 4GB kit offer an active cooler, which combines an aluminium heatsink with a high-performance PWM fan. Active cooler is fully compatible with the Pi OS, which can effectively reduce the temperature of RPi5 and ensure its good performance during long-term high load operation
  • Sturdy ABS Protective Case: Well-fitted for Raspberry Pi 5 board, can be secured with 4 screws to effectively protect the Pi 5 motherboard from damage, reserves full access to all ports and buttons. SANOOV uses ABS material to produce the case, which has a softer texture and feel. Meanwhile, SANOOV case adopts a layered design for easy disassembly and installation. (Tip: The Case cannot install M.2 HAT Add on Board and Solid State Drive!)
  • Wide Application & Full Compatibility: Seamlessly compatible with official OS and mainstream peripheral accessories for Raspberry Pi 5. Whether you are a beginner, student, electronics hobbyist or professional developer, this all-in-one kit meets your diverse needs. It excels in IoT projects, robotics design, retro gaming devices, home media servers and other DIY creations. Backed by a large global community, you can easily find guides, technical support and shared projects online
  • How a session is identified, and whether it is tied to an authenticated user.
  • How many prior turns are included in the prompt, and whether older turns are summarized or dropped.
  • How long conversation records are kept, and how they are deleted on request.
  • Whether one user’s conversations can ever be returned to another user, including through shared retrieved documents.

The managed alternative: AI Search

The official tutorial points to AI Search as a managed option that handles ingestion, indexing, and querying. That removes most of the pipeline code described above. The trade-off is control: you give up some visibility into how documents are chunked, embedded, and ranked, and you depend on the managed behavior as Cloudflare documents it.

The pages reviewed for this article do not compare AI Search with a custom pipeline on cost, latency, answer quality, or feature limits, so they cannot tell you which is cheaper or more accurate for your data. Build a small test with a representative set of documents and questions on each approach, and compare the results before you choose.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What the tutorial does not cover

The tutorial is a working starting point, and several production concerns sit outside it. Its ingestion step accepts text directly, so you will need to decide how to parse source files, split them into chunks, and handle documents that are updated or deleted. It also does not describe how to remove stale vectors when a D1 record changes, which is the step most likely to leave the index out of step with the source data. Access control, logging, and evaluation of answer quality are likewise your responsibility.

Best Value
RasTech Raspberry Pi 5 8GB Kit with Active Cooler and Pi5 Case
  • 【What you Get】You will get 1*Pi 5 8GB Single Board,1*RasTech Case,1*Active Cooler,1*Screwdriver,1*Installation instructions,12-month free warranty, lifetime service, 24-hour prompt and friendly response.
  • 【More Connectors】There are two USB 3.0 ports(5Gbps simultaneously) and two USB 2.0 ports, which triple total bandwidth ,support any combination of up to two cameras or displays. Peak SD card performance is doubled through support for the SDR104 high-speed mode. It provides a smooth desktop experience for you. Offer Gigabit Ethernet and a PCIe interface, along with dual-band Wi-Fi and Bluetooth 5.0/BLE wireless capability. The RasTech Pi 5 Kit use the new 27W 5.1V 5A USB-C power connector.
  • 【 Support Dual 4Kp60 Display 】Each of the two microHDMI sockets can control a 4K display at 60 Hertz, now support HDR, offering super HD video for media streaming projects. RPi 5 is the first RPi model that comes with a PCI Express port (PCIe 2.0 x1 with 500 MB/s) to attach SSDs (requires separate M.2 HAT).
  • 【 Excellent Chips And Applications】Pi 5 is a full-size Pi computer using silicon built in-house at Pi. The RP1 “southbridge” provides the bulk of the I/O capabilities for Pi 5. Pi 5 is more friendly and convenient in the development of Internet of Things, Web development, machine identification, automatic control and other electronic equipment applications and network.
  • 【 Faster CPU, Better GPU 】 Pi 5 features a Broadcom BCM2712 64-bit quad-core Arm Cortex-A76 processor running at 2.4GHz, it delivers a 2–3× increase in CPU performance relative to RaspberryPi 4. The 800MHz VideoCore VII GPU is compatible to OpenGL ES 3.1 and Vulkan 1.2, substantial uplift in graphics performance. Pi 5 Offers lightning-fast CPU speed, a PCI Express interface, a Real Time Clock (RTC) and a power button and runs significantly cooler than Pi 4.

Cloudflare’s own figures for model speed, index capacity, and pricing are not reproduced here, because the pages used for this article do not state them in a form that can be relied on. Look them up in Cloudflare’s current documentation when you size the system.

Finally, the sequence matters. Because the index is fixed at creation and vector identifiers depend on D1 record IDs, decide early how records are identified and how changes will be propagated. Changing those rules after a large ingestion usually means rebuilding the index.

The Bottom Line

Start with the tutorial’s pattern: Workers for requests, Workers AI for embeddings and answers, Vectorize for search, and D1 for the source text, joined by a stable record ID. Use a Workflow-based sequence for a small corpus and a queue with batched consumers when ingestion volume or retry needs grow. Before production, design chat state, document updates and deletions, and access control yourself, and test AI Search against your custom pipeline on your own data rather than assuming either is better.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick Recap

Bestseller No. 1
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
CanaKit Raspberry Pi 5 Starter Kit PRO - Turbine Black (128GB Edition) (8GB RAM)
Includes Raspberry Pi 5 with 2.4Ghz 64-bit quad-core CPU (8GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$259.95
Bestseller No. 2
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
CanaKit Raspberry Pi 5 16GB Starter Kit PRO - Turbine Black (128GB Edition) (16GB RAM)
Includes Raspberry Pi 5 16GB with 2.4Ghz 64-bit quad-core CPU (16GB RAM); CanaKit Turbine Black Case for the Raspberry Pi 5
$419.99
Bestseller No. 3
CanaKit Raspberry Pi 5 Essentials Starter Kit (4GB RAM)
CanaKit Raspberry Pi 5 Essentials Starter Kit (4GB RAM)
CanaKit Raspberry Pi 5 Essentials Starter Kit
$189.99

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.