Retrieval-Augmented Generation (RAG) using Simple Vector Stores - n8n Workflow

Use this powerful n8n workflow to build a custom RAG knowledge base. Upload files via an n8n trigger, embed data using OpenAI, and query context with an AI agent for advanced retrieval.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Technical users and developers setting up proof-of-concept AI systems.

  • Businesses needing to integrate private documentation or data into an AI chatbot.

  • Anyone looking for robust n8n templates focusing on advanced AI features.

  • Users wanting to learn how to deploy a full RAG system using an n8n node approach.

Overview

This comprehensive n8n template provides a complete framework for implementing Retrieval-Augmented Generation (RAG). RAG is crucial for grounding large language models (LLMs) in specific, up-to-date, or private data, overcoming their knowledge limitations. This specific n8n workflow is structured into two main flows: the Load Data Flow and the Retriever Flow.

The Load Data Flow uses an n8n trigger (Form Trigger) to ingest documents (PDFs, CSVs), process them, and convert them into vectors using OpenAI embeddings, storing them in a volatile (in-memory) vector store, identified by the key vectorstorekey.

The Retriever Flow uses an n8n chat trigger to listen for user queries. It then employs an AI Agent that intelligently uses the configured knowledge base tool (the Vector Store) to retrieve relevant context before formulating an accurate answer using the OpenAI Chat Model. This demonstrates the immense capability of using n8n for complex AI orchestration.

How it Works

This n8n workflow operates via two distinct logical pathways:

1. The Load Data Flow (Indexing)


  1. Start/Trigger: The process begins with the Upload your file here n8n trigger, which is an n8n Form Trigger. Users upload their files (like .pdf or .csv) here.

  2. Document Preparation: The binary data is implicitly processed, moving toward the vector store.

  3. Embedding Generation: The Embeddings OpenAI n8n node calculates high-dimensional vector representations for the document chunks using the OpenAI API.

  4. Insertion: The Insert Data to Store n8n node (an In-Memory Vector Store) takes the embedded documents and inserts them into the memory partition identified by the vectorstorekey. This completes the indexing phase.

2. The Retriever Flow (Querying)


  1. Chat Trigger: The When chat message received n8n trigger initiates the query phase whenever a user submits a message to the associated n8n chat interface.

  2. Language Model Setup: The OpenAI Chat Model n8n node (configured to use gpt-4o-mini) provides the core reasoning capability for the AI Agent.

  3. Knowledge Tool: The Query Data Tool n8n node is the interface to the previously indexed vector store. It is configured to retrieve relevant context based on the user's query.

  4. AI Orchestration: The central AI Agent receives the user query from the n8n trigger. It analyzes the query, determines if the knowledge_base tool is necessary, retrieves the relevant context from the vector store, and finally generates a grounded, contextualized response using the connected language model. This sophisticated logic makes this a powerful n8n workflow example.

Installation Guide

To deploy this RAG n8n template, follow these steps:


  1. Import: Copy the provided JSON code and paste it directly into your n8n instance using the 'New' -> 'Import from JSON' option.

  2. Credentials: You must configure credentials for the Embeddings OpenAI and OpenAI Chat Model nodes. Select your existing OpenAI API key or create a new one.

  3. Execution (Load Data): Click the 'Execute Workflow' button (or activate the workflow). The Form Trigger (Upload your file here) can then be accessed via its webhook URL to upload your data files.

  4. Execution (Querying): After data is loaded, open the associated chat interface for the When chat message received n8n trigger (click 'Open Chat'). You can now ask questions related to the content you uploaded. This ensures the full n8n workflow is functional.

Node Details

Upload your file here (n8n Form Trigger):
Function: Serves as the initial n8n trigger for the Load Data Flow, allowing users to upload binary files (PDFs, CSVs) which contain the data to be indexed.
Key Configuration: Accepts file types .pdf, .csv and is set as a required field.
Embeddings OpenAI (n8n LangChain Node):
Function: Generates vector embeddings for document chunks during insertion and for the user query during retrieval, ensuring semantic similarity searches are possible.
Key Configuration: Requires valid OpenAI credentials.
Insert Data to Store (In-Memory Vector Store n8n node):
Function: Stores the embedded chunks of data in a temporary, in-memory knowledge base, using the identifier vectorstorekey.
Key Configuration: Mode set to insert; Key set to vectorstorekey.
When chat message received (n8n Chat Trigger):
Function: The entry point n8n trigger for the Retriever Flow, waiting for user input via the n8n chat interface.
OpenAI Chat Model (n8n LangChain Node):
Function: Provides the LLM reasoning backbone for the AI Agent.
Key Configuration: Model selected is gpt-4o-mini.
Query Data Tool (In-Memory Vector Store n8n node):
Function: Acts as a callable tool for the AI Agent, executing a similarity search on the stored vectors (vectorstorekey) to retrieve relevant contextual documents.
Key Configuration: Mode set to retrieve-as-tool; Tool Name set to knowledgebase.
AI Agent (n8n LangChain Node):
* Function: The orchestrator of this n8n workflow. It decides whether to use the knowledge
base tool before passing context and the user query to the language model to generate the final response.

Related n8n Workflows

Free

Nodes: 8 Nodes
Updated: December 26 2025
View all
Created by
n8n Team
n8n Team

Meet the official n8n team. We specialize in building workflows that transform intricate tasks into seamless operations.

Featured*