Business Data Query Agent with RAG and Text-to-SQL - n8n Workflow

Deploy an advanced AI assistant using this n8n workflow. It combines Retrieval-Augmented Generation (RAG) via Supabase and Text-to-SQL via Peliqan to query internal documents and quantitative business data effectively. This n8n template accelerates BI.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Data teams and Business Intelligence (BI) specialists who need quick, natural language access to complex metrics stored in multiple sources.

  • Developers seeking robust n8n templates for building sophisticated, data-aware chatbots.

  • Organizations that utilize Peliqan for centralized business data and Supabase for vector storage.

  • Anyone looking to implement an AI system where the agent needs access to both unstructured (RAG) and structured (SQL) data.

Overview

This comprehensive n8n workflow solves the challenge of accessing disparate business data sources—unstructured knowledge bases (like Notion) and structured databases (like Chargebee)—through a single, conversational interface. By using the LangChain AI Agent n8n node, the system intelligently decides whether a user's question requires searching the internal knowledge base (RAG) or generating and executing an SQL query (Text-to-SQL) against data brokered by Peliqan. This ensures that the AI assistant, driven by an OpenAI Chat Model, provides accurate and timely answers derived from the freshest business data. This advanced n8n automation leverages specialized tools to make data querying as simple as asking a question, making it an indispensable tool for data accessibility.

How it Works

This n8n workflow is divided into two logical sections: data ingestion for RAG, and the live chatbot agent:

1. Data Ingestion (Manual Trigger)


  1. Manual Trigger: The ingestion process starts with a manual n8n trigger, designed to be run periodically to update the knowledge base.

  2. Peliqan Data Retrieval: The ‘Get table data’ n8n node retrieves raw data (e.g., Notion pages) centralized in Peliqan.

  3. Document Preparation: The ‘Default Data Loader’ formats this raw data. The ‘Recursive Character Text Splitter’ breaks the documents into smaller, manageable chunks.

  4. Embedding and Storage: The chunks are processed by the ‘Embeddings OpenAI for RAG’ n8n node to convert them into vector embeddings, which are then inserted into the ‘Supabase Vector Store to store vectors for RAG’ database.

2. Live Chatbot Interaction


  1. Start Chat: The primary n8n trigger, ‘When chat message received’ (a LangChain Chat Trigger), listens for incoming user queries.

  2. Core Intelligence: The query is routed to the ‘AI Agent’ n8n node. The agent’s system message directs it to use two tools: RAG for knowledge questions and Peliqan for quantitative data.

  3. Context and Conversation: The ‘Simple Memory’ n8n node maintains the conversational history, providing crucial context for multi-turn questions.

  4. Decision Making (Tool Use): The ‘AI Agent’ uses the ‘OpenAI Chat Model’ to determine which tool is appropriate:

RAG Query: If the agent needs internal knowledge, it uses the ‘Supabase Vector Store for search’ tool, leveraging the ‘Embeddings OpenAI for RAG retrieval’ n8n node to perform a similarity search.
Text-to-SQL: If the query is quantitative (e.g., "How many customers last month?"), the agent generates an SQL statement and passes it to the ‘Execute an SQL query via Peliqan’ tool, which runs the query and returns the results. This Peliqan n8n node acts as a secure data proxy.

  1. Response: The agent synthesizes the information received from the tool (or directly generates the answer) and returns the final response to the user via the initial n8n trigger.

Installation Guide

To successfully deploy this advanced n8n workflow using these n8n templates, follow these steps:


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

  2. Peliqan Setup: Obtain your Peliqan API key. Configure the Peliqan credentials in the ‘Get table data’ and ‘Execute an SQL query via Peliqan’ n8n node configurations. Ensure you update the tableId in 'Get table data' to match your relevant dataset.

  3. OpenAI Credentials: Set up the required OpenAI API credentials for all OpenAI-related n8n node instances (Chat Model and both Embedding nodes).

  4. Supabase Credentials: Configure the Supabase API credentials for both ‘Supabase Vector Store’ nodes, ensuring the table name (documents) is correctly set up in your Supabase instance.

  5. RAG Ingestion: Before activating the chatbot, execute the lower section of the n8n workflow (starting with 'When clicking ‘Execute workflow’') to populate the Supabase Vector Store with your initial business data. This creates the RAG knowledge base.

  6. Agent Customization: Crucially, update the System Message within the ‘AI Agent’ n8n node to reflect the exact table names and columns available in your Peliqan data warehouse. This ensures accurate Text-to-SQL generation.

  7. Activate: Save and activate the top part of the n8n workflow (starting with the chat n8n trigger) to deploy the live AI assistant.

Node Details

This n8n workflow utilizes several specialized n8n node types to achieve complex AI logic:

When chat message received (LangChain Chat Trigger): The starting point, acting as the primary n8n trigger for user interaction, defining the chatbot endpoint.
AI Agent (LangChain Agent): The central decision-making component. Its system message dictates its ability to use RAG via Supabase and Text-to-SQL via Peliqan. It orchestrates tool usage based on the user's query.
OpenAI Chat Model (LangChain LLM): Provides the underlying intelligence for the agent, used for parsing questions, generating SQL, and synthesizing final answers.
Simple Memory (LangChain Memory): A crucial n8n node for maintaining conversation context across multiple messages.
Supabase Vector Store (mode: retrieve-as-tool): Configured as a tool named 'Companyknowledgebase' for the agent to perform RAG lookups against internal knowledge documents.
Execute an SQL query via Peliqan (Peliqan Tool): A custom Peliqan n8n node that functions as a secure tool, allowing the AI agent to execute dynamically generated SQL queries against business data, providing accurate quantitative answers.
Get table data (Peliqan node): Used in the ingestion pipeline to retrieve large volumes of source data (e.g., Notion pages) from Peliqan before vectorization. This step initiates the RAG ingestion segment of the n8n workflow.
Supabase Vector Store (mode: insert): Used exclusively in the ingestion sub-workflow to permanently store the vector embeddings generated by the OpenAI embedding n8n node.

Related n8n Workflows

Free

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

Peliqan.io is the one-click data foundation for our n8n AI Agents. Add all your business applications for RAG and "Text to SQL", and build AI chatbots and AI Agents that can interact with all internal company data from CRM, ERP, cloud storage, accounting, HRM/ATS etc.

Featured*