8
n8n 中文网amn8n.com

使用 Google Drive 的 RAG 聊天机器人

高级

这是一个Miscellaneous, AI RAG, Multimodal AI领域的自动化工作流,包含 20 个节点。主要使用 Set, Supabase, GoogleDrive, SplitInBatches, Agent 等节点。 使用OpenAI、Google Drive和Supabase构建RAG知识聊天机器人

前置要求
  • Supabase URL 和 API Key
  • Google Drive API 凭证
  • OpenAI API Key
  • PostgreSQL 数据库连接信息
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "6naAx0wcjHZbs2pM",
  "meta": {
    "instanceId": "d4f16bea1a8eb4bd7217a4d0fe9a09f643e7227b28772e65da5a86a149783124",
    "templateCredsSetupCompleted": true
  },
  "name": "使用 Google Drive 的 RAG 聊天机器人",
  "tags": [],
  "nodes": [
    {
      "id": "4191c842-b484-467e-bea5-d2ff44af79e0",
      "name": "完整设置指南",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        -176
      ],
      "parameters": {
        "color": 2,
        "width": 760,
        "height": 908,
        "content": "## 🚀 完整设置指南 - 请先阅读!"
      },
      "typeVersion": 1
    },
    {
      "id": "5e8a89f6-ef3c-4691-959f-e1a6870f8b97",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        -176
      ],
      "parameters": {
        "color": 4,
        "width": 2020,
        "height": 820,
        "content": "## 数据摄取:将 Google Drive PDF 文件添加到向量数据库"
      },
      "typeVersion": 1
    },
    {
      "id": "e833cbb0-3dde-4d15-bd0d-ee3d53b976c0",
      "name": "文件已更新",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        976,
        192
      ],
      "parameters": {
        "event": "fileUpdated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_DRIVE_FOLDER_ID",
          "cachedResultUrl": "https://drive.google.com/drive/folders/YOUR_FOLDER_ID",
          "cachedResultName": "Your Watch Folder"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0b1d7b3b-1840-4f82-b4e8-3f3dd9c22c38",
      "name": "设置文件 ID",
      "type": "n8n-nodes-base.set",
      "position": [
        1232,
        16
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "79e9c100-c2d0-4fbd-97da-b2559a263eaa",
              "name": "file_id",
              "type": "string",
              "value": "={{ $json.id }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "ed7a80c0-893d-41a5-b5c2-1b7ea5c6c64a",
      "name": "从文件提取",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        2352,
        16
      ],
      "parameters": {
        "options": {},
        "operation": "text"
      },
      "typeVersion": 1
    },
    {
      "id": "0f4833f8-ac06-4069-b935-d4c80fcaae97",
      "name": "Supabase Vector Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        2576,
        16
      ],
      "parameters": {
        "mode": "insert",
        "options": {
          "queryName": "match_documents"
        },
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e5c920c4-06d4-4ed4-8ab7-e7271c7aa495",
      "name": "默认数据加载器",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        2624,
        304
      ],
      "parameters": {
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "file_id",
                "value": "={{ $('Set File ID').item.json.file_id }}"
              }
            ]
          }
        },
        "jsonData": "={{ $json.data }}",
        "jsonMode": "expressionData"
      },
      "typeVersion": 1
    },
    {
      "id": "15b7a747-6c48-4980-b9fe-342ef2695290",
      "name": "递归字符文本分割器",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        2624,
        512
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "0bd90ef9-eadd-40ee-a355-679c25ea00b8",
      "name": "文件已创建",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        976,
        -96
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyHour"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "YOUR_GOOGLE_DRIVE_FOLDER_ID_2",
          "cachedResultUrl": "https://drive.google.com/drive/folders/YOUR_FOLDER_ID_2",
          "cachedResultName": "Your Second Watch Folder"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b7b355c9-f5b9-4284-8279-4ef65e9fafae",
      "name": "OpenAI 嵌入",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        2432,
        304
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "e9d25ee5-28f0-445d-9fff-4ddb0fdc253f",
      "name": "遍历项目",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        1472,
        16
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "4e46f442-6012-4144-924b-4987caee00f1",
      "name": "删除一行",
      "type": "n8n-nodes-base.supabase",
      "position": [
        1776,
        -16
      ],
      "parameters": {
        "tableId": "documents",
        "operation": "delete",
        "filterType": "string",
        "filterString": "=metadata->>file_id=like.*{{ $json.file_id }}*"
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "32a5b87c-2082-4784-8fda-9d2b216b9692",
      "name": "下载文件",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        2096,
        -16
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Set File ID').item.json.file_id }}"
        },
        "options": {
          "googleFileConversion": {
            "conversion": {
              "docsToFormat": "text/plain"
            }
          }
        },
        "operation": "download"
      },
      "typeVersion": 3
    },
    {
      "id": "ce5c5e25-7b29-43ca-ae6c-37478f7311b6",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        912,
        672
      ],
      "parameters": {
        "width": 1160,
        "height": 700,
        "content": "## 对话式 RAG AI 代理"
      },
      "typeVersion": 1
    },
    {
      "id": "cab8ef92-84f1-40b1-ab48-60be42f2af2a",
      "name": "Postgres聊天记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        1488,
        1056
      ],
      "parameters": {
        "sessionKey": "={{ $json.user}}",
        "sessionIdType": "customKey"
      },
      "typeVersion": 1.3
    },
    {
      "id": "a7d2d794-0989-4cb3-bae7-8c3cd8efce94",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1376,
        1056
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "a43a8218-e3ff-41b3-aa7b-a2a77f565a74",
      "name": "当收到聊天消息时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        1088,
        816
      ],
      "webhookId": "5ee7ed2e-2827-41c2-9dfc-5490a9a40825",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "d72474db-da71-4ae5-9fbc-ab575842a5e1",
      "name": "RAG 向量存储",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        1696,
        1008
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 6,
        "options": {
          "queryName": "match_documents"
        },
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        },
        "toolDescription": "Use this knowledge base to answer questions from the user",
        "includeDocumentMetadata": false
      },
      "typeVersion": 1.3
    },
    {
      "id": "af193ff9-dfce-423f-a7b6-28b4be9d3a50",
      "name": "RAG AI 代理",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1392,
        816
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are an intelligent AI assistant connected to a dynamic knowledge base stored in a Supabase vector store. The information in this knowledge base can vary depending on the user and the data they have provided.\nInstructions:\nWhenever you receive a question, always search the knowledge base using the connected tool to retrieve relevant information before answering.\nIf a user asks what you can help with, or about your capabilities, query the knowledge base for a summary or list of available topics, documents, or areas of expertise.\nClearly mention that your abilities depend on the information currently available in the knowledge base, and provide specific examples or categories based on the retrieved data.\nIf the knowledge base is empty or does not contain relevant information, politely inform the user that you currently have no data to assist with their request.\nExample Behaviors:\nIf asked, \"What can you help me with?\"\n\n→ Search the knowledge base for available topics or documents and respond with a summary, e.g.,\n\n\"Based on the current knowledge base, I can assist you with topics such as [Topic A], [Topic B], and [Topic C]. Please let me know what you'd like to know more about!\"\nIf asked a specific question,\n\n→ Retrieve relevant information from the knowledge base and answer accordingly, citing the source or context if appropriate.\nIf the knowledge base is empty,\n\n→ \"I currently do not have any information in my knowledge base. Please add some data or let me know how I can assist you further.\"\nAlways ensure your responses are based on the most recent and relevant information from the knowledge base.\n"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "6ce5b725-2692-4dee-8100-72fe32cfacd1",
      "name": "嵌入 OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1680,
        1168
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7502b182-44d3-4034-b44d-a50ba225cd07",
  "connections": {
    "Set File ID": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete a row": {
      "main": [
        [
          {
            "node": "Download the file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Created": {
      "main": [
        [
          {
            "node": "Set File ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File Updated": {
      "main": [
        [
          {
            "node": "Set File ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items": {
      "main": [
        [],
        [
          {
            "node": "Delete a row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "RAG Vector store": {
      "ai_tool": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Download the file": {
      "main": [
        [
          {
            "node": "Extract from File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Extract from File": {
      "main": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings OpenAI1": {
      "ai_embedding": [
        [
          {
            "node": "RAG Vector store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Postgres Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "RAG AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Supabase Vector Store": {
      "main": [
        [
          {
            "node": "Loop Over Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "RAG AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 杂项, AI RAG 检索增强, 多模态 AI

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量20
分类3
节点类型15
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Babish Shrestha

Babish Shrestha

@bbz

I’m currently obsessed with building cool things using AI automation and AI agents — systems that save time, cut manual work, and actually do stuff on their own. If there’s a way to automate it, I’m probably already trying it out (or planning to). Having worked in IT industry for 15 years, I’m combining that background with AI to help businesses move smarter, not just faster.

外部链接
在 n8n.io 查看

分享此工作流