{
  "name": "Automate a 'Chat with your PDF' Bot on Telegram with Google Gemini & Pinecone",
  "nodes": [
    {
      "id": "c2e95dd8-961b-42d0-89cd-c31e810da2e8",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        1584,
        944
      ]
    },
    {
      "id": "4ed51c5d-23e5-4836-ad13-1a5fb48a0317",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        1648,
        1104
      ]
    },
    {
      "id": "61db0aad-53de-4655-af01-7389c603137f",
      "name": "Stop and Error",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        1936,
        1664
      ]
    },
    {
      "id": "b525eb52-d03f-4b1c-83c1-54855c4f2701",
      "name": "Question and Answer Chain",
      "type": "@n8n/n8n-nodes-langchain.chainRetrievalQa",
      "position": [
        1008,
        1488
      ]
    },
    {
      "id": "666d4966-aa07-4b39-9f9f-6101f6f70b27",
      "name": "Vector Store Retriever",
      "type": "@n8n/n8n-nodes-langchain.retrieverVectorStore",
      "position": [
        1072,
        1680
      ]
    },
    {
      "id": "2ea5294f-def8-43d6-84ca-5f4bbb4b8b4a",
      "name": "Pinecone Vector Store1",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        992,
        1872
      ]
    },
    {
      "id": "d9e88d5c-096b-4a8f-8f17-fb8d1887c95f",
      "name": "Check If is a document",
      "type": "n8n-nodes-base.if",
      "position": [
        288,
        1344
      ]
    },
    {
      "id": "18c639ce-3517-4f1f-b02a-a40ba4f1e14b",
      "name": "Change to application/pdf",
      "type": "n8n-nodes-base.code",
      "position": [
        1072,
        1072
      ]
    },
    {
      "id": "9abd0d30-8bfd-4a9c-94a7-ddfe919f22df",
      "name": "Telegram get File",
      "type": "n8n-nodes-base.telegram",
      "position": [
        752,
        1072
      ]
    },
    {
      "id": "f9af0cdd-7ea3-4e97-b53f-b65fdf4e9355",
      "name": "Telegram Response",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1552,
        1488
      ]
    },
    {
      "id": "048f9df4-1d15-4dcf-b853-52fe376434a0",
      "name": "Telegram Response about Database",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2176,
        768
      ]
    },
    {
      "id": "36017ee3-5c44-469b-aad7-6a44faa57d32",
      "name": "Stop and Error1",
      "type": "n8n-nodes-base.stopAndError",
      "position": [
        2448,
        864
      ]
    },
    {
      "id": "68b2dc90-c4a5-436f-9c17-e811974f333b",
      "name": "Pinecone Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePinecone",
      "position": [
        1488,
        768
      ]
    },
    {
      "id": "fa712022-84c5-4c6d-aff1-dd71f73a7c20",
      "name": "Limit to 1",
      "type": "n8n-nodes-base.limit",
      "position": [
        1904,
        768
      ]
    },
    {
      "id": "71e24d0d-1e70-4c59-acf8-c7b73b5d33c5",
      "name": "Embeddings Google Gemini",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        1456,
        992
      ]
    },
    {
      "id": "0e7c375a-1aaa-459f-b8c2-13659f71320a",
      "name": "Embeddings Google Gemini1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
      "position": [
        1024,
        2016
      ]
    },
    {
      "id": "77d57e70-ef74-49eb-9019-6103a09ae391",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        880,
        1696
      ]
    },
    {
      "id": "92162e34-98e9-44ce-89a2-3ae058133a2d",
      "name": "Telegram Message Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -80,
        1344
      ]
    },
    {
      "id": "01da8891-6cb5-444e-8848-b34ee5af095c",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -224,
        1056
      ],
      "parameters": {
        "width": 368,
        "height": 272,
        "content": "## 1. **Trigger & Router**\n**Task:** This node is the starting point. It listens for *any* message on the configured Telegram bot.\n\n**Output:**\n- **Text:** User's question (goes to the RAG chain).\n- *"
      }
    },
    {
      "id": "246059a8-fbc0-4f33-8cfd-7b33c87c7c02",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        176,
        1056
      ],
      "parameters": {
        "width": 384,
        "height": 256,
        "content": "## 2. **Router Node**\n**Task:** Determines the message type to route the workflow.\n\n**Condition:** Checks if `{{ $json.message.document }}` **exists**.\n- **TRUE (Top Branch):** A file was uploaded. Pr"
      }
    },
    {
      "id": "6e03fbfc-58e6-4cd5-9ce9-82b0942a85e2",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1824,
        944
      ],
      "parameters": {
        "width": 336,
        "height": 272,
        "content": "## 5. **Text Splitter**\n**Task:** Breaks the large PDF text into small, manageable chunks for indexing.\n\n**Configuration:**\n- **Chunk Size:** 3000\n- **Chunk Overlap:** 200 (Ensures context overlaps be"
      }
    },
    {
      "id": "dd26c4da-207a-4b8e-90a4-4d2db8f1c529",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1408,
        544
      ],
      "parameters": {
        "width": 368,
        "height": 336,
        "content": "## 4. **Embeddings (Indexing)**\n**Task:** Converts the split text chunks into high-dimensional numerical **vectors**.\n\n**Model:** `models/gemini-embedding-001`\n\n**Purpose:** These vectors are what the"
      }
    },
    {
      "id": "ed22ea85-0803-4926-b118-fb4100bbf937",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1248,
        1776
      ],
      "parameters": {
        "width": 368,
        "height": 256,
        "content": "## 6. **Vector Store: Indexing**\n**Task:** **Inserts** the Gemini embeddings and their associated text content into the configured Pinecone index (`telegram`).\n\n**Mode:** **`insert`**\n\n**Result:** The"
      }
    },
    {
      "id": "a8cada20-ac48-4c8b-ab0f-de9b56d7d4a2",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        1232
      ],
      "parameters": {
        "width": 416,
        "height": 368,
        "content": "## 7. **Core RAG Engine**\n**Task:** Generates the final, context-based answer.\n\n**Connections:**\n- **LLM:** Google Gemini Chat Model (for generation).\n- **Retriever:** Vector Store Retriever (for cont"
      }
    },
    {
      "id": "2688705d-3dae-4235-84b0-8b880bf4cdeb",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1376,
        1264
      ],
      "parameters": {
        "width": 432,
        "height": 336,
        "content": "## 8. **Final Telegram Response**\n**Task:** Sends the RAG result back to the user.\n\n**Text Input:** `={{ $json.response.text }}`\n\n**CRITICAL SETTING:**\n- **Parse Mode:** **HTML**\nThis is required to p"
      }
    }
  ],
  "connections": {
    "Limit to 1": {
      "main": [
        [
          {
            "node": "Telegram Response about Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Response": {
      "main": [
        [],
        [
          {
            "node": "Stop and Error",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram get File": {
      "main": [
        [
          {
            "node": "Change to application/pdf",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Vector Store": {
      "main": [
        [
          {
            "node": "Limit to 1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check If is a document": {
      "main": [
        [
          {
            "node": "Telegram get File",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Question and Answer Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Vector Store1": {
      "ai_vectorStore": [
        [
          {
            "node": "Vector Store Retriever",
            "type": "ai_vectorStore",
            "index": 0
          }
        ]
      ]
    },
    "Vector Store Retriever": {
      "ai_retriever": [
        [
          {
            "node": "Question and Answer Chain",
            "type": "ai_retriever",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini": {
      "ai_embedding": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Question and Answer Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Message Trigger": {
      "main": [
        [
          {
            "node": "Check If is a document",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Change to application/pdf": {
      "main": [
        [
          {
            "node": "Pinecone Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Google Gemini1": {
      "ai_embedding": [
        [
          {
            "node": "Pinecone Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Question and Answer Chain": {
      "main": [
        [
          {
            "node": "Telegram Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Response about Database": {
      "main": [
        [],
        [
          {
            "node": "Stop and Error1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    }
  }
}