AutomationFlows β€Ί AI & RAG β€Ί Analyze, Classify, and Summarize Gmail with Openai RAG and Google Sheets

Analyze, Classify, and Summarize Gmail with Openai RAG and Google Sheets

ByAmirhosein Zahedi @amirhoseinzahedi on n8n.io

<h2>πŸ“§ Analyze, classify, and summarize emails using RAG (automatic taxonomy learning)</h2>

Event triggerβ˜…β˜…β˜…β˜…β˜† complexityAI-powered29 nodesOpenAI ChatGmail TriggerGoogle SheetsAgentGmailTelegramOpenAIIn-Memory Vector Store
AI & RAG Trigger: Event Nodes: 29 Complexity: β˜…β˜…β˜…β˜…β˜† AI nodes: yes Added:

This workflow corresponds to n8n.io template #13568 β€” we link there as the canonical source.

This workflow follows the Agent β†’ Documentdefaultdataloader recipe pattern β€” see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide β†’

Download .json
{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "8f65edfe-f7a0-4714-b22e-53532cb87870",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -672,
        160
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {
          "topP": 1,
          "temperature": 0.7,
          "frequencyPenalty": 0
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "207e2479-0c2a-4ea5-a6c8-0af45c6f9c86",
      "name": "Gmail Trigger",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        -1328,
        -128
      ],
      "parameters": {
        "filters": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "1225b4f2-b8cf-42eb-9fb7-cfcc666d3186",
      "name": "Get row(s) in sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        368,
        640
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 67988996,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16kSdJJ0imPSq2A7gIhueuEvjwdcvjRaCMYGg-u2QdFs/edit#gid=67988996",
          "cachedResultName": "tagging_sample"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "16kSdJJ0imPSq2A7gIhueuEvjwdcvjRaCMYGg-u2QdFs",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16kSdJJ0imPSq2A7gIhueuEvjwdcvjRaCMYGg-u2QdFs/edit?usp=drivesdk",
          "cachedResultName": "tagging_samples_for_RAG"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "b4fe14bf-c1bc-4379-8e94-44243edb8e4b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        80,
        544
      ],
      "parameters": {
        "color": 6,
        "width": 928,
        "height": 496,
        "content": "## Vector database initialization (manual first run)"
      },
      "typeVersion": 1
    },
    {
      "id": "a6275b75-8599-4d76-b763-23f0ff61e180",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -320,
        784
      ],
      "parameters": {
        "color": 3,
        "width": 368,
        "height": 256,
        "content": "## Create embeddings for taxonomy knowledge base"
      },
      "typeVersion": 1
    },
    {
      "id": "1bf826f0-1e84-449c-9d2b-6e695f131e92",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1376,
        -240
      ],
      "parameters": {
        "color": 4,
        "width": 528,
        "height": 464,
        "content": "## Email ingestion and preprocessing\n"
      },
      "typeVersion": 1
    },
    {
      "id": "1ba270f2-5d61-455b-bf6d-c6a69873ff51",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 896,
        "height": 544,
        "content": "## AI analysis using RAG classification"
      },
      "typeVersion": 1
    },
    {
      "id": "7730e7aa-8796-4a28-9549-26f18c32a7e2",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        112,
        -240
      ],
      "parameters": {
        "color": 5,
        "width": 384,
        "height": 544,
        "content": "## Store processed emails"
      },
      "typeVersion": 1
    },
    {
      "id": "3780afea-b0b3-43f3-aa63-70006cbfcdb2",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        -112
      ],
      "parameters": {
        "color": 3,
        "width": 352,
        "height": 256,
        "content": "## New Category/Subcategory?"
      },
      "typeVersion": 1
    },
    {
      "id": "06d1fc9e-3843-452d-841b-c68592f3d7e6",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        960,
        64
      ],
      "parameters": {
        "color": 5,
        "width": 864,
        "height": 448,
        "content": "## Automatic taxonomy learning"
      },
      "typeVersion": 1
    },
    {
      "id": "38464f22-dd4b-4b0b-992d-3c66b1bb5190",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1664,
        -320
      ],
      "parameters": {
        "color": 4,
        "width": 864,
        "height": 368,
        "content": "## Audio summary notification"
      },
      "typeVersion": 1
    },
    {
      "id": "1dda4ca3-d7d0-4a49-bfb4-2c169af4f028",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        160,
        640
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "02fd56c8-d49e-4a31-8d00-6b44837a7dc4",
      "name": "Analyze email with RAG agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -496,
        -128
      ],
      "parameters": {
        "text": "=sender: {{ $json.sender }}\nemail: {{ $json.email }}\ndate: {{ $json.date }}\nsubject: {{ $json.subject }}\ncontent: {{ $json.content }}",
        "options": {
          "systemMessage": "=You are an email analysis, classification, and summarization assistant operating inside an automated workflow.\n\nYou will receive ONE incoming email object as input.\n\nYour task is to analyze the email and RETURN THE SAME OBJECT with additional structured fields appended.\n\n--------------------------------------------------\nPRIMARY OBJECTIVES\n--------------------------------------------------\n\n1. Summarize the email content in ONE short paragraph (maximum 3 sentences).\n\n2. Classify the email using semantic context retrieved from \"Simple Vector Store1\".\n\n3. The retrieved examples represent the OFFICIAL taxonomy and are the PRIMARY SOURCE OF TRUTH for categories and subcategories.\n\n4. Extract up to 5 meaningful keywords representing the main topics of the email.\n\n5. Provide a confidence score between 0 and 1 indicating classification certainty.\n\n--------------------------------------------------\nCLASSIFICATION RULES (STRICT)\n--------------------------------------------------\n\n- ALWAYS prefer categories and subcategories found in retrieved examples.\n- DO NOT invent new categories or subcategories unless no reasonable semantic match exists.\n- Retrieved examples have higher authority than general model knowledge.\n- If similarity is weak, still choose the closest existing category and LOWER the confidence score.\n- Only create a new category or subcategory when NO retrieved example reasonably matches the email topic.\n\nDecision priority order:\n1) Retrieved vector store examples (highest priority)\n2) Semantic meaning of the email\n3) General reasoning (last resort)\n\n--------------------------------------------------\nTAXONOMY CONSISTENCY CHECK (MANDATORY)\n--------------------------------------------------\n\nAfter selecting a category and subcategory:\n\n1. Compare the selected category against ALL categories present in the retrieved examples from \"Simple Vector Store1\".\n\n2. If the selected category DOES NOT appear in retrieved examples from knowledge_base and you generated new one:\n   set new_category = true\n   otherwise set new_category = false.\n\n3. If the category exists but the selected subcategory DOES NOT appear in retrieved examples from knowledge_base and you generated new one:\n   set new_subcategory = true\n   otherwise set new_subcategory = false.\n\n4. This decision MUST be based ONLY on retrieved examples, not on general knowledge.\n\n--------------------------------------------------\nCONFIDENCE SCORING\n--------------------------------------------------\n\n0.90\u20131.00 \u2192 strong semantic match with retrieved examples\n0.70\u20130.89 \u2192 clear topic with minor ambiguity\n0.50\u20130.69 \u2192 weak similarity but reasonable classification\n0.00\u20130.49 \u2192 uncertain classification\n\nLower confidence when retrieved similarity is weak or ambiguous.\n\n--------------------------------------------------\nOUTPUT REQUIREMENTS (CRITICAL)\n--------------------------------------------------\n\n- Output MUST be valid JSON ONLY.\n- DO NOT include markdown, explanations, comments, or extra text.\n- DO NOT remove, rename, or modify any existing input fields.\n- Preserve all original fields exactly as received.\n- Append ONLY the following fields:\n\n{\n  \"summary\": \"short paragraph summary\",\n  \"short_message\": \"1 long line summary\",\n  \"category\": \"main category\",\n  \"subcategory\": \"specific subcategory\",\n  \"keywords\": [\"keyword1\",\"keyword2\",\"keyword3\"],\n  \"confidence\": 0.0,\n  \"new_category\": false,\n  \"new_subcategory\": false\n}\n\n--------------------------------------------------\nNEW CATEGORY FLAGS\n--------------------------------------------------\n\n- new_category = true ONLY if the selected category is NOT present in retrieved examples.\n- new_subcategory = true ONLY if the category exists but the subcategory is NOT present in retrieved examples.\n\n--------------------------------------------------\nFINAL VALIDATION STEP (MANDATORY)\n--------------------------------------------------\n\nBefore responding, internally verify:\n\n\u2713 Output is valid JSON\n\u2713 No missing commas or trailing text\n\u2713 All original input fields remain unchanged\n\u2713 Exactly the required fields were appended\n\u2713 No additional fields were added\n\u2713 Boolean fields contain true or false values only\n\u2713 confidence is a number between 0 and 1\n\nIf validation fails, correct the output before responding."
        },
        "promptType": "define"
      },
      "typeVersion": 3.1
    },
    {
      "id": "93a4602e-b439-4998-b4f7-5552a14235b1",
      "name": "Fetch full Gmail message",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1168,
        32
      ],
      "parameters": {
        "simple": false,
        "options": {},
        "messageId": "={{ $json.id }}",
        "operation": "get"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "52ebae61-2c71-4a4d-853b-2a960cc4ce7c",
      "name": "Normalize email fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -1008,
        -128
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "7e9eb4f0-4857-4400-aeb8-ed95125e521e",
              "name": "id",
              "type": "string",
              "value": "={{ $json.id }}"
            },
            {
              "id": "38b144e4-656d-455c-97a2-2940a2ef1664",
              "name": "date",
              "type": "string",
              "value": "={{ $json.date}}"
            },
            {
              "id": "c6783bdd-84ec-4b33-87d1-92d9abee0883",
              "name": "sender",
              "type": "string",
              "value": "={{ $json.from.value[0].name }}"
            },
            {
              "id": "6ea9a751-b591-4c48-ae73-b34957baf989",
              "name": "email",
              "type": "string",
              "value": "={{ $json.from.value[0].address }}"
            },
            {
              "id": "94764f32-b319-4402-94ba-3eb5f579f967",
              "name": "subject",
              "type": "string",
              "value": "={{ $json.subject }}"
            },
            {
              "id": "85dae6e6-27b9-4f50-b87a-54321fae5d61",
              "name": "content",
              "type": "string",
              "value": "={{ $json.html.removeTags() }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "27143409-5428-4f7c-adb8-81793455dac6",
      "name": "Parse AI analysis result",
      "type": "n8n-nodes-base.set",
      "position": [
        160,
        32
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "81cda1ee-1de3-4532-8424-63af111b7e5e",
              "name": "sender",
              "type": "string",
              "value": "={{ $json.output.parseJson().sender}}"
            },
            {
              "id": "411d8ed7-b5a0-406b-8cbb-f13fcc2e0cb9",
              "name": "email",
              "type": "string",
              "value": "={{ $json.output.parseJson().email}}"
            },
            {
              "id": "91e1e7ed-4d7b-4f7b-8ce6-256f7534ddaa",
              "name": "date",
              "type": "string",
              "value": "={{ $json.output.parseJson().date}}"
            },
            {
              "id": "339af5c2-4a0a-49a8-9a95-c30038b3c449",
              "name": "subject",
              "type": "string",
              "value": "={{ $json.output.parseJson().subject}}"
            },
            {
              "id": "4e1e6c3f-6db6-451b-90b3-567860a41dca",
              "name": "content",
              "type": "string",
              "value": "={{ $json.output.parseJson().summary}}"
            },
            {
              "id": "01e3df72-a9d8-4e3f-ba6b-34e891a7cc4f",
              "name": "short message",
              "type": "string",
              "value": "={{ $json.output.parseJson().short_message}}"
            },
            {
              "id": "cbfb9eb0-f132-4b28-8523-b67a58f1a640",
              "name": "category",
              "type": "string",
              "value": "={{ $json.output.parseJson().category}} "
            },
            {
              "id": "2d7eaa48-8188-481c-b97a-ca33512f8f9a",
              "name": "subcategory",
              "type": "string",
              "value": "={{ $json.output.parseJson().subcategory}}"
            },
            {
              "id": "20f7f724-4b6a-46a5-9f1e-1d27a477c03c",
              "name": "keyword",
              "type": "string",
              "value": "={{ $json.output.parseJson().keywords.join()}}"
            },
            {
              "id": "2d8fc5fa-83a5-49ae-a47c-0cb720cc4b72",
              "name": "confidence",
              "type": "string",
              "value": "={{ $json.output.parseJson().confidence}}"
            },
            {
              "id": "a3f2f93c-91cf-4b72-b0f4-f0656114f4d7",
              "name": "new category",
              "type": "string",
              "value": "={{ $json.output.parseJson().new_category}}"
            },
            {
              "id": "f0671f31-6cee-49ba-b57f-272901b27555",
              "name": "new subcategory",
              "type": "string",
              "value": "={{ $json.output.parseJson().new_subcategory}}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "48ef6c0c-bf62-4c3f-bb93-4780b6f13792",
      "name": "Store processed email",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        336,
        -16
      ],
      "parameters": {
        "columns": {
          "value": {
            "date": "={{ $json.date }}",
            "name": "={{ $json.sender }}",
            "email": "={{ $json.email }}",
            "subject": "={{ $json.subject }}",
            "category": "={{ $json.category }}",
            "keywords": "={{ $json.keyword }}",
            "subcategory": "={{ $json.subcategory }}",
            "summarized text": "={{ $json.content }}"
          },
          "schema": [
            {
              "id": "date",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "email",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "name",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "name",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "summarized text",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "summarized text",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "category",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subcategory",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "subcategory",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "keywords",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "keywords",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/183Hr0qGVs5sLqoWi_69uRPItvhy_BrdSjgQ8nI9OCz0/edit#gid=0",
          "cachedResultName": "email"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "183Hr0qGVs5sLqoWi_69uRPItvhy_BrdSjgQ8nI9OCz0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/183Hr0qGVs5sLqoWi_69uRPItvhy_BrdSjgQ8nI9OCz0/edit?usp=drivesdk",
          "cachedResultName": "Untitled spreadsheet"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "a29d85ca-cbdf-48d8-9b35-da5884a1ecc7",
      "name": "Check for new taxonomy items",
      "type": "n8n-nodes-base.if",
      "position": [
        672,
        -16
      ],
      "parameters": {
        "options": {
          "ignoreCase": true
        },
        "conditions": {
          "options": {
            "version": 3,
            "leftValue": "",
            "caseSensitive": false,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "550b3cd9-0fb1-4810-9037-2a56b630779c",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Parse AI analysis result').item.json[\"new category\"] }}",
              "rightValue": "true"
            },
            {
              "id": "66af56bc-574b-4565-bfad-75577917b8dc",
              "operator": {
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $('Parse AI analysis result').item.json[\"new subcategory\"] }}",
              "rightValue": "true"
            }
          ]
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "70fd7ea2-3592-4b1d-8140-d0a31467517c",
      "name": "Load taxonomy dataset",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1072,
        176
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 67988996,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16kSdJJ0imPSq2A7gIhueuEvjwdcvjRaCMYGg-u2QdFs/edit#gid=67988996",
          "cachedResultName": "tagging_sample"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "16kSdJJ0imPSq2A7gIhueuEvjwdcvjRaCMYGg-u2QdFs",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16kSdJJ0imPSq2A7gIhueuEvjwdcvjRaCMYGg-u2QdFs/edit?usp=drivesdk",
          "cachedResultName": "tagging_samples_for_RAG"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "45962298-3cf2-40df-af6b-f5b970e1e3c1",
      "name": "Get next taxonomy ID",
      "type": "n8n-nodes-base.code",
      "position": [
        1264,
        304
      ],
      "parameters": {
        "language": "pythonNative",
        "pythonCode": "ids = [item[\"json\"][\"id\"] for item in _items]\n\n# Get the maximum id\nmax_id = max(ids)\n\n\n# Return result\nreturn [{\n    \"json\": {\n        \"max_id\": max_id\n    }\n}]\n"
      },
      "typeVersion": 2
    },
    {
      "id": "ba43f9e7-5cf6-4c08-938f-9d606dbcbf70",
      "name": "Append new taxonomy entry",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1456,
        176
      ],
      "parameters": {
        "columns": {
          "value": {
            "id": "={{ $json.max_id + 1}}",
            "subject": "={{ $('Parse AI analysis result').first().json.subject }}",
            "category": "={{ $('Parse AI analysis result').first().json.category }}",
            "keywords": "={{ $('Parse AI analysis result').first().json.keyword }}",
            "email_text": "={{ $('Parse AI analysis result').first().json['short message'] }}",
            "subcategory": "={{ $('Parse AI analysis result').first().json.subcategory }}"
          },
          "schema": [
            {
              "id": "id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "id",
              "defaultMatch": true,
              "canBeUsedToMatch": true
            },
            {
              "id": "subject",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "subject",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "email_text",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "email_text",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "category",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "subcategory",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "subcategory",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "keywords",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "keywords",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 67988996,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16kSdJJ0imPSq2A7gIhueuEvjwdcvjRaCMYGg-u2QdFs/edit#gid=67988996",
          "cachedResultName": "tagging_sample"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "16kSdJJ0imPSq2A7gIhueuEvjwdcvjRaCMYGg-u2QdFs",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/16kSdJJ0imPSq2A7gIhueuEvjwdcvjRaCMYGg-u2QdFs/edit?usp=drivesdk",
          "cachedResultName": "tagging_samples_for_RAG"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.7
    },
    {
      "id": "8c551b81-7839-42b8-a525-51f2d549e92c",
      "name": "Notify admin about taxonomy update",
      "type": "n8n-nodes-base.telegram",
      "position": [
        1664,
        304
      ],
      "parameters": {
        "text": "=New category/subcategory added:\n{{ $json.category }} / {{ $json.subcategory }}",
        "chatId": "[YOUR_CHAT_ID]",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "6282f451-1235-4aa3-a3d3-086bc70a55b4",
      "name": "Generate audio summary",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        1888,
        -176
      ],
      "parameters": {
        "input": "={{ $('Store processed email').first().json['summarized text'] }}",
        "options": {},
        "resource": "audio"
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "6df2007e-954c-4bbe-81ec-5872e6170213",
      "name": "Send audio summary to Telegram",
      "type": "n8n-nodes-base.telegram",
      "position": [
        2224,
        -176
      ],
      "parameters": {
        "chatId": "=[YOUR_CHAT_ID]",
        "operation": "sendAudio",
        "binaryData": true,
        "additionalFields": {
          "caption": "=\ud83d\udc64 {{ $('Normalize email fields').first().json.sender }}\n{{ $('Normalize email fields').first().json.date .toDateTime().format('\ud83d\udcc5 yyyy-MM-dd \u23f0 hh:mm:ss')}}\n\n\ud83d\udcdc {{ $('Normalize email fields').first().json.subject }}",
          "fileName": "email bite"
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "eb252b88-4336-49e5-8c16-d6b5c7637f72",
      "name": "Vector store \u2014 taxonomy index",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        560,
        640
      ],
      "parameters": {
        "mode": "insert",
        "memoryKey": {
          "__rl": true,
          "mode": "list",
          "value": "email_tagging",
          "cachedResultName": "email_tagging"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "fee89aa8-2981-400e-b415-f5ce8141550d",
      "name": "Vector store retriever (RAG tool)",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        -304,
        160
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 1,
        "memoryKey": {
          "__rl": true,
          "mode": "list",
          "value": "email_tagging"
        },
        "toolDescription": "knowledgebase for email content category and subcategory."
      },
      "typeVersion": 1.3
    },
    {
      "id": "8abed336-a6a4-4dc4-b7ee-f6d1d481fc78",
      "name": "Prepare taxonomy documents",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        608,
        896
      ],
      "parameters": {
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "category",
                "value": "={{ $('Get row(s) in sheet').item.json.category }}"
              },
              {
                "name": "subcategory",
                "value": "={{ $('Get row(s) in sheet').item.json.subcategory }}"
              }
            ]
          }
        },
        "jsonData": "={{ $('Get row(s) in sheet').item.json.subject +\"\\n\"+$('Get row(s) in sheet').item.json.email_text}}",
        "jsonMode": "expressionData"
      },
      "typeVersion": 1.1
    },
    {
      "id": "b23850e5-0c9d-4e5b-8fef-f2ec4dc82cf6",
      "name": "Create embeddings (OpenAI)",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        -176,
        896
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "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 content, then sends it to an AI agent powered by an OpenAI model.\n\nThe agent retrieves examples from a vector database built from a Google Sheets taxonomy dataset. These examples act as the source of truth for email categories and subcategories. Using this context, the AI summarizes the email, assigns a category and subcategory, extracts keywords, and calculates a confidence score.\n\nProcessed emails are stored in a Google Sheet for tracking and analytics. If the AI detects a previously unseen category or subcategory, the workflow automatically expands the taxonomy dataset and notifies the administrator. Optionally, an audio version of the email summary is generated and sent via Telegram.\n\n## Setup steps\n\n1. Connect Gmail credentials for the trigger node.\n2. Connect OpenAI credentials for chat, embeddings, and audio generation.\n3. Connect Google Sheets credentials and duplicate the provided sheets.\n4. Replace Telegram chat IDs with your own.\n5. Run the workflow once manually to populate the vector store before activating it.\n\nAfter setup, the workflow continuously learns and improves email classification over time."
      },
      "typeVersion": 1
    }
  ],
  "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 \u2014 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 \u2014 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 \u2014 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 \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing β€” you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

<h2>πŸ“§ Analyze, classify, and summarize emails using RAG (automatic taxonomy learning)</h2>

Source: https://n8n.io/workflows/13568/ β€” original creator credit. Request a take-down β†’

More AI & RAG workflows β†’ Β· Browse all categories β†’

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Your AI workforce is ready. Are you?

Google Sheets Tool, Mcp Trigger, Google Drive +29
AI & RAG

This intelligent chatbot leverages cutting-edge financial APIs and AI-driven analysis to deliver comprehensive stock research reports. Get instant access to professional-grade investment analysis that

Tool Think, Supabase Vector Store, OpenAI Embeddings +15
AI & RAG

This advanced n8n workflow automates the full lead enrichment, qualification, and personalized outreach process tailored specifically for the B2B real estate sector. Integrating top platforms like Api

N8N Nodes Fillout, OpenAI Chat, Pinecone Vector Store +11
AI & RAG

This n8n template automatically classifies incoming emails (Sales, Support, Internal, Finance, Promotions) and routes them to a dedicated OpenAI LLM Agent for processing. Depending on the category, th

OpenAI, Gmail, Text Classifier +16
AI & RAG

Auto repost job with RAG is a workflow designed to automatically extract, process, and publish job listings from monitored sources using Google Drive, OpenAI, Supabase, and WordPress. This integration

Google Drive, Supabase Vector Store, OpenAI Embeddings +12