RAG AI Agent with Milvus and Cohere
工作流概述
这是一个包含14个节点的复杂工作流,主要用于自动化处理各种任务。
工作流源代码
{
"id": "2Eba0OHGtOmoTWOU",
"meta": {
"instanceId": "9219ebc7795bea866f70aa3d977d54417fdf06c41944be95e20cfb60f992db19",
"templateCredsSetupCompleted": true
},
"name": "RAG AI Agent with Milvus and Cohere",
"tags": [
{
"id": "yj7cF3GCsZiargFT",
"name": "rag",
"createdAt": "2025-05-03T17:14:30.099Z",
"updatedAt": "2025-05-03T17:14:30.099Z"
}
],
"nodes": [
{
"id": "361065cc-edbf-47da-8da7-c59b564db6f3",
"name": "Default Data Loader",
"type": "@n8n/n8n-nodes-langchain.documentDefaultDataLoader",
"position": [
0,
320
],
"parameters": {
"options": {}
},
"typeVersion": 1
},
{
"id": "a01b9512-ced1-4e28-a2aa-88077ab79d9a",
"name": "Embeddings Cohere",
"type": "@n8n/n8n-nodes-langchain.embeddingsCohere",
"position": [
-140,
320
],
"parameters": {
"modelName": "embed-multilingual-v3.0"
},
"credentials": {
"cohereApi": {
"id": "8gcYMleu1b8Hm03D",
"name": "CohereApi account"
}
},
"typeVersion": 1
},
{
"id": "1da6ea4b-de88-44d3-a215-78c55b5592a2",
"name": "When chat message received",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
-800,
520
],
"webhookId": "a4257301-3fb9-4b9d-a965-1fa66f314696",
"parameters": {
"options": {}
},
"typeVersion": 1.1
},
{
"id": "23004477-3f6d-4909-a626-0eba0557a5bd",
"name": "Watch New Files",
"type": "n8n-nodes-base.googleDriveTrigger",
"position": [
-800,
100
],
"parameters": {
"event": "fileCreated",
"options": {},
"pollTimes": {
"item": [
{
"mode": "everyMinute"
}
]
},
"triggerOn": "specificFolder",
"folderToWatch": {
"__rl": true,
"mode": "list",
"value": "15gjDQZiHZuBeVscnK8Ic_kIWt3mOaVfs",
"cachedResultUrl": "https://drive.google.com/drive/folders/15gjDQZiHZuBeVscnK8Ic_kIWt3mOaVfs",
"cachedResultName": "RAG template"
}
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "r1DVmNxwkIL8JO17",
"name": "Google Drive account"
}
},
"typeVersion": 1
},
{
"id": "001fbdbe-dfcb-4552-bf09-de416b253389",
"name": "Download New",
"type": "n8n-nodes-base.googleDrive",
"position": [
-580,
100
],
"parameters": {
"fileId": {
"__rl": true,
"mode": "id",
"value": "={{ $json.id }}"
},
"options": {},
"operation": "download"
},
"credentials": {
"googleDriveOAuth2Api": {
"id": "r1DVmNxwkIL8JO17",
"name": "Google Drive account"
}
},
"typeVersion": 3
},
{
"id": "c1116cba-beb9-4d28-843d-c5c21c0643de",
"name": "Insert into Milvus",
"type": "@n8n/n8n-nodes-langchain.vectorStoreMilvus",
"position": [
-124,
100
],
"parameters": {
"mode": "insert",
"options": {
"clearCollection": false
},
"milvusCollection": {
"__rl": true,
"mode": "list",
"value": "collectionName",
"cachedResultName": "collectionName"
}
},
"credentials": {
"milvusApi": {
"id": "Gpsxqr2l9Qxu48h0",
"name": "Milvus account"
}
},
"typeVersion": 1.1
},
{
"id": "2dbc7139-46f6-41d8-8c13-9fafad5aec55",
"name": "RAG Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-540,
520
],
"parameters": {
"options": {}
},
"typeVersion": 1.8
},
{
"id": "a103506e-9019-41f2-9b0d-9b831434c9e9",
"name": "Retrieve from Milvus",
"type": "@n8n/n8n-nodes-langchain.vectorStoreMilvus",
"position": [
-340,
740
],
"parameters": {
"mode": "retrieve-as-tool",
"topK": 10,
"toolName": "vector_store",
"toolDescription": "You are an AI agent that responds based on information received from a vector database.",
"milvusCollection": {
"__rl": true,
"mode": "list",
"value": "collectionName",
"cachedResultName": "collectionName"
}
},
"credentials": {
"milvusApi": {
"id": "Gpsxqr2l9Qxu48h0",
"name": "Milvus account"
}
},
"typeVersion": 1.1
},
{
"id": "74ccdff1-b976-4e1c-a2c4-237ffff19e34",
"name": "OpenAI 4o",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-580,
740
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4o",
"cachedResultName": "gpt-4o"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "vupAk5StuhOafQcb",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "36e35eaf-f723-4eeb-9658-143d5bc390a0",
"name": "Memory",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
-460,
740
],
"parameters": {},
"typeVersion": 1.3
},
{
"id": "ec7b6b92-065c-455c-a3f0-17586d9e48d7",
"name": "Cohere embeddings",
"type": "@n8n/n8n-nodes-langchain.embeddingsCohere",
"position": [
-220,
900
],
"parameters": {
"modelName": "embed-multilingual-v3.0"
},
"credentials": {
"cohereApi": {
"id": "8gcYMleu1b8Hm03D",
"name": "CohereApi account"
}
},
"typeVersion": 1
},
{
"id": "3c3a8900-0b98-4479-8602-16b21e011ba1",
"name": "Set Chunks",
"type": "@n8n/n8n-nodes-langchain.textSplitterRecursiveCharacterTextSplitter",
"position": [
80,
480
],
"parameters": {
"options": {},
"chunkSize": 700,
"chunkOverlap": 60
},
"typeVersion": 1
},
{
"id": "3a43bf1a-7e22-4b5e-bbb1-6bb2c1798c07",
"name": "Extract from File",
"type": "n8n-nodes-base.extractFromFile",
"position": [
-360,
100
],
"parameters": {
"options": {},
"operation": "pdf"
},
"typeVersion": 1
},
{
"id": "e0c9d4d7-5e3e-4e47-bb1f-dbdca360b20a",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1440,
120
],
"parameters": {
"color": 2,
"width": 540,
"height": 600,
"content": "## Why Milvus
Based on comparisons and user feedback, **Milvus is often considered a more performant and scalable vector database solution compared to Supabase**, particularly for demanding use cases involving large datasets, high-volume vector search operations, and multilingual support.
### Requirements
- Create an account on [Zilliz](https://zilliz.com/) to generate the Milvus cluster.
- There is no need to create docker containers or your own instance, Zilliz provides the cloud infraestructure to build it easily
- Get your credentials ready from Drive, Milvus (Zilliz), and [Cohere](https://cohere.com)
### Usage
Every time a new pdf is added into the Drive folder, it will be inserted into the Milvus Vector Store, allowing for the interaction with the RAG agent in seconds.
## Calculate your company's RAG costs
Want to run Milvus on your own server on n8n? Zilliz provides a great [cost calculator](https://zilliz.com/rag-cost-calculator/)
### Get in touch with us
Want to implement a RAG AI agent for your company? [Shoot us a message](https://1node.ai)
"
},
"typeVersion": 1
}
],
"active": true,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "8b5fc2b8-50f7-425c-8fc8-94ba4f76ecf3",
"connections": {
"Memory": {
"ai_memory": [
[
{
"node": "RAG Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"OpenAI 4o": {
"ai_languageModel": [
[
{
"node": "RAG Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Set Chunks": {
"ai_textSplitter": [
[
{
"node": "Default Data Loader",
"type": "ai_textSplitter",
"index": 0
}
]
]
},
"Download New": {
"main": [
[
{
"node": "Extract from File",
"type": "main",
"index": 0
}
]
]
},
"Watch New Files": {
"main": [
[
{
"node": "Download New",
"type": "main",
"index": 0
}
]
]
},
"Cohere embeddings": {
"ai_embedding": [
[
{
"node": "Retrieve from Milvus",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Embeddings Cohere": {
"ai_embedding": [
[
{
"node": "Insert into Milvus",
"type": "ai_embedding",
"index": 0
}
]
]
},
"Extract from File": {
"main": [
[
{
"node": "Insert into Milvus",
"type": "main",
"index": 0
}
]
]
},
"Default Data Loader": {
"ai_document": [
[
{
"node": "Insert into Milvus",
"type": "ai_document",
"index": 0
}
]
]
},
"Retrieve from Milvus": {
"ai_tool": [
[
{
"node": "RAG Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "RAG Agent",
"type": "main",
"index": 0
}
]
]
}
}
}
功能特点
- 自动检测新邮件
- AI智能内容分析
- 自定义分类规则
- 批量处理能力
- 详细的处理日志
技术分析
节点类型及作用
- @N8N/N8N Nodes Langchain.Documentdefaultdataloader
- @N8N/N8N Nodes Langchain.Embeddingscohere
- @N8N/N8N Nodes Langchain.Chattrigger
- Googledrivetrigger
- Googledrive
复杂度评估
配置难度:
维护难度:
扩展性:
实施指南
前置条件
- 有效的Gmail账户
- n8n平台访问权限
- Google API凭证
- AI分类服务订阅
配置步骤
- 在n8n中导入工作流JSON文件
- 配置Gmail节点的认证信息
- 设置AI分类器的API密钥
- 自定义分类规则和标签映射
- 测试工作流执行
- 配置定时触发器(可选)
关键参数
| 参数名称 | 默认值 | 说明 |
|---|---|---|
| maxEmails | 50 | 单次处理的最大邮件数量 |
| confidenceThreshold | 0.8 | 分类置信度阈值 |
| autoLabel | true | 是否自动添加标签 |
最佳实践
优化建议
- 定期更新AI分类模型以提高准确性
- 根据邮件量调整处理批次大小
- 设置合理的分类置信度阈值
- 定期清理过期的分类规则
安全注意事项
- 妥善保管API密钥和认证信息
- 限制工作流的访问权限
- 定期审查处理日志
- 启用双因素认证保护Gmail账户
性能优化
- 使用增量处理减少重复工作
- 缓存频繁访问的数据
- 并行处理多个邮件分类任务
- 监控系统资源使用情况
故障排除
常见问题
邮件未被正确分类
检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。
Gmail认证失败
确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。
调试技巧
- 启用详细日志记录查看每个步骤的执行情况
- 使用测试邮件验证分类逻辑
- 检查网络连接和API服务状态
- 逐步执行工作流定位问题节点
错误处理
工作流包含以下错误处理机制:
- 网络超时自动重试(最多3次)
- API错误记录和告警
- 处理失败邮件的隔离机制
- 异常情况下的回滚操作