Skip to main content

Build a chatbot with Reinforced Learning Human Feedback (RLHF) and RAG

Workflow preview

Workflow preview
100%
Build a chatbot with Reinforced Learning Human Feedback (RLHF) and RAG preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

Who is this for? This template is designed for internal support teams, product specialists, and knowledge managers who want to build an AI powered knowledge assistant with retrieval augmented gener...

Best for

  • Internal Wiki automation workflows
  • AI RAG automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.lmchatopenai, @n8n/n8n-nodes-langchain.embeddingsopenai, @n8n/n8n-nodes-langchain.documentdefaultdataloader, @n8n/n8n-nodes-langchain.textsplitterrecursivecharactertextsplitter, n8n-nodes-base.googledocs, n8n-nodes-base.stickynote, n8n-nodes-base.manualtrigger

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by NovaNode.

Original n8n.io source

1.1 Workflow description

Title
Build a chatbot with Reinforced Learning Human Feedback (RLHF) and RAG
Workflow name
Build a chatbot with Reinforced Learning Human Feedback (RLHF) and RAG

Who is this for?

This template is designed for internal support teams, product specialists, and knowledge managers who want to build an AI-powered knowledge assistant with retrieval-augmented generation (RAG) and reinforcement learning from human feedback (RLHF) via Telegram.

What problem is this workflow solving?

Manual knowledge management and answering support queries can be time-consuming and error-prone. This solution automates importing and indexing official documentation into MongoDB vector search and enhances AI responses with Telegram-based user feedback to continuously improve answer quality.

What these workflows do

Workflow 1: Document ingestion & indexing
  • Manually triggered workflow imports product documentation from Google Docs.
  • Documents are split into manageable chunks and embedded using OpenAI embeddings.
  • Embedded document chunks are stored in MongoDB Atlas vector store to enable semantic search.
Workflow 2: Telegram chat with RLHF feedback loop
  • Listens for user messages via Telegram bot integration.
  • Uses vector similarity search on MongoDB to retrieve relevant documentation chunks.
  • Generates answers with OpenAI GPT-4o-mini model using retrieval-augmented generation.
  • Sends answers back via Telegram and waits for user feedback (approval or disapproval).
  • Captures feedback, maps it as positive or negative, and stores it with the conversation data for future model improvement.

Setup

Setting up vector embeddings
  1. Authenticate Google Docs and connect your Google Docs URL containing the product documentation you want to index.
  2. Authenticate MongoDB Atlas and connect the collection where you want to store the vector embeddings. Create a search index on this collection to support vector similarity queries.
  3. Ensure the index name matches the one configured in n8n (data_index).
  4. See the example MongoDB search index template below for reference.
Setting up chat with Telegram RLHF
  1. Create a bot in Telegram with @botFather using the /newbot command.
  2. Connect the MongoDB database and search index used for vector search in the previous workflow. Also create two new collections in MongoDB Atlas: one for feedback and one for chat history. Create a search index for feedback, copying the provided template.
  3. Configure the AI system prompt in the “Knowledge Base Agent” node, making sure it references all three tools connected (productDocs, feedbackPositive, feedbackNegative) as provided in the template prompt.

Make sure

  • Product documentation and feedback collections must connect to the same MongoDB database.
  • There are three distinct MongoDB collections: one for product documentation, one for feedback, and one for chat history (chat history collection can be separate).
  • Telegram API credentials are valid and webhook URLs are correctly set up.

MongoDB Search Index Templates

Documentation Collection Index

{ "mappings": { "dynamic": false, "fields": { "_id": { "type": "string" }, "text": { "type": "string" }, "embedding": { "type": "knnVector", "dimensions": 1536, "similarity": "cosine" }, "source": { "type": "string" }, "doc_id": { "type": "string" } } } }

Feedback Collection Index

{ "mappings": { "dynamic": false, "fields": { "prompt": { "type": "string" }, "response": { "type": "string" }, "text": { "type": "string" }, "embedding": { "type": "knnVector", "dimensions": 1536, "similarity": "cosine" }, "feedback": { "type": "token" } } } }

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - Knowledge Base Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.9

Block 2 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1.2

Block 3 - Embeddings OpenAI

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.2

Block 4 - Document Section Loader

Type / Role
@n8n/n8n-nodes-langchain.documentDefaultDataLoader - documentDefaultDataLoader
Config choices
Version 1

Block 5 - Document Chunker

Type / Role
@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter - textSplitterRecursiveCharacterTextSplitter
Config choices
Version 1

Block 6 - OpenAI Embeddings Generator

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.2

Block 7 - Google Docs Importer

Type / Role
n8n-nodes-base.googleDocs - googleDocs
Config choices
Version 2

Block 8 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 10 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 11 - When clicking "Execute Workflow"

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 12 - MongoDB Chat Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryMongoDbChat - memoryMongoDbChat
Config choices
Version 1

Block 13 - Embeddings OpenAI1

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.2

Block 14 - Default Data Loader

Type / Role
@n8n/n8n-nodes-langchain.documentDefaultDataLoader - documentDefaultDataLoader
Config choices
Version 1

Block 15 - Recursive Character Text Splitter

Type / Role
@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter - textSplitterRecursiveCharacterTextSplitter
Config choices
Version 1

Block 16 - Embeddings OpenAI3

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.2

Block 17 - Search Positive Interactions

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreMongoDBAtlas - vectorStoreMongoDBAtlas
Config choices
Version 1.1

Block 18 - Search Documentation

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreMongoDBAtlas - vectorStoreMongoDBAtlas
Config choices
Version 1.1

Block 19 - Search Negative Interactions

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreMongoDBAtlas - vectorStoreMongoDBAtlas
Config choices
Version 1.1

Block 20 - Receive Message on Telegram

Type / Role
n8n-nodes-base.telegramTrigger - telegramTrigger
Config choices
Version 1.2

Block 21 - Send Message on Telegram, Wait for Feedback

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 22 - Map feedback data

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 23 - Set feedback fields for collection storage

Type / Role
n8n-nodes-base.set - set
Config choices
Version 1

Block 24 - Submit embedded chat feedback

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreMongoDBAtlas - vectorStoreMongoDBAtlas
Config choices
Version 1.1

Showing the first 24 of 26 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow Build a chatbot with Reinforced Learning Human Feedback (RLHF) and RAG
Complexity advanced
Nodes 26
Categories Internal Wiki, AI RAG
Author NovaNode
Published 05 Jun 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/4689/4689.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Build a chatbot with Reinforced Learning Human Feedback (RLHF) and RAG do?

Who is this for? This template is designed for internal support teams, product specialists, and knowledge managers who want to build an AI powered knowledge assistant with retrieval augmented gener...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Internal Wiki, AI RAG use case.