Build a RAG document chatbot with Supabase vector search and OpenRouter

Go to Workflow
0 views
Built by Mariyan Nijan Mariyan Nijan
Created on June 13, 2026

Description

What this workflow does

This workflow builds a Retrieval-Augmented Generation (RAG) document chat assistant inside n8n using Supabase Vector Store and AI models.

The workflow allows users to upload documents, convert them into embeddings, store them inside Supabase pgvector, and query them through an AI chat interface using semantic search.

When a user sends a question through the webhook endpoint, the workflow retrieves the most relevant document chunks from Supabase and uses an AI model to generate a grounded response based on the uploaded documents.

This template includes:

Document ingestion pipeline
Recursive text chunking
AI embeddings generation
Supabase vector storage
Semantic retrieval
AI-powered document question answering
Webhook API integration for frontend apps

How it works

The workflow is split into two main parts:

Document ingestion pipeline

Downloads documents from Google Drive
Extracts text from PDFs
Splits text into smaller chunks
Generates embeddings using AI models
Stores embeddings inside Supabase pgvector

RAG chat pipeline

Receives user questions through a webhook
Searches Supabase vector database for relevant content
Retrieves matching document chunks
Sends retrieved context to the AI model
Returns grounded responses back to the frontend

Requirements

n8n instance
Supabase account with pgvector enabled
Google Drive account
AI provider credentials (OpenRouter, Gemini, or OpenAI)

Setup

Create a Supabase project and enable pgvector
Create the required documents table and match_documents function
Connect your Supabase credentials in n8n
Connect your AI model credentials
Add your Google Drive credentials
Upload your documents and run the ingestion workflow
Use the webhook endpoint to connect your frontend application

Setup typically takes around 15–30 minutes.

How to customize

You can customize this workflow by:

Switching AI providers (Gemini, OpenRouter, OpenAI)
Adjusting chunk size and retrieval count
Connecting your own frontend UI
Adding support for multiple document sources
Expanding the workflow into a multi-user knowledge assistant

This workflow is designed as a practical starting point for building AI-powered document assistants and RAG applications inside n8n.

Nodes Used (7)

AI Agent
@n8n/n8n-nodes-langchain.agent
Default Data Loader
@n8n/n8n-nodes-langchain.documentDefaultDataLoader
Embeddings Google Gemini
@n8n/n8n-nodes-langchain.embeddingsGoogleGemini
Google Drive
n8n-nodes-base.googleDrive
OpenRouter Chat Model
@n8n/n8n-nodes-langchain.lmChatOpenRouter
Recursive Character Text Splitter
@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter
Supabase Vector Store
@n8n/n8n-nodes-langchain.vectorStoreSupabase