Factual Learning Assistant using RAG, Gemini, Telegram, and MongoDB - n8n Workflow

Use this professional n8n workflow template to build a secure Retrieval-Augmented Generation (RAG) system. Integrate Telegram, Google Gemini, and MongoDB Atlas to create an expert AI learning assistant based strictly on your proprietary documents.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Educational institutions and coaching centers (e.g., UPSC, specialized training) requiring factual QA based on syllabus documents.
Businesses needing an internal knowledge base that strictly references policy manuals or technical documents.
Users looking to create custom, fact-grounded AI Assistants without relying on general LLM knowledge.
Developers exploring advanced RAG implementation within an n8n workflow.

Overview

This comprehensive n8n workflow template solves the crucial problem of AI hallucination by enforcing a strict RAG mandate. The goal is to create an expert study assistant, exemplified here as a UPSC Analyst, whose responses are derived exclusively from verified, uploaded documents. This powerful n8n automation is split into two robust pipelines: Knowledge Ingestion and AI Query. By using the Google Gemini embedding n8n node and storing vectors in MongoDB Atlas, this n8n workflow ensures a high degree of security and accuracy. Whether you use the Google Drive n8n trigger or the Webhook Form n8n trigger for ingestion, the process creates a verifiable source of truth, making this one of the most reliable n8n templates for knowledge management.

How it Works

This n8n workflow operates in two phases:

1. Knowledge Ingestion Pipeline


  1. Trigger: The process is initiated by either the Google Drive n8n trigger, monitoring a specific folder for new file uploads (File uploaded n8n node), or the Webhook Form n8n trigger (On File Upload).

  2. File Preparation: If triggered by Google Drive, the file is downloaded using the Google Drive n8n node (Download file).

  3. Data Loading: The Default Data Loader processes the binary file data (e.g., PDFs, documents) in preparation for vectorization.

  4. Vectorization: The Convert Documents to Embeddings n8n node, powered by Google Gemini, transforms the document text into numerical vector embeddings.

  5. Storage: The MongoDB Atlas Vector Store - Insert n8n node securely pushes these fresh embeddings into the designated MongoDB Atlas collection, establishing the knowledge base.

2. RAG Chatbot Query Pipeline


  1. Query Trigger: The Listen for Aspirant Question n8n trigger (Telegram) fires when a user sends a message to the configured bot.

  2. AI Agent Initiation: The question is fed into the RAG Agent n8n node, which acts as the orchestrator.

  3. Context Retrieval (RAG): The agent first utilizes its tool—the MongoDB Atlas Vector Store - Retrieve n8n node. This tool performs a semantic search on the vector index using the query and retrieves the most relevant document chunks.

  4. Synthesis: The RAG Agent feeds the user's original query, the retrieved context (from MongoDB), and the comprehensive system prompt (Expert UPSC Analyst persona) into the Google Gemini Chat Model n8n node.

  5. Response: The LLM generates a detailed, analytical, and source-grounded response. The RAG Agent then passes this final answer to the Send Answer via Telegram n8n node, completing the n8n workflow execution.

Installation Guide

To deploy this advanced n8n workflow template, follow these steps:


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

  2. MongoDB Atlas Setup: Ensure you have a running MongoDB Atlas cluster and a database collection configured with a Vector Search Index. You will need the collection name and the two index names (one for insertion, one for retrieval).

  3. Google Gemini Credentials: Configure your credentials for the Google Gemini Chat Model and Embeddings n8n nodes.

  4. Telegram Configuration: Create a bot via BotFather. Set up credentials for the Listen for Aspirant Question n8n trigger and the Send Answer via Telegram n8n node, ensuring you replace CHATID> and configure the appropriate chat group ID for the trigger.

  5. Google Drive Configuration (Optional): If using the ingestion path via Google Drive, set up credentials and replace DRIVEFOLDERIDWATCH> with the ID of the folder containing your source documents.

  6. Activate: Ensure all nodes requiring configuration have their placeholders updated. Activate the n8n workflow to start both the ingestion and query listeners.

Node Details

File uploaded (Google Drive Trigger): This n8n trigger starts the ingestion process when a new file is detected in a specific Google Drive folder. Part of the ingestion pipeline.
On File Upload (Form Trigger): An alternative n8n trigger, allowing users to upload files via a dynamic webhook form to kick off the ingestion pipeline.
Download file (Google Drive n8n node): Retrieves the actual binary content of the file detected by the trigger, making it available for processing.
Default Data Loader: A specialized Langchain n8n node used to structure the raw binary file data into a format suitable for the embedding model.
Convert Documents to Embeddings (Google Gemini n8n node): Essential RAG component. This node converts the documents into numerical vectors using the Google Gemini API.
MongoDB Atlas Vector Store - Insert: This core n8n node takes the generated embeddings and saves them into the specified MongoDB collection, acting as the knowledge base builder.
Listen for Aspirant Question (Telegram Trigger): The primary n8n trigger for the query path. It listens for incoming chat messages in a defined Telegram group or chat.
Google Gemini Chat Model (LLM n8n node): Serves as the large language model component, providing the reasoning and natural language generation for the RAG Agent.
Simple Memory (Langchain n8n node): Provides conversation history storage, allowing the RAG Agent to maintain context across multiple turns.
MongoDB Atlas Vector Store - Retrieve: Configured as a tool for the RAG Agent. It executes the semantic similarity search against the vector index to retrieve relevant document chunks based on the user's query.
RAG Agent (Langchain Agent n8n node): The brain of the operation. It interprets the prompt, decides whether to use the retrieval tool, manages the memory, and orchestrates the final answer synthesis according to the detailed system prompt (UPSC Analyst).
Send Answer via Telegram (Telegram n8n node): The final action n8n node, responsible for sending the synthesized output from the RAG Agent back to the user's chat.

Related n8n Workflows

Free

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

Automation consultant with expertise in n8n, AI models, and workflow optimization. I help educators, startups, and businesses design scalable automation for content creation, exam prep, and process efficiency. Skilled in integrating Google Sheets, Telegram, and AI agents for impactful results.

Featured*