AutomationAdvanced

How to Build a RAG Chatbot Over Your Docs in n8n

Embed your documents into a vector store, then answer questions against them with an AI Agent so replies are grounded in your own content.

12 minAdvanced

Retrieval augmented generation lets a chatbot answer from your own documents instead of guessing from training data. In n8n this is two workflows: one that ingests and embeds your files, and one that retrieves matching chunks and feeds them to an AI Agent. This guide builds both using the built-in Simple Vector Store so you can run it without external infrastructure.

What you need

  • A running n8n instance with an OpenAI credential
  • Some source documents (text, PDF, or markdown)
  • Basic familiarity with the n8n LangChain nodes

Step 1: Build the ingestion workflow

Start a new workflow with a manual trigger. Add a node that reads your documents (Read/Write Files from Disk, or an HTTP Request for remote docs), then a Default Data Loader to convert them into document chunks, and a Recursive Character Text Splitter to keep chunks a sensible size.

n8n - Ingestion workflow canvas
[Manual Trigger] -> [Read Files] -> [Vector Store (Insert)]
|
[Embeddings OpenAI] [Default Data Loader]
|
[Recursive Text Splitter]
Files flow into a loader, splitter, embeddings, and the vector store.

Step 2: Embed and insert into the vector store

Add a Simple Vector Store node in Insert mode and give it a memory key like company-docs. Connect an Embeddings OpenAI sub-node to it. Run the workflow once to load every chunk into memory. The embeddings model turns each chunk into a vector the store can search by similarity.

Simple Vector Store is in-memory
The built-in store lives in RAM and clears on restart, which is great for prototyping. For anything you want to keep, swap it for a persistent store such as Qdrant or Pinecone using the matching n8n node.

Step 3: Build the chat workflow

In a second workflow add a Chat Trigger node, then an AI Agent node. Connect a Chat Model (OpenAI) sub-node to the agent for reasoning, and a Vector Store retrieval tool pointed at the same company-docs key so the agent can look things up.

AI Agent - System Message
You are a support assistant. Answer only using the documents
returned by the company-docs tool. If the answer is not in the
documents, say you do not know and suggest contacting support.
Always cite the section title you used.

Step 4: Ask a question and check grounding

Open the chat panel and ask something only your docs would know. The agent should call the vector store tool, retrieve relevant chunks, and answer from them. If it answers without calling the tool, tighten the system message and confirm the tool is connected.

n8n - Chat panel
You
What is our refund window?
Agent
Per the Returns section, refunds are available within 30 days of delivery with the original receipt.
The agent retrieves a chunk before answering.

Result

You have a chatbot that answers from your own documents and admits when something is not covered. Re-run the ingestion workflow whenever the docs change, and point both workflows at a persistent vector store when you are ready to ship.

Watch related tutorials

Tags
#n8n#rag#vector-store#embeddings#ai-agent