{
  "name": "Gmail assistant with full Gmail history RAG using OpenAI",
  "nodes": [
    {
      "id": "dec780ab-9e05-4305-ba52-8a92dfc266e7",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -7040,
        800
      ]
    },
    {
      "id": "13f21017-5470-4e0e-8d13-aea6d98c4918",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -7440,
        448
      ],
      "parameters": {
        "width": 1162,
        "height": 796,
        "content": "# RAG AI Agent\n"
      }
    },
    {
      "id": "b6615316-94c0-4091-b6e3-8cdf64cb0902",
      "name": "When clicking ‘Test workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -6048,
        1472
      ]
    },
    {
      "id": "349336cd-9373-4553-aa13-9cf6a427a0c6",
      "name": "RAG Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -6944,
        576
      ]
    },
    {
      "id": "16acb16b-8d56-425a-b484-fa4ffc3f5616",
      "name": "Embeddings OpenAI5",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        -5680,
        912
      ]
    },
    {
      "id": "262344fa-8b26-4665-b0ff-e1354e6d84eb",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -6128,
        448
      ],
      "parameters": {
        "width": 1200,
        "height": 788,
        "content": "# Watch Trigger (Email) - New Email\n## Get new Email -> Extract the text -> Add to Vector Store"
      }
    },
    {
      "id": "69d042bf-b75a-414e-a2e2-a62632e6aef2",
      "name": "Embeddings OpenAI11",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        -5200,
        1712
      ]
    },
    {
      "id": "cd126bb7-60a6-450b-b31c-cfd9517e9441",
      "name": "Sticky Note11",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -6128,
        1328
      ],
      "parameters": {
        "width": 1596,
        "height": 740,
        "content": "# Get All Emails -> Store embedding in vector db\n"
      }
    },
    {
      "id": "d7481948-2972-42e9-b2ef-900c55bc6465",
      "name": "Qdrant Email Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
      "position": [
        -6736,
        896
      ]
    },
    {
      "id": "8b9845c3-a9e6-47a1-ae0e-8e66a15b5812",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -7248,
        576
      ]
    },
    {
      "id": "2c320869-b169-4961-a8fd-5403c7a1366e",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        -6864,
        800
      ]
    },
    {
      "id": "7cecd74a-bde6-4fcf-8622-81620c63b20f",
      "name": "Store Emails in Vector DB",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
      "position": [
        -5568,
        672
      ]
    },
    {
      "id": "82da160a-a572-4cdf-a260-f7a0c51a30fa",
      "name": "New Email",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -6064,
        672
      ]
    },
    {
      "id": "954a8ea4-9e00-43b9-9fe2-6d717b6dccd7",
      "name": "Get new Email Body",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -5840,
        672
      ]
    },
    {
      "id": "6735edda-91ff-4872-8c13-bec68a8af925",
      "name": "Get all emails",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -5824,
        1472
      ]
    },
    {
      "id": "f01ccf0e-caf4-44f1-a385-a6eb2b063551",
      "name": "Refactor Email Body data",
      "type": "n8n-nodes-base.code",
      "position": [
        -5616,
        1472
      ]
    },
    {
      "id": "19fe59c6-6576-453a-8098-97e47c72c033",
      "name": "Loop over all emails",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -5344,
        1472
      ]
    },
    {
      "id": "1e6d26d8-60e3-4128-82b4-a5e61d83cff1",
      "name": "Store Emails in Vector DB1",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreQdrant",
      "position": [
        -5024,
        1456
      ]
    },
    {
      "id": "5200b258-2c96-4d38-9c92-b5353ada6957",
      "name": "Set proper metadata",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        -5024,
        1696
      ]
    },
    {
      "id": "512bb68a-94d7-4e0f-ab51-265f19d670bd",
      "name": "Split emails",
      "type": "@n8n/n8n-nodes-langchain.textSplitterCharacterTextSplitter",
      "position": [
        -4944,
        1888
      ]
    },
    {
      "id": "73a26bce-0df2-4755-8175-8a0e367f7418",
      "name": "Set proper metadata1",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        -5424,
        880
      ]
    },
    {
      "id": "c70f74e1-75ab-4ce3-9c84-f92ff1d7a762",
      "name": "Split emails1",
      "type": "@n8n/n8n-nodes-langchain.textSplitterCharacterTextSplitter",
      "position": [
        -5344,
        1056
      ]
    },
    {
      "id": "051c026e-0fd7-4182-a388-0ccd6e0c085e",
      "name": "Embeddings OpenAI",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        -6784,
        1072
      ]
    }
  ],
  "connections": {
    "New Email": {
      "main": [
        [
          {
            "node": "Get new Email Body",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RAG Agent": {
      "main": [
        []
      ]
    },
    "Split emails": {
      "ai_textSplitter": [
        [
          {
            "node": "Set proper metadata",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Split emails1": {
      "ai_textSplitter": [
        [
          {
            "node": "Set proper metadata1",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "Get all emails": {
      "main": [
        [
          {
            "node": "Refactor Email Body data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Qdrant Email Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI5": {
      "ai_embedding": [
        [
          {
            "node": "Store Emails in Vector DB",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Get new Email Body": {
      "main": [
        [
          {
            "node": "Store Emails in Vector DB",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI11": {
      "ai_embedding": [
        [
          {
            "node": "Store Emails in Vector DB1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Set proper metadata": {
      "ai_document": [
        [
          {
            "node": "Store Emails in Vector DB1",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Loop over all emails": {
      "main": [
        [],
        [
          {
            "node": "Store Emails in Vector DB1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set proper metadata1": {
      "ai_document": [
        [
          {
            "node": "Store Emails in Vector DB",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Refactor Email Body data": {
      "main": [
        [
          {
            "node": "Loop over all emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Qdrant Email Vector Store": {
      "ai_tool": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Store Emails in Vector DB1": {
      "main": [
        [
          {
            "node": "Loop over all emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "RAG Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Test workflow’": {
      "main": [
        [
          {
            "node": "Get all emails",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}