AI Agent with Multi-Source RAG: GPT-4, Perplexity, Supabase & Google Sheets - n8n Workflow

Build an advanced AI agent using n8n to combine real-time search (Perplexity), vector databases (Supabase), and structured data (Google Sheets). This n8n workflow leverages RAG and Cohere reranking.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Automation specialists looking for advanced n8n templates.
Businesses needing an AI agent that accesses both internal (Supabase, Sheets) and external (web) data.
Developers interested in implementing complex RAG architectures within an n8n workflow.
Users aiming to leverage LangChain features within n8n, such as chat memory and reranking.

Overview

This advanced n8n workflow demonstrates how to construct a powerful AI agent that transcends single data source limitations. The core value of this n8n template lies in its ability to centralize knowledge retrieval using the MCP (Multi-Channel Protocol) pattern, allowing the agent to dynamically access real-time web search (via Perplexity), structured business data (via Google Sheets), and personalized, vectorized knowledge (stored in Supabase). Every component, from the initial n8n trigger to the final Cohere reranker n8n node, is designed for optimal performance and high-quality response generation. This specific n8n workflow ensures context retention via PostgreSQL memory, making conversations seamless and intelligent. Mastering this complex n8n workflow is key to deploying enterprise-grade conversational AI.

How it Works

This comprehensive n8n workflow initiates when a user sends a message, triggering the process through a specialized n8n trigger node.


  1. Initiation: The When chat message received n8n trigger starts the conversation, passing the query to the AI Agent n8n node.

  2. Agent Logic & Memory: The AI Agent utilizes the OpenAI Chat Model (likely GPT-4) and maintains state using the Postgres Chat Memory n8n node, ensuring conversation continuity.

  3. Tool Call: If the agent determines it needs external information (e.g., to answer a question requiring knowledge outside its LLM training), it calls the MCP Client knowledge tool.

  4. Knowledge Hub Activation: This tool call activates the Knowledge MCP n8n trigger. This trigger acts as a unified endpoint for knowledge requests.

  5. Multi-Source Retrieval: The Knowledge MCP simultaneously queries three distinct data sources:

Real time web search (Perplexity tool).
Tabular data (Google Sheets tool).
* Vectorized personal data (Supabase Vector Store).

  1. RAG Enhancement: Retrieval from Supabase is enhanced by the Embeddings OpenAI n8n node for vector generation and the Reranker Cohere n8n node for filtering and prioritizing the most relevant documents.

  2. Final Response: The retrieved context from all sources is aggregated and sent back through the MCP architecture to the AI Agent. The agent synthesizes this information using the OpenAI Chat Model to generate the final, contextualized response, which is then delivered back to the user via the initial n8n trigger.

Installation Guide

To deploy this powerful n8n workflow template, follow these steps:


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

  2. Credentials Setup: Configure the necessary credentials for each service:

OpenAI: Set up credentials for the Embeddings OpenAI and OpenAI Chat Model n8n node.
Supabase: Configure the Supabase n8n node connection (API URL, Secret Key, Table Name).
Google Sheets: Set up your Google Sheets service account credentials for the Tabular data n8n node.
Perplexity: Configure the required API key for the Real time web search n8n node.
PostgreSQL: Set up credentials for Postgres Chat Memory to store chat history.
Cohere: Configure the API key for the Reranker Cohere n8n node.

  1. Webhook Setup: The When chat message received n8n trigger and the Knowledge MCP n8n trigger will automatically generate webhooks upon activation. Ensure your n8n instance is publicly accessible if you plan to use this n8n workflow in a production environment.

  2. Activation: Save the n8n workflow and set the workflow status to 'Active'.

Node Details

This complex n8n workflow utilizes several specialized LangChain-enabled n8n node types:

When chat message received (n8n trigger): This is the entry point. It captures incoming messages, typically from a chat client connected to n8n, and initiates the entire n8n workflow execution.
AI Agent (n8n node): The brain of the operation. It manages tool usage and reasoning. It is configured with the OpenAI LLM and the Postgres Chat Memory.
OpenAI Chat Model (n8n node): Serves as the primary Language Model for the AI Agent, responsible for generating responses based on the context provided.
Postgres Chat Memory (n8n node): Stores and retrieves previous messages, providing the necessary context for multi-turn conversations in this n8n template.
MCP Client knowledge (n8n node): Acts as a caller tool, designed to initiate a request to the centralized Knowledge MCP n8n trigger.
Knowledge MCP (n8n trigger): This serves as a sub-workflow endpoint. It receives the knowledge request and fans out the retrieval process to the various data sources (Supabase, Sheets, Perplexity).
Vectorized personal data (Supabase n8n node): Handles interaction with the Supabase vector store, retrieving internal documents or data based on semantic similarity. It is configured to use the Cohere reranker and OpenAI embeddings.
Reranker Cohere (n8n node): A crucial step in RAG, this n8n node refines the results retrieved from Supabase, ensuring only the most relevant documents are passed back to the AI agent, significantly improving answer quality.
Tabular data (Google Sheets n8n node): Provides the agent with access to structured data stored in a specified Google Sheet, functioning as a tool for specific queries like pricing or status checks.
Real time web search (Perplexity n8n node): Allows the AI Agent to query the internet for up-to-the-minute information, overcoming the LLM's knowledge cutoff. This is a powerful n8n node for real-time applications.

Related n8n Workflows

Paid

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

Automation expert & n8n power user. I build advanced workflows combining AI, outbound, and business logic. Grab my templates or reach out for custom builds.

Featured*