Now inviting automation leaders: publish your playbook as a skill, under your own name. Publish yours →
Automation Skills
All skills/n8n ai nodes official/RAG
Reference · n8n ai nodes official

RAG

Part of n8n ai nodes official. Install the skill and your agent reads this page when it needs the depth.

RAG (retrieval augmented generation)

RAG in n8n is built on the LangChain primitives: document loaders, embeddings, vector stores, retrievers, and (eventually) rerankers. They wire onto agents and chains the same way models and memory do.

Before you go vector

Not every retrieval problem needs a vector store. Three cheaper alternatives to rule out first:

Reach for vector RAG when there are too many documents to list out, queries are semantic rather than navigational, and you need similarity-based retrieval at low latency.

Quickest start: in-memory vector store

The fastest path to a working RAG flow uses the in-memory vector store (@n8n/n8n-nodes-langchain.vectorStoreInMemory). It needs no external service, no provisioning, and no extra credentials beyond whichever embedding / chat-model provider you already use. Just drop it into the workflow. Data is lost on workflow restart, so this is right for prototypes, learning, and tests, not production.

Setup at a glance:

When the data needs to survive restarts or scale beyond a single instance, swap the in-memory node for a persistent vector store (vectorStoreQdrant, vectorStoreSupabase, etc.). The rest of the wiring stays the same.

n8n ships a starter template that demonstrates the in-memory pattern end-to-end. See n8n's RAG docs.

Vector RAG: the pieces

n8n exposes the LangChain primitives as sub-nodes:

Vector RAG: two workflows

Vector RAG splits cleanly into two workflows, one per direction.

Ingest workflow

Triggered manually, by schedule, by webhook, or as a sub-workflow tool the agent calls when it wants to add to the store. Shape:

[Trigger]
  ->  [Vector Store, mode: 'insert']
        ai_document   <- [Default Data Loader (with metadata)]
        ai_embedding  <- [Embeddings (OpenAI / Cohere / etc.)]

Ingest does not have to be a tool. Most often it's a separate scheduled workflow that pre-populates the vector store on a cadence (e.g. nightly), or a webhook-triggered workflow invoked by the system that produces the documents. Wire it as an agent tool only when the documents change dynamically based on conversation (the agent learns something it should remember). For static or system-managed document sets, a standalone workflow is simpler and easier to reason about.

The Default Data Loader's metadata field is load-bearing: anything you want to filter or display alongside retrieval results (source URL, document type, tenant ID) goes there. Without it, retrieval results are just chunks with no provenance.

Query workflow

[Chat / webhook trigger]
  ->  [Agent]
        ai_tool         <- [Vector Store, mode: 'retrieve-as-tool']
                              ai_embedding <- [Embeddings (same model as ingest)]
        ai_languageModel <- [Chat Model]
        ai_memory       <- [Memory]

Wired as ai_tool, the vector store becomes a tool the agent calls when it judges retrieval relevant. Wire retrieval directly into the main flow (pre-agent) instead only when every turn requires retrieval, which is rare in practice.

Embedding model must match. Whatever model embedded the documents on ingest must also embed the query. Mismatched models produce garbage retrieval. If you change embedding models, re-ingest the documents.

What's still open

Specific defaults depend too much on context to encode here. Verify against current n8n docs and your team's choices.

Vector store selection

Embedding model

OpenAI's text-embedding-3-large, Cohere's embed-v3, and various open-source models are common. Cost, dimension count, and quality differ, choose carefully upfront to avoid the need to reembed.

Retrieval-as-tool vs retrieval-before-agent

Either works. Tool-based composes better in multi-capability agents (retrieval is one tool among several). Always-retrieve is fine for narrow Q&A bots where every question is a knowledge-base question.

Cross-references

Publish your skill

Copy this prompt into Claude Code, Codex or any agent. It walks you through your first skill in about 20 minutes, with you as the author.

Click to copy.