This guide shows how to build a Retrieval Augmented Generation (RAG) workflow using Cloudflare Workers AI and Vectorize with the existing n8n-nodes-cloudflare package.
A RAG workflow consists of two phases:
- Ingestion: Convert documents → Generate embeddings → Store in vector database
- Retrieval: User query → Generate query embedding → Search vectors → Return results
| Node | Purpose |
|---|---|
| Cloudflare Workers AI | Generate text embeddings using @cf/baai/bge-base-en-v1.5 |
| Cloudflare Vectorize | Store and query vectors in Cloudflare's vector database |
Use n8n's built-in nodes to get your text data:
- Read Binary File → Read documents from disk
- HTTP Request → Fetch content from APIs
- Code Node → Transform data into text chunks
Use the Cloudflare Workers AI node:
| Setting | Value |
|---|---|
| Resource | Inference |
| Operation | Run Text Embedding |
| Model | @cf/baai/bge-base-en-v1.5 |
| Text | {{ $json.text }} (your document text) |
Output: An array of embedding vectors (768 dimensions for bge-base-en-v1.5)
Use the Cloudflare Vectorize node:
| Setting | Value |
|---|---|
| Resource | Vector |
| Operation | Create or Update (upsert) |
| Index Name | Your vectorize index |
| Vectors | See JSON format below |
Vectors JSON format:
[
{
"id": "doc-1",
"values": [0.1, 0.2, ...], // From Workers AI output
"metadata": {
"text": "Original document text",
"source": "my-document.pdf"
}
}
]Use Cloudflare Workers AI:
| Setting | Value |
|---|---|
| Resource | Inference |
| Operation | Run Text Embedding |
| Model | @cf/baai/bge-base-en-v1.5 |
| Text | {{ $json.query }} (user's question) |
Use Cloudflare Vectorize:
| Setting | Value |
|---|---|
| Resource | Vector |
| Operation | Query |
| Query Vector | {{ $json.data[0] }} (embedding from step 1) |
| Top K | 5 (number of results) |
| Return Metadata | All (to get the original text) |
Output: Top K matching documents with similarity scores
Use Cloudflare Workers AI again:
| Setting | Value |
|---|---|
| Resource | Inference |
| Operation | Run Text Generation |
| Model | @cf/meta/llama-3-8b-instruct |
| Prompt | See template below |
Prompt template:
Based on the following context, answer the user's question.
Context:
{{ $json.matches.map(m => m.metadata.text).join('\n\n') }}
Question: {{ $('Webhook').item.json.query }}
Answer:
Import this workflow template into n8n:
{
"name": "Cloudflare RAG Example",
"nodes": [
{
"parameters": {
"resource": "inference",
"operation": "textEmbedding",
"accountId": "={{ $credentials.accountId }}",
"modelName": "@cf/baai/bge-base-en-v1.5",
"embeddingText": "={{ $json.text }}"
},
"name": "Generate Embedding",
"type": "n8n-nodes-cloudflare.cloudflareWorkersAi",
"position": [450, 300]
},
{
"parameters": {
"resource": "vector",
"operation": "query",
"accountId": "={{ $credentials.accountId }}",
"indexName": "my-index",
"queryVector": "={{ JSON.stringify($json.data[0]) }}",
"queryOptions": {
"topK": 5,
"returnMetadata": "all"
}
},
"name": "Search Vectorize",
"type": "n8n-nodes-cloudflare.cloudflareVectorize",
"position": [650, 300]
}
]
}This package provides standard n8n nodes, not LangChain "cluster nodes". This means:
- ❌ Cannot connect directly to n8n's Document Loader nodes
- ❌ Cannot plug into AI Agent's "tool" connector
- ❌ Not compatible with n8n's RAG Starter Template UI
Why? n8n's cluster node architecture (NodeConnectionTypes.AiEmbedding, NodeConnectionTypes.AiVectorStore) is internal to the @n8n/nodes-langchain package and not exposed for community nodes.
If you need full LangChain integration, please submit a feature request to n8n:
- Go to n8n Feature Requests
- Request: "Native Cloudflare Vectorize & Workers AI Vector Store nodes"
- Reference the existing Supabase/Pinecone/Qdrant implementations