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.
Download this n8n workflow template and start using it instantly.





















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.
The n8n workflow operates in two main phases: Document Ingestion and Query Processing.
Google Drive Trigger acts as the primary n8n trigger, activating the n8n workflow whenever a new file is created in the designated folder.Loop Over Items and File info nodes extract necessary metadata (File ID, type, URL) before the Google Drive n8n node downloads the file content.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.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.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.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.When clicking ‘Execute workflow’ n8n trigger.OpenAI n8n node pre-processes the input query. The central AI Agent uses a specialized persona (AI Examiner Agent) to orchestrate retrieval.SupaBase Query n8n node (an HTTP Request tool) to search the stored vector knowledge base.Google Gemini Chat Model (Gemini 2.5 Flash), providing a sophisticated, multi-LLM RAG response based on the retrieved context.To deploy this powerful n8n workflow, follow these steps:
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.OpenAI Chat Model, OpenAI (pre-processing), and Embeddings OpenAI nodes. A single set of credentials can typically cover all these uses.Supabase Vector Store n8n node with your Supabase API credentials. Ensure the target table name (documents) is configured in your Supabase instance.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.Google Gemini Chat Model n8n node with the necessary API credentials.Google Drive Trigger to active for automated ingestion, and test the manual trigger for the RAG query path. 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.
A robust n8n workflow template for processing documents (PDF, Word, Images) from Google Drive, generating detailed performance analytics and quality scores using the PDF Vector n8n node.

Use this comprehensive n8n workflow to automate document processing. It integrates Google Drive or a file upload form with OpenAI embeddings and Qdrant, forming a powerful RAG knowledge base queryable via a Gemini-powered chatbot. This n8n template enhances document searchability.

Automate customer feedback processing using n8n, OpenAI for sentiment analysis, generating PDF reports, and sending personalized email summaries via Gmail. Deploy this powerful n8n workflow today.

Use this powerful n8n workflow to automatically remove backgrounds from uploaded images using AI services, track results, and manage temporary download links in Google Sheets.

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.







































