AI Agent To Chat With Files In Supabase Storage n8n Workflow Template

n8n workflow template · 22 nodes · OpenAI

AI Agent To Chat With Files In Supabase Storage is a free n8n workflow template that starts when a chat message is received and works with OpenAI and Supabase. It has 22 nodes, 11 of them AI nodes (Default Data Loader, Recursive Character Text Splitter, OpenAI Embeddings and Chat Trigger). The notes inside the workflow say: “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.” To run it, you add your own credentials for OpenAI API and Supabase API.

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

  • OpenAI
  • Supabase

Node types used

  • HTTP Request
  • Default Data Loader
  • Recursive Character Text Splitter
  • Extract from File
  • OpenAI Embeddings
  • Supabase
  • If
  • Loop Over Items
  • Manual Trigger
  • Aggregate
  • Chat Trigger
  • OpenAI Chat Model
  • Vector Store Question Answer Tool
  • Switch
  • Supabase Vector Store
  • Merge
  • AI Agent

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

  1. 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.
  1. 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.
  1. 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.
  1. 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.
  1. 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.
  1. 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.
  1. 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.
  1. 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:

  1. Get All files (HTTP Request)
  2. Default Data Loader (Default Data Loader)
  3. Recursive Character Text Splitter (Recursive Character Text Splitter)
  4. Extract Document PDF (Extract from File)
  5. Embeddings OpenAI (OpenAI Embeddings)
  6. Create File record2 (Supabase)
  7. If (If)
  8. Get All Files (Supabase)
  9. Download (HTTP Request)
  10. Loop Over Items (Loop Over Items)
  11. When clicking ‘Test workflow’ (Manual Trigger)
  12. Aggregate (Aggregate)
  13. When chat message received (Chat Trigger)
  14. OpenAI Chat Model1 (OpenAI Chat Model)
  15. Embeddings OpenAI2 (OpenAI Embeddings)
  16. OpenAI Chat Model2 (OpenAI Chat Model)
  17. Vector Store Tool1 (Vector Store Question Answer Tool)
  18. Switch (Switch)
  19. Insert into Supabase Vectorstore (Supabase Vector Store)
  20. Merge (Merge)
  21. AI Agent (AI Agent)
  22. 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

  1. Download the JSON file with the button above.
  2. 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.
  3. Open each node that shows a warning and select or create its credential.
  4. 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.

Need this customised?

We can adapt this workflow to your apps, data and process, then deploy and support it.

Contact Us