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-based AI Learning Assistant for Telegram using MongoDB and Google Drive",
  "tags": [],
  "nodes": [
    {
      "name": "デフォルトデータローダー",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        -160,
        256
      ],
      "parameters": {
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1.1,
      "id": "--0"
    },
    {
      "name": "チャットメッセージ受信時",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        96,
        -32
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.3,
      "id": "--1"
    },
    {
      "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,
      "id": "--2"
    },
    {
      "name": "MongoDB Atlas Vector Store - 挿入",
      "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,
      "id": "MongoDB-Atlas-Vector-Store----3"
    },
    {
      "name": "MongoDB Atlas Vector Store - 検索",
      "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,
      "id": "MongoDB-Atlas-Vector-Store----4"
    },
    {
      "name": "Google Gemini チャットモデル",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        272,
        256
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemini-2.5-flash-lite"
      },
      "credentials": {},
      "typeVersion": 1,
      "id": "Google-Gemini--5"
    },
    {
      "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,
      "id": "--6"
    },
    {
      "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,
      "id": "RAG--7"
    },
    {
      "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,
      "id": "--8"
    },
    {
      "name": "学習者質問の待機",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        96,
        96
      ],
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {
          "chatIds": "@educationalch"
        }
      },
      "credentials": {},
      "typeVersion": 1.2,
      "id": "--9"
    },
    {
      "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,
      "id": "Telegram--10"
    },
    {
      "name": "ドキュメントを埋め込みに変換",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        -384,
        416
      ],
      "parameters": {},
      "credentials": {},
      "typeVersion": 1,
      "id": "--11"
    },
    {
      "name": "埋め込みからドキュメントを検索",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        656,
        384
      ],
      "parameters": {},
      "credentials": {},
      "typeVersion": 1,
      "id": "--12"
    },
    {
      "name": "シンプルメモリ",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        400,
        240
      ],
      "parameters": {},
      "typeVersion": 1.3,
      "id": "--13"
    },
    {
      "name": "付箋メモ",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1440,
        -112
      ],
      "parameters": {
        "width": 672,
        "height": 1344,
        "content": "Who's it for?\nThis template is perfect for educational institutions, coaching centers (like UPSC, GMAT, or specialized technical training), internal corporate knowledge bases, and SaaS companies that need to provide instant, accurate, and source-grounded answers based on proprietary documents.\n\nIt's designed for users who want to leverage **Google Gemini's** powerful reasoning but ensure its answers are strictly factual and based only on their verified knowledge repository.\n\n## How it works / What it does\nThis workflow establishes a **Retrieval-Augmented Generation (RAG) pipeline** to build a secure, fact-based AI Agent. It operates in two main phases:\n\n**Knowledge Ingestion:** When a new document (e.g., a PDF, lecture notes, or policy manual) is uploaded via a **form** or **Google Drive**, the **Embeddings Google Gemini** node converts the content into numerical vectors. These vectors are then stored in a secure **MongoDB Atlas Vector Store**, creating a private knowledge base.\n\n**AI Query & Response:** A user asks a question via **Telegram**. The **RAG Agent** uses the question to perform a semantic search on the **MongoDB Vector Store**, retrieving the most relevant, source-specific passages. It then feeds this retrieved context to the **Google Gemini Chat Model** to generate a precise, factual answer, which is sent back to the user on Telegram.\n\nThis process ensures the agent never \"hallucinates\" or uses general internet knowledge, making the responses accurate and trustworthy.\n\n## Requirements\nTo use this template, you will need the following accounts and credentials:\n\n* **n8n Account**\n* **Google Gemini API Key:** For generating vector embeddings and powering the AI Agent.\n* **MongoDB Atlas Cluster:** A free-tier cluster is sufficient, configured with a Vector Search index.\n* **Telegram Bot:** A bot created via BotFather and a Chat ID where the bot will listen for and send messages.\n* **Google Drive Credentials** (if using the Google Drive ingestion path).\n\n## How to set up\n\n1.  **Set up MongoDB Atlas:** Create a free cluster and a database. Create a Vector Search Index on your collection to enable efficient searching.\n2.  **Configure Ingestion Path (Left Side):** Set up the **On File Upload** webhook or connect your **Google Drive** credentials. Configure the **Embeddings** and **MongoDB Insert** nodes with your credentials, collection name, and index name.\n3.  **Configure Chat Path (Right Side):** Set up the **Telegram Trigger** with your Bot Token/Webhook. Configure the **Google Gemini Chat Model** and the **MongoDB Retrieve** tool with your credentials/index details.\n4.  **Final Step:** Configure the **Send Answer via Telegram** node with your Bot Token and the Chat ID."
      },
      "typeVersion": 1,
      "id": "--14"
    },
    {
      "name": "付箋メモ1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -752,
        -160
      ],
      "parameters": {
        "color": 4,
        "width": 816,
        "height": 752,
        "content": "Workflow 1: Knowledge Ingestion Pipeline\n(Triggers on file upload to form or Google Drive)"
      },
      "typeVersion": 1,
      "id": "-1-15"
    },
    {
      "name": "付箋メモ2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        -160
      ],
      "parameters": {
        "color": 6,
        "width": 896,
        "height": 768,
        "content": "Workflow 2: RAG Chatbot Query Pipeline\n(Triggers on question received via Telegram)"
      },
      "typeVersion": 1,
      "id": "-2-16"
    }
  ],
  "active": true,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "connections": {
    "RAG--7": {
      "main": [
        [
          {
            "node": "Telegram--10",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "--6": {
      "main": [
        [
          {
            "node": "MongoDB-Atlas-Vector-Store----3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "--2": {
      "main": [
        [
          {
            "node": "--6",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "--13": {
      "ai_memory": [
        [
          {
            "node": "RAG--7",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "--8": {
      "main": [
        [
          {
            "node": "MongoDB-Atlas-Vector-Store----3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "--0": {
      "ai_document": [
        [
          {
            "node": "MongoDB-Atlas-Vector-Store----3",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Google-Gemini--5": {
      "ai_languageModel": [
        [
          {
            "node": "RAG--7",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "--1": {
      "main": [
        [
          {
            "node": "RAG--7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MongoDB Atlas Vector Store1": {
      "ai_tool": [
        [
          {
            "node": "RAG--7",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "--9": {
      "main": [
        [
          {
            "node": "RAG--7",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "--11": {
      "ai_embedding": [
        [
          {
            "node": "MongoDB-Atlas-Vector-Store----3",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "--12": {
      "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で表示

このワークフローを共有

カテゴリー

カテゴリー: 34