{
  "name": "Chat with your email history using Telegram, Mistral and Pgvector for RAG",
  "nodes": [
    {
      "id": "f0707b32-4d10-457c-9c5e-d120123da4cb",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -180,
        180
      ]
    },
    {
      "id": "2ed04863-6ff8-4770-ad1a-1cab65ac7233",
      "name": "Loop Over Items",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1376,
        180
      ]
    },
    {
      "id": "063ee7b6-2caf-43c1-a4df-f61e8ad52f79",
      "name": "Came from Telegram?",
      "type": "n8n-nodes-base.if",
      "position": [
        936,
        280
      ]
    },
    {
      "id": "137c2273-1967-4251-9a36-b051b2c47d64",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -180,
        380
      ]
    },
    {
      "id": "b3e195a5-6386-487d-b7a5-1a058d5efb89",
      "name": "Postgres PGVector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
      "position": [
        440,
        502.5
      ]
    },
    {
      "id": "daa7bb21-b56c-488f-86f0-e9d802f2ff99",
      "name": "Call the SQL composer Workflow",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "position": [
        740,
        500
      ]
    },
    {
      "id": "7c38ff8f-360f-4fc1-931d-59f9b4916965",
      "name": "Embeddings Ollama",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOllama",
      "position": [
        528,
        700
      ]
    },
    {
      "id": "be038026-7183-4725-8414-7d99418a3113",
      "name": "Beautify chat response",
      "type": "n8n-nodes-base.set",
      "position": [
        1156,
        380
      ]
    },
    {
      "id": "07edbbb3-0cc3-4119-b955-94160c408a1b",
      "name": "Split text into chunks",
      "type": "n8n-nodes-base.code",
      "position": [
        1156,
        180
      ]
    },
    {
      "id": "535ec1a9-1a01-42be-b85a-bca58a59a17b",
      "name": "Respond on Telegram in batches",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1816,
        180
      ]
    },
    {
      "id": "d7a95d68-53c9-46f6-8a4c-cb187426df9f",
      "name": "Escape Markdown",
      "type": "n8n-nodes-base.code",
      "position": [
        1596,
        180
      ]
    },
    {
      "id": "4ad0b66b-7054-4bda-ac31-e47cca1efc61",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        1596,
        -20
      ]
    },
    {
      "id": "a7972e4b-e4ef-417d-9dac-9c0f9d9401c4",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -240,
        -20
      ],
      "parameters": {
        "width": 400,
        "height": 880,
        "content": "## Chat around!\nYou can use this workflow both as a Telegram bot, or by chatting with it in n8n's interface."
      }
    },
    {
      "id": "1710735e-c9b4-475b-a68d-0fc75f1c5da0",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -20
      ],
      "parameters": {
        "width": 520,
        "height": 880,
        "content": "## 🤖 \nThis AI Agent has the mission to query both **structured** and **vectorized** databases containing all your e-mail communications.\n\nAdjust the *SQL composer Workflow* to point at a copy of my *T"
      }
    },
    {
      "id": "864ab75f-8793-4a9f-b330-ccb7f189504e",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        680,
        -20
      ],
      "parameters": {
        "width": 200,
        "height": 880,
        "content": "## IMPORTANT\nFor this step to work, you must download my other template *Translate questions about e-mails into SQL queries and run them*."
      }
    },
    {
      "id": "b1a76e48-f05c-48ed-85ee-d08f1b840130",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        -20
      ],
      "parameters": {
        "width": 1120,
        "height": 880,
        "content": "## Response\nThis section takes care of formatting the answer\nand either responding over Telegram, or in n8n's chat."
      }
    },
    {
      "id": "c0723534-dfa7-4474-94d6-44d9e430a56f",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        320,
        500
      ]
    },
    {
      "id": "3320de92-0d97-4165-978d-e2bf29d44781",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        336,
        280
      ]
    },
    {
      "id": "582625d2-a751-4aa6-abdf-7e686f936d23",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        200,
        500
      ]
    },
    {
      "id": "5715df4d-712f-4539-a259-456747297b13",
      "name": "Generate session id",
      "type": "n8n-nodes-base.set",
      "position": [
        20,
        280
      ]
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Came from Telegram?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Escape Markdown": {
      "main": [
        [
          {
            "node": "Respond on Telegram in batches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Escape Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Generate session id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Ollama": {
      "ai_embedding": [
        [
          {
            "node": "Postgres PGVector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Came from Telegram?": {
      "main": [
        [
          {
            "node": "Split text into chunks",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Beautify chat response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate session id": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split text into chunks": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Postgres PGVector Store": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Generate session id",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call the SQL composer Workflow": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Respond on Telegram in batches": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}