Recursive Document RAG Pipeline with Supabase and Multi-LLM Context - n8n Workflow

Implement a robust n8n workflow for Retrieval-Augmented Generation (RAG) using recursive chunking. Integrate Google Drive, OpenAI, and Supabase Vector Store for powerful knowledge base automation.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Data scientists and AI practitioners building high-fidelity RAG applications.

  • Developers seeking advanced, customizable n8n templates for knowledge management.

  • Organizations managing large volumes of internal documentation (PDFs, text files).

  • Users needing to connect Google Drive, OpenAI, and Supabase into a unified automation using an n8n node.

Overview

This comprehensive n8n workflow provides a sophisticated solution for creating a high-quality Retrieval-Augmented Generation (RAG) knowledge base. Unlike basic systems, this n8n template employs custom logic for recursive chunking, ensuring that crucial document context (such as table integrity or partial sentences) is preserved or reconstructed. The automation starts with an n8n trigger watching Google Drive for new documents. It then uses an OpenAI Chat Model to intelligently enrich potentially broken chunks before they are vectorized. This critical pre-processing step drastically improves retrieval accuracy later on. The embedded vectors and metadata are then stored in a Supabase Vector Store, ready to be queried by an AI Agent powered by both OpenAI and Google Gemini models. This is a highly technical and powerful n8n workflow.

How it Works

The n8n workflow operates in two main phases: Document Ingestion and Query Processing.

Phase 1: Document Ingestion (Google Drive Trigger)


  1. Trigger: The Google Drive Trigger acts as the primary n8n trigger, activating the n8n workflow whenever a new file is created in the designated folder.

  2. Metadata and Download: The Loop Over Items and File info nodes extract necessary metadata (File ID, type, URL) before the Google Drive n8n node downloads the file content.

  3. Extraction: A Switch n8n node directs the flow based on the file's MIME type, routing PDFs to the Extract from PDF n8n node and plain text to Extract from TEXT.

  4. Recursive Chunking: The Recursive Splitter n8n node (a custom Code node) performs intelligent chunking (Chunk Size 1000, Overlap 200). This logic prioritizes splitting on paragraphs and sentences to maintain semantic cohesion, a key feature of this advanced n8n workflow.

  5. Contextual Enrichment: The Chunk Splitting node processes the chunks individually. The Basic LLM Chain, powered by the OpenAI Chat Model (GPT-4o-mini), reviews each chunk alongside the full document text to add necessary context, repair incomplete data (like cut-off numbers or tables), and prepare it for better retrieval.

  6. Embedding and Storage: The enriched chunks are prepared by the Default Data Loader (attaching metadata like the file URL) and broken down by the Character Text Splitter. The Embeddings OpenAI n8n node calculates the vector representations, which are then inserted into the Supabase Vector Store.

Phase 2: Query Processing (Manual Trigger)


  1. Activation: The query path is initiated manually via the When clicking ‘Execute workflow’ n8n trigger.

  2. Agent Orchestration: The OpenAI n8n node pre-processes the input query. The central AI Agent uses a specialized persona (AI Examiner Agent) to orchestrate retrieval.

  3. Hybrid Retrieval: The agent utilizes the SupaBase Query n8n node (an HTTP Request tool) to search the stored vector knowledge base.

  4. Final Response: The final answer generation is handled by the Google Gemini Chat Model (Gemini 2.5 Flash), providing a sophisticated, multi-LLM RAG response based on the retrieved context.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import the n8n Workflow: Copy the provided JSON data and import it into your n8n instance via the 'Workflows' > 'New' > 'Import from JSON' option.

  2. Google Drive Credentials: Configure the Google Drive Trigger and Google Drive n8n node with OAuth2 credentials pointing to the Google account that monitors the input folder. Ensure the folder ID in the Google Drive Trigger parameters is correct.

  3. OpenAI Credentials: Set up or select your OpenAI API credentials for the OpenAI Chat Model, OpenAI (pre-processing), and Embeddings OpenAI nodes. A single set of credentials can typically cover all these uses.

  4. Supabase Credentials: Configure the Supabase Vector Store n8n node with your Supabase API credentials. Ensure the target table name (documents) is configured in your Supabase instance.

  5. Supabase Tool Setup: In the SupaBase Query n8n node (HTTP Request), update the URL to your actual Supabase Function URL and replace the placeholder value in the Authorization header with your actual Supabase API key/secret.

  6. Google Gemini Credentials: Configure the Google Gemini Chat Model n8n node with the necessary API credentials.

  7. Activate: Save the n8n workflow and set the Google Drive Trigger to active for automated ingestion, and test the manual trigger for the RAG query path.

Node Details

Google Drive Trigger (n8n trigger): Starts the n8n workflow upon file creation. Configured to watch a specific folder ID.
Recursive Splitter (Code n8n node): Custom JavaScript for intelligent document segmentation. Implements recursive chunking logic (1000 character size, 200 overlap) prioritizing paragraph and sentence breaks for better context preservation.
Google Drive (n8n node): Downloads the file content after the trigger fires, converting the file (if necessary, like Google Docs) to text/plain.
Switch (n8n node): Routes documents based on File_Type (MIME type). Directs PDFs to Extract from PDF and plain text files to Extract from TEXT.
OpenAI Chat Model (n8n node): Used within the Basic LLM Chain to perform chunk enrichment and contextualization, utilizing gpt-4o-mini to correct data integrity issues in segmented chunks.
Supabase Vector Store (n8n node): The final storage destination. Configured for the insert operation into the documents table, storing embeddings generated by the n8n template.
Embeddings OpenAI (n8n node): Calculates the vector embeddings for the chunked and enriched documents.
AI Agent (n8n node): Orchestrates the RAG retrieval process during the query phase. Configured with a system message defining its role as an examiner agent, utilizing the Supabase Query tool.


  • Google Gemini Chat Model (n8n node): Used as the final language model within the AI Agent for generating high-quality, retrieved answers.

Related n8n Workflows

Free

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

As an AI Automation Specialist on a mission to revolutionise how businesses operate, I’m passionate about turning complex technology into actionable solutions. My journey into AI isn’t just about algorithms—it’s about empowering leaders like you to reclaim time, slash inefficiencies, and unlock growth through smart automation.

Featured*