Retrieval Augmented Generation (RAG)

Last updated Oct 13, 2025 Retrieval-Augmented Generation (RAG) is an innovative approach in natural language processing that integrates retrieval mechanisms with generative models to enhance text generation.

By incorporating external knowledge from pre-existing sources, RAG addresses the challenge of generating contextually relevant and informative text. This integration enables RAG to overcome the limitations of traditional generative models by ensuring that the generated text is grounded in factual information and context. RAG aims to solve the problem of information overload by efficiently retrieving and incorporating only the most relevant information into the generated text, leading to improved coherence and accuracy. Overall, RAG represents a significant advancement in NLP, offering a more robust and contextually aware approach to text generation.

Examples for application of these technique includes for instance customer service chat bots that use a knowledge base to answer support requests.

In the context of Retrieval-Augmented Generation (RAG), knowledge seeding involves incorporating external information from pre-existing sources into the generative process, while querying refers to the mechanism of retrieving relevant knowledge from these sources to inform the generation of coherent and contextually accurate text. Both are shown below.

Looking for a managed option?

AI Search offers a fully managed way to build RAG pipelines on Cloudflare, handling ingestion, indexing, and querying out of the box. Get started with AI Search.

Knowledge Seeding

Figure 1: Knowledge seeding

Figure 1: Knowledge seeding

  1. Client upload: Send POST request with documents to API endpoint.
  2. Input processing: Process incoming request using Workers and send messages to Queues to add processing backlog.
  3. Batch processing: Use Queues to trigger a consumer that process input documents in batches to prevent downstream overload.
  4. Embedding generation: Generate embedding vectors by calling Workers AI text embedding models for the documents.
  5. Vector storage: Insert the embedding vectors to Vectorize.
  6. Document storage: Insert documents to D1 for persistent storage.
  7. Ack/Retry mechanism: Signal success/error by using the Queues Runtime API in the consumer for each document. Queues will schedule retries, if needed.

Knowledge Queries

Figure 2: Knowledge queries

Figure 2: Knowledge queries

  1. Client query: Send GET request with query to API endpoint.
  2. Embedding generation: Generate embedding vectors by calling Workers AI text embedding models for the incoming query.
  3. Vector search: Query Vectorize using the vector representation of the query to retrieve related vectors.
  4. Document lookup: Retrieve related documents from D1 based on search results from Vectorize.
  5. Text generation: Pass both the original query and the retrieved documents as context to Workers AI text generation models to generate a response.

Was this helpful?

YesNo

On this page

Retrieval Augmented Generation (RAG) - 图3Docs

{"@context":"https://schema.org","@type":"WebPage","@id":"https://developers.cloudflare.com/reference-architecture/diagrams/ai/ai-rag/#page","headline":"Retrieval Augmented Generation (RAG)","description":"RAG combines retrieval with generative models for better text. It uses external knowledge to create factual, relevant responses, improving coherence and accuracy in NLP tasks like chatbots.","url":"https://developers.cloudflare.com/reference-architecture/diagrams/ai/ai-rag/","inLanguage":"en","image":"https://developers.cloudflare.com/reference-architecture/diagrams/ai/ai-rag/og.png?v=a24c47418c2c3a53","dateModified":"2025-10-13","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["AI"]}


description: Cloudflare's low-latency, fully serverless compute platform, Workers offers powerful capabilities to enable A/B testing using a server-side implementation. title: AI Vibe Coding Platform image: https://developers.cloudflare.com/reference-architecture/diagrams/ai/ai-vibe-coding-platform/og.png?v=ea3717cba5ef7981


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/reference-architecture/llms.txt
Use this file to discover all available pages before exploring further.