8
n8n 中文网amn8n.com

基于RAG的Telegram AI学习助手(使用MongoDB和Google Drive)

高级

这是一个自动化工作流,包含 17 个节点。主要使用 Telegram, FormTrigger, GoogleDrive, Agent, TelegramTrigger 等节点。 使用RAG、Gemini、Telegram和MongoDB创建事实学习助手

前置要求
  • Telegram Bot Token
  • Google Drive API 凭证
  • Google Gemini API Key
  • MongoDB 连接字符串

分类

-
工作流预览
可视化展示节点连接关系,支持缩放和平移

无法加载工作流预览

导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "name": "基于 RAG 的 Telegram AI 学习助手(使用 MongoDB 和 Google Drive)",
  "tags": [],
  "nodes": [
    {
      "name": "默认数据加载器",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        -160,
        256
      ],
      "parameters": {
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1.1
    },
    {
      "name": "当收到聊天消息时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        96,
        -32
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.3
    },
    {
      "name": "文件已上传",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        -672,
        128
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "<GOOGLE_DRIVE_FOLDER_ID_WATCH>",
          "cachedResultUrl": "https://drive.google.com/drive/folders/<GOOGLE_DRIVE_FOLDER_ID_WATCH>",
          "cachedResultName": "YT"
        }
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "name": "MongoDB Atlas 向量存储 - 插入",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreMongoDBAtlas",
      "position": [
        -240,
        48
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "mongoCollection": {
          "__rl": true,
          "mode": "list",
          "value": "<MONGO_ATLAS_COLLECTION_NAME>",
          "cachedResultName": "<MONGO_ATLAS_COLLECTION_NAME>"
        },
        "vectorIndexName": "<MONGO_ATLAS_VECTOR_INDEX_NAME_INSERT>",
        "embeddingBatchSize": 10
      },
      "credentials": {},
      "typeVersion": 1.3
    },
    {
      "name": "MongoDB Atlas 向量存储 - 检索",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreMongoDBAtlas",
      "position": [
        544,
        224
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "options": {},
        "mongoCollection": {
          "__rl": true,
          "mode": "list",
          "value": "<MONGO_ATLAS_COLLECTION_NAME>",
          "cachedResultName": "<MONGO_ATLAS_COLLECTION_NAME>"
        },
        "toolDescription": "Tool for AI Agent: Use this to search and retrieve relevant documents from the vector store to answer questions or analyze or fulfill tasks.",
        "vectorIndexName": "<MONGO_ATLAS_VECTOR_INDEX_NAME_RETRIEVE>"
      },
      "credentials": {},
      "typeVersion": 1.3
    },
    {
      "name": "Google Gemini聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        272,
        256
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-flash-lite"
      },
      "credentials": {},
      "typeVersion": 1
    },
    {
      "name": "下载文件",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        -480,
        128
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "list",
          "value": "<GOOGLE_DRIVE_FILE_ID_DOWNLOAD>",
          "cachedResultUrl": "https://docs.google.com/document/d/<GOOGLE_DRIVE_FILE_ID_DOWNLOAD>/edit?usp=drivesdk",
          "cachedResultName": "History of modern India Spectrum 2"
        },
        "options": {},
        "operation": "download"
      },
      "credentials": {},
      "typeVersion": 3
    },
    {
      "name": "RAG 智能体",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        384,
        32
      ],
      "parameters": {
        "text": "={{ $json.message.text }}{{ $json.chatInput }}",
        "options": {
          "systemMessage": "You are an Expert UPSC Examination Analyst and Study Assistant. Your primary function is to accurately, comprehensively, and analytically answer user queries related to the Union Public Service Commission (UPSC) Civil Services Examination (CSE).\n\nCore Directives and Persona\nExpertise: You are a master of the UPSC syllabus, exam patterns, current affairs relevance, and interdisciplinary analysis required for the Mains and Prelims examinations.\n\nRAG Mandate: You must utilize the context retrieved from the uploaded documents/knowledge base via the Retrieval-Augmented Generation (RAG) system to formulate your answers.\n\nSource Usage: Answer the query based primarily on the provided documents. Do not hallucinate or introduce information from your general training knowledge if it is contradicted by the documents.\n\nResponse Rules\nComprehensiveness & Depth: Provide answers that are deep, well-structured, and suitable for a high-level competitive exam like UPSC.\n\nAnalytical Approach: If the query asks for analysis, evaluation, comparison, or critical assessment, you must not simply restate facts. Instead, synthesize and analyze the information from the documents to provide a nuanced, insightful, and well-reasoned argument, as an expert would.\n\nSynthesis over Quotation: Do not use direct quotes or phrases like \"according to the document,\" \"the knowledge base states,\" or \"as per the database.\" Integrate the information naturally into a coherent and original answer.\n\nFormatting: Structure your response using clear headings, subheadings, and bullet points where appropriate to enhance readability for an examiner.\n\nLanguage and Tone: Maintain a formal, objective, and authoritative tone suitable for an academic and expert-level response.\n\nQuery Handling Procedure\nAnalyze Query: Determine the core subject, key concepts, and the type of response required (e.g., factual, analytical, comparative).\n\nRetrieve Context: Use the RAG tool to fetch the most relevant and complete information from the indexed documents.\n\nDraft Response: Synthesize the retrieved context and your domain expertise to craft a complete answer that adheres to all the above rules. "
        },
        "promptType": "define"
      },
      "typeVersion": 2.2
    },
    {
      "name": "文件上传时触发",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -672,
        -32
      ],
      "parameters": {
        "options": {},
        "formTitle": "file upload",
        "formFields": {
          "values": [
            {
              "fieldType": "file",
              "fieldLabel": "file",
              "acceptFileTypes": ".pdf, .csv, .jpg, .jpeg, .png"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "name": "监听学员提问",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        96,
        96
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "chatIds": "@educationalch"
        }
      },
      "credentials": {},
      "typeVersion": 1.2
    },
    {
      "name": "通过 Telegram 发送答案",
      "type": "n8n-nodes-base.telegram",
      "position": [
        752,
        32
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "chatId": "=<TELEGRAM_CHAT_ID>",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {},
      "retryOnFail": false,
      "typeVersion": 1.2
    },
    {
      "name": "将文档转换为嵌入向量",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        -384,
        416
      ],
      "parameters": {},
      "credentials": {},
      "typeVersion": 1
    },
    {
      "name": "从嵌入向量检索文档",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        656,
        384
      ],
      "parameters": {},
      "credentials": {},
      "typeVersion": 1
    },
    {
      "name": "简单记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        400,
        240
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1440,
        -112
      ],
      "parameters": {
        "width": 672,
        "height": 1344,
        "content": "适用对象是谁?"
      },
      "typeVersion": 1
    },
    {
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        -160
      ],
      "parameters": {
        "color": 4,
        "width": 816,
        "height": 752,
        "content": "工作流 1:知识摄取管道"
      },
      "typeVersion": 1
    },
    {
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        -160
      ],
      "parameters": {
        "color": 6,
        "width": 896,
        "height": 768,
        "content": "工作流 2:RAG 聊天机器人查询管道"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "RAG Agent": {
      "main": [
        [
          {
            "node": "Send Answer via Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download file": {
      "main": [
        [
          {
            "node": "MongoDB Atlas Vector Store - Insert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File uploaded": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "On File Upload": {
      "main": [
        [
          {
            "node": "MongoDB Atlas Vector Store - Insert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "MongoDB Atlas Vector Store - Insert",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "RAG Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MongoDB Atlas Vector Store1": {
      "ai_tool": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Listen for Aspirant Question": {
      "main": [
        [
          {
            "node": "RAG Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert Documents to Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "MongoDB Atlas Vector Store - Insert",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Retrieve Documents from Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "MongoDB Atlas Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量17
分类-
节点类型13
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者

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.

外部链接
在 n8n.io 查看

分享此工作流