Advanced AI Use Cases: RAG, Agents, and Classification - n8n Workflow

A comprehensive n8n workflow demonstrating advanced AI techniques: Retrieval Augmented Generation (RAG) with Pinecone, autonomous agents for scheduling, and LLM-powered email classification using n8n.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Automation Specialists looking for advanced n8n templates.
Technical Teams interested in building RAG knowledge bases.
Developers needing to implement autonomous AI agents using n8n.
Users aiming to leverage powerful language models (LLMs) within their n8n trigger flows.

Overview

This advanced n8n workflow serves as a powerful demonstration of three distinct, cutting-edge AI automation techniques available within n8n. It moves far beyond simple integration, showcasing the true capability of the platform for technical teams.

First, it presents an example of an LLM-powered email classifier, automatically labeling incoming emails based on content. Second, and most complex, is the Retrieval Augmented Generation (RAG) setup, which indexes a PDF document into a vector database (Pinecone) and then uses an n8n trigger (Chat Trigger) to allow querying against that custom knowledge base using GPT-4o. Finally, it illustrates how to build an autonomous AI assistant using the Agent n8n node, capable of using external tools (like Google Calendar API calls) to fulfill user requests, such as booking appointments. This collection of n8n templates is invaluable for understanding modern AI integration.

How it Works

The n8n workflow is divided into three primary examples:

Example 1: Email Classification


  1. An event, simulated by the disabled Gmail Trigger, starts the process upon a new email.

  2. The Assign label with AI LangChain Text Classifier n8n node takes the email text.

  3. It uses an OpenAI Chat Model to categorize the email into 'automation' or 'music' based on descriptions.

  4. The flow splits, and a respective Gmail n8n node (Add automation label or Add music label) applies the correct label to the message.

Example 2: RAG Knowledge Base (PDF Chat)


  1. Indexing: The flow begins with PDFs to download (a placeholder) providing the PDF URL and metadata. The Download PDF HTTP Request node retrieves the binary file.

  2. The Recursive Character Text Splitter breaks the PDF into manageable chunks.

  3. The Default Data Loader processes the binary data, and Embeddings OpenAI generates vector representations.

  4. The Insert into Pinecone vector store n8n node uploads these vectors into the specified Pinecone index and namespace ('whitepaper').

  5. Querying: A When chat message received n8n trigger starts the query process.

  6. The query path uses the Read Pinecone Vector Store (linked to Embeddings OpenAI2) to access the vectors.

  7. The Vector Store Retriever fetches the most relevant document chunks.

  8. The Question and Answer Chain feeds these chunks, along with the user query, to the OpenAI Chat Model (GPT-4o) to generate a grounded response, ensuring the answer is based only on the PDF content.

Example 3: AI Booking Agent


  1. A separate chat interface (simulated by a manual execution or external input) initiates a conversation.

  2. The Appointment booking agent n8n node uses a detailed system prompt and Window Buffer Memory to maintain context.

  3. It is powered by the Anthropic Chat Model (for the LLM reasoning).

  4. If the user asks to book an appointment, the Agent autonomously decides to use the Get calendar availability tool (a specialized n8n node for API calls) to check Max’s schedule.

  5. If availability is confirmed, the Agent uses the Book appointment tool to execute the Google Calendar API call, scheduling the 30-minute event.

Installation Guide

To use this powerful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON data and import it into your n8n instance using the 'New' menu > 'Import from JSON'.

  2. Credentials: You will need to configure the following credentials for the respective n8n node types:

OpenAI/Anthropic: API keys for the Language Model nodes (OpenAI Chat Model, Anthropic Chat Model, Embeddings OpenAI).
Google Calendar OAuth2 API: Required for the Agent tools (Get calendar availability, Book appointment).
Slack OAuth2: Required for the simple introductory Send message n8n node.
Pinecone: API credentials for the vector database nodes.

  1. RAG Setup (Example 2): Ensure your Pinecone instance is configured and the index 'whitepapers' exists, or update the Insert into Pinecone vector store n8n node configuration.

  2. Testing: Since some parts are demonstrative (like the disabled Gmail trigger), execute the workflow steps manually or trigger the relevant Webhook or Chat Trigger endpoints to test the different AI examples.

Node Details

This n8n workflow utilizes numerous specialized LangChain and core n8n node types:

Webhook / Chat Trigger: Core n8n trigger nodes (Webhook, When chat message received). They define the starting point for execution.
LangChain Text Classifier (Assign label with AI): Uses an LLM (OpenAI Chat Model1) to categorize input text (email body) into predefined classes (automation, music). This is a key AI component of the n8n workflow.
n8n Gmail Node: Performs operations like adding labels (addLabels) based on AI classification.
LangChain Agent (Appointment booking agent): The core intelligence of Example 3. It utilizes system messages and memory to act autonomously and decide which tools to use.
LangChain Tool HTTP Request (Get calendar availability, Book appointment): Specialized n8n nodes that expose API endpoints (Google Calendar) to the AI Agent for decision-making and execution.
LangChain Vector Store Pinecone: Used in two modes: insert (for uploading embedded chunks) and read (for retrieval during RAG querying). Requires Pinecone credentials for this n8n template.
LangChain Question and Answer Chain: Orchestrates the RAG process, taking context from the retriever and generating an answer via the OpenAI Chat Model (GPT-4o).
Core n8n Node (Execute JavaScript, If): Demonstrates basic data manipulation and conditional logic early in the n8n workflow structure.

Related n8n Workflows

Free

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

Principal Product Designer @ n8n

Featured*