Retrieval-Augmented Generation (RAG) grounds LLM responses in your actual documents rather than relying on the model's training data.
Retrieval-Augmented Generation (RAG) grounds LLM responses in your actual documents rather than relying on the model's training data. n8n supports this natively via vector store nodes (Supabase, Pinecone, Qdrant, Postgres with pgvector) combined with embedding models and the AI Agent or Chain nodes.
Real-world example: Build an internal knowledge base chatbot that answers questions using your company's HR policy documents stored in Supabase.
Ingestion workflow (run once when documents change):
[Google Drive Trigger] → [Extract Text] → [Text Splitter] → [Embeddings OpenAI] → [Supabase Vector Store: Insert]
Query workflow (runs per user question):
[Chat Trigger] → [AI Agent] → [Chat Response]
│
Sub-nodes:
├── [Embeddings OpenAI]
├── [Supabase Vector Store: Retrieve]
└── [OpenAI Chat Model]
```text
Supabase table setup:
```sql
-- Enable the vector extension
CREATE EXTENSION IF NOT EXISTS vector;
-- Create the documents table
CREATE TABLE documents (
id bigserial PRIMARY KEY,
content text,
metadata jsonb,
embedding vector(1536) -- OpenAI text-embedding-3-small dimension
);
-- Create an index for fast similarity search
CREATE INDEX ON documents
USING ivfflat (embedding vector_cosine_ops)
WITH (lists = 100);
```text
Vector Store Retriever configuration:
| Setting | Value |
|--------------------|--------------------------|
| Top K | 4 |
| Metadata Filter | `{ "source": "hr_docs" }`|
AI Agent system prompt incorporating retrieved context:
```text
You are an HR assistant for Acme Corp. Answer questions using ONLY the
context provided from our HR policy documents. If the answer is not in
the provided context, say "I don't have information about that in our
HR policies. Please contact hr@acme.com."
Always cite the document name and section when answering.
```text
The retriever fetches the 4 most semantically similar document chunks, and the LLM synthesizes an answer grounded in those chunks.
**Related:** [Use Manual Trigger During Development Instead of Webhook or Schedule](../api-cost-optimization/01-use-manual-trigger-during-development-instead-of-webhook-or-schedule.md) | [Flatten Deeply Nested API Responses](../code-node-mastery/01-flatten-deeply-nested-api-responses.md)
I build production n8n and Cloudflare automation for teams — the same engineering behind HarperFlow. Fixed-price, escrow-protected, US-based.