8
n8n 中文网amn8n.com

使用Supabase为您的网站构建RAG聊天机器人

高级

这是一个Support Chatbot, AI RAG领域的自动化工作流,包含 18 个节点。主要使用 FormTrigger, HtmlExtract, HttpRequest, ConvertToFile, Agent 等节点。 使用RAG、OpenAI GPT-4o-mini和Supabase向量数据库构建网站问答聊天机器人

前置要求
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
  • PostgreSQL 数据库连接信息
  • Supabase URL 和 API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "klsAKNm0Q07J8RXY",
  "meta": {
    "instanceId": "fcb622cbd5234c565b9b78babeaf0ea2455df9d2aad0d1adff7c1ef99583e685",
    "templateCredsSetupCompleted": true
  },
  "name": "使用 Supabase 为您的网站构建 RAG 聊天机器人",
  "tags": [],
  "nodes": [
    {
      "id": "c2c34da8-27e8-4881-a3fd-3b5f6987e0bf",
      "name": "当收到聊天消息时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        500,
        -580
      ],
      "webhookId": "dec328cc-f47e-4727-b1c5-7370be86a958",
      "parameters": {
        "mode": "webhook",
        "public": true,
        "options": {}
      },
      "typeVersion": 1.1
    },
    {
      "id": "31f5d600-1694-4d50-a581-0880f65a7755",
      "name": "HTML 提取",
      "type": "n8n-nodes-base.htmlExtract",
      "position": [
        -460,
        -540
      ],
      "parameters": {
        "options": {},
        "extractionValues": {
          "values": [
            {
              "key": "title",
              "cssSelector": "title, h1"
            },
            {
              "key": "content",
              "cssSelector": "p, article, .content, .post-content, main"
            },
            {
              "key": "meta_description",
              "attribute": "content",
              "cssSelector": "meta[name='description']",
              "returnValue": "attribute"
            },
            {
              "key": "links",
              "attribute": "href",
              "cssSelector": "a[href]",
              "returnValue": "attribute"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d48d0d67-cfb6-4058-96e2-4198b40650bc",
      "name": "默认数据加载器",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        20,
        -360
      ],
      "parameters": {
        "loader": "jsonLoader",
        "options": {
          "metadata": {
            "metadataValues": [
              {
                "name": "website_url",
                "value": "={{ $('Enter Website Url').item.json['Website Url'] }}"
              }
            ]
          }
        },
        "dataType": "binary"
      },
      "typeVersion": 1
    },
    {
      "id": "32b79786-e8d1-4083-80e9-4d2eada2c46b",
      "name": "递归字符文本分割器",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        120,
        -160
      ],
      "parameters": {
        "options": {},
        "chunkSize": 3000,
        "chunkOverlap": 500
      },
      "typeVersion": 1
    },
    {
      "id": "b7541584-131f-4868-b8dd-053ab509ab1b",
      "name": "Supabase 向量存储",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        -40,
        -540
      ],
      "parameters": {
        "mode": "insert",
        "options": {},
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        },
        "embeddingBatchSize": 100
      },
      "credentials": {
        "supabaseApi": {
          "id": "E3H0gensGX1OYVwU",
          "name": "Supabase account"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "7b923d0f-c803-4b3c-afd8-ee680793c955",
      "name": "输入网站 URL",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -820,
        -540
      ],
      "webhookId": "b02a5096-11b0-4677-acfa-fcac5722498c",
      "parameters": {
        "options": {},
        "formTitle": "Form",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Website Url",
              "placeholder": "Enter Website Url"
            }
          ]
        },
        "formDescription": "Enter Website Url"
      },
      "typeVersion": 2.2
    },
    {
      "id": "9e961fc5-b937-4f0e-b9f5-8ada4f3598f5",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -180,
        -680
      ],
      "parameters": {
        "color": 3,
        "width": 520,
        "height": 100,
        "content": "## 从网站内容生成嵌入"
      },
      "typeVersion": 1
    },
    {
      "id": "7f4feec8-62a8-47a0-a8d6-9bce01261b1a",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        380,
        -680
      ],
      "parameters": {
        "width": 300,
        "height": 80,
        "content": "## 用户发起的问题"
      },
      "typeVersion": 1
    },
    {
      "id": "1c11199e-d217-4f2d-8afe-913f902ef47c",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        700,
        -680
      ],
      "parameters": {
        "color": 3,
        "width": 540,
        "height": 80,
        "content": "## 基于向量的答案检索"
      },
      "typeVersion": 1
    },
    {
      "id": "ddb37d99-4e8d-4eef-83da-6b3088360062",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -840,
        -680
      ],
      "parameters": {
        "width": 640,
        "height": 100,
        "content": "## 网站数据提取"
      },
      "typeVersion": 1
    },
    {
      "id": "eeffcae9-2e9c-48f2-ad13-2b75b7218fe2",
      "name": "网站数据抓取",
      "type": "n8n-nodes-base.httpRequest",
      "maxTries": 3,
      "position": [
        -640,
        -540
      ],
      "parameters": {
        "url": "={{ $json['Website Url'] }}",
        "options": {
          "timeout": 30000,
          "redirect": {
            "redirect": {
              "maxRedirects": 5
            }
          }
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.1
    },
    {
      "id": "df8e6032-41f2-4f95-8906-7150ce565d8a",
      "name": "转换为文件",
      "type": "n8n-nodes-base.convertToFile",
      "position": [
        -320,
        -540
      ],
      "parameters": {
        "options": {},
        "operation": "toJson"
      },
      "typeVersion": 1.1
    },
    {
      "id": "697c29c6-6bcd-4748-a874-3c754f9b034e",
      "name": "嵌入 Cohere",
      "type": "@n8n/n8n-nodes-langchain.embeddingsCohere",
      "position": [
        -100,
        -360
      ],
      "parameters": {},
      "credentials": {
        "cohereApi": {
          "id": "5VhbvbDzLliD5nO9",
          "name": "CohereApi account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d8d3a79a-1ac2-42dd-b383-e39bbcbded75",
      "name": "问答检索",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        820,
        -580
      ],
      "parameters": {
        "options": {
          "systemMessage": "=# Overview  \nYou are an AI agent that responds strictly using information from stored document embeddings in a supabase vector store.  \n\n## Context  \n- The agent is designed to provide accurate, document-based answers.  \n- It must avoid using external knowledge or assumptions.  \n\n## Instructions  \n1. Analyze the user's question.  \n2. Retrieve relevant content from the document embeddings using supabase.  \n3. Construct a response only from the matching document chunks.\n## Tools  \n- Vector store containing embedded documents\n- Embeddings Cohere  \n\n## SOP (Standard Operating Procedure)  \n1. Receive user query.  \n2. Search the vector store for relevant document chunks.  \n3. Extract and synthesize an answer using only that content.  \n4. If no matches, issue fallback message.  \n\n## Final Notes  \n- Do not rely on prior training or external facts.  \n- The response must remain strictly grounded in the documents.  "
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "65d51d86-cae3-4cdb-9d95-025962195953",
      "name": "来自 Supabase Vector Store 的数据",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreSupabase",
      "position": [
        1000,
        -360
      ],
      "parameters": {
        "mode": "retrieve-as-tool",
        "topK": null,
        "options": {},
        "toolName": "documents_knowledge_base",
        "tableName": {
          "__rl": true,
          "mode": "list",
          "value": "documents",
          "cachedResultName": "documents"
        },
        "toolDescription": "work with documents data in Supabase vector store",
        "includeDocumentMetadata": false
      },
      "credentials": {
        "supabaseApi": {
          "id": "E3H0gensGX1OYVwU",
          "name": "Supabase account"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "6ef28803-e21f-4733-a6a9-d894b97dbb35",
      "name": "使用 Cohere 嵌入",
      "type": "@n8n/n8n-nodes-langchain.embeddingsCohere",
      "position": [
        1020,
        -140
      ],
      "parameters": {},
      "credentials": {
        "cohereApi": {
          "id": "5VhbvbDzLliD5nO9",
          "name": "CohereApi account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4796d1f3-ab76-4ed4-86b3-96bca2aae4e9",
      "name": "聊天记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryPostgresChat",
      "position": [
        900,
        -320
      ],
      "parameters": {
        "tableName": "chat_memory",
        "contextWindowLength": 3
      },
      "credentials": {
        "postgres": {
          "id": "lf7D6rk7s95k7I12",
          "name": "Postgres account 2"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "2ce21a19-e586-4cc6-88ed-b1957b04a06a",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        760,
        -340
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "FWzCPYhm2kVkOjE5",
          "name": "OpenAi account 7"
        }
      },
      "typeVersion": 1.2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "1fe65722-2127-4e4c-8af6-d8c967259653",
  "connections": {
    "Chat Memory": {
      "ai_memory": [
        [
          {
            "node": "Question & Answer Retrieve",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "HTML Extract": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Cohere": {
      "ai_embedding": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Enter Website Url": {
      "main": [
        [
          {
            "node": "Website Data Scrapping",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Modell": {
      "ai_languageModel": [
        [
          {
            "node": "Question & Answer Retrieve",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "Supabase Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings With Cohere": {
      "ai_embedding": [
        [
          {
            "node": "Data From Supabase Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Website Data Scrapping": {
      "main": [
        [
          {
            "node": "HTML Extract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "Question & Answer Retrieve",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Data From Supabase Vector Store": {
      "ai_tool": [
        [
          {
            "node": "Question & Answer Retrieve",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

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

需要付费吗?

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

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

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

作者
InfyOm Technologies

InfyOm Technologies

@infyom

We are an AI Automation Agency focusing on various AI Automation Services like, workflow automation, shopify automation, chatbot developerment, custom ai agent development and more.

外部链接
在 n8n.io 查看

分享此工作流