A support assistant earns trust when every answer points back to the help content it came from. On Cloudflare Workers, you can build that with a single endpoint: it retrieves passages from your knowledge base, passes them to a model as context, and returns the generated answer together with the source documents behind it. Cloudflare’s guide “Show source citations in responses” (last updated July 8, 2026) describes this pattern, and the steps below follow it.
How the retrieval-to-citation flow works
The citation comes from retrieval, not from the model’s memory. Each request moves through four stages:
As an Amazon Associate I earn from qualifying purchases.
- Question in. A user’s question reaches your Worker endpoint.
- Retrieve. The retrieval layer finds the stored content chunks that best match the question.
- Generate. Those chunks are passed to the model as context, and the model writes an answer from them.
- Return. The response carries the answer plus the retrieved chunks, so the application can show where the answer came from.
Cloudflare’s guide puts it directly: “AI Search returns the source chunks it uses to generate an answer.” A citation therefore tells a reader which passage was used. It does not, by itself, prove that the generated answer is correct. Readers need to open the source and check the claim, and your interface should make that easy.
Turn retrieved chunks into citations
Raw chunks are too granular to show a reader. Turning them into citations takes three decisions.
#1 Best Overall
- Identify the document with
item.key. Cloudflare recommends this field as the document identifier. It is usually a filename or a URL, which makes it meaningful to a user who wants to open the original. - Group chunks from the same document. A support article can match several times for one question. Show it once, with each relevant snippet listed under it, rather than repeating the same link.
- Keep snippets and metadata. Retain the matching text and any custom metadata so the reader can verify the passage without leaving the page. The retrieved chunks also carry an item timestamp and relevance scoring fields, which are useful for debugging why a given article was chosen.
The guide notes that both standard and streaming responses can be handled this way, so the same grouping logic applies whichever response mode your interface uses.
Choose a retrieval path
Cloudflare offers two main routes, plus an agent-based option. They differ in how much of the retrieval stack you assemble yourself.
Rank #2
Managed retrieval with AI Search
AI Search is Cloudflare’s managed search service for indexing and querying connected websites, R2 buckets, or uploaded documents. Its overview page (updated October 1, 2026) describes automated indexing, custom metadata filtering, hybrid semantic and keyword retrieval (on by default), OCR for scanned PDFs and images, and a built-in MCP endpoint. This is the shorter route when your main job is to bring existing support content into a retrieval pipeline and query it from a Worker.
Recommended Free Tools
From a Worker, the binding reference (also updated October 1, 2026) describes chatCompletions() as the call that retrieves relevant content and generates a response using that content as context.
Rank #3
Self-managed RAG with Workers AI, Vectorize, and D1
Cloudflare’s RAG tutorial (updated August 25, 2026) builds a Worker application from Workers AI for model access, Vectorize for vector storage, and D1 for relational data. It starts with npm create cloudflare@latest and uses Wrangler for local development and deployment. Cloudflare describes AI Search as its managed option for ingestion, indexing, and querying, so this route is for teams that want to control those stages directly, at the cost of more code and more infrastructure to run.
Agent-based option
Cloudflare’s Agents SDK documentation describes a stateful agent on Workers that provisions an AI Search instance and exposes search as a tool the agent calls before answering. This article does not walk through that setup. If you go that way, the core citation logic above still applies: the tool’s retrieved chunks are what you need to surface to the reader.
Quick Recap
Best Value
Rank #4
| Decision | Option A | Option B | What to weigh |
|---|---|---|---|
| Retrieval architecture | Managed AI Search | Self-managed Workers AI, Vectorize, and D1 | How much ingestion, indexing, and retrieval infrastructure your team wants to assemble and operate versus delegate. |
| Binding type | Namespace binding | Instance binding | Namespace bindings can access and manage multiple instances at runtime. Instance bindings suit a Worker that needs one specific instance. |
| Retrieval tuning | Default hybrid search | Add reranking | Reranking may improve ordering on large or noisy datasets but adds a request step that can increase latency. No quantified latency increase is published. |
| Model provider | Workers AI models | Other providers through AI Gateway | Model availability and lifecycle. Cloudflare documents model deprecation and recommends monitoring lifecycle information and testing replacements before migrating. |
Build the endpoint, step by step
- Create the project. Run
npm create cloudflare@latestand choose a Worker project. Wrangler handles local development and deployment. - Configure the binding. For AI Search, use the binding type that matches your setup: a namespace binding, as in Cloudflare’s citation guide, or an instance binding if the Worker only needs one instance. Add the AI binding for model access if you use Workers AI models directly.
- Load the support content. Connect a website, an R2 bucket, or uploaded documents. The overview describes automated, continuous indexing, so new or changed articles are picked up without a manual rebuild, though the exact indexing delay is not stated in the documentation.
- Call the retrieval-and-generation method. Pass the user’s question to
chatCompletions(). It retrieves matching chunks, generates the answer from them, and returns the chunks alongside it. - Build the response. Group chunks by
item.key, attach snippets and metadata, and send the answer and citation list to your front end in either standard or streaming form. - Tune only when needed. Hybrid search is already on. Reranking is off by default. Turn it on if testing on your own questions shows poor ordering on a large or noisy knowledge base, and measure the added latency in your own deployment.
- Develop and deploy. Test locally with
wrangler dev, then publish withwrangler deploy. The RAG tutorial documents both commands.
What the evidence does and does not establish
- Citations show evidence, not correctness. Cloudflare’s documentation describes retrieved evidence and source display. It does not promise that cited answers are factually accurate, so keep a human review path for high-stakes content.
- No independent performance figures. The official pages reviewed for this article publish no latency, accuracy, or cost benchmarks for a support agent like this one. Measure these on your own content and query set.
- Model choices expire. Cloudflare documents model deprecation. Pin your model deliberately, watch the lifecycle information, and test a replacement before switching.
- Agent framework details are out of scope here. Setup for the Agents SDK path is not covered in this guide.
- Page dates. The citation guide, RAG tutorial, and product pages carry the update dates given above. Cloudflare’s product behavior can change, so check the current pages before you build.
“
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.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →




