RAG Chatbot for Multi-Format Documents (PDF, CSV, JSON) - n8n Workflow

Use this powerful n8n workflow to create a conversational AI agent capable of reading and answering questions based on complex multi-format file uploads (PDF, CSV, images, JSON). Leverage OpenAI and Gemini for advanced RAG capabilities.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Technical teams needing to analyze diverse document types (e.g., CSV reports, XML data, PDFs) via a conversational interface.

  • Developers seeking robust n8n templates for building complex AI agents.

  • Businesses requiring a versatile internal knowledge base tool integrated into an n8n solution.

  • Users wanting to combine the power of multiple AI models (OpenAI for chat, Gemini for embeddings) within a single n8n workflow.

Overview

This sophisticated n8n workflow offers a two-pronged approach to AI-powered document interaction. First, it provides a dedicated intake mechanism (a standard form n8n trigger) to load long-term knowledge documents into an in-memory vector store, establishing the Retrieval-Augmented Generation (RAG) base. Second, and more uniquely, it features a primary chat interface (the chat n8n trigger) that allows users to ask questions while simultaneously uploading various file formats (PDF, images, CSV, JSON, XML, etc.).

The automation automatically routes the uploaded file based on its MIME type, extracting the relevant content before feeding it, alongside the user's prompt, into the AI Agent. This ensures the agent considers both the static knowledge base (via the RAG tool) and the immediate context provided by the uploaded files, making this n8n template highly versatile for complex data queries.

How it Works

The entire process is initiated by one of two n8n trigger nodes.

Document Loading Flow (RAG Setup):


  1. On form submission n8n trigger captures documents (like PDFs) uploaded via a web form.

  2. The document is passed through the Default Data Loader and the Recursive Character Text Splitter to prepare it for embedding.

  3. Embeddings Google Gemini node creates vector representations of the document chunks.

  4. The Simple Vector Store n8n node inserts these vectors, establishing the long-term knowledge base used by the chatbot.

Chat and File Processing Flow:


  1. The primary entry point is the When chat message received n8n trigger, which captures user queries and optional file uploads.

  2. A Code n8n node checks for binary file data.

  3. The Split Out and Loop Over Items nodes iterate through each uploaded file.

  4. The Switch n8n node analyzes the file's MIME type (e.g., image/jpeg, application/pdf, text/csv) and routes the item to the appropriate extraction pipeline (using a combination of Convert to File and format-specific Extract from File n8n nodes).

  5. Extracted text and data are collected by the Aggregate node.

  6. The extracted content and the user's question are passed to the AI Agent n8n node.

  7. The AI Agent uses the OpenAI Chat Model for generation, the Window Buffer Memory for conversation history, and the Query Data Tool1 (which leverages the RAG knowledge base setup using Gemini Embeddings) to formulate a comprehensive answer, considering both the uploaded documents and the static knowledge base.

Installation Guide

To deploy this comprehensive n8n workflow, follow these steps:


  1. Import the n8n template: Copy the provided JSON data and paste it into your n8n canvas using the 'Import from JSON' function.

  2. Setup Credentials: You will need two external services configured:

OpenAI API Key: Configure this credential for the OpenAI Chat Model n8n node (ID: a4611591).
Google Gemini (PaLM) API Key: Configure this credential for the two Embeddings Google Gemini n8n nodes (IDs: 511e0c19 and 7d38210e).

  1. Activate the RAG Loader: Execute the secondary n8n trigger (On form submission) to expose its public form URL. Upload initial documents (e.g., PDFs) to populate the RAG knowledge base.

  2. Activate the Chatbot: Execute the primary n8n trigger (When chat message received) to access the chatbot interface URL. You can now chat with the agent and upload new files on the fly.

Node Details

When chat message received (n8n trigger): The primary conversational entry point. Key feature is allowFileUploads: true, enabling users to upload documents while chatting.
On form submission (n8n trigger): Used exclusively for loading long-term documents into the vector store. Configured to accept file inputs.
Switch (n8n node): Crucial for multi-format support. It evaluates the incoming file's mimeType and routes the data specifically for extraction (e.g., application/pdf, text/csv, image/).
Extract from File (n8n nodes): A suite of dedicated n8n nodes configured with operations like pdf, fromJson, xml, xlsx, and rtf to handle structured and unstructured data extraction from binary files.
AI Agent (n8n node): The core intelligence, orchestrating the request. Its system message guides it to use the uploaded file content (extractedFile) and the RAG tool for answers.
OpenAI Chat Model (n8n node): Used as the generative language model, connected to the AI Agent.
Window Buffer Memory (n8n node): Ensures session continuity by tracking the conversation history using the user's sessionId provided by the chat n8n trigger.


  • Query Data Tool1 (Simple Vector Store n8n node): Configured in retrieve-as-tool mode. This is the RAG component that allows the AI Agent to query the pre-loaded knowledge base, significantly expanding the scope of what this n8n workflow can answer.

Related n8n Workflows

Free

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

Featured*