Deploy an advanced n8n workflow to chat with your email history via Telegram. This RAG system uses an n8n AI Agent, PGVector, structured SQL tools, and a local LLM (Mistral via Ollama).
Download this n8n workflow template and start using it instantly.
n8n Automation Specialists seeking complex RAG implementations.
Developers wanting to integrate PGVector and local LLMs (like Mistral via Ollama) for semantic search.
Businesses needing a conversational interface to query their historical email data.
Users looking for advanced examples of the n8n agent node using multiple tools.
This sophisticated n8n workflow solves the challenge of querying unstructured personal data (like emails) by combining semantic and structured search techniques, known as Dual RAG. The core of this automation is a powerful n8n AI Agent that utilizes two distinct data sources:
By leveraging the n8n trigger capabilities of Telegram, this entire system is deployed as a conversational bot, providing instant, highly accurate answers based on historical email communication. This demonstrates how a comprehensive n8n workflow can manage complex information retrieval.
The n8n workflow initiates when a message is received via either the Telegram Trigger or the When chat message received n8n trigger (for manual chat execution or API use).
Generate session id n8n node standardizes the incoming message and creates a unique session key for conversation memory.AI Agent n8n node receives the user query. It is configured with system instructions detailing the email database schema and critical time handling rules. It uses the OpenAI Chat Model (pointing to a local Mistral instance) and Simple Memory to maintain context.Postgres PGVector Store n8n node for semantic RAG or the Call the SQL composer Workflow n8n node for structured SQL RAG.Came from Telegram? n8n node checks the origin.Split text into chunks) to ensure messages adhere to size limits. It then loops through these chunks (Loop Over Items), escapes Markdown characters (Escape Markdown n8n node) to prevent formatting errors in Telegram's MarkdownV2 parser, and finally uses the Respond on Telegram in batches n8n node to send the answer piece by piece. If the input came from the n8n chat, the Beautify chat response n8n node prepares the output for display within the n8n interface.To use this n8n workflow, follow these steps:
Call the SQL composer Workflow n8n node.Telegram Trigger n8n node and the Respond on Telegram in batches n8n node, specifying your bot token and allowing access for your specific chat ID.Postgres PGVector Store n8n node to connect to your email embeddings database.OpenAI Chat Model (for the Mistral LLM) and the Embeddings Ollama n8n node.Telegram Trigger n8n trigger is active and initialized (listening for messages).This n8n workflow utilizes several specialized n8n node types:
Telegram Trigger: This specialized n8n trigger starts the workflow upon receiving a message update in Telegram, capturing the chat and message IDs.
AI Agent: The central orchestration n8n node, which interprets the user query, manages conversation state via memory, and decides which tool (emailsvectorsearch or emailsqlsearch) to execute based on its system prompt.
OpenAI Chat Model: Despite the name, this n8n node is configured here to use a local LLM (mistral-small3.1:latest) accessed via an Ollama endpoint, acting as the brain for the AI Agent.
Postgres PGVector Store: Configured as the emailsvectorsearch tool, this n8n node performs semantic retrieval against the embedded email content (RAG). It uses the 'retrieve-as-tool' mode.
Embeddings Ollama: Provides the necessary embedding model (nomic-embed-text:latest) used by the PGVector n8n node for vector similarity calculation.
Call the SQL composer Workflow: Configured as the emailsqlsearch tool, this powerful n8n node links to a separate n8n workflow template responsible for translating complex questions into database queries.
Split text into chunks (Code): A custom Code n8n node designed to handle large AI responses by splitting them at word boundaries into manageable chunks (max 500 characters) before sending them to Telegram.
Escape Markdown (Code): Another crucial Code n8n node that sanitizes the output string, escaping special characters (like underscores, dots, and brackets) to ensure correct rendering under Telegram's strict MarkdownV2 rules before using the response n8n node.
Use this n8n workflow to integrate Novita AI's Dolphin Mixtral 8x22B large language model for advanced, customizable chat completions in your n8n automation projects.

Deploy this powerful n8n workflow template to create an AI agent that converses with your QuickBooks Online customer data using OpenAI. Use this advanced n8n workflow to integrate complex tools via an MCP bridge.

Build a custom AI assistant using n8n that can chat directly with your PostgreSQL database. This n8n workflow uses an OpenAI agent to generate and execute complex SQL queries.

Deploy an expert AI Agent using this n8n workflow to query HubSpot Contacts and Deals instantly. Ideal for sales and ops teams using powerful n8n templates.








































