评估指标:答案相似度
高级
这是一个Engineering、AI领域的自动化工作流,包含 21 个节点。主要使用 Set、Code、Merge、SplitOut、Aggregate 等节点,结合人工智能技术实现智能自动化。 评估指标:答案相似度
前置要求
- •可能需要目标 API 的认证凭证
- •OpenAI API Key
使用的节点 (21 个)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"meta": {
"instanceId": "408f9fb9940c3cb18ffdef0e0150fe342d6e655c3a9fac21f0f644e8bedabcd9"
},
"nodes": [
{
"id": "c5365531-2d66-4e67-9db2-37059e9e97a3",
"name": "OpenAI 聊天模型1",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
-1512,
420
],
"parameters": {
"model": {
"__rl": true,
"mode": "list",
"value": "gpt-4.1-mini",
"cachedResultName": "gpt-4.1-mini"
},
"options": {}
},
"credentials": {
"openAiApi": {
"id": "8gccIjcuf3gvaoEr",
"name": "OpenAi account"
}
},
"typeVersion": 1.2
},
{
"id": "3881b831-b575-4b2f-8ebb-ac956a714f10",
"name": "当获取数据集行时",
"type": "n8n-nodes-base.evaluationTrigger",
"position": [
-2040,
100
],
"parameters": {
"sheetName": {
"__rl": true,
"mode": "list",
"value": 1176192270,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YOnu2JJjlxd787AuYcg-wKbkjyjyZFgASYVV0jsij5Y/edit#gid=1176192270",
"cachedResultName": "Similarity"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1YOnu2JJjlxd787AuYcg-wKbkjyjyZFgASYVV0jsij5Y",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YOnu2JJjlxd787AuYcg-wKbkjyjyZFgASYVV0jsij5Y/edit?usp=drivesdk",
"cachedResultName": "96. Evaluations Test"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "XHvC7jIRR8A2TlUl",
"name": "Google Sheets account"
}
},
"typeVersion": 4.6
},
{
"id": "dd5a14f7-7321-4dfd-9f08-1f35efba1a07",
"name": "重新映射输入",
"type": "n8n-nodes-base.set",
"position": [
-1820,
100
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "00924b90-278f-49f5-80f2-c297df0fcc97",
"name": "chatInput",
"type": "string",
"value": "={{ $json.input }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "78d87631-7d52-4fbb-9313-f47263bd101f",
"name": "评估",
"type": "n8n-nodes-base.evaluation",
"position": [
-1180,
200
],
"parameters": {
"operation": "checkIfEvaluating"
},
"typeVersion": 4.6
},
{
"id": "1d8b12ba-ec63-4f92-a4dc-1885cbcd4d95",
"name": "设置输入字段",
"type": "n8n-nodes-base.set",
"position": [
-960,
100
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "d58952c1-d346-4fbf-881e-d5c04b6781a5",
"name": "question",
"type": "string",
"value": "={{ $('When fetching a dataset row').first().json.input }}"
},
{
"id": "0f10a3d0-cf6e-4715-9ded-2cee54aa62ec",
"name": "answer",
"type": "string",
"value": "={{ $json.output }}"
},
{
"id": "edbe42ed-36a7-438a-989f-900673e61d0f",
"name": "groundTruth",
"type": "array",
"value": "={{ $('When fetching a dataset row').first().json['ground truth'].split('\\n') }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "518cecea-9bcc-47dd-83b1-73ef0880e808",
"name": "无操作,不执行任何操作",
"type": "n8n-nodes-base.noOp",
"position": [
-960,
300
],
"parameters": {},
"typeVersion": 1
},
{
"id": "c1a9cf2f-8e5d-4db9-a29b-b426e1932ab3",
"name": "AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
-1600,
200
],
"parameters": {
"options": {}
},
"typeVersion": 2
},
{
"id": "6c5602d1-59c0-479e-b9aa-fb8ce037d4b1",
"name": "当收到聊天消息时",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
-1820,
300
],
"webhookId": "ba1fadeb-b566-469a-97b3-3159a99f1805",
"parameters": {
"options": {}
},
"typeVersion": 1.1
},
{
"id": "6fb01095-7b93-41dd-8d7c-364cb685ddbb",
"name": "更新输出",
"type": "n8n-nodes-base.evaluation",
"position": [
520,
300
],
"parameters": {
"outputs": {
"values": [
{
"outputName": "output",
"outputValue": "={{ $('Set Input Fields').item.json.answer }}"
},
{
"outputName": "score",
"outputValue": "={{ $json.score }}"
}
]
},
"sheetName": {
"__rl": true,
"mode": "list",
"value": 1176192270,
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YOnu2JJjlxd787AuYcg-wKbkjyjyZFgASYVV0jsij5Y/edit#gid=1176192270",
"cachedResultName": "Similarity"
},
"documentId": {
"__rl": true,
"mode": "list",
"value": "1YOnu2JJjlxd787AuYcg-wKbkjyjyZFgASYVV0jsij5Y",
"cachedResultUrl": "https://docs.google.com/spreadsheets/d/1YOnu2JJjlxd787AuYcg-wKbkjyjyZFgASYVV0jsij5Y/edit?usp=drivesdk",
"cachedResultName": "96. Evaluations Test"
}
},
"credentials": {
"googleSheetsOAuth2Api": {
"id": "XHvC7jIRR8A2TlUl",
"name": "Google Sheets account"
}
},
"typeVersion": 4.6
},
{
"id": "18e8dbb6-df98-4d36-9686-9ec481a37754",
"name": "更新指标",
"type": "n8n-nodes-base.evaluation",
"position": [
700,
300
],
"parameters": {
"metrics": {
"assignments": [
{
"id": "1fd7759c-f4ef-4eda-87ad-9d9563b63e99",
"name": "score",
"type": "number",
"value": "={{ $json.score }}"
}
]
},
"operation": "setMetrics"
},
"typeVersion": 4.6
},
{
"id": "a685c9e7-0b21-4873-a502-5826a916e31f",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2120,
-120
],
"parameters": {
"color": 7,
"width": 840,
"height": 720,
"content": "## 1. 设置您的 AI 工作流以使用评估"
},
"typeVersion": 1
},
{
"id": "2e57d911-8fef-456d-8e5c-3849350553e1",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
-1240,
-120
],
"parameters": {
"color": 7,
"width": 1700,
"height": 720,
"content": "## 2. 答案相似度:AI 响应与真实答案的相似度如何?"
},
"typeVersion": 1
},
{
"id": "9962bbf8-01bc-463c-ad3b-499618c5b1f9",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-2580,
-120
],
"parameters": {
"width": 420,
"height": 720,
"content": "## 试试看!"
},
"typeVersion": 1
},
{
"id": "47699677-545f-4eca-8b46-89c6862a56f1",
"name": "获取嵌入",
"type": "n8n-nodes-base.httpRequest",
"position": [
-520,
300
],
"parameters": {
"url": "https://api.openai.com/v1/embeddings",
"method": "POST",
"options": {},
"sendBody": true,
"authentication": "predefinedCredentialType",
"bodyParameters": {
"parameters": [
{
"name": "input",
"value": "={{ $json.groundTruth }}"
},
{
"name": "model",
"value": "text-embedding-3-small"
},
{
"name": "encoding_format",
"value": "float"
}
]
},
"nodeCredentialType": "openAiApi"
},
"credentials": {
"openAiApi": {
"id": "8gccIjcuf3gvaoEr",
"name": "OpenAi account"
}
},
"typeVersion": 4.2
},
{
"id": "1a022046-80f2-4df3-b075-be8e9294b951",
"name": "真实答案到项目",
"type": "n8n-nodes-base.splitOut",
"position": [
-720,
300
],
"parameters": {
"options": {},
"fieldToSplitOut": "groundTruth"
},
"typeVersion": 1
},
{
"id": "0cea3a79-23ab-4d0f-9c6c-2522af6a506f",
"name": "获取嵌入向量1",
"type": "n8n-nodes-base.httpRequest",
"position": [
-520,
100
],
"parameters": {
"url": "https://api.openai.com/v1/embeddings",
"method": "POST",
"options": {},
"sendBody": true,
"authentication": "predefinedCredentialType",
"bodyParameters": {
"parameters": [
{
"name": "input",
"value": "={{ $json.answer }}"
},
{
"name": "model",
"value": "text-embedding-3-small"
},
{
"name": "encoding_format",
"value": "float"
}
]
},
"nodeCredentialType": "openAiApi"
},
"credentials": {
"openAiApi": {
"id": "8gccIjcuf3gvaoEr",
"name": "OpenAi account"
}
},
"typeVersion": 4.2
},
{
"id": "1b5740cc-4b79-4690-88ae-fa31c5a1c16c",
"name": "聚合",
"type": "n8n-nodes-base.aggregate",
"position": [
-120,
300
],
"parameters": {
"options": {},
"aggregate": "aggregateAllItemData",
"destinationFieldName": "groundTruth"
},
"typeVersion": 1
},
{
"id": "d32f979b-7d96-4730-8324-de0d34ed659a",
"name": "重新映射嵌入向量",
"type": "n8n-nodes-base.set",
"position": [
-320,
100
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "3db07c98-f926-46e0-85f2-ed1eb137f842",
"name": "answer",
"type": "array",
"value": "={{ $json.data[0].embedding }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "188864fb-3d6a-4c01-9d23-73c731de023d",
"name": "重新映射嵌入向量1",
"type": "n8n-nodes-base.set",
"position": [
-320,
300
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "3db07c98-f926-46e0-85f2-ed1eb137f842",
"name": "data",
"type": "array",
"value": "={{ $json.data[0].embedding }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "5cc6c1c7-240b-4129-b57a-e7d0ef2e72e6",
"name": "创建嵌入向量结果",
"type": "n8n-nodes-base.merge",
"position": [
80,
300
],
"parameters": {
"mode": "combine",
"options": {},
"combineBy": "combineByPosition"
},
"typeVersion": 3.1
},
{
"id": "7aa037d2-31a6-4efe-81b1-26a95c4c6d38",
"name": "计算相似度分数",
"type": "n8n-nodes-base.code",
"position": [
280,
300
],
"parameters": {
"jsCode": "const { answer, groundTruth = [] } = $input.item.json;\n\nconst scores = await Promise.all(groundTruth.map(truth =>\n cosineSimilarity(answer, truth.data)\n));\n\nconst averageScore = scores.reduce((acc,i) => acc + i, 0) / scores.length;\n\nreturn { json: { score: averageScore } };\n\nfunction cosineSimilarity(a, b) { \n let dotProduct = normA = normB = 0;\n for (let i = 0; i < a.length; i++) {\n dotProduct += a[i] * b[i];\n normA += a[i] ** 2;\n normB += b[i] ** 2;\n }\n return dotProduct / (Math.sqrt(normA) * Math.sqrt(normB));\n}"
},
"typeVersion": 2
}
],
"pinData": {},
"connections": {
"AI Agent": {
"main": [
[
{
"node": "Evaluation",
"type": "main",
"index": 0
}
]
]
},
"Aggregate": {
"main": [
[
{
"node": "Create Embeddings Result",
"type": "main",
"index": 1
}
]
]
},
"Evaluation": {
"main": [
[
{
"node": "Set Input Fields",
"type": "main",
"index": 0
}
],
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
},
"Remap Input": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"Update Output": {
"main": [
[
{
"node": "Update Metrics",
"type": "main",
"index": 0
}
]
]
},
"Get Embeddings": {
"main": [
[
{
"node": "Remap Embeddings1",
"type": "main",
"index": 0
}
]
]
},
"Get Embeddings1": {
"main": [
[
{
"node": "Remap Embeddings",
"type": "main",
"index": 0
}
]
]
},
"Remap Embeddings": {
"main": [
[
{
"node": "Create Embeddings Result",
"type": "main",
"index": 0
}
]
]
},
"Set Input Fields": {
"main": [
[
{
"node": "Get Embeddings1",
"type": "main",
"index": 0
},
{
"node": "GroundTruth to Items",
"type": "main",
"index": 0
}
]
]
},
"Remap Embeddings1": {
"main": [
[
{
"node": "Aggregate",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model1": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"GroundTruth to Items": {
"main": [
[
{
"node": "Get Embeddings",
"type": "main",
"index": 0
}
]
]
},
"Create Embeddings Result": {
"main": [
[
{
"node": "Calculate Similarity Score",
"type": "main",
"index": 0
}
]
]
},
"Calculate Similarity Score": {
"main": [
[
{
"node": "Update Output",
"type": "main",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
},
"When fetching a dataset row": {
"main": [
[
{
"node": "Remap Input",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
这是一个高级难度的工作流,适用于Engineering、AI等场景。适合高级用户,包含 16+ 个节点的复杂工作流
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
使用OpenAI和RAGAS方法评估AI代理响应正确性
使用OpenAI和RAGAS方法评估AI代理响应正确性
Set
Code
Merge
+12
27 节点Jimleuk
Engineering
使用OpenAI和余弦相似度评估AI代理响应相关性
使用OpenAI和余弦相似度评估AI代理响应相关性
Set
Code
Evaluation
+9
20 节点Jimleuk
Engineering
使用OpenAI评估RAG响应准确性:文档基础性指标
使用OpenAI评估RAG响应准确性:文档基础性指标
Set
Evaluation
Http Request
+13
25 节点Jimleuk
Engineering
基于Voyage-Context-3嵌入和MongoDB Atlas的文档问答系统
基于Voyage-Context-3嵌入和MongoDB Atlas的文档问答系统
Set
Code
Wait
+18
53 节点Jimleuk
Engineering
使用 n8n、Apify 和 OpenAI o3 自托管 AI 深度研究代理
使用 n8n、Apify 和 OpenAI o3 自托管 AI 深度研究代理
If
Set
Code
+20
87 节点Jimleuk
AI
使用Excel、Outlook和AI的每日新闻简报服务
使用Excel、Outlook和AI的每日新闻简报服务
If
Set
Html
+13
33 节点Jimleuk
AI
工作流信息
难度等级
高级
节点数量21
分类2
节点类型13
作者
Jimleuk
@jimleukFreelance consultant based in the UK specialising in AI-powered automations. I work with select clients tackling their most challenging projects. For business enquiries, send me an email at hello@jimle.uk LinkedIn: https://www.linkedin.com/in/jimleuk/ X/Twitter: https://x.com/jimle_uk
外部链接
在 n8n.io 上查看 →
分享此工作流