๐ŸŽซ Analyze, classify, and summarize Gmail with OpenAI RAG and Google Sheets

โšก 33 views ยท ๐ŸŽซ Ticket Management & Triage

Description

๐Ÿ“ง Analyze, classify, and summarize emails using RAG (automatic taxonomy learning)

This workflow automatically reads incoming Gmail messages, analyzes them using AI with a retrieval-augmented classification system (RAG), organizes emails into structured categories, stores results in Google Sheets, and even generates an audio summary sent directly to Telegram.


โš™๏ธ How It Works

The workflow creates an intelligent email processing pipeline combining Gmail, OpenAI, vector embeddings, and Google Sheets to continuously learn and improve email categorization accuracy.

  1. Email Trigger
    The workflow starts automatically whenever a new email arrives in Gmail using the Gmail Trigger node.
  2. Email Extraction & Cleaning
    The full email content, sender information, subject, and timestamp are retrieved and normalized. HTML formatting is removed so the AI receives clean text data.
  3. Knowledge Base Loading (RAG)
    Email tagging examples stored in a Google Sheets document are loaded and converted into embeddings. These examples act as the official taxonomy for categories and subcategories.
  4. Vector Store Creation
    The workflow builds an in-memory vector database containing historical tagging samples. This allows semantic similarity search during classification.
  5. AI Analysis Agent
    An OpenAI-powered AI Agent performs multiple tasks in a single step:
    • Summarizes the email (short paragraph)
    • Creates a one-line short message
    • Classifies the email using retrieved vector examples
    • Extracts keywords
    • Assigns confidence score
    • Detects whether a new category or subcategory was created

    The agent strictly prioritizes retrieved taxonomy examples to maintain consistent labeling.

  6. Structured Data Storage
    Processed email data โ€” including summary, category, keywords, and metadata โ€” is appended to a Google Sheets log, creating a searchable email intelligence database.
  7. Self-Learning Taxonomy
    If the AI determines a new category or subcategory is required:
    • The new label is automatically added to the tagging samples sheet
    • An admin notification is sent via Telegram
    This allows the system to evolve over time.
  8. Audio Summary Generation
    The summarized email text is converted into speech using OpenAI audio generation.
  9. Telegram Notification
    The generated audio summary is automatically delivered to Telegram, allowing quick email review without reading.

๐Ÿงฉ Features


๐Ÿš€ Setup Steps

1. Required Accounts

2. Configure Credentials in n8n

Create the following credentials inside n8n:

3. Prepare Google Sheets

Sheet 1 โ€” Email Log

Sheet 2 โ€” Tagging Samples (Knowledge Base)

This sheet acts as the classification training reference used by the vector store.

4. Configure Telegram

5. Connect OpenAI

6. Activate the Workflow


๐Ÿ’ก Recommended Usage


๐Ÿง  Architecture Notes

This workflow uses a Retrieval-Augmented Generation (RAG) pattern inside n8n by combining Google Sheets as a lightweight knowledge base with an in-memory vector store. Instead of relying purely on model reasoning, classification decisions are grounded in previously approved examples, producing stable and explainable categorization.

Over time, the workflow becomes smarter as new categories are automatically added, effectively turning your inbox into a continuously learning AI system.

๐Ÿ”— Nodes Used

Google Sheets, Telegram, Gmail, Gmail Trigger, AI Agent, Embeddings OpenAI

๐Ÿ“ฅ Import

Download workflow.json and import into n8n: Workflow menu โ†’ Import from File

๐Ÿ“– Importing guide ยท ๐Ÿ”‘ Credential setup