新邮件的Email RAG
中级
这是一个Personal Productivity, AI RAG领域的自动化工作流,包含 13 个节点。主要使用 Gmail, GmailTrigger, Agent, ChatTrigger, LmChatOpenAi 等节点。 使用Gmail、OpenAI GPT和PGVector的实时邮件RAG助手
前置要求
- •Google 账号和 Gmail API 凭证
- •OpenAI API Key
使用的节点 (13)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "6m6Tp8bUVb0t6lwo",
"meta": {
"instanceId": "b50483b2122f6dc268662b45507d575d939570ea8e1e086601ebb3b6273c1cfd"
},
"name": "新邮件的 Email RAG",
"tags": [
{
"id": "PNmVCFjr9sq0xind",
"name": "RAG",
"createdAt": "2025-07-12T09:30:51.202Z",
"updatedAt": "2025-07-12T09:30:51.202Z"
},
{
"id": "3Jr6wxDndYE0FaUt",
"name": "email",
"createdAt": "2025-07-12T10:08:56.337Z",
"updatedAt": "2025-07-12T10:08:56.337Z"
}
],
"nodes": [
{
"id": "a896498a-dc44-4d77-8268-7f7001510974",
"name": "Gmail 触发器",
"type": "n8n-nodes-base.gmailTrigger",
"position": [
740,
340
],
"parameters": {
"filters": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
}
},
"typeVersion": 1.2
},
{
"id": "7fa7e6b4-ea5e-4716-be0e-58b96458ec0d",
"name": "获取邮件数据",
"type": "n8n-nodes-base.gmail",
"position": [
960,
340
],
"webhookId": "[REDACTED_WEBHOOK_ID]",
"parameters": {
"simple": false,
"options": {},
"messageId": "={{ $json.id }}",
"operation": "get"
},
"typeVersion": 2.1
},
{
"id": "bce4a290-a71c-4277-9381-3cf86867341e",
"name": "递归字符文本分割器2",
"type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
"position": [
1460,
700
],
"parameters": {
"options": {
"splitCode": "markdown"
},
"chunkSize": 2000,
"chunkOverlap": 200
},
"typeVersion": 1
},
{
"id": "71ae9619-51ae-4c9a-8697-031725d037af",
"name": "OpenAI嵌入3",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"position": [
1080,
620
],
"parameters": {
"options": {}
},
"credentials": {
"openAiApi": {
"id": "K8T7HIhpd7gMJG20",
"name": "OpenAi account"
}
},
"typeVersion": 1.1
},
{
"id": "9e7bd487-f657-4522-9f29-e937f604fff0",
"name": "增强的默认数据加载器",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"position": [
1380,
540
],
"parameters": {
"options": {
"metadata": {
"metadataValues": [
{
"name": "=data_source",
"value": "=gmail"
},
{
"name": "=created_at",
"value": "={{ $json.date }}"
}
]
}
},
"jsonData": "=Email details:\nDate: {{ $json.headers.date }}\n\nFrom Email: {{ $json.from.value[0].address }}\nFrom Name: {{ $json.from.value[0].name }}\n\nTo Email: {{ $json.to.value[0].address }}\n\nEmail Subject:\n{{ $json.subject }}\n\nEmail body:\n{{ $json.text }}",
"jsonMode": "expressionData"
},
"typeVersion": 1
},
{
"id": "251eaeab-ec58-48ad-b51c-556c739ba777",
"name": "Postgres PGVector Store3",
"type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
"position": [
1220,
340
],
"parameters": {
"mode": "insert",
"options": {},
"tableName": "emails_vector_history"
},
"typeVersion": 1.1
},
{
"id": "c0930431-754d-4f87-bf44-6415a816aa7d",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
680,
120
],
"parameters": {
"color": 4,
"width": 1200,
"height": 740,
"content": "## 监视触发器(邮件)- 新邮件"
},
"typeVersion": 1
},
{
"id": "c6abb6a2-bc2a-4b2c-98c8-4de628c2776d",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-60,
540
],
"parameters": {
"options": {}
},
"credentials": {
"openAiApi": {
"id": "K8T7HIhpd7gMJG20",
"name": "OpenAi account"
}
},
"typeVersion": 1
},
{
"id": "fa5ca8d4-5997-4e77-8ab3-f0efe560042d",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-380,
120
],
"parameters": {
"width": 902,
"height": 928,
"content": "## RAG AI Agent"
},
"typeVersion": 1
},
{
"id": "99153412-5aa8-4ab0-918e-172802fc8590",
"name": "新 RAG Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
60,
320
],
"parameters": {
"options": {
"systemMessage": "=You are a helpful assistant that will get data from RAG and send a good response to user.\n\nToday date is this if user ask for dated or latest data: {{ $now }}"
}
},
"typeVersion": 1.7
},
{
"id": "00e80343-3f3c-4fed-93d9-213435012df7",
"name": "Postgres PGVector Store",
"type": "@n8n/n8n-nodes-langchain.vectorStorePGVector",
"position": [
240,
640
],
"parameters": {
"mode": "retrieve-as-tool",
"topK": 5,
"options": {},
"toolName": "emails_vector_search",
"tableName": "emails_vector_history",
"toolDescription": "Call this tool to perform a vector embeddings search in my e-mail database. For time-specific queries:\n1. ALWAYS include the time frame in your query (e.g., \"interviews scheduled after April 27, 2025\" or \"interviews for next week April 28-May 4, 2025\")\n2. For future events, explicitly mention \"future\" or \"upcoming\" in your query"
},
"typeVersion": 1.1
},
{
"id": "2c39ec49-ac2b-42bc-b176-7f15a712c6b7",
"name": "Embeddings OpenAI",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"position": [
200,
800
],
"parameters": {
"options": {}
},
"credentials": {
"openAiApi": {
"id": "K8T7HIhpd7gMJG20",
"name": "OpenAi account"
}
},
"typeVersion": 1.1
},
{
"id": "e569097d-79b8-4648-86d5-67298c2a25d6",
"name": "当收到聊天消息时",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
-220,
320
],
"webhookId": "c91764c2-0b51-4025-ad74-d5f44127aa5a",
"parameters": {
"options": {}
},
"typeVersion": 1.1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "13c464b8-66a1-4503-b853-4b9ae2365146",
"connections": {
"Get Mail Data": {
"main": [
[
{
"node": "Postgres PGVector Store3",
"type": "main",
"index": 0
}
]
]
},
"Gmail Trigger": {
"main": [
[
{
"node": "Get Mail Data",
"type": "main",
"index": 0
}
]
]
},
"New RAG Agent": {
"main": [
[]
]
},
"Embeddings OpenAI": {
"ai_embedding": [
[
{
"node": "Postgres PGVector Store",
"type": "ai_embedding",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "New RAG Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Embeddings OpenAI3": {
"ai_embedding": [
[
{
"node": "Postgres PGVector Store3",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Postgres PGVector Store": {
"ai_tool": [
[
{
"node": "New RAG Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "New RAG Agent",
"type": "main",
"index": 0
}
]
]
},
"Enhanced Default Data Loader": {
"ai_document": [
[
{
"node": "Postgres PGVector Store3",
"type": "ai_document",
"index": 0
}
]
]
},
"Recursive Character Text Splitter2": {
"ai_textSplitter": [
[
{
"node": "Enhanced Default Data Loader",
"type": "ai_textSplitter",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 个人效率, AI RAG 检索增强
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
邮件历史RAG
使用Gmail、OpenAI和Qdrant向量数据库创建邮件知识库
Code
Gmail
Gmail Trigger
+11
23 节点Zain Ali
内部知识库
产品推荐RAG
使用OpenAI、Qdrant和Google表格RAG将医疗症状匹配到产品
Google Sheets
Manual Trigger
Split In Batches
+9
17 节点Zain Ali
客户培育
AI驱动的客户支持:邮件、知识库与人工升级自动化
AI邮件支持系统:集成Gmail、Gemini、GPT-4、Slack和Google Sheets的工作流程
Set
Gmail
Slack
+13
26 节点David Olusola
工单管理
Gmail智能自动回复器,含GPT-4o和Google Drive上下文记忆
Gmail智能自动回复器,含GPT-4o和Google Drive上下文记忆
If
Set
Code
+11
18 节点Usama Rehman
个人效率
基于AI的MIS代理
基于AI的管理信息系统代理
If
Set
Code
+29
129 节点Kumar Shivam
客户支持
高级AI演示(在AI开发者第14次聚会中展示)
高级AI演示(在AI开发者第14次聚会中展示)
If
Code
Gmail
+19
39 节点Max Tkacz
构建模块