๐Ÿ“– Build a RAG chatbot using Google Gemini and a Supabase vector store

โšก 415 views ยท ๐Ÿ“– Internal Wiki & Knowledge Base

Description

๐Ÿง  AI Chatbot with RAG: Google Gemini & Supabase Vector Store

๐Ÿ“Œ Summary

Build a custom, intelligent knowledge base in minutes. This n8n workflow provides a complete Retrieval-Augmented Generation (RAG) system using Google Gemini and Supabase. It features a seamless dual-flow design: an ingestion pipeline to process and store your uploaded documents, and a conversational AI agent that queries those documents to provide accurate, context-aware answers while remembering past interactions.


โœจ Key Features


๐Ÿ› ๏ธ How It Works

  1. Data Ingestion (Knowledge Base Setup): * Documents are uploaded via the Form Trigger and validated for size (<10MB) to prevent parsing timeouts.
    • The text is parsed and split into optimized 1000-character chunks with a 100-character overlap.
    • Gemini generates embeddings for these chunks, which are permanently stored in your Supabase Vector Store.
  2. Query Processing (Chat Interface):
    • A user asks a question via the Chat Trigger.
    • The AI Agent accesses the Postgres database to load previous chat context for that specific userโ€™s session.
    • The Agent uses the Supabase Retriever tool to pull the top 5 most relevant document chunks based on the userโ€™s query.
    • Gemini formulates a concise, factual response citing the retrieved data.

๐Ÿš€ Setup Instructions

1. Create Database Tables

Before running the workflow, ensure your Supabase/Postgres database has the required tables. โš ๏ธ See the โ€œDATABASE SETUP (SQL)โ€ sticky note on the canvas for the complete SQL script.

2. Connect Credentials

Connect your Google Gemini API, Supabase (URL and Service Role Key), and Postgres databases. (Note: Your Postgres memory can be hosted within your Supabase project). Ensure your Supabase database has pgvector enabled.

3. Update Table Names

Open the Supabase and Postgres nodes and replace:

4. Configure Error Notifications (Important)

The workflow catches errors and formats an alert message, but you must manually connect a messaging node (like Slack, Microsoft Teams, or Email) directly after the Format Error Alert node to receive these notifications.

5. Ingest Data

Open the Upload Knowledge Base Form node, click โ€œTest stepโ€, and upload a sample document to index it into your database.

6. Test the Agent

Open the User Chat Trigger node, click โ€œChatโ€, and ask a question related to the document you just uploaded!


๐Ÿ“ฆ Nodes Used

User-Facing Interfaces:

Data Processing Pipeline (Ingestion):

AI & Memory (Query):

Error Handling:


โš ๏ธ Limitations & Guidelines

๐Ÿ”— Nodes Used

Stop and Error, AI Agent, Character Text Splitter, n8n Form Trigger, Supabase Vector Store, Default Data Loader

๐Ÿ“ฅ Import

Download workflow.json and import into n8n: Workflow menu โ†’ Import from File

๐Ÿ“– Importing guide ยท ๐Ÿ”‘ Credential setup