8
n8n 中文网amn8n.com

基于文档的 AI 聊天机器人,带 RAG、OpenAI 和 Cohere 重排器

高级

这是一个Internal Wiki, AI RAG领域的自动化工作流,包含 18 个节点。主要使用 GoogleDrive, ManualTrigger, Agent, ExtractFromFile, ChatTrigger 等节点。 基于文档的 AI 聊天机器人,带 RAG、OpenAI 和 Cohere 重排器

前置要求
  • Google Drive API 凭证
  • OpenAI API Key
  • Supabase URL 和 API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "6052a1b29f061469e8139dae44556603650099c3365d7598798f132ae827fa1c"
  },
  "nodes": [
    {
      "id": "a8afd8c2-2bfd-49f3-9687-0d68c83db4ad",
      "name": "聊天界面",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        80,
        100
      ],
      "webhookId": "de210796-2512-4c20-97eb-87b7f05298cb",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "00c21cda-1193-4cf5-9681-bf21ac2b269c",
      "name": "RAG 智能体",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        300,
        100
      ],
      "parameters": {
        "options": {
          "systemMessage": "You are an intelligent assistant with access to a knowledge base. Always search for relevant information before answering questions. Be helpful, accurate, and cite your sources when providing information from the knowledge base."
        }
      },
      "typeVersion": 2
    },
    {
      "id": "c74d3fac-14ef-4809-b290-d0344db04c79",
      "name": "AI 模型 (OpenAI)",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        180,
        320
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4-mini"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "e8a473c1-4934-491b-8283-80d48982d604",
      "name": "搜索嵌入向量",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        540,
        460
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "6fc17058-70f2-4bbe-a8b5-e35116f14853",
      "name": "对话记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        340,
        320
      ],
      "parameters": {
        "contextWindowLength": 10
      },
      "typeVersion": 1.3
    },
    {
      "id": "ba366390-61e3-4a25-8008-fb172145486a",
      "name": "加载文档触发器",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        100,
        760
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "f97d305b-3a96-445c-ace2-535c60055a4f",
      "name": "从 Google Drive 下载 PDF",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        320,
        760
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "url",
          "value": "{{GOOGLE_DRIVE_FILE_URL}}"
        },
        "options": {},
        "operation": "download"
      },
      "typeVersion": 3
    },
    {
      "id": "9eec6cb6-f445-4add-8de9-1464b61dfa7a",
      "name": "文档嵌入向量",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "position": [
        700,
        960
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "e64b2357-0238-45ca-87bd-10f8deddd6e4",
      "name": "处理文档文本",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        840,
        960
      ],
      "parameters": {
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "source",
                "value": "={{ $node['Download PDF from Drive'].json.name }}"
              },
              {
                "name": "type",
                "value": "pdf"
              }
            ]
          }
        },
        "jsonData": "={{ $json.text }}",
        "jsonMode": "expressionData"
      },
      "typeVersion": 1.1
    },
    {
      "id": "8b0645f9-dbcb-4613-9126-9efa824615bc",
      "name": "知识库搜索",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        540,
        320
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": 10,
        "options": {
          "queryName": "{{MATCH_FUNCTION_NAME}}"
        },
        "tableName": {
          "__rl": true,
          "mode": "id",
          "value": "{{VECTOR_TABLE_NAME}}"
        },
        "useReranker": true,
        "toolDescription": "Use this tool to search for information in the knowledge base. Always use this before answering questions to ensure accurate, up-to-date responses."
      },
      "credentials": {
        "supabaseApi": {
          "id": "PgMEWpeDY6PHLFXp",
          "name": "Supabase Zenithon Suporte IA"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "4cb8869a-de07-44f5-8f79-9b3c1207d21c",
      "name": "存储到向量数据库",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        700,
        760
      ],
      "parameters": {
        "mode": "insert",
        "options": {
          "queryName": "{{MATCH_FUNCTION_NAME}}"
        },
        "tableName": {
          "__rl": true,
          "mode": "id",
          "value": "{{VECTOR_TABLE_NAME}}"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "c8d8674d-ebe7-42fa-918e-ea9c5dc56b98",
      "name": "提取 PDF 内容",
      "type": "n8n-nodes-base.extractFromFile",
      "position": [
        500,
        760
      ],
      "parameters": {
        "options": {
          "maxPages": 500
        },
        "operation": "pdf"
      },
      "typeVersion": 1
    },
    {
      "id": "c5af8b70-bbda-4138-9598-dfd6c44a0eb5",
      "name": "Cohere 重排序器",
      "type": "@n8n/n8n-nodes-langchain.rerankerCohere",
      "position": [
        700,
        460
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "c3af22b6-830c-43a6-9a8f-0f38f3dec647",
      "name": "注意:聊天触发器",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        20,
        -40
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 120,
        "content": "### 1️⃣ 聊天触发器"
      },
      "typeVersion": 1
    },
    {
      "id": "c3655d77-d3ee-4c21-8166-da08b15175d3",
      "name": "注意:RAG 代理",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        300,
        -40
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 120,
        "content": "### 2️⃣ RAG 代理"
      },
      "typeVersion": 1
    },
    {
      "id": "ba9f02ea-6def-433a-9ccc-6f0ec1a1792b",
      "name": "注意:知识搜索",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        560,
        180
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 100,
        "content": "### 3️⃣ 知识搜索"
      },
      "typeVersion": 1
    },
    {
      "id": "ba558d29-fa87-4a2d-a63f-64a768bb2efb",
      "name": "注意:重排序器",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        820,
        440
      ],
      "parameters": {
        "color": 5,
        "width": 200,
        "height": 100,
        "content": "### 4️⃣ 重排序器"
      },
      "typeVersion": 1
    },
    {
      "id": "0ff39f38-d67e-4517-8f5b-834c032383dd",
      "name": "注意:配置",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        880,
        0
      ],
      "parameters": {
        "color": 4,
        "width": 260,
        "height": 180,
        "content": "### 配置变量"
      },
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "Chat Interface": {
      "main": [
        [
          {
            "node": "RAG Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cohere Reranker": {
      "ai_reranker": [
        [
          {
            "node": "Knowledge Base Search",
            "type": "ai_reranker",
            "index": 0
          }
        ]
      ]
    },
    "AI Model (OpenAI)": {
      "ai_languageModel": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Search Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Knowledge Base Search",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Conversation Memory": {
      "ai_memory": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Document Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Store in Vector Database",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Extract PDF Content": {
      "main": [
        [
          {
            "node": "Store in Vector Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Knowledge Base Search": {
      "ai_tool": [
        [
          {
            "node": "RAG Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Process Document Text": {
      "ai_document": [
        [
          {
            "node": "Store in Vector Database",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Load Documents Trigger": {
      "main": [
        [
          {
            "node": "Download PDF from Drive",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download PDF from Drive": {
      "main": [
        [
          {
            "node": "Extract PDF Content",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

高级 - 内部知识库, AI RAG 检索增强

需要付费吗?

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

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

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

外部链接
在 n8n.io 查看

分享此工作流