Tips > AI & LLM Integration

Implement RAG with Vector Stores for Document Q&A

Retrieval-Augmented Generation (RAG) grounds LLM responses in your actual documents rather than relying on the model's training data.

Retrieval-Augmented Generation grounds LLM responses in your own documents instead of the model's training data. n8n supports it natively with vector store nodes -- Supabase, Pinecone, Qdrant, or Postgres with pgvector -- combined with an embedding model and the AI Agent. An ingestion workflow embeds and stores document chunks; a query workflow retrieves the most relevant chunks and synthesizes a grounded answer.

What is RAG with vector stores in n8n?

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.

How do you build the ingestion and query workflows?

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]

Supabase table setup:

-- 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);

Vector Store Retriever configuration:

SettingValue
Top K4
Metadata Filter{ "source": "hr_docs" }

AI Agent system prompt incorporating retrieved context:

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.

How does the retriever produce a grounded answer?

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 · Flatten Deeply Nested API Responses

Showcase builds

19 complete workflows from my own projects, each with its n8n workflow JSON to import. Showcase entries link the file at the end of the article.

See the showcase builds

Keep reading

190 entries grouped by topic, from first workflow to queue mode. Free, no signup.

Browse the encyclopedia

Need it built?

I design, build and run n8n systems for clients. Every engagement starts with a $1,500 diagnostic audit, credited toward the build.

Book an introductory call