← all posts
AI
2026-07-16
10 min read
n8n RAG Pipelines: Build AI That Actually Knows Your Business
A generic LLM doesn't know your pricing, your SOPs, or your product quirks. RAG fixes that. Here's how to wire it up in n8n without a single line of Python.
Every business we work with has the same problem: they want an AI chatbot or support agent, but the moment it's asked something specific — a refund policy, a product spec, an internal process — it either hallucinates or falls back to "I don't have that information." That's a fine-tuning problem that nobody needs. What they actually need is RAG.
Retrieval-Augmented Generation (RAG) is the pattern where, instead of baking knowledge into a model, you pull the right chunks of information at query time and hand them to the LLM as context. The model reasons over real data. No hallucinations about your return policy. No outdated specs. Just accurate answers — updated whenever your source docs change.
The good news: n8n has first-class RAG support via its Vector Store nodes. You don't need LangChain, Python, or a data engineer. You need a Supabase (or Pinecone, or Qdrant) account, an embeddings model, and about 45 minutes.
the two flows you're building
A RAG pipeline has two distinct workflows. Keep them separate in your head:
- ingestion — runs when your knowledge base changes: reads docs, chunks them, embeds chunks, stores vectors
- query — runs on every user question: embeds the query, retrieves top-K similar chunks, injects into LLM prompt, returns answer
Two workflows. One vector database in the middle. That's the whole architecture.
step 1: choose your vector store
n8n supports Pinecone, Qdrant, Supabase (pgvector), Weaviate, and others. For most clients, Supabase is the easiest entry point — you probably already use Postgres, and pgvector is a one-extension setup. Pinecone makes sense if you're scaling to millions of vectors and want managed infrastructure.
create extension vector;
create table documents (
id bigserial primary key,
content text,
metadata jsonb,
embedding vector(1536)
);
create index on documents
using ivfflat (embedding vector_cosine_ops)
with (lists = 100);
vector(1536) matches OpenAI's text-embedding-3-small. Change the dimension if you switch models.
step 2: ingestion workflow
This workflow runs on schedule or webhook trigger when docs change. Node chain:
- trigger — schedule (weekly) or webhook (on-demand when a doc is updated)
- source node — read from Google Drive, HTTP, local files, Notion, Confluence — wherever your docs live
- extract from file — pull raw text from PDFs, DOCX, HTML
- text splitter — chunk into 400–600 token segments with ~50 token overlap (n8n has this built in)
- embeddings openai — embed each chunk using
text-embedding-3-small
- supabase vector store (insert) — upsert chunks with metadata: filename, page, category, source URL
The metadata is underrated. Tag every chunk with its document category — it's what lets you do filtered retrieval later.
⚠ chunking strategy matters
- under 200 tokens: chunks lose context, retrieval gets noisy
- over 800 tokens: burns context window budget, retrieval precision drops
- sweet spot: 400–600 tokens with 10–15% overlap
- for structured docs (FAQs, pricing tables): chunk by section heading, not token count
step 3: query workflow
This runs on every user message. Node chain:
- webhook / chat trigger — receive the user's question
- embeddings openai — embed the question using the same model as ingestion
- supabase vector store (query) — top-K cosine similarity search (K=5 to start)
- aggregate — concatenate retrieved chunks into a single context string
- openai chat / ai agent — pass context + question with a constrained system prompt
- respond to webhook — return the answer
The system prompt is where most RAG implementations fail. Be explicit:
You are a support agent for [Company].
Answer ONLY using the context below.
If the answer is not in the context, say:
"I don't have that information — let me connect you with a human."
Do not fabricate. Do not use general knowledge about competitors
or industry norms. Cite the source document when possible.
Context:
{{ $json.context }}
Question:
{{ $json.userMessage }}
filtered retrieval (the power move)
Once you've tagged chunks with metadata, you can filter retrieval by document category based on query intent. This dramatically cuts noise.
In n8n's vector store query node, pass a filter JSON. Detect the query category first (via classification step or keyword match), then filter:
{ "category": "pricing" }
{ "category": "support" }
A bot searching 50K chunks of product documentation won't accidentally pull warranty text when someone asks about upgrade pricing. The metadata filter is the difference between 70% accuracy and 95% accuracy.
keeping it fresh
- schedule ingestion weekly minimum — or trigger via webhook on doc update events
- store a file hash in metadata — only re-embed chunks from files that have actually changed
- delete before re-insert — filter-delete all chunks with the same
source_file before ingesting updated versions
- monitor retrieved chunks — log what was retrieved alongside each answer; if relevance looks wrong, revisit chunk sizing
real use cases
- internal ops FAQ bot — 200-page company handbook in Supabase; Slack bot answers HR questions. Saved ~3h/week of manager time in month one.
- e-commerce support agent — 10K-SKU product catalogue + return policy. Handles 70% of support tickets without escalation.
- legal Q&A — contract templates and standard terms; salespeople ask "does our SLA cover this?" and get accurate answers with source references.
- onboarding assistant — retrieves from engineering docs, process guides, tool tutorials. Reduces new hire onboarding time by ~2 days.
what it costs
RAG is one of the cheapest AI patterns at scale. A 5,000-page knowledge base costs under $2 to embed with text-embedding-3-small. Each query (embed + retrieve + LLM call with 2K context) runs about $0.003–0.008 with GPT-4o-mini. 1,000 queries/day ≈ $3–8/day in API fees.
where to start
pick one high-value knowledge source: FAQ doc, product catalogue, or handbook
set up supabase pgvector — 10 minutes, free tier is generous
build ingestion workflow, ingest source, verify chunk quality
build query workflow, test 10 real questions your team actually asks
add metadata filtering once you have multiple document categories
connect to slack, web chat widget, or CRM — wherever questions come in
See also: ai customer support automation end-to-end, n8n ai agent workflow patterns, and multi-agent orchestration patterns.
Want this built? we build and maintain rag pipelines for clients → from ingestion to monitoring, no python required on your end.