Supabase Vector Database Management: Insert, Upsert, and RAG Retrieval - n8n Workflow

A robust n8n workflow for managing a Supabase vector database, featuring document insertion, record upserting, and RAG retrieval using OpenAI embeddings. Use this n8n template for knowledge bases.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Technical users building a custom Retrieval Augmented Generation (RAG) system.

  • Developers needing a reliable n8n workflow for syncing documents to Supabase.

  • Data scientists and engineers looking for ready-made n8n templates for vector database operations.

  • Anyone seeking to operationalize a knowledge base leveraging the power of Supabase and the flexibility of an n8n node structure.

Overview

This comprehensive n8n workflow provides a blueprint for effective vector database management within Supabase. It addresses three critical phases: bulk insertion of new documents, precision upserting of existing records, and live retrieval (RAG) driven by an n8n trigger.

By leveraging the integrated LangChain n8n node collection alongside the core Supabase n8n node, this solution ensures that your vector index remains current and searchable. The insertion path handles large files by splitting them and creating OpenAI embeddings. The retrieval path initiates a real-time chat service using an n8n trigger, embedding the user's query, fetching relevant documents from Supabase, and passing them to an LLM for conversational answers. This n8n workflow eliminates the need for complex custom API scripts for these standard database operations, making knowledge management highly efficient.

How it Works

The n8n workflow is divided into three primary functional areas:

1. Document Insertion


  1. Source Data: The n8n workflow starts by fetching a document (e.g., an EPUB file) from a Google Drive n8n node.

  2. Data Preparation: The Default Data Loader processes the binary file, and the Recursive Character Text Splitter breaks the content into manageable chunks suitable for vectorization.

  3. Embedding: The Embeddings OpenAI Insertion n8n node generates vector embeddings for each text chunk.

  4. Database Write: The Insert Documents Supabase n8n node securely stores these embeddings, along with the original content and metadata, into the configured Supabase vector table (e.g., 'Kadampa').

2. Document Upsertion


  1. Content Setup: The Placeholder n8n node provides the content and metadata for the record to be updated, including dynamic fields like the current date and time.

  2. Embedding Generation: The Embeddings OpenAI Upserting n8n node creates the vector for the updated content.

  3. Record Update: The Update Documents Supabase n8n node targets a specific record ID to replace the existing content and embedding, ensuring data accuracy.

3. RAG Retrieval


  1. Query Trigger: The When chat message received n8n trigger initiates the flow when a user inputs a query into the built-in chat UI.

  2. Query Vectorization: The user's text input is processed by the Embeddings OpenAI Retrieval n8n node to generate a query vector.

  3. Vector Search: The Retrieve by Query Supabase vector store n8n node uses the custom match_documents function (critical setup requirement) to find the 'Top K' (configured as 10) most similar document chunks.

  4. Answer Generation: The Vector Store Retriever feeds the relevant chunks to the Question and Answer Chain, which utilizes the OpenAI Chat Model to formulate a coherent, context-aware response.

  5. Final Output: A Customize Response n8n node formats the final text output back to the user via the initial chat n8n trigger.

Installation Guide

To deploy this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON data and paste it directly into your n8n instance using the 'Import Workflow' option.

  2. Supabase Setup (Critical): Before running, you must configure your Supabase instance as detailed in the sticky notes:

Enable the pgvector extension.
Ensure your target table (e.g., 'Kadampa') has content TEXT, metadata JSONB, and embedding VECTOR(1536) columns (matching the OpenAI text-embedding-3-small dimension).
Create the custom SQL function match_documents for vector similarity search.

  1. Credentials:

OpenAI: Set up credentials for the OpenAI integration used by the embedding and chat model n8n node types.
Google Drive: If using the insertion path, authenticate the Google Drive n8n node.
Supabase Vector Store: Configure credentials for the Supabase n8n node, ensuring the required API key and connection details are provided.

  1. Configuration: Update the table names and file IDs within the Insert Documents and Google Drive n8n node settings to match your specific environment and data sources. This specific n8n workflow is designed for high performance.

Node Details

When chat message received (n8n trigger): This is the conversational n8n trigger, initiating the RAG flow. It is configured to be public and provides an initial welcome message, making this an ideal interactive n8n workflow start.
Google Drive: Downloads the source document (e.g., an EPUB file) required for the insertion process. Key configuration requires setting the specific File ID.
Default Data Loader: Processes the input file (e.g., a document or book) into a format LangChain can handle. Configured here as an epubLoader using binary data.
Recursive Character Text Splitter1: A critical n8n node in RAG, it splits large texts into smaller, contextually relevant chunks before embedding, ensuring accurate retrieval. Uses default options.
Embeddings OpenAI Insertion/Upserting/Retrieval: These n8n node instances generate the vector representations of the text. They are configured to use the text-embedding-3-small model, maintaining dimensional consistency (1536) across the entire n8n workflow.
Insert Documents (Vector Store Supabase): The core database write n8n node for batch uploading new documents and their embeddings to the Supabase table, utilizing the specified Kadampa table.
Update Documents (Vector Store Supabase): Performs the upsert operation, targeting a specific record ID (1 in this template) to modify existing vector data. Uses table n8n in this configuration.
Retrieve by Query (Vector Store Supabase): This n8n node executes the vector search operation against Supabase. Crucially, it references the required custom function match_documents in its queryName parameter.
Question and Answer Chain: The coordinating RAG n8n node. It links the LLM (OpenAI Chat) with the vector store retriever to synthesize final answers from the retrieved context.
Customize Response (Set n8n node): Final formatting node, extracting only the clean text response from the LLM output ($json.response.text) before returning the result via the n8n trigger.

Related n8n Workflows

Free

Nodes: 12 Nodes
Updated: December 26 2025
View all
Created by

Support Engineer @n8n

Featured*