Skip to main content

Gmail assistant with full Gmail history RAG using OpenAI

Workflow preview

Workflow preview
100%
Gmail assistant with full Gmail history RAG using OpenAI preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

RAG with Full Gmail history + Real time email updates in RAG using OpenAI & Qdrant Summary: This workflow listens for new Gmail messages, extracts and cleans email content, generates e...

Best for

  • Internal Wiki automation workflows
  • AI RAG automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

@n8n/n8n-nodes-langchain.lmchatopenai, n8n-nodes-base.stickynote, n8n-nodes-base.manualtrigger, @n8n/n8n-nodes-langchain.agent, @n8n/n8n-nodes-langchain.embeddingsopenai, @n8n/n8n-nodes-langchain.vectorstoreqdrant, @n8n/n8n-nodes-langchain.chattrigger, @n8n/n8n-nodes-langchain.memorybufferwindow

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Zain Ali.

Original n8n.io source

1.1 Workflow description

Title
Gmail assistant with full Gmail history RAG using OpenAI
Workflow name
Gmail assistant with full Gmail history RAG using OpenAI

🧠 RAG with Full Gmail history + Real time email updates in RAG using OpenAI & Qdrant

> Summary:
> This workflow listens for new Gmail messages, extracts and cleans email content, generates embeddings via OpenAI, stores them in a Qdrant vector database, and then enables a Retrieval‑Augmented‑Generation (RAG) agent to answer user queries against those stored emails. It’s designed for teams or bots that need conversational access to past emails.


🧑‍🤝‍🧑 Who’s it for

  • Support teams who want to surface past customer emails in chatbots or help‑desk portals
  • Sales ops that need AI‑powered summaries and quick lookup of email histories
  • Developers building RAG agents over email archives

⚙️ How it works / What it does

  1. Trigger
    • Gmail Trigger polls every minute for new messages.
  2. Fetch & Clean
    • Get Mail Data pulls full message metadata and body.
    • Code node normalizes the body (removes line breaks, collapses spaces).
  3. Embed & Store
    • Embeddings OpenAI node computes vector embeddings.
    • Qdrant Vector Store inserts embeddings + metadata into the emails_history collection.
  4. Batch Processing
    • SplitInBatches handles large inbox loads in chunks of 50.
  5. RAG Interaction
    • When chat message received → RAG Agent → uses Qdrant Email Vector Store as a tool to retrieve relevant email snippets before responding.
  6. Memory
    • Simple Memory buffer ensures the agent retains recent context.

🛠️ How to set up

  1. n8n Instance
    • Deploy n8n (self‑hosted or via Coolify/Docker).
  2. Credentials
    • Create an OAuth2 credential in n8n for Gmail (with Gmail API scopes).
    • Add your OpenAI API key in n8n credentials.
  3. Qdrant
    • Stand up a Qdrant instance (self‑hosted or Qdrant Cloud).
    • Note your host, port, and API key (if any).
  4. Import Workflow
    • In n8n, go to Workflows → Import → paste the JSON you provided.
    • Ensure each credential reference (Gmail & OpenAI) matches your n8n credential IDs.
  5. Test
    • Click Execute Workflow or send a test email to your Gmail.
    • Monitor n8n logs: you should see new points in Qdrant and RAG responses.

📋 Requirements

  • n8n (Self-hosted or Cloud)
  • Gmail API enabled on a Google Cloud project
  • OpenAI API access (with Embedding & Chat endpoints)
  • Qdrant (hosted or cloud) with a collection named emails_history

🎨 How to customize the workflow

  • Change Collection Name
    • Update the qdrantCollection.value in all Qdrant nodes if you prefer a different collection.
  • Adjust Polling Frequency
    • In the Gmail Trigger node, switch from everyMinute to everyFiveMinutes or a webhook‑style trigger.
  • Metadata Tags
    • In Enhanced Default Data Loader, tweak the metadataValues to tag by folder, label, or sender domain.
  • Batch Size
    • In SplitInBatches, change batchSize to suit your inbox volume.
  • RAG Agent Prompt
    • Customize the systemMessage in the RAG Agent node to set the assistant’s tone, instruct on date handling, or add additional tools.
  • Additional Tools
    • Chain other n8n nodes (e.g., Slack, Discord) after the RAG Agent to broadcast AI answers to team channels.

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - OpenAI Chat Model

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenAi - lmChatOpenAi
Config choices
Version 1

Block 2 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 3 - When clicking ‘Test workflow’

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 4 - RAG Agent

Type / Role
@n8n/n8n-nodes-langchain.agent - agent
Config choices
Version 1.7

Block 5 - Embeddings OpenAI5

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.1

Block 6 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 7 - Embeddings OpenAI11

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.1

Block 8 - Sticky Note11

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 9 - Qdrant Email Vector Store

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreQdrant - vectorStoreQdrant
Config choices
Version 1.1

Block 10 - When chat message received

Type / Role
@n8n/n8n-nodes-langchain.chatTrigger - chatTrigger
Config choices
Version 1.1

Block 11 - Simple Memory

Type / Role
@n8n/n8n-nodes-langchain.memoryBufferWindow - memoryBufferWindow
Config choices
Version 1.3

Block 12 - Store Emails in Vector DB

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreQdrant - vectorStoreQdrant
Config choices
Version 1.1

Block 13 - New Email

Type / Role
n8n-nodes-base.gmailTrigger - gmailTrigger
Config choices
Version 1.2

Block 14 - Get new Email Body

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 15 - Get all emails

Type / Role
n8n-nodes-base.gmail - gmail
Config choices
Version 2.1

Block 16 - Refactor Email Body data

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 17 - Loop over all emails

Type / Role
n8n-nodes-base.splitInBatches - splitInBatches
Config choices
Version 3

Block 18 - Store Emails in Vector DB1

Type / Role
@n8n/n8n-nodes-langchain.vectorStoreQdrant - vectorStoreQdrant
Config choices
Version 1.1

Block 19 - Set proper metadata

Type / Role
@n8n/n8n-nodes-langchain.documentDefaultDataLoader - documentDefaultDataLoader
Config choices
Version 1

Block 20 - Split emails

Type / Role
@n8n/n8n-nodes-langchain.textSplitterCharacterTextSplitter - textSplitterCharacterTextSplitter
Config choices
Version 1

Block 21 - Set proper metadata1

Type / Role
@n8n/n8n-nodes-langchain.documentDefaultDataLoader - documentDefaultDataLoader
Config choices
Version 1

Block 22 - Split emails1

Type / Role
@n8n/n8n-nodes-langchain.textSplitterCharacterTextSplitter - textSplitterCharacterTextSplitter
Config choices
Version 1

Block 23 - Embeddings OpenAI

Type / Role
@n8n/n8n-nodes-langchain.embeddingsOpenAi - embeddingsOpenAi
Config choices
Version 1.1

3. Summary Table

Workflow Gmail assistant with full Gmail history RAG using OpenAI
Complexity advanced
Nodes 23
Categories Internal Wiki, AI RAG
Author Zain Ali
Published 19 Jul 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/6169/6169.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does Gmail assistant with full Gmail history RAG using OpenAI do?

RAG with Full Gmail history + Real time email updates in RAG using OpenAI & Qdrant Summary: This workflow listens for new Gmail messages, extracts and cleans email content, generates e...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Internal Wiki, AI RAG use case.