At a glance
- Trigger
- Chat Trigger (When chat message received)
- Nodes
- 22
- Apps
- OpenAI and Supabase
- AI nodes
- 11
- Credentials
- 2 types
- Category
- RAG, documents and vector search
Apps and integrations
Node types used
How it works
The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.
AI Agent To Chat With Files In Supabase Storage
Made by Mark Shcherbakov from community 5minAI
Manually retrieving and analyzing specific information from large document repositories is time-consuming and inefficient. This workflow automates the process by vectorizing documents and enabling AI-powered interactions, making it easy to query and retrieve context-based information from uploaded files.
The workflow integrates Supabase with an AI-powered chatbot to process, store, and query text and PDF files. The steps include
- Fetching and comparing files to avoid duplicate processing.
- Handling file downloads and extracting content based on the file type.
- Converting documents into vectorized data for contextual information retrieval.
- Storing and querying vectorized data from a Supabase vector store.
Scenario 1 - Flow for adding new files from Supabase storage
Setup notes
The text below comes from the sticky notes inside the workflow. We removed links, code samples and anything that looks like a key or token.
Set up steps
- Fetch File List from Supabase
- Use Supabase to retrieve the stored file list from a specified bucket.
- Add logic to manage empty folder placeholders returned by Supabase, avoiding incorrect processing.
- Compare and Filter Files
- Aggregate the files retrieved from storage and compare them to the existing list in the Supabase files table.
- Exclude duplicates and skip placeholder files to ensure only unprocessed files are handled.
- Handle File Downloads
- Download new files using detailed storage configurations for public/private access.
- Adjust the storage settings and GET requests to match your Supabase setup.
- File Type Processing
- Use a Switch node to target specific file types (e.g., PDFs or text files).
- Employ relevant tools to process the content
- For PDFs, extract embedded content.
- For text files, directly process the text data.
- Content Chunking
- Break large text data into smaller chunks using the Text Splitter node.
- Define chunk size (default: 500 tokens) and overlap to retain necessary context across chunks.
- Vector Embedding Creation
- Generate vectorized embeddings for the processed content using OpenAI's embedding tools.
- Ensure metadata, such as file ID, is included for easy data retrieval.
- Store Vectorized Data
- Save the vectorized information into a dedicated Supabase vector store.
- Use the default schema and table provided by Supabase for seamless setup.
- AI Chatbot Integration
- Add a chatbot node to handle user input and retrieve relevant document chunks.
- Use metadata like file ID for targeted queries, especially when multiple documents are involved.
... or watch set up video [10 min]
Replace Storage name, database ID and credentials.
Replace Storage name, database ID and credentials.
Nodes in this workflow
The 22 nodes in file order (sticky notes excluded). Branches and connections determine execution order in n8n:
- Get All files (HTTP Request)
- Default Data Loader (Default Data Loader)
- Recursive Character Text Splitter (Recursive Character Text Splitter)
- Extract Document PDF (Extract from File)
- Embeddings OpenAI (OpenAI Embeddings)
- Create File record2 (Supabase)
- If (If)
- Get All Files (Supabase)
- Download (HTTP Request)
- Loop Over Items (Loop Over Items)
- When clicking ‘Test workflow’ (Manual Trigger)
- Aggregate (Aggregate)
- When chat message received (Chat Trigger)
- OpenAI Chat Model1 (OpenAI Chat Model)
- Embeddings OpenAI2 (OpenAI Embeddings)
- OpenAI Chat Model2 (OpenAI Chat Model)
- Vector Store Tool1 (Vector Store Question Answer Tool)
- Switch (Switch)
- Insert into Supabase Vectorstore (Supabase Vector Store)
- Merge (Merge)
- AI Agent (AI Agent)
- Supabase Vector Store (Supabase Vector Store)
Credentials you need
- OpenAI API – used by Embeddings OpenAI, Embeddings OpenAI2, OpenAI Chat Model1 and OpenAI Chat Model2
- Supabase API – used by Create File record2, Download, Get All Files and Get All files and others
Configure your own credentials after importing. Create each credential in n8n, then select it in the node.
How to import into n8n
- Download the JSON file with the button above.
- In n8n, open a new workflow, select the ... menu and choose Import from File. You can also paste the JSON straight into the editor canvas.
- Open each node that shows a warning and select or create its credential.
- Read the notes on the canvas, test the workflow with sample data, then activate it.
Do you need somewhere to run it? Read our guide to self-hosted n8n.