How to Build a RAG Chatbot with n8n, Supabase and Google Drive
Imagine this: it is 4:55 p.m., someone pings you with “Where is the latest HR policy on remote work?” and you start the classic ritual of hunting through Google Drive folders, old PDFs, and that one spreadsheet named final-FINAL-v3.xlsx. Again.
If that scenario feels a bit too real, it is probably time to let a chatbot do the boring part for you. In this guide, we will walk through an n8n workflow template that turns your Google Drive docs into a Retrieval-Augmented Generation (RAG) chatbot backed by Supabase. You get instant, factual answers from your own documents, and you get to stop playing “Where did I save that file?” every day.
This article shows you how the template connects Google Drive, OpenAI embeddings, and a Supabase vector store to build a production-ready RAG pipeline for document ingestion, indexing, and secure chat via a webhook. You will see how each n8n node fits into the puzzle, how the data flows, and what to tweak for better results.
First things first: what is RAG, and why should you care?
Retrieval-Augmented Generation (RAG) is a simple but powerful idea. Instead of asking a language model to magically “know” everything, you give it a brain extension in the form of your own documents.
RAG has two main parts:
- Retriever – runs vector search over your documents and finds the most relevant chunks.
- Generator – a large language model that uses those chunks as context to answer questions.
So instead of the model guessing or hallucinating, it looks up the relevant pieces from your knowledge base and uses them to craft grounded, up-to-date responses. Think of it as “open book” mode for your chatbot.
What this n8n RAG template actually does
The provided n8n template is a complete, ready-to-use pipeline that connects:
- Google Drive for document storage and updates
- OpenAI embeddings to turn text into vectors
- Supabase as a vector store for fast similarity search
- A webhook that powers a secure chat interface
Under the hood, the workflow is split into two main sections:
- RAG AI Agent with Chat Interface – handles incoming chat requests, retrieves relevant document chunks, and generates responses through a chat model.
- Tool to Add a Google Drive File to Vector DB – ingests new or updated Drive files, extracts their text, splits it into chunks, embeds it, and stores it in Supabase.
Whether you are building an HR assistant, an internal knowledge base, or a support FAQ bot, this template gives you a production-ready structure that you can adapt to your use case.
Meet the key building blocks
Here is a quick tour of the most important nodes you will find in the template:
- Webhook – exposes a POST endpoint that your frontend can call with a chat request.
- Code node – validates JWTs (for example with AWS Cognito JWKS verification) and extracts user info.
- If node – routes the request based on whether authentication passed or failed.
- RAG Agent – uses a system prompt and an OpenAI chat model and calls the “Retrieve Documents” tool.
- Supabase Vector Store – stores your document embeddings and returns the top K most relevant chunks.
- Embeddings OpenAI – generates vector embeddings using the
text-embedding-3-smallmodel. - File Updated trigger + Download File – listens for changes in a Google Drive file and pulls the latest version.
- Extractors (PDF / Excel / Docs) – handle text extraction from different file formats such as PDFs, XLSX, Google Docs, and plain text.
- Text Splitter and Summarize nodes – split large documents into chunks and optionally summarize to reduce token usage.
- Insert into Supabase Vectorstore – writes the embeddings and metadata into Supabase for fast retrieval.
How the magic happens: high-level data flow
The workflow really has two separate paths, which keeps things fast and tidy:
- Document ingestion from Google Drive into the vector database.
- Chat flow from a webhook request to a RAG-powered answer.
Let us walk through both, starting from the ingestion side so you know where your data goes.
From Google Drive to Supabase: document ingestion pipeline
Whenever a watched file in Google Drive is updated, the ingestion flow kicks in so your chatbot does not keep quoting last year’s policies.
Step-by-step ingestion flow
- File Updated trigger fires
The workflow starts when a watched file changes in Google Drive. The trigger passes the file ID to the next node. - Set File ID
The file ID is captured and standardized for downstream nodes so every step knows exactly which file is being processed. - Delete Old Doc Rows
Any previous rows in Supabase for that file are deleted. This avoids duplicate chunks and keeps your vector store aligned with the latest version of the document. - Download File
The file is downloaded via the Google Drive API. For Google Docs, it is converted to plain text so it can be processed like any other document. - Switch node to choose extractor
Based on the file MIME type, the workflow routes the document to the correct extractor:- PDF extractor
- Excel / XLSX extractor
- Google Docs extractor
- Plain text extractor
- Aggregate and optional Summarize
The extracted text is combined in an Aggregate node, which is especially useful for multi-page or multi-sheet files. Optionally, a Summarize node condenses the content into smaller sections to reduce token usage later. - Character Text Splitter
The text is split into overlapping chunks using a character-based splitter. In the template, there is an overlap of around 200 characters so context is preserved between chunks and sentences are not cut off mid-thought. - Embeddings OpenAI
Each chunk is sent to the OpenAI embeddings modeltext-embedding-3-small. This turns your text into vectors that can be searched efficiently. - Insert into Supabase Vectorstore
The vectors, along with metadata such asfile_id, chunk index, and original text or summary, are inserted into Supabase. This is what powers fast, accurate retrieval later on.
The result: every time your document changes, your vector store is refreshed automatically. No more manual re-indexing or “I forgot to update the bot” moments.
From chat message to grounded answer: the RAG chat flow
Now for the fun part: how a user question turns into a precise, document-backed answer.
Step-by-step chat flow
- Webhook receives the request
Your frontend sends a POST request to the webhook endpoint with:chatInput– the user’s questionAuthorizationheader – a JWT for authentication
- Code node validates the JWT
The Code node:- Fetches the JWKS from your identity provider
- Converts the JWK to PEM
- Verifies the JWT signature and claims
- Returns user information if the token is valid
- If node checks authentication
If the token is valid, the request continues. If not, the webhook responds with an error and the conversation ends there, politely but firmly. - Edit Fields prepares the input
The chat input is normalized and passed to the RAG AI Agent node in the clean format it expects. - RAG AI Agent with system message
The agent is configured with a system prompt that tells the model to:- Answer only based on retrieved handbook or document content
- Say “I don’t know” if the answer is not present in the documents
This keeps the model grounded and stops it from confidently inventing new company policies.
- Retrieve Documents from Supabase
The agent calls the Retrieve Documents tool, which queries the Supabase vector store. In the template, it fetches the top K relevant chunks withtopK = 6. These chunks are provided to the chat model as context. - OpenAI Chat Model generates the answer
With the retrieved chunks as context, the chat model produces a response that is grounded in your actual documents. - Respond to Webhook
The generated answer is returned to the client through the webhook. Your user gets a clear, context-aware reply, and you do not have to dig through Drive again.
Why this architecture works so well
This setup is not just convenient, it is also thoughtfully structured for performance and reliability.
- Separate ingestion and query paths – document processing is handled independently from chat queries, which keeps latency low for users while heavy extraction and embedding work happens in the background.
- Accurate, document-based answers – the chatbot responds based on your own content, which reduces hallucinations and keeps answers aligned with your policies and docs.
- Automatic updates from Google Drive – when your Drive files change, the vectors are refreshed so the chatbot stays in sync with the latest version.
- Secure access with JWT verification – the Code node validates tokens before exposing the agent, so only authorized users can query your knowledge base.
- Extensible design – you can add more extractors, integrate other vector stores, or switch to alternative LLMs as your needs grow.
Configuration tips, best practices, and ways to avoid pain
Embeddings configuration
- Use
text-embedding-3-small(or a newer compatible model) for cost-effective embeddings that still perform well. - Clean your text before embedding. Remove headers, footers, repeated boilerplate, and unrelated noise that can confuse similarity search.
Chunking strategy
- Keep an overlap between chunks, such as the 200-character overlap used in the template, so important context is not chopped off between segments.
- Choose chunk sizes that play nicely with your model’s context window and token limits to get the best retrieval performance.
Security practices
- Validate JWTs using your provider’s JWKS endpoint in the Code node, and verify both signatures and claims such as expiration and audience.
- Protect your Supabase API keys and use row-level security policies to control who can access which data.
- Log access and keep an audit trail for document fetches and re-indexing events so you can trace what happened if something looks off.
Scaling and reliability tips
- Batch embedding generation when ingesting large numbers of documents to avoid unnecessary API overhead.
- Queue heavy operations, such as huge PDFs, or run them on scheduled workers so they do not cause webhook timeouts.
- Reindex or refresh embeddings regularly if the underlying content changes in meaning, such as policy updates or new product documentation.
Fixing common headaches
JWT verification keeps failing
If authentication is not working, check the following:
- Make sure the Code node is using the correct JWKS URL from your identity provider.
- Confirm that the token is actually being passed in the
Authorizationheader. - Verify that the token has not expired and that the
aud(audience) claim matches what your app expects.
Search results feel irrelevant
If the chatbot is pulling the wrong chunks, try:
- Adjusting chunk size so each piece has enough context but is not overly large.
- Removing repetitive boilerplate that can add noise to similarity search.
- Increasing
topKto retrieve more candidate chunks. - Adding metadata filters to the vector search query, such as restricting by document type, department, or date.
Long documents cause timeouts
When documents get huge, timeouts love to appear. To avoid that:
- Process extraction and storage asynchronously instead of in a single request.
- For Drive triggers, keep the initial webhook response short and offload heavy processing to a background worker or queue.
Ideas to extend and improve your RAG chatbot
- Semantic search filters – add metadata like department, language, or effective date so you can do targeted retrieval.
- Hybrid search – combine vector similarity with keyword or boolean queries for use cases where precision is critical.
- Human feedback loop – let users or agents flag uncertain answers, then review and use that feedback to refine summaries or tweak retrieval weighting.
Example system prompt for your RAG agent
A short, strict system message keeps the model focused and grounded. Here is the example used in the template:
"You are a helpful HR assistant answering questions strictly based on the following handbook content. If the answer is not found, say you don't know."
You can adapt this to your own domain, but keep the same spirit: answer only from the provided context, and admit when the information is not there.
Where to go from here
This n8n template gives you an end-to-end pattern for building a secure, document-backed RAG chatbot. It handles:
- Ingestion from Google Drive
- Text extraction and optional summarization
- Chunking and embedding generation
- Vector indexing in Supabase
- Chat queries via a token-verified webhook
Once configured, your chatbot becomes the coworker who actually knows where everything is stored and answers instantly, without complaining about repetitive questions.
Ready to deploy your new favorite coworker?
Here is a simple rollout plan:
- Deploy the template to your n8n instance.
- Connect your Google Drive and Supabase accounts.
- Run ingestion on one representative document.
- Ask three targeted questions to validate accuracy and coverage.
If you run into limits, confusing errors, or odd answers, collect the error logs or sample queries and share them. With those details, it is much easier to debug and optimize your pipeline, including prompt wording, retrieval settings, and access control rules.
