Build RAG Workflows with n8n: Vector Stores & AI Memory Guide
Building RAG workflows with n8n gives your AI agents access to your own company data — product docs, support tickets, internal wikis — so they generate accurate, grounded answers instead of hallucinating. Unlike generic chatbots that rely on training data alone, a RAG pipeline retrieves relevant context at query time and feeds it directly into the LLM prompt. n8n makes this possible with a visual, no-code approach using built-in vector store nodes, embedding integrations, and AI memory chains.
What Is RAG and Why It Matters for n8n Workflows
Retrieval-Augmented Generation is a pattern where you split the AI workflow into two stages: retrieve relevant documents from a knowledge base, then generate an answer using those documents as context. The LLM doesn't need to have been trained on your data — it just needs to see the right snippets at inference time.
This matters for n8n users because most business automation involves proprietary data. You might want a Slack bot that answers questions about your internal processes, a support agent that references your knowledge base, or a workflow that summarizes the latest project updates from Notion. RAG makes all of these possible without fine-tuning a model.
The core components of any RAG pipeline are:
- Document loader — pulls content from sources like Google Drive, Notion, or a database
- Text splitter — breaks documents into chunks small enough for embedding
- Embedding model — converts text chunks into numerical vectors
- Vector store — indexes and searches those vectors by similarity
- LLM — generates the final answer using retrieved context
n8n has nodes for every one of these steps.
RAG Architecture in n8n: How the Pieces Fit Together
A typical n8n RAG setup uses two separate workflows: one for ingestion (loading and embedding your documents) and one for querying (retrieving context and generating answers).
For the ingestion side, you'll use a combination of document loader nodes (Google Drive, Notion, HTTP Request, or Read Binary File), the Text Splitter node to chunk content, an Embeddings node (OpenAI Embeddings, Google Vertex AI Embeddings, or Cohere), and a Vector Store node configured in insert mode. Supported vector stores in n8n include Pinecone, Qdrant, Supabase Vector Store, PGVector (Postgres), and the in-memory vector store for testing.
For the query side, you'll use the AI Agent node or a Basic LLM Chain connected to a Vector Store Retriever sub-node. The retriever searches your indexed vectors, returns the top-k most relevant chunks, and the LLM uses them as context to generate a response.
Tip: Start with the In-Memory Vector Store for prototyping. It requires zero setup and lets you test your chunking strategy and prompts before committing to a hosted vector database.
Build the Document Ingestion Pipeline
Here's how to build a document ingestion workflow step by step:
Step 1: Trigger the workflow. Use a Schedule Trigger to re-index on a cadence (e.g., daily), or use a Webhook node so you can trigger ingestion on demand. For Google Drive or Notion sources, you can also use their respective trigger nodes to re-index when documents change.
Step 2: Load your documents. Add the appropriate document loader. For Google Drive files, use the Google Drive node to download files, then pass them through the Extract from File node to get the text content. For Notion pages, the Notion node can pull page content directly. For web pages, use the HTTP Request node combined with the HTML Extract node.
Step 3: Split text into chunks. Add a Text Splitter node. Set the chunk size between 500 and 1,000 characters with an overlap of 100–200 characters. The overlap ensures context isn't lost at chunk boundaries. The Recursive Character Text Splitter is the most reliable default — it tries to split on paragraphs first, then sentences, then characters.
Step 4: Generate embeddings and store vectors. Connect the text splitter output to a Vector Store node in insert mode. Attach an Embeddings sub-node (e.g., Embeddings OpenAI using text-embedding-3-small) to the vector store node. Configure your vector store credentials — for Supabase, you'll need your project URL and service key; for Qdrant, the API endpoint and collection name.
Include metadata with each chunk: the source document name, URL, and last-modified date. This lets you filter results later and show users where the answer came from.
Build the RAG Query Workflow
The query workflow is where your users interact with the system. Here's how to wire it up:
Step 1: Set up the entry point. Use a Chat Trigger node for an interactive chat interface, or a Webhook node if you're integrating with Slack, Teams, or another front end. The Chat Trigger gives you a built-in test chat window inside the n8n editor.
Step 2: Configure the AI Agent. Add an AI Agent node and connect it to your LLM of choice — the OpenAI Chat Model node (GPT-4o), Anthropic Chat Model (Claude), or Google Vertex Chat Model (Gemini). Set the system prompt to instruct the model to answer only from retrieved context:
You are a helpful assistant. Answer questions using ONLY the provided context.
If the context doesn't contain enough information, say so.
Always cite which document your answer comes from.
Step 3: Attach the Vector Store Retriever. Add a Vector Store node in retrieve mode as a tool for the AI Agent. Configure it to return the top 4–6 results. Use the same embedding model you used during ingestion — mismatched models will produce garbage results.
Step 4: Test with real queries. Open the Chat Trigger's test panel and ask questions that require specific knowledge from your documents. Check that the retrieved chunks are relevant and that the LLM's answer is grounded in them.
text-embedding-3-small to text-embedding-3-large, you need to re-index all your documents.
Add Conversational Memory to Your RAG Agent
A single-turn RAG workflow is useful, but most real applications need conversational context. If a user asks "What's our refund policy?" and then follows up with "How long does it take?", the agent needs to remember the topic was refund policy.
n8n provides several memory nodes you can attach to the AI Agent:
- Window Buffer Memory — stores the last N message pairs in memory. Simple and effective for short conversations. Set it to 5–10 exchanges for most use cases.
- Redis Chat Memory — persists conversation history in Redis with sub-millisecond reads. Ideal for production workloads where you need conversations to survive workflow restarts. You'll need Redis credentials — if you're running on n8nautomation.cloud, you can connect to any external Redis instance.
- Postgres Chat Memory — stores conversations in a Postgres table. Good when you want to query or audit conversation history using SQL.
- Motorhead Memory — uses the Motorhead server for memory management with automatic summarization of older messages.
To add memory, connect a memory sub-node to your AI Agent node's memory input. Set a session ID using an expression — typically the user's email, Slack user ID, or a unique conversation identifier from your webhook payload. This ensures each user gets their own conversation thread.
For RAG specifically, the combination of Window Buffer Memory (for conversation context) and the Vector Store Retriever (for document context) is the most common pattern. The agent sees both the recent chat history and the retrieved documents when generating each response.
Production Tips for Reliable RAG Workflows
Getting a RAG prototype working takes an afternoon. Getting it production-ready takes more thought. Here's what matters:
Chunk size tuning. Smaller chunks (300–500 chars) give more precise retrieval but may miss surrounding context. Larger chunks (800–1,200 chars) preserve context but may dilute relevance. Test with your actual data and queries. There's no universal right answer.
Metadata filtering. Tag chunks with source, category, or date metadata during ingestion. In the retriever, use metadata filters to narrow the search scope. For example, a support bot should only search support docs, not marketing copy.
Re-indexing strategy. Documents change. Set up a scheduled workflow that re-indexes modified documents daily or weekly. Use the document's last-modified timestamp to avoid re-processing unchanged content. The If node can compare timestamps to filter which documents need re-embedding.
Error handling. Add an Error Trigger workflow that notifies you (via Slack, email, or Teams) when the ingestion or query workflow fails. Embedding API rate limits are the most common failure point — use the Wait node to add delays between batches if you're processing hundreds of documents.
Cost management. Embedding API calls cost money. Cache your embeddings in the vector store and only re-embed when content actually changes. The text-embedding-3-small model from OpenAI is significantly cheaper than its larger sibling with minimal quality loss for most business use cases.
Tip: Run your RAG workflows on a dedicated n8n instance so embedding jobs don't compete with your other automations for resources. n8nautomation.cloud gives you a dedicated instance starting at $15/month — no shared infrastructure, no resource contention.
Real-World RAG Use Cases You Can Build Today
Here are five practical RAG workflows you can build in n8n right now:
1. Internal knowledge base chatbot. Ingest your Notion wiki, Google Drive docs, or Confluence pages. Expose a Chat Trigger endpoint and embed it in your internal tools. Employees get instant, accurate answers without searching through dozens of documents.
2. Customer support agent with context. Connect your Zendesk or Intercom knowledge base to a vector store. When a support ticket arrives, the workflow retrieves relevant articles and drafts a response for the agent to review. Attach a human-in-the-loop approval step before sending.
3. Sales proposal generator. Index your case studies, product specs, and pricing docs. When a sales rep triggers the workflow with a prospect's requirements, the RAG pipeline pulls relevant content and generates a tailored proposal draft.
4. Meeting notes Q&A. After each meeting, ingest the transcript (from Fireflies, Otter, or a Whisper transcription workflow) into your vector store. Team members can query past meetings: "What did we decide about the API migration timeline?"
5. Regulatory compliance checker. Ingest your compliance documents, policies, and regulatory guidelines. When a new process or feature is proposed, query the RAG pipeline to check for potential compliance issues. Useful in finance, healthcare, and legal teams.
Each of these can run entirely on a managed n8n instance at n8nautomation.cloud — connect your vector store, configure your embedding model credentials, and you're in production. No infrastructure to manage, no Docker containers to babysit, just workflows that run.