8
n8n 中文网amn8n.com

使用Google Drive、OpenAI和Pinecone Assistant的RAG文档聊天

高级

这是一个Internal Wiki, AI RAG领域的自动化工作流,包含 18 个节点。主要使用 Set, Wait, Switch, GoogleDrive, HttpRequest 等节点。 使用Google Drive、OpenAI和Pinecone Assistant的RAG文档聊天

前置要求
  • Google Drive API 凭证
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "6ae6d27e57788e6797af2bf16734f2cac83ad4b8f8ebbf57445f55ef5d3a52da",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "42bb3e3b-1636-46e2-958e-64af75fade80",
      "name": "上传文件到助手",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1456,
        -512
      ],
      "parameters": {
        "url": "=https://prod-1-data.ke.pinecone.io/assistant/files/n8n-assistant",
        "method": "POST",
        "options": {},
        "sendBody": true,
        "sendQuery": true,
        "contentType": "multipart-form-data",
        "authentication": "predefinedCredentialType",
        "bodyParameters": {
          "parameters": [
            {
              "name": "file",
              "parameterType": "formBinaryData",
              "inputDataFieldName": "data"
            }
          ]
        },
        "queryParameters": {
          "parameters": [
            {
              "name": "metadata",
              "value": "={\n  \"external_file_id\": \"{{ $json.id }}\",\n  \"external_file_name\": \"{{ $json.name }}\"\n}"
            }
          ]
        },
        "nodeCredentialType": "pineconeApi"
      },
      "credentials": {
        "pineconeApi": {
          "id": "pBm0ARHJdLXfTUXe",
          "name": "Pinecone"
        },
        "httpHeaderAuth": {
          "id": "GvkhUuYna3y7p9e8",
          "name": "Pinecone API key - HTTP"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "df16c93e-d136-470e-981d-2c0cb0b8c75d",
      "name": "下载文件",
      "type": "n8n-nodes-base.googleDrive",
      "position": [
        1264,
        -512
      ],
      "parameters": {
        "fileId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.id }}"
        },
        "options": {
          "fileName": "={{ $json.name }}"
        },
        "operation": "download"
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "jfHLEN7hcvGOLbW5",
          "name": "Google Drive account"
        }
      },
      "typeVersion": 3
    },
    {
      "id": "6b6b8e41-79a0-48a8-a8cc-077abb4e9593",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        880,
        400
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 2.2
    },
    {
      "id": "a42a4cf7-abb2-4be4-a1b8-2bd8e12603c6",
      "name": "OpenAI 聊天模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        816,
        624
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "gv5VN25jRLU7YkML",
          "name": "OpenAI"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4e8f58d3-9867-4783-9d6a-c3698fa67df9",
      "name": "从助手删除文件",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        848,
        -224
      ],
      "parameters": {
        "url": "=https://prod-1-data.ke.pinecone.io/assistant/files/n8n-assistant/{{ $json.files[0].id }}",
        "method": "DELETE",
        "options": {
          "response": {
            "response": {
              "responseFormat": "text"
            }
          }
        },
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "pineconeApi"
      },
      "credentials": {
        "pineconeApi": {
          "id": "pBm0ARHJdLXfTUXe",
          "name": "Pinecone"
        },
        "httpHeaderAuth": {
          "id": "GvkhUuYna3y7p9e8",
          "name": "Pinecone API key - HTTP"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "a1bee741-f334-4348-8364-70d078da2bb0",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        368,
        -608
      ],
      "parameters": {
        "color": 7,
        "width": 1776,
        "height": 640,
        "content": "## 1. 从 Google Drive 添加新文件或更新文件到 Pinecone Assistant"
      },
      "typeVersion": 1
    },
    {
      "id": "61a18380-76af-4e1c-af56-3c80cd1ddc95",
      "name": "文件已更新",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        448,
        -224
      ],
      "parameters": {
        "event": "fileUpdated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": "n8n-pinecone-demo"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "jfHLEN7hcvGOLbW5",
          "name": "Google Drive account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "af09de5a-495e-489e-9d05-1b434d4500d6",
      "name": "文件已添加",
      "type": "n8n-nodes-base.googleDriveTrigger",
      "position": [
        432,
        -512
      ],
      "parameters": {
        "event": "fileCreated",
        "options": {},
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "triggerOn": "specificFolder",
        "folderToWatch": {
          "__rl": true,
          "mode": "list",
          "value": "",
          "cachedResultUrl": "",
          "cachedResultName": "n8n-pinecone-demo"
        }
      },
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "jfHLEN7hcvGOLbW5",
          "name": "Google Drive account"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "245b7f1d-66c5-4f96-acd9-14d75fe5b4a0",
      "name": "获取要删除的文件",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        656,
        -224
      ],
      "parameters": {
        "url": "https://prod-1-data.ke.pinecone.io/assistant/files/n8n-assistant",
        "options": {},
        "sendQuery": true,
        "authentication": "predefinedCredentialType",
        "queryParameters": {
          "parameters": [
            {
              "name": "filter",
              "value": "={\n  \"external_file_id\": \"{{ $json.id }}\"\n}"
            }
          ]
        },
        "nodeCredentialType": "pineconeApi"
      },
      "credentials": {
        "pineconeApi": {
          "id": "pBm0ARHJdLXfTUXe",
          "name": "Pinecone"
        },
        "httpHeaderAuth": {
          "id": "GvkhUuYna3y7p9e8",
          "name": "Pinecone API key - HTTP"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "b646d256-1ac7-452c-aa5e-a15cf7c6bee1",
      "name": "设置文件数据",
      "type": "n8n-nodes-base.set",
      "position": [
        1040,
        -224
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "={\n  \"id\": \"{{ $('File updated').item.json.id }}\",\n  \"name\": \"{{ $('File updated').item.json.name }}\"\n}\n"
      },
      "typeVersion": 3.4
    },
    {
      "id": "8b073801-e2c5-48ec-adba-d80ee4634399",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        368,
        160
      ],
      "parameters": {
        "color": 7,
        "width": 1344,
        "height": 640,
        "content": "## 2. 与您的文档聊天"
      },
      "typeVersion": 1
    },
    {
      "id": "2774dcc8-f067-4a81-bfa6-7559c93c3320",
      "name": "聊天输入",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        512,
        400
      ],
      "webhookId": "1bdcb9d4-a367-4d25-9405-ab765e595bf4",
      "parameters": {
        "options": {}
      },
      "typeVersion": 1.3
    },
    {
      "id": "8c2465d8-1dda-462e-9e85-42dc299cb32c",
      "name": "Pinecone Assistant",
      "type": "@n8n/n8n-nodes-langchain.mcpClientTool",
      "position": [
        1216,
        640
      ],
      "parameters": {
        "options": {},
        "endpointUrl": "https://prod-1-data.ke.pinecone.io/mcp/assistants/n8n-assistant",
        "authentication": "bearerAuth",
        "serverTransport": "httpStreamable"
      },
      "credentials": {
        "httpBearerAuth": {
          "id": "8w7bFCA8t1S9UJgx",
          "name": "Pinecone Bearer (n8n-demo)"
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "2df456a3-331e-42ee-9f70-582e72d83e6f",
      "name": "便签7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        -608
      ],
      "parameters": {
        "width": 636,
        "height": 1408,
        "content": "## 试用"
      },
      "typeVersion": 1
    },
    {
      "id": "0e6c99c7-b606-49e2-8360-103364ab22d0",
      "name": "检查文件状态",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        1504,
        -224
      ],
      "parameters": {
        "url": "=https://prod-1-data.ke.pinecone.io/assistant/files/n8n-assistant/{{ $json.id }}",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "pineconeApi"
      },
      "credentials": {
        "pineconeApi": {
          "id": "pBm0ARHJdLXfTUXe",
          "name": "Pinecone"
        },
        "httpHeaderAuth": {
          "id": "GvkhUuYna3y7p9e8",
          "name": "Pinecone API key - HTTP"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "81b56a1e-ae46-4457-aaea-7dc5f8259d69",
      "name": "等待",
      "type": "n8n-nodes-base.wait",
      "position": [
        1952,
        -224
      ],
      "webhookId": "67aeb741-7264-44d9-af9d-a349d1d32eac",
      "parameters": {
        "amount": 3
      },
      "typeVersion": 1.1
    },
    {
      "id": "08870689-0537-49ab-9a12-07b4719f0500",
      "name": "如果状态为可用则结束",
      "type": "n8n-nodes-base.switch",
      "position": [
        1696,
        -224
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Available",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "7d41378e-7b21-4dbf-8586-f027b3f57d91",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "Available"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Processing",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "5d7d1c72-0fdc-4258-ae0f-045f58c37242",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.status }}",
                    "rightValue": "Processing"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.3
    },
    {
      "id": "a743300c-c238-47ce-8c5b-fa266b0eb26d",
      "name": "对话记忆",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        976,
        656
      ],
      "parameters": {},
      "typeVersion": 1.3
    }
  ],
  "pinData": {},
  "connections": {
    "Wait": {
      "main": [
        [
          {
            "node": "Check file status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat input": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File added": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "File updated": {
      "main": [
        [
          {
            "node": "Get file to delete",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download file": {
      "main": [
        [
          {
            "node": "Upload file to assistant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set file data": {
      "main": [
        [
          {
            "node": "Download file",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check file status": {
      "main": [
        [
          {
            "node": "End if status Available",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Get file to delete": {
      "main": [
        [
          {
            "node": "Delete file from assistant",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pinecone Assistant": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Conversation Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "End if status Available": {
      "main": [
        [],
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Upload file to assistant": {
      "main": [
        [
          {
            "node": "Check file status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delete file from assistant": {
      "main": [
        [
          {
            "node": "Set file data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

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

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

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

需要付费吗?

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

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

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

作者
Pinecone

Pinecone

@pinecone

Helping you build knowledgeable AI.

外部链接
在 n8n.io 查看

分享此工作流