RAG Chatbot for PDF Documents via Telegram - n8n Workflow

Use this comprehensive n8n workflow to create a Retrieval-Augmented Generation (RAG) chatbot on Telegram. Index PDFs into Pinecone and answer queries using Groq LLMs.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

-
Technical users and developers looking for robust n8n templates for RAG.
Businesses needing to instantly query large documentation or knowledge bases.
Automation specialists seeking advanced examples of Groq, Pinecone, and n8n integration.
Teams wanting to deploy a secure, searchable knowledge bot via Telegram.

Overview

This sophisticated n8n workflow solves the problem of unstructured data accessibility by transforming raw PDF documents into a searchable knowledge base. It leverages the power of vector databases (Pinecone) and cutting-edge Language Models (Groq) to provide accurate, context-aware answers in real-time. When a user sends a document, the n8n node logic intelligently processes and indexes the data. When a user sends a question, the n8n trigger initiates a RAG process, ensuring responses are grounded in the provided documents. This specific n8n workflow is a perfect example of how to combine complex AI operations with user-friendly chat interfaces.

How it Works

The entire automation process begins with the n8n trigger set up on the Telegram platform. This robust n8n workflow operates in two distinct modes:


  1. Document Indexing (Knowledge Base Creation):

The Telegram Trigger receives an incoming message.
The Check If is a document n8n node determines if the message contains a file.
If a document exists, the Telegram get File n8n node downloads the binary data.
A Change to application/pdf code n8n node ensures the file metadata is correctly set for PDF parsing.
The document is split into manageable chunks using the Recursive Character Text Splitter.
Embeddings OpenAI generates vector representations (embeddings) of these chunks.
The Pinecone Vector Store (in 'insert' mode) saves the chunk and embedding pairs to the designated Pinecone index.
A confirmation message is sent via Telegram Response about Database.


  1. Question Answering (RAG Retrieval):

If the message is a text query, the flow bypasses the document steps and proceeds to the Question and Answer Chain.
This chain uses the user's message as a query.
The Vector Store Retriever, connected to the dedicated Pinecone Vector Store1 (configured for retrieval), fetches the most relevant document chunks based on semantic similarity.
The retrieved context, along with the user's original query, is passed to the Groq Chat Model (utilizing a high-performance LLM like Llama-3.1).
The LLM generates a grounded response.
The final response is delivered back to the user using the Telegram Response n8n node.

Installation Guide

To deploy this specialized n8n templates solution, follow these steps:


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

  2. Configure Credentials:

Telegram: Set up a Telegram API credential (Bot Token) for both the Telegram Trigger, Telegram get File, and the Telegram Response n8n nodes.
OpenAI: Set up an OpenAI API credential for the embedding generation n8n node (Embeddings OpenAI).
Groq: Set up a Groq API credential for the Groq Chat Model n8n node.
Pinecone: Set up a Pinecone API credential for both Pinecone Vector Store n8n nodes, ensuring they point to the correct index (named 'telegram' in this n8n workflow example).

  1. Activate the Trigger: Ensure the Telegram Trigger n8n trigger is correctly configured and the workflow is set to 'Active' to start listening for incoming messages.

Node Details

This n8n workflow relies on several core and specialized nodes:

Telegram Trigger (n8n trigger):
Function: Starts the n8n workflow upon receiving a message update in the configured Telegram bot chat.
Key Configuration: Listens specifically for message updates.
Check If is a document (If n8n node):
Function: Routes the flow based on the presence of a file attachment in the message payload ($json.message.document exists).
Key Configuration: Condition checks if the document object exists.
Telegram get File:
Function: Downloads the actual binary file content using the file ID provided by the Telegram API.
Change to application/pdf (Code n8n node):
Function: Crucial intermediary step that programmatically sets the MIME type of the downloaded binary file to application/pdf, ensuring proper handling by the LangChain data loader.
Recursive Character Text Splitter:
Function: Breaks the large PDF text content into smaller, overlapping chunks suitable for embedding and retrieval.
Key Configuration: Chunk Size set to 3000, Chunk Overlap set to 200.
Embeddings OpenAI:
Function: Converts the document chunks into numerical vectors stored in Pinecone for semantic searching.
Pinecone Vector Store (Insert Mode):
Function: The destination for the processed documents, inserting the text chunks and their corresponding embeddings into the 'telegram' index.
Groq Chat Model:
Function: Acts as the Large Language Model (LLM) component in the RAG chain.
Key Configuration: Uses the llama-3.1-70b-versatile model for high-quality, fast responses.
Vector Store Retriever:
Function: Performs the similarity search query against the Pinecone Vector Store1 to pull relevant context for the LLM.
Question and Answer Chain:
Function: Orchestrates the RAG process, combining the user's query, the retrieved context, and the output from the Groq Chat Model to formulate the final answer.

Related n8n Workflows

Free

Nodes: 14 Nodes
Updated: December 26 2025
View all
Created by
felipe biava cataneo
felipe biava cataneo

Engineer who likes to code as hobby

Featured*