{
  "name": "Analyze, classify, and summarize Gmail with OpenAI RAG and Google Sheets",
  "nodes": [
    {
      "id": "8f65edfe-f7a0-4714-b22e-53532cb87870",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -672,
        160
      ]
    },
    {
      "id": "207e2479-0c2a-4ea5-a6c8-0af45c6f9c86",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -1328,
        -128
      ]
    },
    {
      "id": "1225b4f2-b8cf-42eb-9fb7-cfcc666d3186",
      "name": "Get row(s) in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        368,
        640
      ]
    },
    {
      "id": "b4fe14bf-c1bc-4379-8e94-44243edb8e4b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        544
      ],
      "parameters": {
        "width": 928,
        "height": 496,
        "content": "## Vector database initialization (manual first run)"
      }
    },
    {
      "id": "a6275b75-8599-4d76-b763-23f0ff61e180",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        784
      ],
      "parameters": {
        "width": 368,
        "height": 256,
        "content": "## Create embeddings for taxonomy knowledge base"
      }
    },
    {
      "id": "1bf826f0-1e84-449c-9d2b-6e695f131e92",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1376,
        -240
      ],
      "parameters": {
        "width": 528,
        "height": 464,
        "content": "## Email ingestion and preprocessing\n"
      }
    },
    {
      "id": "1ba270f2-5d61-455b-bf6d-c6a69873ff51",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        -240
      ],
      "parameters": {
        "width": 896,
        "height": 544,
        "content": "## AI analysis using RAG classification"
      }
    },
    {
      "id": "7730e7aa-8796-4a28-9549-26f18c32a7e2",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        -240
      ],
      "parameters": {
        "width": 384,
        "height": 544,
        "content": "## Store processed emails"
      }
    },
    {
      "id": "3780afea-b0b3-43f3-aa63-70006cbfcdb2",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        -112
      ],
      "parameters": {
        "width": 352,
        "height": 256,
        "content": "## New Category/Subcategory?"
      }
    },
    {
      "id": "06d1fc9e-3843-452d-841b-c68592f3d7e6",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        960,
        64
      ],
      "parameters": {
        "width": 864,
        "height": 448,
        "content": "## Automatic taxonomy learning"
      }
    },
    {
      "id": "38464f22-dd4b-4b0b-992d-3c66b1bb5190",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1664,
        -320
      ],
      "parameters": {
        "width": 864,
        "height": 368,
        "content": "## Audio summary notification"
      }
    },
    {
      "id": "1dda4ca3-d7d0-4a49-bfb4-2c169af4f028",
      "name": "When clicking ‘Execute workflow’",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        160,
        640
      ]
    },
    {
      "id": "02fd56c8-d49e-4a31-8d00-6b44837a7dc4",
      "name": "Analyze email with RAG agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -496,
        -128
      ]
    },
    {
      "id": "93a4602e-b439-4998-b4f7-5552a14235b1",
      "name": "Fetch full Gmail message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1168,
        32
      ]
    },
    {
      "id": "52ebae61-2c71-4a4d-853b-2a960cc4ce7c",
      "name": "Normalize email fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -1008,
        -128
      ]
    },
    {
      "id": "27143409-5428-4f7c-adb8-81793455dac6",
      "name": "Parse AI analysis result",
      "type": "n8n-nodes-base.set",
      "position": [
        160,
        32
      ]
    },
    {
      "id": "48ef6c0c-bf62-4c3f-bb93-4780b6f13792",
      "name": "Store processed email",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        336,
        -16
      ]
    },
    {
      "id": "a29d85ca-cbdf-48d8-9b35-da5884a1ecc7",
      "name": "Check for new taxonomy items",
      "type": "n8n-nodes-base.if",
      "position": [
        672,
        -16
      ]
    },
    {
      "id": "70fd7ea2-3592-4b1d-8140-d0a31467517c",
      "name": "Load taxonomy dataset",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1072,
        176
      ]
    },
    {
      "id": "45962298-3cf2-40df-af6b-f5b970e1e3c1",
      "name": "Get next taxonomy ID",
      "type": "n8n-nodes-base.code",
      "position": [
        1264,
        304
      ]
    },
    {
      "id": "ba43f9e7-5cf6-4c08-938f-9d606dbcbf70",
      "name": "Append new taxonomy entry",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1456,
        176
      ]
    },
    {
      "id": "8c551b81-7839-42b8-a525-51f2d549e92c",
      "name": "Notify admin about taxonomy update",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1664,
        304
      ]
    },
    {
      "id": "6282f451-1235-4aa3-a3d3-086bc70a55b4",
      "name": "Generate audio summary",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1888,
        -176
      ]
    },
    {
      "id": "6df2007e-954c-4bbe-81ec-5872e6170213",
      "name": "Send audio summary to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2224,
        -176
      ]
    },
    {
      "id": "eb252b88-4336-49e5-8c16-d6b5c7637f72",
      "name": "Vector store — taxonomy index",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        560,
        640
      ]
    },
    {
      "id": "fee89aa8-2981-400e-b415-f5ce8141550d",
      "name": "Vector store retriever (RAG tool)",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        -304,
        160
      ]
    },
    {
      "id": "8abed336-a6a4-4dc4-b7ee-f6d1d481fc78",
      "name": "Prepare taxonomy documents",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        608,
        896
      ]
    },
    {
      "id": "b23850e5-0c9d-4e5b-8fef-f2ec4dc82cf6",
      "name": "Create embeddings (OpenAI)",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        -176,
        896
      ]
    },
    {
      "id": "f5a501d4-a09d-4d21-8a56-7af4b33aa7a9",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1216,
        400
      ],
      "parameters": {
        "width": 704,
        "height": 592,
        "content": "## How it works\n\nThis workflow automatically analyzes incoming Gmail messages using a Retrieval-Augmented Generation (RAG) approach. When a new email arrives, the workflow extracts and normalizes its "
      }
    }
  ],
  "connections": {
    "Gmail Trigger": {
      "main": [
        [
          {
            "node": "Fetch full Gmail message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Analyze email with RAG agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "Vector store — taxonomy index",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get next taxonomy ID": {
      "main": [
        [
          {
            "node": "Append new taxonomy entry",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Load taxonomy dataset": {
      "main": [
        [
          {
            "node": "Get next taxonomy ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Store processed email": {
      "main": [
        [
          {
            "node": "Check for new taxonomy items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate audio summary": {
      "main": [
        [
          {
            "node": "Send audio summary to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize email fields": {
      "main": [
        [
          {
            "node": "Analyze email with RAG agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch full Gmail message": {
      "main": [
        [
          {
            "node": "Normalize email fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse AI analysis result": {
      "main": [
        [
          {
            "node": "Store processed email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Append new taxonomy entry": {
      "main": [
        [
          {
            "node": "Notify admin about taxonomy update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create embeddings (OpenAI)": {
      "ai_embedding": [
        [
          {
            "node": "Vector store — taxonomy index",
            "type": "ai_embedding",
            "index": 0
          },
          {
            "node": "Vector store retriever (RAG tool)",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Prepare taxonomy documents": {
      "ai_document": [
        [
          {
            "node": "Vector store — taxonomy index",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Analyze email with RAG agent": {
      "main": [
        [
          {
            "node": "Parse AI analysis result",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check for new taxonomy items": {
      "main": [
        [
          {
            "node": "Load taxonomy dataset",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Generate audio summary",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Vector store retriever (RAG tool)": {
      "ai_tool": [
        [
          {
            "node": "Analyze email with RAG agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Notify admin about taxonomy update": {
      "main": [
        [
          {
            "node": "Generate audio summary",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}