AI Knowledge Assistant with RAG and RLHF via Telegram - n8n Workflow

Build an intelligent knowledge base chatbot using this advanced n8n workflow. Integrates GPT-4o-mini, MongoDB RAG, and human feedback (RLHF) for continuous learning.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Teams needing an internal, self-learning documentation search bot.
Users looking for advanced examples of n8n templates integrating Langchain and MongoDB Atlas.
Developers interested in implementing Reinforcement Learning from Human Feedback (RLHF) in an n8n workflow.
Automation Specialists seeking to build complex, multi-tool AI agents using n8n.

Overview

This sophisticated n8n workflow demonstrates how to deploy a powerful AI knowledge base agent using state-of-the-art techniques. It leverages the Langchain framework within n8n to connect a GPT-4o-mini model with three distinct vector stores hosted on MongoDB Atlas: official documentation, positively rated past interactions, and negatively rated past interactions.

This setup achieves two primary goals: high-accuracy RAG (by searching official docs) and continuous improvement via RLHF. Every time a user interacts with the bot via the Telegram n8n trigger, the response is generated, sent back, and immediately assessed for quality. This human feedback (positive or negative) is automatically embedded and re-indexed into the RLHF vector stores, ensuring the AI model learns what works and what does not. This is a robust, production-ready n8n template for AI automation.

How it Works

The n8n workflow operates in two main phases: Indexing and Runtime.

1. Indexing Flow (Manual n8n Trigger)


  1. The flow is initiated manually using the When clicking “Execute Workflow” n8n trigger.

  2. The Google Docs Importer n8n node retrieves the latest official documentation from the specified URL.

  3. This content is then prepared and inserted into the MongoDB Atlas vector store via the MongoDB Documentation Inserter node, using the OpenAI Embeddings Generator node to convert the text into searchable vectors.

2. Runtime Flow (Telegram n8n Trigger)


  1. The Receive Message on Telegram n8n trigger activates when a user sends a message to the bot.

  2. The user's chat ID is used by the MongoDB Chat Memory node to retrieve previous conversation context, enabling sustained conversations.

  3. The core intelligence resides in the Knowledge Base Agent n8n node. This agent uses the powerful GPT-4o-mini model and operates with three dedicated tools:

Search Documentation: The primary RAG tool for retrieving technical facts.
Search Positive Interactions: Used to reference previously successful answers (positive RLHF data).
* Search Negative Interactions: Used to identify and avoid previously poorly rated answers (negative RLHF data).

  1. The agent generates a comprehensive response.

  2. The Send Message on Telegram, Wait for Feedback n8n node sends the response and waits for the user to click thumbs up/down, capturing the human feedback.

  3. The Map feedback data n8n node processes the webhook data, classifying the result as 'positive' or 'negative'.

  4. The Set feedback fields for collection storage node prepares the prompt/response/feedback data for storage.

  5. The Submit embedded chat feedback n8n node uses an embedding generator to vectorize this new RLHF data and inserts it into the feedback collection, instantly updating the agent's knowledge base for future queries. This continuous feedback loop makes this an incredibly adaptive n8n workflow.

Installation Guide

To use this powerful n8n template, follow these steps:


  1. Import the n8n workflow: Copy the provided JSON and import it directly into your n8n instance.

  2. Credentials Setup: You will need three sets of credentials:

OpenAI API Key: For the GPT-4o-mini model and all embedding generation (used in multiple n8n nodes).
Telegram API: Set up a Telegram Bot and connect the API credential to the Receive Message on Telegram and Send Message on Telegram nodes.
* MongoDB Atlas: You must configure a connection to a MongoDB Atlas cluster that has the Vector Search feature enabled. Note the collection names (n8n-template and n8n-template-feedback) and index names (data_index and template-feedback-search) mentioned in the workflow’s sticky note.

  1. Indexing MongoDB: Manually trigger the indexing sub-workflow (starting with the When clicking “Execute Workflow” n8n trigger) to populate your documentation collection.

  2. Activate the n8n Trigger: Ensure the Receive Message on Telegram n8n trigger is active and listening for messages.

Node Details

This n8n workflow utilizes numerous specialized nodes to manage the AI, database, and messaging components:

Receive Message on Telegram (n8n Trigger): The entry point for the runtime flow. Function: Listens for incoming chat messages in Telegram.
Knowledge Base Agent (n8n node): The primary RAG component. Function: Acts as the orchestrator, deciding which of the three vector stores to consult based on the query and system rules. Key Configuration: Uses the gpt-4o-mini model and a detailed instruction prompt (system message) governing language detection, link prohibition, and rule enforcement.
Search Documentation (MongoDB Atlas Vector Store n8n node): Function: Performs vector similarity search on the primary documentation knowledge base (collection n8n-template). Key Configuration: Configured as the productDocs tool for the Agent.
Search Positive Interactions / Search Negative Interactions (MongoDB Atlas Vector Store n8n nodes): Function: Retrieve historical, human-rated responses to improve AI quality via RLHF. Key Configuration: Configured as feedbackPositive and feedbackNegative tools, filtering by metadata.
MongoDB Chat Memory (n8n node): Function: Stores and retrieves chat history for context persistence across messages, crucial for conversational flow.
Send Message on Telegram, Wait for Feedback (n8n node): Function: Sends the generated AI response and activates a subsequent webhook to capture user feedback (approval/disapproval).


  • Submit embedded chat feedback (MongoDB Atlas Vector Store n8n node): Function: Takes the structured feedback data, generates embeddings using the OpenAI Embeddings Generator1 node, and stores the new RLHF example in the feedback collection (n8n-template-feedback).

Related n8n Workflows

Free

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

NovaNode is a software factory building scalable AI for modern businesses. We specialize in omni-channel AI agents that automate customer support, sales, and operations across voice, WhatsApp, email, and chat. We serve both enterprise clients and SMEs, balancing deep integrations with speed and cost-efficiency. By combining automation with adaptability, we help companies scale faster and operate smarter. NovaNode is where AI meets execution.

Featured*