Advanced Multi-Query Retrieval-Augmented Generation (RAG) System - n8n Workflow

Build a robust RAG system using n8n and Supabase. This advanced n8n workflow template uses AI agents to decompose complex queries, filter results, and synthesize high-quality answers with GPT-5.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

AI Engineers and Developers needing sophisticated, hallucination-resistant RAG solutions.
Technical writers and content creators looking to build Q&A bots based on structured documentation using an n8n workflow.
Users implementing knowledge base retrieval systems who require strict relevance filtering.
n8n automation specialists seeking advanced n8n templates for LangChain integration and custom tooling.

Overview

Traditional RAG systems often fail on complex, multi-faceted queries because the single retrieval call returns inadequate or conflicting information. This powerful n8n workflow solves this by implementing an Advanced Multi-Query RAG Agent pattern. The core of this system is a sophisticated AI agent that automatically breaks down the user's complex question into 1 to 5 smaller sub-queries.

These sub-queries are processed by a dedicated sub-workflow, which retrieves relevant chunks from a Supabase vector store, cleans the data, and crucially, applies a relevance filter (score > 0.4) to ensure only high-quality context is returned. This robust filtering mechanism, managed within an n8n node, significantly improves the accuracy of the final answer. This n8n workflow template provides a blueprint for reliable, production-ready knowledge retrieval.

How it Works

The process begins with the When chat message received n8n trigger, initiating the chat conversation flow.


  1. Decomposition: The input message flows into the AI Agent n8n node. Based on its system prompt, the agent, utilizing the OpenAI Chat Model (GPT-5 Mini), analyzes the request and breaks it down into an array of sub-queries (1 to 5 questions).

  2. Tool Call (Retrieval): The agent executes the Query knowledge base n8n tool (a sub-workflow call), passing the array of sub-queries.

  3. Sub-workflow Execution (RAG): The sub-workflow uses the Split Out n8n node to process each query individually. Each sub-query is embedded via Embeddings OpenAI1 and used to query the Supabase Vector Store1 n8n node.

  4. Filtering & Aggregation: Retrieved chunks are processed. The Keep score over 0.4 n8n node filters out low-relevance results. If chunks remain, they are aggregated (Aggregate chunks). If no chunks pass the filter, a 'no match' message is generated.

  5. Synthesis: The aggregated, high-quality context is returned to the main AI Agent. The agent then uses the Think n8n tool to reason over the retrieved information, ensuring coherence and adherence to the course content before finally crafting and returning the comprehensive response to the user. This structured use of n8n nodes ensures reliability and traceable outputs.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import the JSON: Copy the provided n8n workflow JSON and paste it into your n8n instance.

  2. Locate Credentials: This n8n template requires connections to both Supabase and OpenAI.

  3. Configure OpenAI Credentials: Ensure your OpenAI credentials are set up for the OpenAI Chat Model (for the LLM) and the Embeddings OpenAI1 n8n node (for embedding lookup). Note that these might use different OpenAI API accounts.

  4. Configure Supabase: Set up your Supabase API credentials for the Supabase Vector Store1 n8n node. Verify that the table name is correctly set to 'documents' or your specified vector table.

  5. Link Sub-workflow: The Query knowledge base n8n tool must be linked to the secondary RAG sub-workflow that contains the vector store retrieval logic. If you imported both workflows, ensure the workflowId is updated to match the ID of your RAG retrieval workflow (Template: c9FlK6mLuWAwqLsP).

  6. Customize the Agent: Review and modify the System Message in the AI Agent n8n node to align with the specific domain or course content of your knowledge base.

Node Details

When chat message received (n8n trigger): The starting point, listening for incoming chat messages to begin the automation.
AI Agent (LangChain n8n node): The core control structure. It manages conversational flow, utilizes memory (Simple Memory), connects to the LLM (OpenAI Chat Model), and orchestrates the use of retrieval tools.
Query knowledge base (Tool Workflow n8n node): A crucial custom tool that allows the Agent to execute a dedicated n8n workflow for complex data retrieval, passing an array of generated sub-queries.
Supabase Vector Store1 (n8n node): Performs similarity searches against the Supabase database, fetching relevant text chunks based on the query embedding generated by the OpenAI embedding model.
Keep score over 0.4 (Filter n8n node): Implements strict quality control. This n8n node filters out any retrieved documents where the relevance score is below 0.4, drastically reducing noise and potential hallucinations in the final output.
Think (LangChain n8n node): A reasoning tool used by the agent to critically analyze the retrieved knowledge and plan the final synthesis before responding to the user's initial prompt.

Related n8n Workflows

Free

Nodes: 16 Nodes
Updated: December 26 2025
View all
Created by

AI and automation expert

Featured*