Chat with PDF Knowledge Base via Telegram and Google Gemini - n8n Workflow

Deploy a powerful RAG system using this n8n workflow. Index PDFs via Telegram, leverage Google Gemini LLM, and store vectors in Pinecone. A robust n8n template for conversational AI.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • AI/ML Developers: Who need an efficient way to deploy RAG applications.

  • Content Managers: Seeking to make large document libraries searchable via a simple chat interface.

  • n8n Automation Specialists: Looking for advanced n8n workflow examples combining LLMs, vector databases, and messaging apps.

  • Businesses: Requiring internal tools for quick information retrieval from documentation.

Overview

This advanced n8n workflow provides a complete solution for creating a 'Chat with PDF' bot on Telegram. It addresses the common challenge of making unstructured data searchable and conversational. The n8n template elegantly handles two separate functions: first, allowing users to upload a PDF file for indexing (creating searchable embeddings in Pinecone), and second, executing a Retrieval-Augmented Generation (RAG) chain to answer questions based on the indexed content. Every component, from the initial n8n trigger to the final response, is optimized for performance and accuracy, relying heavily on the n8n node suite for LangChain integration, Gemini, and Pinecone, ensuring a seamless user experience.

How it Works

The entire process is initiated by the Telegram Message n8n trigger when a user sends any message to the bot.


  1. Trigger and Routing: The n8n workflow starts with the Telegram Message Trigger. The Check If is a document n8n node then acts as a router, checking if the incoming message contains a binary file (a PDF).

  2. Indexing Path (PDF Upload): If a PDF is detected (TRUE branch), the Telegram get File n8n node downloads it. A subsequent Code n8n node ensures the binary metadata is correctly set to application/pdf. The document is then loaded and split into manageable chunks using the Recursive Character Text Splitter. These chunks are converted into numerical vectors using the Embeddings Google Gemini n8n node, and finally inserted into the Pinecone vector database using the dedicated Pinecone Vector Store n8n node. A confirmation message is sent via Telegram.

  3. Querying Path (Text Question): If the message is a text question (FALSE branch), the workflow proceeds to the RAG engine. The user's question is embedded (using a second Embeddings Google Gemini n8n node) and used by the Vector Store Retriever to find relevant context from Pinecone.

  4. Generation and Response: This context, along with the user's question, is fed into the Question and Answer Chain. This powerful n8n node utilizes the Google Gemini Chat Model to generate a precise answer, strictly adhering to the prompt which mandates using Telegram's HTML parse mode for formatting. The final response is delivered back to the user via the Telegram Response n8n node, completing the n8n workflow execution.

Installation Guide


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

  2. Set Credentials: This n8n template requires three sets of credentials:

Telegram API: Configure your Telegram Bot token.
Google Gemini: Set up credentials for accessing the Google Gemini LLM and Embedding services.
* Pinecone API: Input your Pinecone API key and environment details. Note the index name telegram used in this specific n8n workflow.

  1. Configure Webhooks: Ensure the Telegram n8n trigger is active. Since this uses the polling method for the trigger, n8n handles the webhook setup automatically upon activation.

  2. Activate: Deploy the n8n workflow to start listening for messages on your Telegram bot.

Node Details


  • Telegram Message Trigger (n8n trigger): The starting point of this n8n workflow, configured to listen for new messages, including those containing documents, on the linked Telegram bot.

  • Check If is a document (If n8n node): Routes the workflow based on the presence of the document object in the Telegram message payload, determining if the intent is indexing or querying.

  • Recursive Character Text Splitter (n8n node): Used in the indexing path to break down the large document text into chunks (3000 chars) with overlap (200 chars), crucial for effective RAG context retrieval.

  • Embeddings Google Gemini (n8n node): Used twice—once for indexing the document chunks and once for embedding the user query. It uses the models/gemini-embedding-001 model.

  • Pinecone Vector Store (n8n node): Manages the Pinecone index named 'telegram'. Configured in 'insert' mode for the indexing path and utilized for connection setup in the querying path.

  • Vector Store Retriever (n8n node): Acts as the retrieval mechanism, connecting the query embeddings to the Pinecone index to fetch the most relevant text chunks (context).

  • Google Gemini Chat Model (n8n node): The primary LLM used for synthesizing the final answer based on the retrieved context.

  • Question and Answer Chain (n8n node): The core RAG component that orchestrates the query, retrieval, and generation steps, applying strict formatting rules (HTML parse mode) defined in the custom prompt.

Related n8n Workflows

Free

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

Workflow automation can help automate your routine activities and help saves $$$, as well as hours of time. As a boutique tech consulting company, Intuz help businesses with custom AI/ML, AI Workflow Automations, and software development. Automate your business workflow for: Sales Marketing Accounting Finance Operations E-Commerce Customer Support Admin & Backoffice Logistics & Supply Chain

Featured*