RAG Chatbot Builder for Google Drive Documents using Supabase - n8n Workflow

Build an advanced RAG chatbot using this n8n workflow. Connect Google Drive documents, use OpenAI embeddings, and store knowledge in a Supabase vector database for intelligent conversations.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Data scientists and developers building custom AI solutions.
Businesses needing searchable knowledge bases from proprietary documents.
Users looking for advanced, practical n8n templates integrating multiple cloud services.
Anyone interested in using the n8n node ecosystem for AI orchestration.

Overview

This powerful n8n workflow provides a complete solution for creating a dynamic, Retrieval-Augmented Generation (RAG) chatbot. It solves the problem of connecting scattered business knowledge (stored as PDFs or documents in Google Drive) directly to an intelligent AI conversational agent. The automation is split into two distinct processes: data ingestion and conversational query handling. When a file is added or updated in Google Drive, the n8n workflow processes the document, generates embeddings via OpenAI, and persists the data in Supabase. The second half of the n8n workflow operates as a live chat agent, using the stored knowledge and Postgres for session memory to provide highly relevant, context-aware answers, making this one of the most practical n8n templates available.

How it Works

This n8n workflow operates in two main phases:

Phase 1: Document Ingestion and Vectorization


  1. Google Drive Trigger (File Created/Updated): The process starts using two Google Drive n8n trigger nodes, monitoring a specified folder for newly created documents and updated documents.

  2. Set File ID: A Set n8n node extracts the unique fileid from the Google Drive payload.

  3. Handle Updates (Deletion): If a file was updated, the workflow uses a Supabase n8n node to delete any existing associated document chunks from the documents table, ensuring data freshness before proceeding.

  4. Download and Extract: The Google Drive n8n node downloads the file. The subsequent Extract from File n8n node extracts the raw text content from the downloaded document (e.g., converting PDF text to plain text).

  5. Data Loading and Splitting: The Default Data Loader prepares the text data, attaching crucial metadata (like the fileid). The Recursive Character Text Splitter n8n node ensures the document is broken into appropriately sized chunks for effective vectorization.

  6. Embedding Generation and Storage: The Embeddings OpenAI n8n node calculates the vector representations of these text chunks. Finally, the Supabase Vector Store n8n node inserts these embeddings and text chunks into the documents table in Supabase.

Phase 2: Conversational RAG Agent


  1. Chat Trigger: The conversational flow starts with the When chat message received n8n trigger, initiating the RAG process upon a user query.

  2. Agent Orchestration: The core RAG AI Agent n8n node coordinates the conversation. Its custom system message instructs it to always search the connected knowledge base first.

  3. Memory: The Postgres Chat Memory n8n node (using Supabase's database) maintains conversation history, ensuring context is preserved across turns.

  4. Language Model: The OpenAI Chat Model n8n node serves as the large language model for generating final responses.

  5. Knowledge Retrieval Tool: The RAG Vector store n8n node is configured as a retrieval tool, connected via the Embeddings OpenAI1 n8n node. When the AI agent determines a knowledge search is needed, this tool queries the Supabase vector database (documents table) for the top 6 most relevant document chunks to inform the final answer.

Installation Guide


  1. Import: Copy the provided JSON into your n8n instance using the "Import Workflow" function.

  2. Credentials: This n8n workflow requires four sets of credentials:

Google Drive (OAuth2): Enable the Drive API.
OpenAI: Input your API key for embedding and chat services.
Supabase (API/Service Role Key): Input project URL and Service Role Key.
PostgreSQL: Input connection details for chat memory storage.

  1. Supabase Setup: Run the required SQL commands in your Supabase SQL editor to enable the pgvector extension and set up the necessary documents table and matchdocuments query function (referencing the guide in the workflow's sticky note).

  2. Configuration: In the two Google Drive n8n trigger nodes, replace placeholder folder IDs with the actual IDs of the folder you wish to watch.

  3. Activation: Activate the n8n workflow. Documents uploaded to the specified Google Drive folder will now be automatically vectorized and ready for the AI agent to use.

Node Details

Google Drive Trigger (File Created / File Updated): These n8n trigger nodes monitor specific folders in Google Drive, initiating the ingestion pipeline. Key Configuration: triggerOn: specificFolder, configured with the desired folder IDs.
Supabase (Delete a row): This n8n node ensures data integrity by deleting outdated vector entries associated with an updated file ID using a metadata filter.
Download the file (Google Drive node): Downloads the file content from Drive, optionally using Google File Conversion to convert files like Docs to plain text.
Extract from File: Extracts the raw text from the binary file data downloaded by the previous n8n node, preparing it for splitting.
Recursive Character Text Splitter: This n8n node splits the large document text into smaller chunks for effective embedding and indexing, a core RAG component.
Embeddings OpenAI: Used twice in this n8n workflow. This critical n8n node calls the OpenAI API to convert text into vector embeddings, enabling similarity search.
Supabase Vector Store (Insert): The primary storage n8n node for the ingestion pipeline. It inserts the processed text chunks and their vectors into the Supabase documents table.
When chat message received (Chat Trigger): The main entry point n8n trigger for the conversational agent, starting the RAG chain upon a user query.
RAG AI Agent: The orchestrator n8n node that uses system instructions, the connected memory, language model, and tools to generate informed responses.
RAG Vector store (Retrieve): Configured as an AI Tool, this n8n node executes a vector similarity search against the Supabase database, retrieving the topK (set to 6) relevant document chunks based on the user's question embedding.


  • Postgres Chat Memory: An essential n8n node for stateful conversations, leveraging PostgreSQL for secure and reliable storage of chat history based on the user session ID.

Related n8n Workflows

Free

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

I’m currently obsessed with building cool things using AI automation and AI agents — systems that save time, cut manual work, and actually do stuff on their own. If there’s a way to automate it, I’m probably already trying it out (or planning to). Having worked in IT industry for 15 years, I’m combining that background with AI to help businesses move smarter, not just faster.

Featured*