Animated data flow diagram

AI Agent for Conversational Q&A with Your Supabase Files (PDFs & TXT)

Version: 1.0.0 | Last Updated: 2025-05-16

Integrates with:

Supabase OpenAI Langchain

Overview

Unlock Instant Answers from Your Supabase Documents with this AI Agent

This n8n workflow transforms your Supabase file storage into an interactive knowledge base. It automates the ingestion of new PDF and text files, processes their content, creates vector embeddings using OpenAI, and stores them in a Supabase vector store. Once set up, you can 'chat' with your documents via an AI-powered agent, asking natural language questions and receiving contextually relevant answers. Stop tedious manual searching and start getting immediate, AI-driven insights from your file repositories.

This AI-driven automation handles two main scenarios:

  1. File Ingestion & Vectorization: Monitors your Supabase storage, processes new documents (PDFs, TXT), extracts text, chunks it, generates OpenAI embeddings, and stores them in a Supabase vector database. It intelligently avoids reprocessing existing files.
  2. Conversational AI Agent: Provides a chat interface (triggered by the Langchain Chat Trigger) that uses an AI Agent (powered by OpenAI chat models and Langchain) to understand your questions, retrieve relevant information from the vectorized documents in Supabase, and generate coherent answers.

Key Features & Benefits

  • Automated Document Pipeline: Fetches, processes, and vectorizes new PDF and text files from Supabase Storage automatically.
  • AI-Powered Embeddings: Utilizes OpenAI's text-embedding-3-small model for efficient and context-rich document vectorization.
  • Supabase Vector Store Integration: Leverages Supabase as both a file store and a pgvector-powered database for storing and querying document embeddings.
  • Conversational AI Agent (RAG): Chat with your documents using natural language. The agent employs Retrieval Augmented Generation (RAG) with OpenAI models to provide accurate, context-aware answers based on your files.
  • Duplicate Prevention: Smart logic ensures files are ingested and vectorized only once, optimizing cost and performance.
  • Support for Multiple File Types: Handles PDF and plain text files, extracting content seamlessly.
  • Customizable & Extensible: Built with n8n and Langchain nodes, allowing for easy customization of models, chunking strategies, and integrations.

Use Cases

  • Building an internal knowledge base that team members can query via chat.
  • Automating customer support by enabling an AI to answer questions based on product documentation (PDFs, FAQs).
  • Creating a research assistant to quickly find information within a large corpus of academic papers or reports.
  • Developing a personal productivity tool to chat with your notes, articles, and e-books stored in Supabase.
  • Streamlining legal document review by asking specific questions to find relevant clauses or information.

Prerequisites

  • An n8n instance (Cloud or self-hosted).
  • A Supabase account and project. You'll need:
    • Supabase API Key and Project URL.
    • A Supabase Storage bucket for your files.
    • A Supabase table (e.g., files) to track processed files (columns like name, storage_id).
    • A Supabase table (e.g., documents) configured for pgvector to serve as the vector store (Langchain Supabase nodes will typically create this if the schema is standard, but ensure pgvector is enabled).
  • An OpenAI API Key with access to an embedding model (e.g., text-embedding-3-small as used in the template) and a chat completion model (e.g., gpt-3.5-turbo or gpt-4).

Setup Instructions

  1. Download the n8n workflow JSON file.
  2. Import the workflow into your n8n instance.
  3. Configure Supabase Credentials & Endpoints:
    • Update the 'Get All files' HTTP Request node: Set the URL to your Supabase Storage list objects endpoint (e.g., https://YOUR_PROJECT_ID.supabase.co/storage/v1/object/list/YOUR_BUCKET_NAME). Set its nodeCredentialType to supabaseApi and select/create your Supabase API credentials.
    • Update the 'Get All Files' Supabase node: Select/create your Supabase API credentials and configure it to read from your files table.
    • Update the 'Download' HTTP Request node: Set the URL to your Supabase Storage download object endpoint (e.g., https://YOUR_PROJECT_ID.supabase.co/storage/v1/object/private/YOUR_BUCKET_NAME/{{ $json.name }}). Set its nodeCredentialType to supabaseApi and select/create your Supabase API credentials.
    • Update the 'Create File record2' Supabase node: Select/create your Supabase API credentials and configure it to insert into your files table.
    • Update the 'Insert into Supabase Vectorstore' Langchain node: Select/create your Supabase API credentials and set the tableName to your vector store table (e.g., documents).
    • Update the 'Supabase Vector Store' Langchain node (in the AI Agent path): Select/create your Supabase API credentials and set the tableName to your vector store table.
  4. Configure OpenAI Credentials:
    • Update 'Embeddings OpenAI', 'OpenAI Chat Model1', 'Embeddings OpenAI2', and 'OpenAI Chat Model2' nodes with your OpenAI API Key by selecting or creating the appropriate credentials.
  5. Review Node Parameters:
    • Recursive Character Text Splitter: Adjust chunkSize (default 500) and chunkOverlap (default 200) as needed for your document types and desired granularity.
    • Vector Store Tool1: Review and adjust topK (default 8), which determines how many relevant document chunks are retrieved for the AI agent.
    • If Node: Verify the conditions, especially the check for .emptyFolderPlaceholder if your Supabase bucket might return this.
  6. File Ingestion Setup:
    • The file ingestion part of the workflow starts with the 'When clicking ‘Test workflow’' manual trigger. Run this manually to process initial files or change the trigger to a schedule (e.g., 'Cron' node) for continuous syncing.
  7. Test AI Agent:
    • The AI Agent part starts with the 'When chat message received' Chat Trigger. After files are ingested and vectorized, send messages via the configured chat input (e.g., n8n's chat UI if enabled, or by calling the webhook) to ask questions about your documents.
  8. Refer to Sticky Notes: The workflow contains sticky notes with hints for specific configurations. Use these as a guide during setup.
  9. Activate the workflow(s) (the ingestion part and the agent part if they are separate or if the ingestion is on a schedule).

Tags:

AI AgentRAGSupabaseOpenAIDocument Q&AKnowledge BaseAutomationPDF ProcessingText ProcessingVector DatabaseLangchainStartup AutomationSolopreneur Tool

Want your own unique AI agent?

Talk to us - we know how to build custom AI agents for your specific needs.

Schedule a Consultation