使用Gemini和Supabase从Google Drive文档创建RAG向量数据库
高级
这是一个Document Extraction, AI RAG领域的自动化工作流,包含 16 个节点。主要使用 Code, Postgres, GoogleDrive, SplitInBatches, ExecuteWorkflowTrigger 等节点。 通过Gemini和Supabase从Google Drive文档创建RAG向量数据库
前置要求
- •PostgreSQL 数据库连接信息
- •Google Drive API 凭证
- •Supabase URL 和 API Key
使用的节点 (16)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "a243f35537ecbb3a29ba49c4cf2200720075b362bcc7d02523f79748238bcfd6"
},
"nodes": [
{
"id": "97927b62-d8b9-4c98-b3d1-160c81c524e5",
"name": "Embeddings Google Gemini4",
"type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
"position": [
208,
320
],
"parameters": {},
"credentials": {
"googlePalmApi": {
"id": "VCZQfcHNj0rHxcNf",
"name": "GEMINI_API_KUDDUS"
}
},
"typeVersion": 1
},
{
"id": "a9afa4ed-5e53-423c-9521-a79b17dbdde1",
"name": "Default Data Loader2",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"position": [
384,
304
],
"parameters": {
"options": {},
"dataType": "binary"
},
"typeVersion": 1.1
},
{
"id": "478d1053-af37-451e-9baf-7708f43653fa",
"name": "执行 SQL 查询",
"type": "n8n-nodes-base.postgres",
"position": [
-624,
48
],
"parameters": {
"query": "DROP TABLE IF EXISTS documents CASCADE;\n\nCREATE EXTENSION IF NOT EXISTS vector;\n\nCREATE TABLE IF NOT EXISTS documents (\n id bigserial PRIMARY KEY,\n content text,\n metadata jsonb,\n embedding vector(768)\n);\n\nCREATE OR REPLACE FUNCTION match_documents(\n query_embedding vector(768),\n match_count int DEFAULT NULL,\n filter jsonb DEFAULT '{}'::jsonb\n)\nRETURNS TABLE (\n id bigint,\n content text,\n metadata jsonb,\n similarity double precision\n)\nLANGUAGE sql\nAS $$\n SELECT\n d.id,\n d.content,\n d.metadata,\n 1 - (d.embedding <=> query_embedding) AS similarity\n FROM documents d\n WHERE (filter = '{}'::jsonb OR d.metadata @> filter)\n ORDER BY d.embedding <=> query_embedding\n LIMIT match_count;\n$$;\n",
"options": {},
"operation": "executeQuery"
},
"credentials": {
"postgres": {
"id": "KbYSAyR6T3ljhFKn",
"name": "Postgres account"
}
},
"typeVersion": 2.6
},
{
"id": "7e4395b7-b822-41b6-aac3-0d4c2e3a749b",
"name": "JavaScript 代码",
"type": "n8n-nodes-base.code",
"position": [
-848,
48
],
"parameters": {
"jsCode": "// Get the Drive_Folder_link from the workflow input\nconst driveUrl = $input.first().json.Drive_Folder_link;\n\n// Extract Google Drive folder/file ID from URL\nfunction getDriveId(url) {\n const folderMatch = url.match(/\\/folders\\/([a-zA-Z0-9_-]+)/);\n const fileMatch = url.match(/\\/file\\/d\\/([a-zA-Z0-9_-]+)/);\n return folderMatch ? folderMatch[1] : (fileMatch ? fileMatch[1] : null);\n}\n\n// Process input items\nreturn items.map(item => {\n const chatInput = item.json.chatInput || driveUrl || '';\n const driveId = getDriveId(chatInput);\n\n return {\n json: {\n originalInput: chatInput,\n folderId: driveId,\n driveId: driveId\n }\n };\n});\n"
},
"typeVersion": 2
},
{
"id": "3a4041d1-25ac-4ab4-974e-a5460c9a8ffa",
"name": "当由另一个工作流执行时",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
-1056,
48
],
"parameters": {
"inputSource": "jsonExample",
"jsonExample": "{\n \"Drive_Folder_link\": \"https://drive.google.com/drive/folders/example\"\n}"
},
"typeVersion": 1.1
},
{
"id": "92141102-016e-4e8a-b69f-f09d0522924d",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1504,
-128
],
"parameters": {
"color": 5,
"width": 368,
"height": 512,
"content": "# 📁 从 Google Drive 到 Supabase 向量存储的学习 RAG 工作流"
},
"typeVersion": 1
},
{
"id": "6960ace8-fd01-4f9e-acfc-05185a0b197f",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1104,
208
],
"parameters": {
"width": 176,
"height": 128,
"content": "**触发器节点** - 当从另一个 n8n 工作流调用时启动工作流。接受 Drive 文件夹 URL 作为输入。"
},
"typeVersion": 1
},
{
"id": "2befa4d1-ded3-4eeb-93ec-acdc9a9e22fb",
"name": "便签 2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-864,
208
],
"parameters": {
"width": 150,
"height": 128,
"content": "**提取文件夹 ID** - 使用正则表达式解析 Google Drive URL 以提取文件夹/文件 ID 用于 API 调用。"
},
"typeVersion": 1
},
{
"id": "e71b4968-43de-477f-9de6-474cd471c405",
"name": "便签 3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-656,
208
],
"parameters": {
"width": 176,
"content": "**初始化数据库** - 使用 pgvector 扩展创建 Supabase 向量表和 match_documents 搜索函数。⚠️ 会删除现有表!"
},
"typeVersion": 1
},
{
"id": "4ac27951-096f-44ba-8e66-be73b3c0d380",
"name": "遍历项目",
"type": "n8n-nodes-base.splitInBatches",
"position": [
-192,
48
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "d556d5eb-6216-4e39-bf8f-07a948fcbb0d",
"name": "搜索文件和文件夹",
"type": "n8n-nodes-base.googleDrive",
"position": [
-416,
48
],
"parameters": {
"filter": {
"folderId": {
"__rl": true,
"mode": "id",
"value": "={{ $('Code in JavaScript').item.json.folderId }}"
}
},
"options": {},
"resource": "fileFolder"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "CVN95k3ctbjWs60e",
"name": "Google_Drive_gaming"
}
},
"typeVersion": 3
},
{
"id": "db2f57b6-1aa9-4926-a211-7362d5d4533e",
"name": "插入到 Supabase 向量存储",
"type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
"position": [
256,
48
],
"parameters": {
"mode": "insert",
"options": {
"queryName": "match_documents"
},
"tableName": {
"__rl": true,
"mode": "list",
"value": "documents",
"cachedResultName": "documents"
}
},
"credentials": {
"supabaseApi": {
"id": "OweRv8RLSfhKJyfg",
"name": "Supabase account"
}
},
"typeVersion": 1
},
{
"id": "09addf62-6c1a-4af4-a5d5-6b2323f64886",
"name": "下载文件",
"type": "n8n-nodes-base.googleDrive",
"position": [
48,
64
],
"parameters": {
"fileId": {
"__rl": true,
"mode": "id",
"value": "={{ $json.id }}"
},
"options": {
"googleFileConversion": {
"conversion": {
"docsToFormat": "text/plain"
}
}
},
"operation": "download"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "CVN95k3ctbjWs60e",
"name": "Google_Drive_gaming"
}
},
"typeVersion": 3
},
{
"id": "0c929411-a2d2-49ff-ab92-09aeece9d892",
"name": "便签 4",
"type": "n8n-nodes-base.stickyNote",
"position": [
-432,
224
],
"parameters": {
"width": 176,
"height": 128,
"content": "**列出 Drive 文件** - 使用提取的文件夹 ID 从指定的 Google Drive 文件夹检索所有文件。"
},
"typeVersion": 1
},
{
"id": "b2b6df82-5145-4719-b3bc-a5501e31ed08",
"name": "便签 5",
"type": "n8n-nodes-base.stickyNote",
"position": [
16,
-112
],
"parameters": {
"width": 150,
"content": "**列出 Drive 文件** - 使用提取的文件夹 ID 从指定的 Google Drive 文件夹检索所有文件。"
},
"typeVersion": 1
},
{
"id": "0d6c2252-f11a-4a12-978c-b121c68c8663",
"name": "便签6",
"type": "n8n-nodes-base.stickyNote",
"position": [
240,
-208
],
"parameters": {
"color": 7,
"height": 240,
"content": "**存储嵌入** - 通过 Gemini 生成 768 维向量并将文档插入 Supabase 用于语义搜索。"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"Download File": {
"main": [
[
{
"node": "Insert into Supabase Vectorstore",
"type": "main",
"index": 0
}
]
]
},
"Loop Over Items": {
"main": [
[],
[
{
"node": "Download File",
"type": "main",
"index": 0
}
]
]
},
"Code in JavaScript": {
"main": [
[
{
"node": "Execute a SQL query",
"type": "main",
"index": 0
}
]
]
},
"Execute a SQL query": {
"main": [
[
{
"node": "Search files and folders",
"type": "main",
"index": 0
}
]
]
},
"Default Data Loader2": {
"ai_document": [
[
{
"node": "Insert into Supabase Vectorstore",
"type": "ai_document",
"index": 0
}
]
]
},
"Search files and folders": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"Embeddings Google Gemini4": {
"ai_embedding": [
[
{
"node": "Insert into Supabase Vectorstore",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Insert into Supabase Vectorstore": {
"main": [
[
{
"node": "Loop Over Items",
"type": "main",
"index": 0
}
]
]
},
"When Executed by Another Workflow": {
"main": [
[
{
"node": "Code in JavaScript",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
高级 - 文档提取, AI RAG 检索增强
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
AI学习助手(RAG):Google Gemini与Drive及Supabase向量搜索
AI学习助手(RAG):Google Gemini与Drive及Supabase向量搜索
Code
Postgres
Google Drive
+12
28 节点Mantaka Mahir
个人效率
上下文混合RAG AI文案
Google Drive到Supabase上下文向量数据库同步用于RAG应用
If
Set
Code
+25
76 节点Michael Taleb
AI RAG 检索增强
创建自更新的RAG聊天机器人(Google Drive、Gemini和Supabase)
使用Google Drive、Gemini和Supabase创建自更新的RAG聊天机器人
Set
Code
Merge
+19
45 节点Anirudh Aeran
内容创作
从网站获取所有页面内容并存储至Pinecone的Gemini嵌入
从网站获取所有页面内容并存储至Pinecone的Gemini嵌入
Xml
Code
Html
+11
16 节点Zain Khan
文档提取
RAG系统 V2 - 更新文档
通过Google Drive文件变更保持RAG系统在Supabase向量数据库中的更新
If
Set
Limit
+15
22 节点edisantosa
文档提取
RAG系统V2 - 上传文档
集成Google Drive和Supabase的多格式文档处理RAG聊天机器人
Set
Switch
Aggregate
+11
18 节点edisantosa
文档提取
工作流信息
难度等级
高级
节点数量16
分类2
节点类型9
作者
Mantaka Mahir
@mantakamahirAl Automation Expert || Al Agents || n8n || Python || LangChain || Helping businesses scale revenue and reduce costs with Al driven automation .
外部链接
在 n8n.io 查看 →
分享此工作流