AI-Powered Document Chat with Supabase Storage and RAG - n8n Workflow

Index documents (PDF/TXT) from Supabase Storage into a vector database using this advanced n8n workflow. This automation enables real-time AI agents to answer complex queries based on your file content.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Data Engineers or Developers needing automated RAG pipeline deployment.
Businesses using Supabase for document storage who require AI-powered search capabilities.
Users looking for advanced n8n templates integrating LangChain functionality with external databases.
n8n Automation Specialists setting up complex, two-part automated systems (indexing and querying).

Overview

Manually retrieving and analyzing specific information from large document repositories is time-consuming. This powerful n8n workflow solves this by creating a robust Retrieval-Augmented Generation (RAG) system using Supabase and OpenAI.

This single n8n workflow is divided into two main scenarios:


  1. Indexing Flow (Manual Trigger): Scans Supabase Storage for new PDF or text files, checks for duplicates against an existing records table, extracts content, performs text splitting, creates vector embeddings using an OpenAI n8n node, and stores them in a Supabase vector store.

  2. Chat Flow (Chat Trigger): A live AI agent utilizes the indexed Supabase vector store as a 'knowledge base' tool. When a user sends a message, the n8n agent retrieves contextually relevant document chunks before generating a precise answer. This demonstrates a high level of sophistication achievable within an n8n automation environment.

How it Works

This n8n workflow operates in two distinct, integrated stages:

Scenario 1: File Indexing and Vectorization


  1. Start & Check Existing Data: The flow begins with the When clicking ‘Test workflow’ manual n8n trigger. It first queries the Supabase files table to get a list of already indexed documents.

  2. Fetch Storage Contents: An HTTP Request n8n node retrieves a list of all files in the Supabase Storage bucket.

  3. Deduplication and Filter: The Loop Over Items node processes each file. An If conditional node checks two criteria: 1) Is the file ID already present in the indexed list? 2) Is the file name not an .emptyFolderPlaceholder? Only new, valid files continue.

  4. Download and Routing: The new file is downloaded via a secure HTTP request. The Switch node routes the binary data based on the file extension (PDF or TXT/other).

  5. Content Extraction: For PDFs, the Extract Document PDF n8n node extracts the text content. All data streams merge together.

  6. Chunking and Embedding: The Recursive Character Text Splitter breaks the large document text into manageable chunks. The Default Data Loader formats the data, and the Embeddings OpenAI n8n node generates high-quality vector embeddings (text-embedding-3-small).

  7. Storage: The Insert into Supabase Vectorstore n8n node stores these vectors in the dedicated documents table, completing the indexing. Finally, a record of the processed file is added to the Supabase files table.

Scenario 2: AI Agent Querying


  1. Chat Trigger: The process starts with the When chat message received LangChain n8n trigger, listening for user input.

  2. AI Agent Orchestration: The AI Agent n8n node (using the OpenAI Chat Model1 as its brain) processes the user query.

  3. Tool Use: The agent identifies that it needs to retrieve context and calls the Vector Store Tool1.

  4. Vector Search: The Vector Store Tool1 uses the Embeddings OpenAI2 node to vectorize the user query and searches the connected Supabase Vector Store for the 8 most relevant document chunks (Top K: 8).

  5. Final Response: The relevant document chunks are provided to the agent, allowing the LLM to generate a precise, context-aware response based exclusively on the uploaded Supabase files.

Installation Guide

To deploy this expert-level n8n workflow, follow these setup steps:


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

  2. Supabase Credentials: You will need one Supabase API credential setup connecting to your project. This single credential must be applied to the Get All Files, Get All files, Download, Create File record2, and Insert into Supabase Vectorstore n8n nodes. Ensure your Supabase RLS policies allow for listing, downloading, and database insertion.

  3. OpenAI Credentials (Indexing): Configure the Embeddings OpenAI n8n node with an OpenAI API key for vector generation.

  4. OpenAI Credentials (Chat): Configure separate OpenAI API keys for the OpenAI Chat Model1 (Agent Brain), OpenAI Chat Model2 (Tool LLM), and Embeddings OpenAI2 (Tool Embeddings). Note that the example uses different keys for the chat components (OpenAi club, Test club key).

  5. Supabase Configuration: Verify the database URLs and storage names in the Get All files and Download HTTP Request n8n nodes match your exact Supabase configuration.

  6. Activate: Save the n8n workflow. The Indexing flow should be run manually (or set up with a Cron n8n trigger for scheduling), and the Chat flow will be live via its webhook.

Node Details

When clicking ‘Test workflow’ (n8n trigger): Initiates the file indexing process manually.
Get All Files / Create File record2 (Supabase node): Manages the internal database record of processed files (files table) to prevent duplicate processing.
Get All files / Download (HTTP Request n8n node): Handles interaction with the Supabase Storage API, listing files and downloading the binary content for processing. Requires custom Supabase URL configuration.
If (n8n node): Implements the core deduplication logic, skipping files that already exist in the database or are placeholder files.
Switch (n8n node): Directs the flow based on binary file extension, specifically routing PDFs to the extraction step.
Extract Document PDF (n8n node): Specialized tool used to parse text content out of PDF binary data.
Recursive Character Text Splitter (LangChain node): Breaks down large text documents into smaller, context-rich chunks (configured for 500 characters with 200 overlap).
Embeddings OpenAI (LangChain n8n node): Generates numerical vector representations (text-embedding-3-small) of the text chunks, ready for storage.
Insert into Supabase Vectorstore (LangChain n8n node): Connects the vectors to the Supabase database (documents table), completing the RAG indexing.
When chat message received (n8n trigger): The primary n8n trigger for the chat application, activating the AI Agent upon receiving user input.
AI Agent (LangChain n8n node): The core intelligence orchestrating the RAG retrieval and response generation, using an LLM and the knowledge_base tool.
Vector Store Tool1 (LangChain n8n node): Provides the agent with the ability to query the indexed knowledge base.


  • Supabase Vector Store (LangChain n8n node): Connects the agent tool directly to the indexed Supabase vector data.

Related n8n Workflows

Free

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

I am a business analyst with a development background, dedicated to helping small businesses and entrepreneurs leverage cloud services for increased efficiency. My expertise lies in automating manual workflows, integrating data from multiple cloud service providers, creating insightful dashboards, and building custom CRM systems.

Featured*