RAG系统V2 - 上传文档
高级
这是一个Document Extraction, AI RAG领域的自动化工作流,包含 18 个节点。主要使用 Set, Switch, Aggregate, Summarize, GoogleDrive 等节点。 集成Google Drive和Supabase的多格式文档处理RAG聊天机器人
前置要求
- •Google Drive API 凭证
- •可能需要目标 API 的认证凭证
- •OpenAI API Key
- •Supabase URL 和 API Key
使用的节点 (18)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "vAtv4ejDkrQLAj9t",
"meta": {
"instanceId": "90587241b61f532dbe71be441310f86b24bd62a247fd87ce3f4b074464fa220d",
"templateCredsSetupCompleted": true
},
"name": "RAG 系统 V2 - 上传文档",
"tags": [
{
"id": "X3XA7mO6MQZQ8uNT",
"name": "RAG",
"createdAt": "2024-12-23T14:38:50.002Z",
"updatedAt": "2024-12-23T14:38:50.002Z"
},
{
"id": "bQac7pgkCzmq5Nt5",
"name": "template",
"createdAt": "2025-01-14T11:43:47.391Z",
"updatedAt": "2025-01-14T11:43:47.391Z"
},
{
"id": "pms2jtgY49JCgVDW",
"name": "chatbot",
"createdAt": "2024-12-19T04:39:23.549Z",
"updatedAt": "2024-12-19T04:39:23.549Z"
}
],
"nodes": [
{
"id": "f7e70a86-f762-46ff-a38c-dd03f8cc44be",
"name": "聚合1",
"type": "n8n-nodes-base.aggregate",
"position": [
1780,
1380
],
"parameters": {
"options": {},
"aggregate": "aggregateAllItemData"
},
"typeVersion": 1
},
{
"id": "21c23538-5a7f-419d-a217-e163411f4ea6",
"name": "总结1",
"type": "n8n-nodes-base.summarize",
"position": [
1980,
1380
],
"parameters": {
"options": {},
"fieldsToSummarize": {
"values": [
{
"field": "data",
"aggregation": "concatenate"
}
]
}
},
"typeVersion": 1
},
{
"id": "73577db5-3e5f-4764-9ac0-ef5a300ae616",
"name": "提取PDF文本",
"type": "n8n-nodes-base.extractFromFile",
"position": [
1580,
1040
],
"parameters": {
"options": {},
"operation": "pdf"
},
"typeVersion": 1
},
{
"id": "9ab1b75d-e2c6-4adf-851f-0e12ef181d59",
"name": "从Excel提取",
"type": "n8n-nodes-base.extractFromFile",
"position": [
1580,
1380
],
"parameters": {
"options": {},
"operation": "xlsx"
},
"typeVersion": 1
},
{
"id": "f6736e78-4665-4834-8057-fb226a5a623b",
"name": "转换为 Google 文档1",
"type": "n8n-nodes-base.httpRequest",
"position": [
1580,
1560
],
"parameters": {
"url": "=https://www.googleapis.com/drive/v3/files/{{ $('Set File ID1').item.json.file_id }}/copy",
"method": "POST",
"options": {},
"sendBody": true,
"authentication": "predefinedCredentialType",
"bodyParameters": {
"parameters": [
{
"name": "name",
"value": "={{ $('Set File ID1').item.json.name }}"
},
{
"name": "mimeType",
"value": "application/vnd.google-apps.document"
}
]
},
"nodeCredentialType": "googleDriveOAuth2Api"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "yGiuxvKzLUzVYa2d",
"name": "Google Drive account"
}
},
"typeVersion": 4.1
},
{
"id": "740cdb21-cb2a-4797-925d-6a52058abfc9",
"name": "删除文件",
"type": "n8n-nodes-base.googleDrive",
"position": [
1780,
1560
],
"parameters": {
"fileId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Set File ID1').item.json.file_id }}"
},
"options": {},
"operation": "deleteFile"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "yGiuxvKzLUzVYa2d",
"name": "Google Drive account"
}
},
"typeVersion": 3
},
{
"id": "d14991af-cca4-4677-a0bd-2c2e54c2663c",
"name": "设置文件ID1",
"type": "n8n-nodes-base.set",
"position": [
280,
1340
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "10646eae-ae46-4327-a4dc-9987c2d76173",
"name": "file_id",
"type": "string",
"value": "={{ $('File Created').item.json.id }}"
},
{
"id": "f4536df5-d0b1-4392-bf17-b8137fb31a44",
"name": "file_type",
"type": "string",
"value": "={{ $('File Created').item.json.mimeType }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "6908359b-74bb-4a9c-9f55-cc8b3c702762",
"name": "下载文件1",
"type": "n8n-nodes-base.googleDrive",
"position": [
600,
1500
],
"parameters": {
"fileId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Set File ID1').item.json.file_id }}"
},
"options": {
"googleFileConversion": {
"conversion": {
"docsToFormat": "text/plain"
}
}
},
"operation": "download"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "yGiuxvKzLUzVYa2d",
"name": "Google Drive account"
}
},
"executeOnce": true,
"typeVersion": 3
},
{
"id": "40c88ce1-ac7f-4e4c-8a63-c2569ceb92f5",
"name": "递归字符文本分割器",
"type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
"position": [
2440,
1420
],
"parameters": {
"options": {
"splitCode": "markdown"
},
"chunkSize": 2000,
"chunkOverlap": 200
},
"typeVersion": 1
},
{
"id": "4d8b2f11-0eaf-4fa5-a9a8-5d02114b3cf7",
"name": "OpenAI 嵌入1",
"type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
"position": [
2200,
1360
],
"parameters": {
"options": {}
},
"credentials": {
"openAiApi": {
"id": "9SPpIIxBvgYPZlo8",
"name": "OpenAi account"
}
},
"typeVersion": 1.1
},
{
"id": "70466e58-b38e-47ac-b2d1-9efe394fe216",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-160,
920
],
"parameters": {
"color": 4,
"width": 3060,
"height": 920,
"content": "# 监视触发器 (Drive) - 文件创建"
},
"typeVersion": 1
},
{
"id": "2e91ada5-a052-4c5a-9dda-36340de054cc",
"name": "遍历项目",
"type": "n8n-nodes-base.splitInBatches",
"position": [
440,
1340
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "430a6cd1-1ffe-477d-88f3-58539898b38e",
"name": "增强型默认数据加载器1",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"position": [
2360,
1260
],
"parameters": {
"options": {
"metadata": {
"metadataValues": [
{
"name": "=file_id",
"value": "={{ $('Set File ID1').item.json.file_id }}"
},
{
"name": "=version",
"value": "v1"
},
{
"name": "=creator",
"value": "={{ $('File Created').item.json.owners[0].displayName }}"
},
{
"name": "=created_at",
"value": "={{ $('File Created').item.json.createdTime }}"
},
{
"name": "last_modified",
"value": "={{ $('File Created').item.json.modifiedTime }}"
},
{
"name": "folder_path",
"value": "DOCUMENTS"
},
{
"name": "file_name",
"value": "={{ $('File Created').item.json.name }}"
},
{
"name": "file_extension",
"value": "={{ $('File Created').item.json.mimeType }}"
}
]
}
},
"jsonData": "={{ $json.data || $json.text || $json.concatenated_data }}",
"jsonMode": "expressionData"
},
"typeVersion": 1
},
{
"id": "37835911-6114-437c-b10f-d321086e51cf",
"name": "文件已创建",
"type": "n8n-nodes-base.googleDriveTrigger",
"position": [
80,
1340
],
"parameters": {
"event": "fileCreated",
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"triggerOn": "specificFolder",
"folderToWatch": {
"__rl": true,
"mode": "list",
"value": "1M9h9OnDSWa0kV7_Yj7fdSFHhM57pMPX8",
"cachedResultUrl": "https://drive.google.com/drive/folders/1M9h9OnDSWa0kV7_Yj7fdSFHhM57pMPX8",
"cachedResultName": "DOCUMENTS"
}
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "yGiuxvKzLUzVYa2d",
"name": "Google Drive account"
}
},
"typeVersion": 1
},
{
"id": "a29c58f1-4a87-40c7-8326-13c976e43a45",
"name": "从文本文件提取",
"type": "n8n-nodes-base.extractFromFile",
"position": [
1580,
1200
],
"parameters": {
"options": {},
"operation": "text"
},
"typeVersion": 1,
"alwaysOutputData": true
},
{
"id": "20cbced4-0d98-4f80-99a4-94c0ae7d05d4",
"name": "切换2",
"type": "n8n-nodes-base.switch",
"position": [
1000,
1260
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "PDF",
"conditions": {
"options": {
"version": 1,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Set File ID1').item.json.file_type }}",
"rightValue": "application/pdf"
}
]
},
"renameOutput": true
},
{
"outputKey": "Text File",
"conditions": {
"options": {
"version": 1,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "fc193b06-363b-4699-a97d-e5a850138b0e",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Set File ID1').item.json.file_type }}",
"rightValue": "application/vnd.google-apps.document"
}
]
},
"renameOutput": true
},
{
"outputKey": "Excel",
"conditions": {
"options": {
"version": 1,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "2ae7faa7-a936-4621-a680-60c512163034",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Set File ID1').item.json.file_type }}",
"rightValue": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}
]
},
"renameOutput": true
},
{
"outputKey": "Windows Doc(1)",
"conditions": {
"options": {
"version": 1,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "7ddfa924-1c26-4ee3-9890-5c9d2b96717a",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Set File ID1').item.json.file_type }}",
"rightValue": "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
}
]
},
"renameOutput": true
},
{
"outputKey": "Windows Doc(2)",
"conditions": {
"options": {
"version": 1,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "f53caf8b-7a8f-4d1e-98f4-deaf0e0171f0",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Set File ID1').item.json.file_type }}",
"rightValue": "application/msword"
}
]
},
"renameOutput": true
},
{
"outputKey": "Windows Doc(3)",
"conditions": {
"options": {
"version": 1,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "cd9ca627-d00d-4c30-903a-41f603c8e36f",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $('Set File ID1').item.json.file_type }}",
"rightValue": "application/vnd.ms-word"
}
]
},
"renameOutput": true
}
]
},
"options": {
"fallbackOutput": 2
}
},
"typeVersion": 3
},
{
"id": "c7ba8d80-5aa5-4012-8af4-37d7a13e19de",
"name": "插入到 Supabase Vectorstore1",
"type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
"position": [
2180,
1060
],
"parameters": {
"mode": "insert",
"options": {
"queryName": "match_documents"
},
"tableName": {
"__rl": true,
"mode": "id",
"value": "=documents"
}
},
"credentials": {
"supabaseApi": {
"id": "J5U7ge3sFHh1WYka",
"name": "Supabase API"
}
},
"typeVersion": 1
},
{
"id": "a0632671-bc58-4129-bc96-7f7aa04c4baf",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-160,
1880
],
"parameters": {
"width": 440,
"height": 120,
"content": "## 致谢"
},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "20dea69a-1a23-4a35-8694-f1658686fb3f",
"connections": {
"Switch2": {
"main": [
[
{
"node": "Extract PDF Text",
"type": "main",
"index": 0
}
],
[
{
"node": "Extract from Text File",
"type": "main",
"index": 0
}
],
[
{
"node": "Extract from Excel",
"type": "main",
"index": 0
}
],
[
{
"node": "Convert to Google Doc1",
"type": "main",
"index": 0
}
],
[
{
"node": "Convert to Google Doc1",
"type": "main",
"index": 0
}
],
[
{
"node": "Convert to Google Doc1",
"type": "main",
"index": 0
}
]
]
},
"Aggregate1": {
"main": [
[
{
"node": "Summarize1",
"type": "main",
"index": 0
}
]
]
},
"Summarize1": {
"main": [
[
{
"node": "Insert into Supabase Vectorstore1",
"type": "main",
"index": 0
}
]
]
},
"File Created": {
"main": [
[
{
"node": "Set File ID1",
"type": "main",
"index": 0
}
]
]
},
"Set File ID1": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Download File1": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[
{
"node": "Switch2",
"type": "main",
"index": 0
}
],
[
{
"node": "Download File1",
"type": "main",
"index": 0
}
]
]
},
"Extract PDF Text": {
"main": [
[
{
"node": "Insert into Supabase Vectorstore1",
"type": "main",
"index": 0
}
]
]
},
"Embeddings OpenAI1": {
"ai_embedding": [
[
{
"node": "Insert into Supabase Vectorstore1",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Extract from Excel": {
"main": [
[
{
"node": "Aggregate1",
"type": "main",
"index": 0
}
]
]
},
"Convert to Google Doc1": {
"main": [
[
{
"node": "Delete File",
"type": "main",
"index": 0
}
]
]
},
"Extract from Text File": {
"main": [
[
{
"node": "Insert into Supabase Vectorstore1",
"type": "main",
"index": 0
}
]
]
},
"Enhanced Default Data Loader1": {
"ai_document": [
[
{
"node": "Insert into Supabase Vectorstore1",
"type": "ai_document",
"index": 0
}
]
]
},
"Recursive Character Text Splitter": {
"ai_textSplitter": [
[
{
"node": "Enhanced Default Data Loader1",
"type": "ai_textSplitter",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 文档提取, AI RAG 检索增强
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
RAG系统 V2 - 更新文档
通过Google Drive文件变更保持RAG系统在Supabase向量数据库中的更新
If
Set
Limit
+15
22 节点edisantosa
文档提取
上下文混合RAG AI文案
Google Drive到Supabase上下文向量数据库同步用于RAG应用
If
Set
Code
+25
76 节点Michael Taleb
AI RAG 检索增强
[模板] AI宠物店 v8
🐶 AI宠物店助手 - 集成GPT-4o、Google日历和WhatsApp/Instagram/Facebook
If
N8n
Set
+38
244 节点Amanda Benks
销售
AI 代理餐厅 [模板]
🤖 WhatsApp、Instagram 和 Messenger 的 AI 餐厅助手
If
N8n
Set
+37
239 节点Amanda Benks
其他
AIAutomationPro终极RAG聊天机器人v1 n8n市场模板
多语言Telegram RAG聊天机器人,集成监督AI和自动化Google Drive流程
If
Set
Wait
+29
128 节点Daniel Ng
客服机器人
宠物店 4
🐶 宠物店预约 AI 代理
If
Set
Code
+41
187 节点Bruno Dias
人工智能