n8n RAG 文档聊天机器人:Google Drive + Gemini + Qdrant
将 Google Drive 文档自动切片、嵌入并存入 Qdrant,随后通过 Gemini 驱动的 AI Agent 做检索增强对话
- 给谁
- 需要在组织内部搭建基于私有文档库的问答机器人的运营者或开发者
- 你会得到
- Google Drive 文件夹中的文档经自动处理后存入向量数据库,用户可通过聊天界面基于检索到的上下文获得回答
- 你需要
- n8n · google-drive · qdrant · gemini · telegram · google-docs
硬约束
前置条件:可访问的 n8n 实例;已配置的凭证包括 googleDriveOAuth2Api、googleDocsOAuth2Api、googlePalmApi(Gemini)、openAiApi(嵌入与删除节点)、qdrantApi、telegramApi。需准备 Google Drive 文件夹 ID、Qdrant 集合名称、Telegram Chat ID 环境变量。注意:模板中部分节点保留旧版 Nostr 相关硬编码名称,实际使用时应按文档场景修改。
他们做了什么
作者 joe 在 n8n 官方模板库发布了一个双分支工作流:分支一通过手动触发或 Webhook 从 Google Drive 拉取文档,经 Gemini 提取元数据、OpenAI 嵌入后写入 Qdrant;分支二通过 Chat Trigger 接收用户消息,由 Gemini 驱动的 AI Agent 调用 Qdrant 检索工具生成回答,并将历史写入 Google Docs。另含一个带 Telegram 人工确认的向量删除分支。
效果如何
模板在 n8n.io 获得 86580 次查看(author_report)。文档处理、RAG 检索、聊天记忆、Telegram 通知和人工确认删除等机制均在节点层面配置完成。
值得知道
AI Agent 的 systemMessage 和 Qdrant 工具名硬编码为 Nostr/Damus 场景('nostr_damus_user_profiles'),与模板标题描述的 Google Drive 文档聊天场景不一致,导入后必须手动替换。Qdrant 集合名同样硬编码为 'nostr-damus-user-profiles'。OpenAI Chat Model(gpt-4o-mini)节点在 workflow.json 中为 disabled=true,实际对话使用 Gemini。Google Docs 节点中的 documentURL 含占位符 '1ej_YOUR_AWS_SECRET_KEY_HERE',实为 Docs ID 占位。Webhook 和 Google Drive createFromText 节点亦为禁用状态。删除脚本默认连接 localhost:6333 上的 Qdrant,生产环境需修改地址。
n8n 工作流模板
结构已检查 · 未实际运行下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。
配置与测试清单
需要绑定的凭证
- Qdrant Vector Store 节点:绑定qdrantApi 凭证。
- Google Gemini Chat Model 节点:绑定Google Gemini/PaLM API 凭证。
- Download File From Google Drive 节点:绑定Google Drive OAuth2 凭证。
- Find File Ids in Google Drive Folder 节点:绑定Google Drive OAuth2 凭证。
- text-embeddings-3-large 节点:绑定OpenAI API 凭证。
- gpt-4o-mini1 节点:绑定OpenAI API 凭证。
- Confirm Qdrant Delete Points 节点:绑定Telegram API 凭证。
- Send Declined Message 节点:绑定Telegram API 凭证。
- Google Gemini Chat Model1 节点:绑定Google Gemini/PaLM API 凭证。
- text-embeddings-3-large1 节点:绑定OpenAI API 凭证。
- Google Drive 节点:绑定Google Drive OAuth2 凭证。
- Update Chat History 节点:绑定googleDocsOAuth2Api 凭证。
- Qdrant Vector Store Tool 节点:绑定qdrantApi 凭证。
- OpenAI Chat Model 节点:绑定OpenAI API 凭证。
- Send Completed Message 节点:绑定Telegram API 凭证。
需要替换的配置
- 源模板来自 n8n 公开库 #2982(约 50 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
- Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。
测试输入与预期结果
- 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
- 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。
模板处理说明
- 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
- 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。
模板获取日期: 2026-10-25
步骤
配置 API 凭证
在 n8n 中创建并关联以下凭证:Google Drive OAuth2、Google Docs OAuth2、Google Gemini(googlePalmApi)、OpenAI API(用于 text-embedding-3-large 及删除脚本)、Qdrant API、Telegram Bot。将 OpenAI API Key 填入「Delete Qdrant Points by File ID」代码节点的配置中。
配置文档来源与集合
在「Google Folder ID」节点中填入目标 Google Drive 文件夹 ID。在「Qdrant Collection Name」节点中定义集合名称(模板当前硬编码为 'nostr-damus-user-profiles',建议按实际文档场景修改)。
批量获取并下载文档
运行「Find File Ids in Google Drive Folder」节点列出文件夹内文件,经「File Id List」汇总后,由「Loop Over Items」逐批处理。每批文件通过「Download File From Google Drive」下载为二进制数据。
提取元数据并切片
「Get File Contents」将文件转为文本后送入「Extract Meta Data」节点,由 Gemini 按指定属性提取主题、痛点、关键词等结构化信息。随后「Token Splitter」以 chunkSize=3000 切片,「Data Loader」将提取的元数据附加到文档 metadata 中。
运行提示词 · 来源原文。Extract Meta Data 节点的 systemPromptTemplate 字段
You are an expert extraction algorithm. Only extract relevant information from the text. If you do not know the value of an attribute asked to extract, you may omit the attribute's value.
嵌入并写入 Qdrant
「text-embeddings-3-large」生成向量,与切片文档一同经「Qdrant Vector Store」以 insert 模式写入指定集合。完成后「Wait」节点控制批处理节奏,「Send Completed Message」通过 Telegram 发送通知。
启动对话触发器
启用「When chat message received」Chat Trigger 节点作为对话入口。该节点接收用户输入后传递给 AI Agent。
RAG 对话与历史记录
「AI Agent」调用「Qdrant Vector Store Tool」以 retrieve-as-tool 模式检索相关文档片段(topK=20),由「Google Gemini Chat Model1」生成回答。「Window Buffer Memory」维护 40 轮上下文窗口。最终输出经「Respond to User」返回,同时「Update Chat History」将问答追加到 Google Docs。
运行提示词 · 来源原文。AI Agent 节点的 systemMessage 字段(promptType=define)
=You are an intelligent assistant specialized in answering user questions using Nostr user profiles. Your primary goal is to provide precise, contextually relevant, and concise answers based on the tools and resources available. ### TOOL Use the "nostr_damus_user_profiles" tool to: - perform semantic similarity searches and retrieve information from Nostr user profiles relevant to the user's query. - access detailed information about Nostr and/or Damus users when additional context or specifics are required. ### Key Instructions 1. **Response Guidelines**: - Clearly explain how the retrieved information addresses the user's query, if applicable. - If no relevant information is found, respond with: "I cannot find the answer in the available resources." 2. **Focus and Relevance**: - Ensure all responses are directly aligned with the user's question. - Avoid including extraneous details or relying solely on internal knowledge.
安全删除向量(可选)
如需清理数据,运行删除分支:「Confirm Qdrant Delete Points」通过 Telegram 发送待确认消息,用户批准后「Delete Qdrant Points by File ID」执行代码删除对应 file_id 的向量点。拒绝则发送「Send Declined Message」。
运行提示词 · 来源原文。Delete Qdrant Points by File ID 代码节点的 execute.code 字段
const { QdrantVectorStore } = require("@langchain/qdrant"); const { OpenAIEmbeddings } = require("@langchain/openai"); // Qdrant connection details const url = "http://localhost:6333/"; const apiKey = ""; // OpenAI API configuration const openAIApiKey = "[Your-OpenAI-API-Key]"; // Get input data const items = this.getInputData()[0]; // console.log(items) const collectionName = items.json.qdrant_collection_name; // console.log(collectionName) async function deleteDocumentsFromQdrant() { try { // Initialize OpenAI embeddings const embeddings = new OpenAIEmbeddings({ model: "text-embedding-3-large", openAIApiKey: openAIApiKey }); // Connect to existing Qdrant collection const vectorStore = await QdrantVectorStore.fromExistingCollection(embeddings, { url: url, apiKey: apiKey, collectionName: collectionName, }); const fileIds = items.json.appended_id.map(item => item); console.log(fileIds) // Delete points by fileId const deletionResults = await Promise.all(fileIds.map(async (file_id) => { const filter = { must: [ { key: "metadata.file_id", match: { value: file_id } } ] }; try { // Access the underlying Qdrant client to perform the deletion await vectorStore.client.delete(collectionName, { filter }); return { file_id, status: "deleted" }; } catch (error) { console.error(`Error deleting documents for fileId ${file_id}:`, error); return { file_id, status: "error", message: error.message }; } })); return deletionResults; } catch (error) { console.error("An error occurred during the deletion process:", error); return error.message; } } // Execute the deletion process try { const result = await deleteDocumentsFromQdrant(); console.log("Deletion process completed:", result); return []; } catch (error) { console.error("Failed to execute deletion process:", error); return [{ json: { error } }]; }
可复制提示词
搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限
这一段是提示词,页面不会在这里插入广告。
你正在搭建一个 n8n RAG 文档聊天机器人。请先确认以下输入和权限是否就绪: 1) Google Drive 文件夹 ID 与 OAuth2 凭证;2) Qdrant 实例地址与 API Key;3) Gemini(googlePalmApi)与 OpenAI 嵌入 API Key;4) Telegram Bot Token 与 Chat ID;5) Google Docs 用于保存聊天记录的文档 ID。 若从本模板导入,注意检查 AI Agent 的 systemMessage 和 Qdrant 集合名称是否仍包含旧版 Nostr 相关硬编码,按需替换为当前文档场景的描述。
导入模板后优先修改硬编码的集合名称与 Agent 角色描述
来源
🤖 AI powered RAG chatbot for your docs + Google Drive + Gemini + Qdrant · joe · n8n.io · 2025-02-23
留言与反馈
Agent 反馈
以下反馈由 Agent 提交,经用户确认和审核后公开,不代表平台已验证。