AI Study Assistant (RAG) using Gemini, Supabase, and Google Drive - n8n Workflow

Build an advanced AI Study Assistant n8n workflow. This n8n template uses Google Gemini, Supabase vector search (RAG), and handles file indexing automatically from Google Drive links.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Students and Researchers: Anyone needing a conversational interface to query large volumes of PDF, text, or documentation files.

  • Automation Developers: Users looking for advanced n8n templates integrating LangChain agents, custom tools, and vector databases (Supabase/Postgres).

  • Technical Content Managers: Teams requiring an automated system for indexing knowledge base documents via Google Drive into a searchable vector store using an n8n workflow.

Overview

This robust n8n workflow solves the problem of information overload by providing an interactive, intelligent study assistant. It combines the power of Google Gemini with a Retrieval-Augmented Generation (RAG) system, ensuring answers are grounded in specific user documents.

Unlike standard chatbots, this advanced n8n template manages a comprehensive RAG pipeline:


  1. Conversational Interface: The When chat message received n8n trigger initializes the process, making the AI interactive.

  2. Automatic Indexing: If a user shares a Google Drive link, the agent automatically triggers a separate n8n workflow (used as a tool) to ingest and embed those files into the Supabase vector store.

  3. Contextual Search: The Study Agent intelligently decides whether to use the Supabase Vector Store tool for semantic search or the Calculator tool for math problems, maintaining context via Postgres Chat Memory.

This complete n8n solution ensures your study materials are always searchable, providing accurate and contextually relevant responses.

How it Works

This powerful automation operates in two distinct, interconnected n8n workflows: the Main Chat Agent and the Indexing Sub-Workflow.

Main Chat Agent (The Conversational Flow)


  1. Trigger: The When chat message received n8n trigger waits for new messages or inputs.

  2. Agent Orchestration: The Study Agent receives the message. It is configured with a system message instructing it on behavior, including handling Drive links, general conversation, and searching the vector store.

  3. Model & Memory: The Agent uses the Google Gemini Chat Model (Gemini 2.5 Pro) for reasoning and maintains long-term memory via the Postgres Chat Memory n8n node, ensuring conversation context persists.

  4. Tool Use: The Agent can invoke three tools:

Supabase Vector Store: Used for RAG retrieval against indexed study documents.
Calculator: Used for mathematical queries.
* Folder all file to vector: If the input contains a Google Drive URL, this toolWorkflow n8n node executes the secondary indexing workflow.

  1. Final Response: The Agent synthesizes the information from the LLM, memory, and tools, generating a natural, helpful response back to the user.

Indexing Sub-Workflow (Drive to Supabase RAG Pipeline)


  1. Internal Trigger: This secondary n8n workflow is activated by the Folder all file to vector n8n node in the main agent flow.

  2. Input Parsing: A Code in JavaScript n8n node extracts the necessary Google Drive folder or file ID from the input URL.

  3. DB Initialization: The Execute a SQL query n8n node (Postgres) initializes the database by creating or recreating the documents table, setting up the pgvector extension, and defining the match_documents search function.

  4. File Retrieval: The Search files and folders (Google Drive n8n node) retrieves all files within the specified folder.

  5. Batch Processing: The workflow iterates over the files using Loop Over Items.

  6. Download & Load: Each file is downloaded (and optionally converted to text/plain) and processed by the Default Data Loader n8n node.

  7. Embedding & Storage: The Embeddings Google Gemini4 n8n node generates 768-dimensional vector embeddings, which are then stored alongside the document content in the Supabase documents table using the Insert into Supabase Vectorstore n8n node, completing the RAG setup.

Installation Guide

To deploy this comprehensive n8n workflow and its associated components, follow these steps:


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

  2. Credentials Setup: You must configure the following credentials for both the main workflow and the indexing sub-workflow:

Google Gemini API: Set up a Google Palm API credential to use the Gemini models for chat and embeddings.
Supabase/Postgres Database: Configure credentials for connecting to your Supabase PostgreSQL instance. Ensure the pgvector extension is enabled in your database.
* Google Drive OAuth2: Set up a Google Drive OAuth2 credential with necessary permissions to read and download files from the specified study folders.

  1. Sub-Workflow Linking: If the sub-workflow (Drive Indexer) is not automatically imported, ensure you save it separately and correctly update the Folder all file to vector n8n node in the main agent flow to reference the specific ID of the indexing workflow.

  2. Activation: Activate the main n8n trigger (When chat message received) to make the agent endpoint live.

Node Details

This n8n template utilizes a complex network of LangChain and core n8n nodes:

When chat message received (n8n trigger): The starting point of the main n8n workflow. It exposes a public webhook URL to receive chat inputs.
Study Agent (LangChain Agent n8n node): The core intelligence. It orchestrates the flow, routes requests to the correct tools (Supabase Vector Store, Calculator, Folder all file to vector), and handles conversational context.
Google Gemini Chat Model (LangChain LM n8n node): Provides the reasoning capabilities using the models/gemini-2.5-pro model.
Postgres Chat Memory (LangChain Memory n8n node): Stores and retrieves previous messages using a Postgres database, allowing the AI to maintain long conversations based on sessionId.
Supabase Vector Store (LangChain Tool n8n node): Configured for retrieval, this node searches the documents table in Supabase, using vector similarity to find relevant study material.
Embeddings Google Gemini (LangChain Embeddings n8n node): Used by the Supabase Vector Store tool to generate 768-dimensional embeddings for search queries and for document insertion.
Folder all file to vector (LangChain ToolWorkflow n8n node): This crucial custom tool executes a secondary n8n workflow to handle the complex process of indexing Google Drive content.
Code in JavaScript (n8n node): In the indexing workflow, this node uses custom JavaScript to reliably parse Google Drive URLs and extract the necessary file or folder ID.
Execute a SQL query (Postgres n8n node): Initializes the RAG database schema, dropping and recreating the documents table to ensure clean indexing.
Search files and folders (Google Drive n8n node): Retrieves metadata for all relevant documents in the specified Drive location based on the ID extracted by the previous n8n node.

Related n8n Workflows

Free

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

Al Automation Expert || Al Agents || n8n || Python || LangChain || Helping businesses scale revenue and reduce costs with Al driven automation .

Featured*