WhatsApp Retrieval-Augmented Generation (RAG) Chatbot using Supabase, Gemini, and OpenAI - n8n Workflow

Build an advanced WhatsApp RAG chatbot using this powerful n8n workflow. It uses the n8n node ecosystem to integrate Gemini 2.5 Flash, OpenAI embeddings, and Supabase for efficient knowledge retrieval.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Technical teams needing to deploy a scalable knowledge base accessible via WhatsApp.

  • Developers interested in leveraging RAG architectures with n8n.

  • Businesses looking for customer support automation using context-aware AI.

  • Users searching for robust n8n templates integrating multiple AI services (Gemini, OpenAI) and Supabase.

Overview

This sophisticated n8n workflow provides a complete solution for deploying a Retrieval-Augmented Generation (RAG) system directly accessible via WhatsApp. The primary challenge this n8n template solves is turning unstructured knowledge (documents uploaded via chat) into structured, queryable data, and then using a state-of-the-art Large Language Model (LLM) to deliver accurate, context-specific answers.

The system features two main components: a Document Flow for ingestion and a Query Flow for retrieval. The Document Flow leverages OpenAI embeddings to vectorize uploaded documents and stores these vectors securely in a Supabase vector database. The Query Flow uses the power of a custom RAG agent in n8n, powered by the Gemini 2.5 Flash LLM, to search the Supabase vectors and formulate an informed response, guaranteeing high accuracy and relevance. This robust n8n workflow showcases the flexibility of the n8n node environment for complex AI tasks.

How it Works

This n8n workflow begins with the New WhatsApp Message n8n trigger.


  1. Trigger and Routing: The dedicated n8n trigger captures any incoming WhatsApp message. The Check if Query or Document n8n node immediately evaluates the payload to determine if the message is a text query or a document upload.

  2. Document Ingestion Flow: If a document is detected, the flow proceeds to fetch the document URL, download the file, convert the file content to text, generate vector embeddings using OpenAI, and finally, store these embeddings in the designated 'documents' table in the Supabase vector database using the specialized n8n node.

  3. Query Retrieval Flow: If a text query is detected, the message is routed to the RAG Query Agent n8n node. This agent is configured to use the powerful Google Gemini LLM and leverages the Retrieve Context from Supabase n8n node as a tool. The tool uses OpenAI embeddings (the same model used for ingestion) to query the Supabase database, fetching the most relevant documents.

  4. Response Generation: The context retrieved from Supabase is passed to the Gemini LLM. The LLM generates a concise, contextual answer.

  5. Final Action: The final output is formatted and sent back to the user instantly via the Send WhatsApp Reply n8n node, completing the automated cycle.

Installation Guide

To install this specific n8n workflow and run it successfully, follow these steps:


  1. Import the n8n Template: Copy the provided JSON and import it directly into your n8n instance via the 'Workflows' section using the 'New' button and 'Import from JSON'.

  2. Set up Credentials: You must configure credentials for all required services in the n8n credential manager:

WhatsApp Business API/Trigger API: Required for the n8n trigger and reply nodes.
Supabase: Needed for the Vector Store operations (retrieval and insertion).
OpenAI: Required for generating document and query embeddings.
Google Gemini (PaLM): Required for the Large Language Model response generation.
* HTTP Header Auth (WhatsApp): Used for authorizing the document download requests.

  1. Webhook Setup: Ensure the WhatsApp Business API webhook is correctly pointing to the exposed URL for the New WhatsApp Message n8n trigger.

  2. Database Configuration: Verify that your Supabase instance has the necessary table ('documents') set up for vector storage, matching the configuration within the n8n node parameters.

Node Details

New WhatsApp Message (n8n trigger): The starting point of the n8n workflow. It fires upon receiving any new message (text or document) from a WhatsApp user.
Check if Query or Document (Switch n8n node): Essential core logic flow control. It uses conditional checks (presence of text or document fields) to branch the n8n workflow into RAG Query or Document Ingestion paths.
Get Document URL & Download WhatsApp Document (WhatsApp API & HTTP Request n8n node): Collaboratively handle binary data. They first retrieve the direct media URL and then download the binary file content, ready for processing.
Generate OpenAI Embeddings (n8n node): Crucial for RAG. It takes the text content and creates high-dimensional vector representations using the OpenAI embedding model.
Store Embeddings in Supabase (n8n node): Manages the persistent storage of vector data in the Supabase database, enabling future context retrieval.
Retrieve Context from Supabase (n8n node): Configured as a tool for the RAG Agent. This specialized n8n node performs the vector similarity search against the stored Supabase data based on the user's query embeddings.
Google Gemini LLM (n8n node): Provides the conversational intelligence. This node is connected to the RAG Agent to process the user query and the retrieved context, generating a final, coherent answer.
RAG Query Agent (n8n node): The control center for the RAG process. It orchestrates the use of the Gemini LLM and the Supabase retrieval tool to generate the best possible response.


  • Send WhatsApp Reply (n8n node): The final action node, responsible for sending the contextual response generated by the LLM back to the originating WhatsApp contact.

Related n8n Workflows

Free

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

Exploring AI and automation with n8n. Here to share builds, learn from the community, and create useful workflows together.

Featured*