AI学习助手(RAG):Google Gemini与Drive及Supabase向量搜索
高级
这是一个Personal Productivity, AI RAG领域的自动化工作流,包含 28 个节点。主要使用 Code, Postgres, GoogleDrive, SplitInBatches, Agent 等节点。 AI学习助手(RAG):Google Gemini与Drive及Supabase向量搜索
前置要求
- •PostgreSQL 数据库连接信息
- •Google Drive API 凭证
- •Google Gemini API Key
- •Supabase URL 和 API Key
使用的节点 (28)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "a243f35537ecbb3a29ba49c4cf2200720075b362bcc7d02523f79748238bcfd6",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "0db018d8-693f-4e47-be62-4b34d7b8d77f",
"name": "嵌入 Google Gemini",
"type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
"position": [
912,
592
],
"parameters": {},
"credentials": {
"googlePalmApi": {
"id": "VCZQfcHNj0rHxcNf",
"name": "GEMINI_API_KUDDUS"
}
},
"typeVersion": 1
},
{
"id": "edf2e17e-a730-486b-8e2a-8acaef9e84a3",
"name": "Supabase 向量存储",
"type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
"position": [
912,
400
],
"parameters": {
"mode": "retrieve-as-tool",
"options": {},
"tableName": {
"__rl": true,
"mode": "list",
"value": "documents",
"cachedResultName": "documents"
},
"toolDescription": "Use this tool to search and retrieve relevant information from the user's study materials stored in the vector database. Query the documents to answer user questions accurately."
},
"credentials": {
"supabaseApi": {
"id": "OweRv8RLSfhKJyfg",
"name": "Supabase account"
}
},
"typeVersion": 1.3
},
{
"id": "1a55495f-44be-4c71-9a9d-f4886a8980a8",
"name": "Postgres 聊天记忆",
"type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
"position": [
368,
608
],
"parameters": {
"sessionKey": "={{ $json.sessionId }}",
"sessionIdType": "customKey",
"contextWindowLength": 10
},
"credentials": {
"postgres": {
"id": "KbYSAyR6T3ljhFKn",
"name": "Postgres account"
}
},
"typeVersion": 1.3
},
{
"id": "39d7a9b3-66d8-41fb-8454-6a80885131d1",
"name": "计算器",
"type": "@n8n/n8n-nodes-langchain.toolCalculator",
"position": [
768,
464
],
"parameters": {},
"typeVersion": 1
},
{
"id": "d943532d-4ae7-4829-a381-191cf84ea622",
"name": "当收到聊天消息时",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
176,
192
],
"webhookId": "6f7911bb-b08c-40ba-b613-a81d3d26ee18",
"parameters": {
"public": true,
"options": {}
},
"typeVersion": 1.3
},
{
"id": "f37c1723-0049-4b1d-8354-3acfd5179cb4",
"name": "Google Gemini聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
"position": [
256,
448
],
"parameters": {
"options": {},
"modelName": "models/gemini-2.5-pro"
},
"credentials": {
"googlePalmApi": {
"id": "VCZQfcHNj0rHxcNf",
"name": "GEMINI_API_KUDDUS"
}
},
"typeVersion": 1
},
{
"id": "225fb496-37d1-4dd7-b008-179ebb0880cc",
"name": "文件夹所有文件到向量",
"type": "@n8n/n8n-nodes-langchain.toolWorkflow",
"position": [
576,
448
],
"parameters": {
"workflowId": {
"__rl": true,
"mode": "list",
"value": "DXm6uptDmBBGVVWV",
"cachedResultUrl": "/workflow/DXm6uptDmBBGVVWV",
"cachedResultName": "Drive folder all file to Supabase Vector Store Database for RAG"
},
"workflowInputs": {
"value": {
"Drive_Folder_link": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Drive_Folder_link', ``, 'string') }}"
},
"schema": [
{
"id": "Drive_Folder_link",
"type": "string",
"display": true,
"removed": false,
"required": false,
"displayName": "Drive_Folder_link",
"defaultMatch": false,
"canBeUsedToMatch": true
}
],
"mappingMode": "defineBelow",
"matchingColumns": [
"Drive_Folder_link"
],
"attemptToConvertTypes": false,
"convertFieldsToString": false
}
},
"typeVersion": 2.2
},
{
"id": "2cec8fcc-a3ed-459e-9e30-1fad8a7b6765",
"name": "学习助手",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
448,
192
],
"parameters": {
"text": "={{ $json.chatInput }}",
"options": {
"systemMessage": "You are a Study AI Assistant that helps users interact with their study materials in a natural, conversational way.\n\n## Core Behavior\n\n**Always respond conversationally and helpfully.** You can answer questions, provide information from stored materials, and assist with file uploads - all while maintaining a friendly, natural dialogue.\n\n## Input Handling\n\n### 1. Google Drive Links\nWhen you detect a Google Drive URL (folder or file):\n- **Pattern**: `https://drive.google.com/drive/folders/` or `https://drive.google.com/file/d/`\n- **Action**: Automatically trigger the `DriveFolderToSupabase` workflow\n- **Response**: Confirm the upload is processing: \"I'm uploading your files to the vector store. This will take a moment...\"\n\n### 2. Study Material Queries\nWhen users ask questions about their materials:\n- **Search the vector store** using available retrieval tools\n- **Always check the vector store first** before saying you don't have information\n- Provide clear, helpful answers with citations\n- Include document names, sections, or page numbers when available\n\n### 3. General Conversation\nWhen users engage in general conversation:\n- Respond naturally and helpfully\n- If they're asking about themselves or their materials, **search the vector store**\n- Use context from previous messages in the conversation\n- Be conversational, not robotic\n\n## Critical Rules\n\n1. **Never refuse to search**: If someone asks \"what is in the documents\" or \"tell me about X\", immediately query the vector store with relevant keywords\n2. **Infer intent**: Questions like \"about me\", \"what's my name\", or \"vector database\" should trigger a vector store search for relevant content\n3. **Use broad searches**: When unsure, search with general terms rather than refusing to help\n4. **Acknowledge limitations gracefully**: Only say you can't find information AFTER searching, not before\n5. **Maintain conversation context**: Reference previous exchanges naturally\n\n## Search Strategy\n\nWhen querying the vector store:\n- Use **keywords and concepts** from the user's question\n- Try **multiple related terms** if the first search yields poor results\n- For vague queries like \"tell me what's in the documents\", search with terms like: \"overview\", \"introduction\", \"main topic\", \"summary\"\n- **Always attempt a search** before saying you don't have the information\n\n## Response Format\n\n- **Direct answers** to questions\n- **Cite sources** when providing information from documents\n- **Suggest related topics** when appropriate\n- **Ask clarifying questions** only when absolutely necessary (not as a default)\n\n## Examples\n\n**Bad Response**: \"I need a specific question or topic to search for.\"\n**Good Response**: *[Searches vector store]* \"Based on your uploaded materials, I found information about [topic]. Here's what I can tell you...\"\n\n**Bad Response**: \"I don't have access to personal information like your name.\"\n**Good Response**: *[Searches vector store for personal info]* \"I searched your documents and found [relevant information], or if nothing is found: \"I searched your uploaded materials but didn't find personal information stored. What would you like to know about your study content?\"\n"
},
"promptType": "define"
},
"typeVersion": 2.2
},
{
"id": "cf65699a-9e5a-4c24-b256-fe3892c154fd",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-224,
96
],
"parameters": {
"width": 336,
"height": 640,
"content": "# 🤖 AI 学习助手(RAG 聊天)"
},
"typeVersion": 1
},
{
"id": "eddf672b-4bd8-45d6-bf4e-29ddd688f1e5",
"name": "便签 1",
"type": "n8n-nodes-base.stickyNote",
"position": [
416,
32
],
"parameters": {
"color": 4,
"width": 288,
"height": 352,
"content": "**AI Agent(核心)** - 协调所有工具和记忆。处理 Drive 链接、搜索文档、维护上下文,并使用 Gemini 2.5 Pro 自然响应"
},
"typeVersion": 1
},
{
"id": "c201dfbd-714c-4629-8a49-9acc006af38a",
"name": "便签 2",
"type": "n8n-nodes-base.stickyNote",
"position": [
912,
256
],
"parameters": {
"height": 272,
"content": "**文档搜索工具** - 使用 768 维嵌入的语义相似性搜索从上传的学习材料中检索相关信息"
},
"typeVersion": 1
},
{
"id": "e29b5f39-3fcb-40b2-9ba0-02ef7d070f2a",
"name": "便签 3",
"type": "n8n-nodes-base.stickyNote",
"position": [
512,
512
],
"parameters": {
"height": 208,
"content": ""
},
"typeVersion": 1
},
{
"id": "54a5e290-1ec4-4b97-96ed-d424aaf3c2ca",
"name": "嵌入 Google Gemini4",
"type": "@n8n/n8n-nodes-langchain.embeddingsGoogleGemini",
"position": [
1232,
1392
],
"parameters": {},
"credentials": {
"googlePalmApi": {
"id": "VCZQfcHNj0rHxcNf",
"name": "GEMINI_API_KUDDUS"
}
},
"typeVersion": 1
},
{
"id": "7682b868-5215-452d-b110-ff8007f2d059",
"name": "默认数据加载器2",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"position": [
1408,
1376
],
"parameters": {
"options": {},
"dataType": "binary"
},
"typeVersion": 1.1
},
{
"id": "ceacbea3-3c6a-47d1-83a6-386cb1166414",
"name": "执行 SQL 查询",
"type": "n8n-nodes-base.postgres",
"position": [
400,
1120
],
"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": "90883ae9-8d17-4a72-83be-da4dae013343",
"name": "JavaScript 代码",
"type": "n8n-nodes-base.code",
"position": [
176,
1120
],
"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": "1e5ac5c6-ae2c-400d-b531-a18c823a3d07",
"name": "当由其他工作流执行时",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
-32,
1120
],
"parameters": {
"inputSource": "jsonExample",
"jsonExample": "{\n \"Drive_Folder_link\": \"https://drive.google.com/drive/folders/example\"\n}"
},
"typeVersion": 1.1
},
{
"id": "472c0470-a590-476a-b23b-77617b042a39",
"name": "遍历项目",
"type": "n8n-nodes-base.splitInBatches",
"position": [
832,
1120
],
"parameters": {
"options": {}
},
"typeVersion": 3
},
{
"id": "8e8a66a7-9a2c-4ed9-91b3-80d805b1dbab",
"name": "搜索文件和文件夹",
"type": "n8n-nodes-base.googleDrive",
"position": [
608,
1120
],
"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": "21559a2e-f0d3-40a1-8809-5f2a31cde811",
"name": "插入到 Supabase Vectorstore",
"type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
"position": [
1280,
1120
],
"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": "a818d7b0-1c5e-4273-96d1-d72ff2960823",
"name": "下载文件",
"type": "n8n-nodes-base.googleDrive",
"position": [
1072,
1136
],
"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": "0cf08172-6b3e-44a9-aec7-44a2b5e582ff",
"name": "便签 4",
"type": "n8n-nodes-base.stickyNote",
"position": [
592,
1296
],
"parameters": {
"width": 176,
"height": 128,
"content": "**列出 Drive 文件** - 使用提取的文件夹 ID 从指定的 Google Drive 文件夹检索所有文件"
},
"typeVersion": 1
},
{
"id": "98009dab-d49a-4205-9d9b-da29c3560d98",
"name": "便签 5",
"type": "n8n-nodes-base.stickyNote",
"position": [
1040,
960
],
"parameters": {
"width": 150,
"content": "**列出 Drive 文件** - 使用提取的文件夹 ID 从指定的 Google Drive 文件夹检索所有文件"
},
"typeVersion": 1
},
{
"id": "57415dae-d6cd-4c5a-8305-ee9100bec975",
"name": "便签6",
"type": "n8n-nodes-base.stickyNote",
"position": [
1264,
864
],
"parameters": {
"color": 7,
"height": 240,
"content": "**存储嵌入** - 通过 Gemini 生成 768 维向量并将文档插入 Supabase 进行语义搜索"
},
"typeVersion": 1
},
{
"id": "677fd038-4cd9-483b-84ff-98373a6affb4",
"name": "便签7",
"type": "n8n-nodes-base.stickyNote",
"position": [
-480,
944
],
"parameters": {
"color": 5,
"width": 368,
"height": 512,
"content": "# 📁 Drive 到 Supabase 向量存储用于学习 RAG"
},
"typeVersion": 1
},
{
"id": "975c4447-f0fe-48fd-afb9-e4da35b30080",
"name": "便签8",
"type": "n8n-nodes-base.stickyNote",
"position": [
-80,
1280
],
"parameters": {
"width": 176,
"height": 128,
"content": "**触发器节点** - 当从另一个 n8N 工作流调用时启动工作流。接受 Drive 文件夹 URL 作为输入"
},
"typeVersion": 1
},
{
"id": "a9cdb11e-fbb5-43b8-aa5d-6ea48be4fc85",
"name": "便签9",
"type": "n8n-nodes-base.stickyNote",
"position": [
160,
1280
],
"parameters": {
"width": 150,
"height": 128,
"content": "**提取文件夹 ID** - 使用正则表达式解析 Google Drive URL 以提取用于 API 调用的文件夹/文件 ID"
},
"typeVersion": 1
},
{
"id": "01282543-fd57-4815-af73-bf26a2ff4a12",
"name": "便签 10",
"type": "n8n-nodes-base.stickyNote",
"position": [
368,
1280
],
"parameters": {
"width": 176,
"content": "**初始化数据库** - 使用 pgvector 扩展和 match_documents 搜索函数创建 Supabase 向量表。⚠️ 删除现有表!"
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"Calculator": {
"ai_tool": [
[
{
"node": "Study Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"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
}
]
]
},
"Postgres Chat Memory": {
"ai_memory": [
[
{
"node": "Study Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"Supabase Vector Store": {
"ai_tool": [
[
{
"node": "Study Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Embeddings Google Gemini": {
"ai_embedding": [
[
{
"node": "Supabase Vector Store",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Google Gemini Chat Model": {
"ai_languageModel": [
[
{
"node": "Study Agent",
"type": "ai_languageModel",
"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
}
]
]
},
"Folder all file to vector": {
"ai_tool": [
[
{
"node": "Study Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "Study Agent",
"type": "main",
"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)可能需要您自行付费。
相关工作流推荐
使用Gemini和Supabase从Google Drive文档创建RAG向量数据库
通过Gemini和Supabase从Google Drive文档创建RAG向量数据库
Code
Postgres
Google Drive
+6
16 节点Mantaka Mahir
文档提取
在可视化参考库中探索n8n节点
在可视化参考库中探索n8n节点
If
Ftp
Set
+93
113 节点I versus AI
其他
创建自更新的RAG聊天机器人(Google Drive、Gemini和Supabase)
使用Google Drive、Gemini和Supabase创建自更新的RAG聊天机器人
Set
Code
Merge
+19
45 节点Anirudh Aeran
内容创作
上下文混合RAG AI文案
Google Drive到Supabase上下文向量数据库同步用于RAG应用
If
Set
Code
+25
76 节点Michael Taleb
AI RAG 检索增强
基于AI的MIS代理
基于AI的管理信息系统代理
If
Set
Code
+29
129 节点Kumar Shivam
客户支持
宠物店 4
🐶 宠物店预约 AI 代理
If
Set
Code
+41
187 节点Bruno Dias
人工智能
工作流信息
难度等级
高级
节点数量28
分类2
节点类型15
作者
Mantaka Mahir
@mantakamahirAl Automation Expert || Al Agents || n8n || Python || LangChain || Helping businesses scale revenue and reduce costs with Al driven automation .
外部链接
在 n8n.io 查看 →
分享此工作流