8
n8n 中文网amn8n.com

使用Google Drive和GPT-4o通过向量搜索创建知识库聊天机器人

高级

这是一个Support Chatbot, AI RAG领域的自动化工作流,包含 26 个节点。主要使用 Set, Code, Webhook, GoogleDrive, HttpRequest 等节点。 使用Google Drive和GPT-4o通过向量搜索创建知识库聊天机器人

前置要求
  • HTTP Webhook 端点(n8n 会自动生成)
  • Google Drive API 凭证
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "0f4ab867ceb8faa35a96b3ba8bfe372ed23fd9289fb2f308ae76570118367d6d"
  },
  "name": "我的工作流",
  "tags": [],
  "nodes": [
    {
      "id": "3c701a7e-738e-44d4-af9b-c3629d0e471e",
      "name": "递归字符文本分割器",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        760,
        920
      ],
      "parameters": {
        "options": {},
        "chunkOverlap": 100
      },
      "typeVersion": 1
    },
    {
      "id": "51a61f7f-610b-4cda-8405-11983fec7c8a",
      "name": "默认数据加载器",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        780,
        740
      ],
      "parameters": {
        "options": {},
        "dataType": "binary",
        "binaryMode": "specificField"
      },
      "typeVersion": 1
    },
    {
      "id": "805a12e8-2d85-4951-929c-76df85ad4e0f",
      "name": "简单向量存储",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        700,
        540
      ],
      "parameters": {
        "mode": "insert",
        "memoryKey": {
          "__rl": true,
          "mode": "list",
          "value": "vector_store_key"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "c17de454-87ab-4a69-b129-bf77a5afbb66",
      "name": "OpenAI 嵌入",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        620,
        740
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "14c2ff00-618f-4ea3-aeb8-212aa76d28ef",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1400,
        680
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "318ca8eb-0e06-4ba9-bcc2-c57b65254794",
      "name": "使用向量存储回答问题",
      "type": "@n8n/n8n-nodes-langchain.toolVectorStore",
      "position": [
        1700,
        640
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "286f2e2b-1a70-48c8-a619-1e01cacf8cee",
      "name": "简单向量存储2",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        1560,
        840
      ],
      "parameters": {
        "memoryKey": {
          "__rl": true,
          "mode": "list",
          "value": "vector_store_key"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "1603e15d-db26-4174-bb32-0d8f429d3fca",
      "name": "Embeddings OpenAI1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        1540,
        980
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "c6623fd4-2ccc-4a15-9b10-07024c916eeb",
      "name": "OpenAI 聊天模型1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        1840,
        840
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "e7c3e7a9-5d38-4dd4-983f-1f4a104f4fe9",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3200,
        1020
      ],
      "parameters": {
        "color": 4,
        "width": 620,
        "height": 920,
        "content": "## Google Drive 连接"
      },
      "typeVersion": 1
    },
    {
      "id": "fac8b33c-f829-4d39-8eee-c773c93980e6",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        3200,
        0
      ],
      "parameters": {
        "color": 6,
        "width": 620,
        "height": 980,
        "content": "## 🛠️ 导入模板后的配置指南"
      },
      "typeVersion": 1
    },
    {
      "id": "6bbd55eb-29bb-4322-83a8-ebb46292802b",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2540,
        0
      ],
      "parameters": {
        "width": 620,
        "height": 520,
        "content": "# 🤖 在 n8n 中使用 Google Drive 知识的简单 AI 聊天机器人"
      },
      "typeVersion": 1
    },
    {
      "id": "3a3ff629-4664-4b11-8de0-56eeb236044e",
      "name": "下载文件",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        500,
        540
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {},
        "operation": "download"
      },
      "typeVersion": 3
    },
    {
      "id": "79414561-32d3-4d1c-924f-341ce16aeb76",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        0
      ],
      "parameters": {
        "color": 3,
        "width": 1080,
        "height": 1160,
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "d64086c3-31bb-4876-8652-df1c287f4a53",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1120,
        0
      ],
      "parameters": {
        "color": 5,
        "width": 1380,
        "height": 1160,
        "content": "### 🧠 第二部分:**用于问答的 AI 聊天机器人**"
      },
      "typeVersion": 1
    },
    {
      "id": "0eeeddda-95e7-46a2-8c0a-d09b1da5ecf1",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        1160,
        440
      ],
      "webhookId": "bfb0e32d-659b-4fc5-a7a3-695c55137855",
      "parameters": {
        "path": "bfb0e32d-659b-4fc5-a7a3-695c55137855",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "6428ae4e-6702-4776-9430-6c808b1588df",
      "name": "编辑字段",
      "type": "n8n-nodes-base.set",
      "position": [
        1340,
        440
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e2a61b06-dc33-4c30-8197-cf6de3dc4a5d",
              "name": "chatInput",
              "type": "string",
              "value": "={{ $json.body.Data.ChatMessage.Content }}"
            },
            {
              "id": "fc96dfe9-cc87-4004-b812-cb1fa84e7f67",
              "name": "sessionId",
              "type": "string",
              "value": "={{ $json.body.Data.ChatMessage.RoomId }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "5bb23164-475f-45ee-a1c7-59ca9600a07a",
      "name": "AI Agent 输出是否存在?",
      "type": "n8n-nodes-base.code",
      "position": [
        1860,
        440
      ],
      "parameters": {
        "jsCode": "const ai = items.find(i => i.json.output);\nconst fallback = \"Sorry, I didn’t understand your message. Please try again or send a text.\";\n\nreturn [\n  {\n    json: {\n      content: ai?.json.output || fallback\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "bb54bb65-8bf0-440f-9479-da920e2a8da3",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1520,
        440
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are a friendly and well-informed customer support specialist for Venio, a third-party multichannel messaging platform. Stay factual. You must answer the user's question using only the information provided in the document content below. Do not invent or guess information outside the context. Remember to ensure the answer is correct refer to the file.\n\nYour task is to answer customer questions clearly, patiently, and in a warm, supportive tone.\n\nDo not to say feel free to ask or something like that"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "4b847538-28d1-4e61-ba01-89d46e74fc24",
      "name": "令牌认证",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2080,
        440
      ],
      "parameters": {
        "url": "<Your-Token-Url>",
        "method": "POST",
        "options": {
          "redirect": {
            "redirect": {}
          }
        },
        "sendBody": true,
        "contentType": "form-urlencoded",
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "grant_type",
              "value": "client_credentials"
            },
            {
              "name": "client_id",
              "value": "<Your-Client-Id>"
            },
            {
              "name": "client_secret",
              "value": "<Your-Client-Secret>"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Ocp-Apim-Subscription-Key",
              "value": "<Your-Subscription-Key>"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "1aa5a0b5-304f-43ac-9119-13938c815010",
      "name": "发送到聊天应用",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        2300,
        440
      ],
      "parameters": {
        "url": "<Your-Chat-Url>",
        "method": "POST",
        "options": {
          "redirect": {
            "redirect": {}
          }
        },
        "sendBody": true,
        "sendHeaders": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "roomId",
              "value": "={{ $('Webhook').item.json.body.Data.ChatMessage.RoomId }}"
            },
            {
              "name": "content",
              "value": "={{ $('Is AI Agent output exist?').item.json.content }}"
            },
            {
              "name": "type",
              "value": "message"
            },
            {
              "name": "platform",
              "value": "={{ $('Webhook').item.json.body.Data.ChatMessage.Platform }}"
            },
            {
              "name": "companyId",
              "value": "={{ $('Webhook').item.json.body.Data.ChatMessage.User.CompanyId }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.access_token }}"
            },
            {
              "name": "Ocp-Apim-Subscription-Key",
              "value": "<Your-Subscription-Key>"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "01d71fdf-4979-4478-a480-a0d15de8dab5",
      "name": "文件夹中的文件创建",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        80,
        460
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "1Ve5ZLtQwpK5Hq4YxZTNRduRgPlSMZ1hJ",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1Ve5ZLtQwpK5Hq4YxZTNRduRgPlSMZ1hJ",
          "cachedResultName": "ChatbotTest"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "a2cf29ab-fa4d-4185-9a0d-eb22e04bf836",
      "name": "文件夹中的文件更新",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        80,
        660
      ],
      "parameters": {
        "event": "fileUpdated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "1Ve5ZLtQwpK5Hq4YxZTNRduRgPlSMZ1hJ",
          "cachedResultUrl": "https://drive.google.com/drive/folders/1Ve5ZLtQwpK5Hq4YxZTNRduRgPlSMZ1hJ",
          "cachedResultName": "ChatbotTest"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f8c00b8a-13da-451a-855c-ccc424fd56c1",
      "name": "在您的 Google Drive 文件夹中搜索文件",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        300,
        540
      ],
      "parameters": {
        "filter": {
          "driveId": {
            "__rl": true,
            "mode": "list",
            "value": "My Drive",
            "cachedResultUrl": "https://drive.google.com/drive/my-drive",
            "cachedResultName": "My Drive"
          },
          "folderId": {
            "__rl": true,
            "mode": "list",
            "value": "1Ve5ZLtQwpK5Hq4YxZTNRduRgPlSMZ1hJ",
            "cachedResultUrl": "https://drive.google.com/drive/folders/1Ve5ZLtQwpK5Hq4YxZTNRduRgPlSMZ1hJ",
            "cachedResultName": "ChatbotTest"
          }
        },
        "options": {},
        "resource": "fileFolder"
      },
      "typeVersion": 3
    },
    {
      "id": "a4f972ff-d5cb-4ac0-ad79-a7a582b2d4c3",
      "name": "窗口缓冲内存",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        1560,
        680
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "0df89f09-5e2b-4242-a276-10c48df7f1c5",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2540,
        560
      ],
      "parameters": {
        "color": 2,
        "width": 620,
        "height": 1380,
        "content": "---"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "",
  "connections": {
    "0eeeddda-95e7-46a2-8c0a-d09b1da5ecf1": {
      "main": [
        [
          {
            "node": "6428ae4e-6702-4776-9430-6c808b1588df",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "bb54bb65-8bf0-440f-9479-da920e2a8da3": {
      "main": [
        [
          {
            "node": "5bb23164-475f-45ee-a1c7-59ca9600a07a",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "6428ae4e-6702-4776-9430-6c808b1588df": {
      "main": [
        [
          {
            "node": "bb54bb65-8bf0-440f-9479-da920e2a8da3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3a3ff629-4664-4b11-8de0-56eeb236044e": {
      "main": [
        [
          {
            "node": "805a12e8-2d85-4951-929c-76df85ad4e0f",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "c17de454-87ab-4a69-b129-bf77a5afbb66": {
      "ai_embedding": [
        [
          {
            "node": "805a12e8-2d85-4951-929c-76df85ad4e0f",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "14c2ff00-618f-4ea3-aeb8-212aa76d28ef": {
      "ai_languageModel": [
        [
          {
            "node": "bb54bb65-8bf0-440f-9479-da920e2a8da3",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "1603e15d-db26-4174-bb32-0d8f429d3fca": {
      "ai_embedding": [
        [
          {
            "node": "286f2e2b-1a70-48c8-a619-1e01cacf8cee",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "c6623fd4-2ccc-4a15-9b10-07024c916eeb": {
      "ai_languageModel": [
        [
          {
            "node": "318ca8eb-0e06-4ba9-bcc2-c57b65254794",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "51a61f7f-610b-4cda-8405-11983fec7c8a": {
      "ai_document": [
        [
          {
            "node": "805a12e8-2d85-4951-929c-76df85ad4e0f",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "286f2e2b-1a70-48c8-a619-1e01cacf8cee": {
      "ai_vectorStore": [
        [
          {
            "node": "318ca8eb-0e06-4ba9-bcc2-c57b65254794",
            "type": "ai_vectorStore",
            "index": 0
          }
        ]
      ]
    },
    "4b847538-28d1-4e61-ba01-89d46e74fc24": {
      "main": [
        [
          {
            "node": "1aa5a0b5-304f-43ac-9119-13938c815010",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "a4f972ff-d5cb-4ac0-ad79-a7a582b2d4c3": {
      "ai_memory": [
        [
          {
            "node": "bb54bb65-8bf0-440f-9479-da920e2a8da3",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "5bb23164-475f-45ee-a1c7-59ca9600a07a": {
      "main": [
        [
          {
            "node": "4b847538-28d1-4e61-ba01-89d46e74fc24",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "01d71fdf-4979-4478-a480-a0d15de8dab5": {
      "main": [
        [
          {
            "node": "f8c00b8a-13da-451a-855c-ccc424fd56c1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "a2cf29ab-fa4d-4185-9a0d-eb22e04bf836": {
      "main": [
        [
          {
            "node": "f8c00b8a-13da-451a-855c-ccc424fd56c1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "3c701a7e-738e-44d4-af9b-c3629d0e471e": {
      "ai_textSplitter": [
        [
          {
            "node": "51a61f7f-610b-4cda-8405-11983fec7c8a",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "318ca8eb-0e06-4ba9-bcc2-c57b65254794": {
      "ai_tool": [
        [
          {
            "node": "bb54bb65-8bf0-440f-9479-da920e2a8da3",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "f8c00b8a-13da-451a-855c-ccc424fd56c1": {
      "main": [
        [
          {
            "node": "3a3ff629-4664-4b11-8de0-56eeb236044e",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 客服机器人, AI RAG 检索增强

需要付费吗?

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

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

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

作者
Gofive

Gofive

@gofive

We create word-class software experience. Our offering includes "Venio" a highly innovative mobile-first CRM for B2B solution. "empeo" the complete HR solution for a multi-generational workplace and "eTaxGo" electronic tax invoice for organization.

外部链接
在 n8n.io 查看

分享此工作流

分类

分类: 34