{
  "name": "Telegram AI chatbot with document-based answers using OpenAI and PGVector RAG",
  "nodes": [
    {
      "id": "ab11aca6-163b-4995-a2c1-89146aca4d13",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        3100,
        460
      ]
    },
    {
      "id": "5397732c-4b72-4d67-bc83-d131d6fe6a6a",
      "name": "Default Data Loader",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        2160,
        1000
      ]
    },
    {
      "id": "15b136fe-d236-4016-82e5-2cd45188cfc3",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        2040,
        1000
      ]
    },
    {
      "id": "67f63eac-3d80-4453-8378-31c245e40158",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        160
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "96577cfc-9c82-48da-a8bb-6b3c1bafc232",
      "name": "Download File",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        560,
        660
      ]
    },
    {
      "id": "b3805cd6-52e7-462c-9239-a573c8484bf9",
      "name": "File Created",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        -320,
        660
      ]
    },
    {
      "id": "b6a8743b-1e69-41a4-b410-410943583512",
      "name": "File Updated",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        -320,
        840
      ]
    },
    {
      "id": "36af5de3-7bfc-473a-a14d-f671a38c8212",
      "name": "Extract Document Text",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        780,
        660
      ]
    },
    {
      "id": "cb6f5d94-033e-4dd0-a09c-4d92fe07ecb6",
      "name": "Set File ID",
      "type": "n8n-nodes-base.set",
      "position": [
        120,
        660
      ]
    },
    {
      "id": "23f43960-5c13-43be-9450-af9c82c5f4d2",
      "name": "RAG AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        3140,
        240
      ]
    },
    {
      "id": "a2a4faee-8109-4f55-b30b-6e6294845088",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -100,
        660
      ]
    },
    {
      "id": "ceef932c-f667-4ed8-8014-b650a3546fb0",
      "name": "Recursive Character Text Splitter",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        2160,
        1160
      ]
    },
    {
      "id": "f59122eb-4e34-4765-90be-86f3507e9a65",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        2600,
        240
      ]
    },
    {
      "id": "61852ba7-292a-4b8c-b774-6df4d2d4d7c5",
      "name": "Create Chunks From Doc",
      "type": "n8n-nodes-base.code",
      "position": [
        1000,
        660
      ]
    },
    {
      "id": "5231cf12-4061-4793-b918-f02bd021c333",
      "name": "Chunks To List",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1220,
        660
      ]
    },
    {
      "id": "a37aa716-8d50-4ecd-a8de-44ca198386c3",
      "name": "Generate Contextual Text",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        1440,
        660
      ]
    },
    {
      "id": "b053ea08-d6a9-4718-a86b-3d44aa8e19b9",
      "name": "OpenAI Chat Model3",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1460,
        820
      ]
    },
    {
      "id": "6cf0dbc3-835f-4c99-b3b0-c5db7c379394",
      "name": "Get Values",
      "type": "n8n-nodes-base.set",
      "position": [
        1820,
        660
      ]
    },
    {
      "id": "05270c8c-a1de-4be9-80ff-84fbf84e8578",
      "name": "Postgres PGVector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
      "position": [
        2060,
        780
      ]
    },
    {
      "id": "71b60f18-4e1c-45bd-840c-5f3f113675f7",
      "name": "Delete Old Doc Records",
      "type": "n8n-nodes-base.postgres",
      "position": [
        340,
        660
      ]
    },
    {
      "id": "3ff8d9fb-f420-4939-b925-03e8fa7506d7",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        2600,
        400
      ]
    },
    {
      "id": "b1d273cb-1730-40eb-93e7-95305e6ce091",
      "name": "Docs RAG Tool",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
      "position": [
        3520,
        380
      ]
    },
    {
      "id": "9609e4cc-6d65-4364-97f8-0e79c0b36a2d",
      "name": "Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        3520,
        520
      ]
    },
    {
      "id": "df6ee67c-f983-4428-b0b8-cd0522d45298",
      "name": "Chat Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        3260,
        460
      ]
    },
    {
      "id": "6e33fb90-9dd1-4ef8-a5e6-9081aca23ec5",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2540,
        160
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "0b6cd331-8202-413f-a721-43290d9e51d0",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        -1180
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "e2d556be-1c64-4834-b6f6-ed469753ce09",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2540,
        -740
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "e54d26de-fb3e-491d-a23d-3986dfd36a2e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -380,
        1380
      ],
      "parameters": {
        "width": null,
        "height": null,
        "content": ""
      }
    },
    {
      "id": "5d1a8354-a538-44d8-8d30-fd74084e2ea3",
      "name": "TestData",
      "type": "n8n-nodes-base.set",
      "position": [
        2820,
        400
      ]
    }
  ],
  "connections": {
    "TestData": {
      "main": [
        [
          {
            "node": "RAG AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Docs RAG Tool",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Get Values": {
      "main": [
        [
          {
            "node": "Postgres PGVector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Set File ID": {
      "main": [
        [
          {
            "node": "Delete Old Doc Records",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Created": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Updated": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Docs RAG Tool": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Download File": {
      "main": [
        [
          {
            "node": "Extract Document Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chunks To List": {
      "main": [
        [
          {
            "node": "Generate Contextual Text",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Set File ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "Postgres PGVector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model3": {
      "ai_languageModel": [
        [
          {
            "node": "Generate Contextual Text",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Postgres PGVector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Extract Document Text": {
      "main": [
        [
          {
            "node": "Create Chunks From Doc",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Chunks From Doc": {
      "main": [
        [
          {
            "node": "Chunks To List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete Old Doc Records": {
      "main": [
        [
          {
            "node": "Download File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres PGVector Store": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate Contextual Text": {
      "main": [
        [
          {
            "node": "Get Values",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        []
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "TestData",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}