workflows.fit
Back to n8n workflows
n8n templateFreeBy Guillaume Duvernay

Build an advanced multi-query RAG system with Supabase and GPT-5

Go beyond basic Retrieval-Augmented Generation (RAG) with this advanced template. While a simple RAG setup can answer straightforward questions, it often fails when faced with complex queries and can be polluted by ir...

AILangchainCore NodesAgentChat TriggerLm Chat Open AiMemory Buffer Window
Loading interactive preview...

Template notes

Go beyond basic Retrieval-Augmented Generation (RAG) with this advanced template. While a simple RAG setup can answer straightforward questions, it often fails when faced with complex queries and can be polluted by irrelevant information. This workflow introduces a sophisticated architecture that empowers your AI agent to think and act like a true research assistant.

By decoupling the agent from the knowledge base with a smart sub-workflow, this template enables multi-query decomposition, relevance-based filtering, and an intermediate reasoning step. The result is an AI agent that can handle complex questions, filter out noise, and synthesize high-quality, comprehensive answers based on your data in Supabase.

Who is this for?

AI and automation developers: Anyone building sophisticated Q&A bots, internal knowledge base assistants, or complex research agents. n8n power users: Users looking to push the boundaries of AI agents in n8n by implementing production-ready, robust architectural patterns. Anyone building a RAG system: This provides a superior architectural pattern that overcomes the common limitations of basic RAG setups, leading to dramatically better performance.

What problem does this solve?

Handles complex questions: A standard RAG agent sends one query and gets one set of results. This agent is designed to break down a complex question like "How does natural selection work at the molecular, organismal, and population levels?" into multiple, targeted sub-queries, ensuring all facets of the question are answered. Prevents low-quality answers: A simple RAG agent can be fed irrelevant information if the semantic search returns low-quality matches. This workflow includes a crucial relevance filtering step, discarding any data chunks that fall below a set similarity score, ensuring the agent only reasons with high-quality context. Improves answer quality and coherence: By introducing a dedicated "Think" tool, the agent has a private scratchpad to synthesize the information it has gathered from multiple queries. This intermediate reasoning step allows it to connect the dots and structure a more comprehensive and logical final answer. Gives you more control and flexibility: By using a sub-workflow to handle data retrieval, you can add any custom logic you need (like filtering, formatting, or even calling other APIs) without complicating the main agent's design.

How it works

This template consists of a main agent workflow and a smart sub-workflow that handles knowledge retrieval.