8
n8n 中文网amn8n.com

基础 RAG 聊天

中级

这是一个Support, Building Blocks, AI领域的自动化工作流,包含 14 个节点。主要使用 ManualTrigger, ReadWriteFile, LmChatGroq, ChatTrigger, ChainRetrievalQa 等节点,结合人工智能技术实现智能自动化。 基础 RAG 聊天

前置要求
  • AI 服务 API Key(如 OpenAI、Anthropic 等)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "nodes": [
    {
      "id": "3bc2f88b-c14e-4ee5-84ce-dc16a54aa12b",
      "name": "递归字符文本分割器",
      "type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
      "position": [
        -580,
        320
      ],
      "parameters": {
        "options": {
          "splitCode": "markdown"
        },
        "chunkOverlap": 50
      },
      "typeVersion": 1
    },
    {
      "id": "6bd91468-17db-4918-a232-87fb295a30c2",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1240,
        -140
      ],
      "parameters": {
        "color": 7,
        "width": 978.0454109366399,
        "height": 806.6556079800943,
        "content": "### 将数据加载到数据库"
      },
      "typeVersion": 1
    },
    {
      "id": "3af4e8e9-0503-470e-b449-4551191fb405",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        0,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 795.4336844920119,
        "height": 849.4411596574598,
        "content": "### 与数据库聊天"
      },
      "typeVersion": 1
    },
    {
      "id": "6f94ec58-4fca-40ee-a1a0-012998093589",
      "name": "默认数据加载器",
      "type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
      "position": [
        -580,
        200
      ],
      "parameters": {
        "options": {},
        "dataType": "binary"
      },
      "typeVersion": 1
    },
    {
      "id": "3e145342-458d-4222-a707-9fee78e91c4d",
      "name": "问答链",
      "type": "@n8n/n8n-nodes-langchain.chainRetrievalQa",
      "position": [
        60,
        -20
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "7f2b288a-a002-4cd3-93c0-b2a0e491699c",
      "name": "向量存储检索器",
      "type": "@n8n/n8n-nodes-langchain.retrieverVectorStore",
      "position": [
        240,
        200
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "ca930ba7-b45d-47d8-9f36-9db3a25ee77a",
      "name": "当点击 '测试工作流' 按钮时",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1420,
        -20
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "90782052-5df2-4f1e-84fc-c47095a81852",
      "name": "当点击下面的 '聊天' 按钮时",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -140,
        -20
      ],
      "webhookId": "066b342b-f2b6-401e-b560-12f5d23b6103",
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "712dc9d3-af2d-4436-9315-78f66f748b91",
      "name": "从磁盘读取/写入文件",
      "type": "n8n-nodes-base.readWriteFile",
      "position": [
        -1200,
        -20
      ],
      "parameters": {
        "options": {},
        "fileSelector": "/tmp/external_data/news.txt"
      },
      "typeVersion": 1,
      "alwaysOutputData": true
    },
    {
      "id": "1cd768c1-fcc0-480a-8b33-fbe714788b32",
      "name": "内存向量存储1",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        240,
        380
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "2393e667-7e4f-4392-9a7e-b2b4d74d46e8",
      "name": "内存向量存储",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "position": [
        -980,
        -20
      ],
      "parameters": {
        "mode": "insert",
        "clearStore": true
      },
      "typeVersion": 1
    },
    {
      "id": "e53f51f3-04f3-46ef-aebd-e0b32b415101",
      "name": "嵌入 Cohere",
      "type": "@n8n/n8n-nodes-langchain.embeddingsCohere",
      "position": [
        -940,
        300
      ],
      "parameters": {
        "modelName": "embed-multilingual-v3.0"
      },
      "credentials": {
        "cohereApi": {
          "id": "rXh87ikYuJfDKuCk",
          "name": "CohereApi account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "cf1333b6-b69b-4ff1-bfc3-d3d579585efb",
      "name": "Groq聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "notes": "使用繁體中文",
      "position": [
        100,
        220
      ],
      "parameters": {
        "model": "llama-3.3-70b-versatile",
        "options": {}
      },
      "credentials": {
        "groqApi": {
          "id": "dznjL979E8j0L4Zc",
          "name": "Groq account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e49cfb2e-5eca-4b43-973d-4bf7285b5d94",
      "name": "Cohere 嵌入1",
      "type": "@n8n/n8n-nodes-langchain.embeddingsCohere",
      "position": [
        340,
        560
      ],
      "parameters": {
        "modelName": "embed-multilingual-v3.0"
      },
      "credentials": {
        "cohereApi": {
          "id": "rXh87ikYuJfDKuCk",
          "name": "CohereApi account"
        }
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Question and Answer Chain",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Cohere": {
      "ai_embedding": [
        [
          {
            "node": "In-Memory Vector Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Embeddings Cohere1": {
      "ai_embedding": [
        [
          {
            "node": "In-Memory Vector Store1",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Default Data Loader": {
      "ai_document": [
        [
          {
            "node": "In-Memory Vector Store",
            "type": "ai_document",
            "index": 0
          }
        ]
      ]
    },
    "Vector Store Retriever": {
      "ai_retriever": [
        [
          {
            "node": "Question and Answer Chain",
            "type": "ai_retriever",
            "index": 0
          }
        ]
      ]
    },
    "In-Memory Vector Store1": {
      "ai_vectorStore": [
        [
          {
            "node": "Vector Store Retriever",
            "type": "ai_vectorStore",
            "index": 0
          }
        ]
      ]
    },
    "Read/Write Files from Disk": {
      "main": [
        [
          {
            "node": "In-Memory Vector Store",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Recursive Character Text Splitter": {
      "ai_textSplitter": [
        [
          {
            "node": "Default Data Loader",
            "type": "ai_textSplitter",
            "index": 0
          }
        ]
      ]
    },
    "When clicking 'Chat' button below": {
      "main": [
        [
          {
            "node": "Question and Answer Chain",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking 'Test Workflow' button": {
      "main": [
        [
          {
            "node": "Read/Write Files from Disk",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

中级 - 客户支持, 构建模块, 人工智能

需要付费吗?

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

工作流信息
难度等级
中级
节点数量14
分类3
节点类型11
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

外部链接
在 n8n.io 查看

分享此工作流