{
  "name": "Evaluate AI agent response correctness with OpenAI and RAGAS methodology",
  "nodes": [
    {
      "id": "20985bbf-3a4f-4e7c-8c7d-4d4bee4e1eaa",
      "name": "Correctness Classifier",
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "position": [
        340,
        -320
      ]
    },
    {
      "id": "d40a51d3-6ea0-4a16-b094-7862c061904f",
      "name": "Examples1",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        520,
        -140
      ]
    },
    {
      "id": "32195796-6f39-47e1-b531-c7583a4bfc2d",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        340,
        -140
      ]
    },
    {
      "id": "23186242-a4e5-4e70-a010-acbfa2eafb35",
      "name": "OpenAI Chat Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -752,
        50
      ]
    },
    {
      "id": "2e6b4d45-f0e0-434a-92bb-c76bf96588ad",
      "name": "When fetching a dataset row",
      "type": "n8n-nodes-base.evaluationTrigger",
      "position": [
        -1280,
        -270
      ]
    },
    {
      "id": "9d8b8b85-819a-4762-a573-4e4f50f3c2ba",
      "name": "Remap Input",
      "type": "n8n-nodes-base.set",
      "position": [
        -1060,
        -270
      ]
    },
    {
      "id": "781b1a23-0359-46ab-bf8e-c86b1bcc0cf9",
      "name": "Evaluation",
      "type": "n8n-nodes-base.evaluation",
      "position": [
        -464,
        -170
      ]
    },
    {
      "id": "7f8623d7-4263-45f2-a2f1-dcb07dc17c90",
      "name": "Set Input Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        -244,
        -320
      ]
    },
    {
      "id": "a126142b-bd50-48fb-ab3d-e20fea082dc7",
      "name": "No Operation, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -244,
        -70
      ]
    },
    {
      "id": "b896a963-5fe8-4566-9f11-9c963d93e467",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -840,
        -170
      ]
    },
    {
      "id": "526b0248-d81b-428f-8f02-aa69acebd05c",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -1060,
        -70
      ]
    },
    {
      "id": "acd7d0aa-00fa-4d9d-9995-f468e1f4770a",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        1220,
        -320
      ]
    },
    {
      "id": "a183f7f7-0071-42ae-a17d-fc7b087f0f49",
      "name": "Calculate F1 Score",
      "type": "n8n-nodes-base.code",
      "position": [
        980,
        -320
      ]
    },
    {
      "id": "cd961c4b-170d-46dc-9aa2-128eb4b1ffe7",
      "name": "Correctness Score",
      "type": "n8n-nodes-base.code",
      "position": [
        1400,
        -320
      ]
    },
    {
      "id": "4a6f9201-8c09-4210-9322-bd14bd86d4fd",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1352,
        -530
      ],
      "parameters": {
        "width": 840,
        "height": 720,
        "content": "## 1. Setup Your AI Workflow to Use Evaluations\n[Learn more about the Evaluations Trigger](https://docs.n8n.io/integrations/builtin/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&u"
      }
    },
    {
      "id": "4be720d8-8a34-4f8d-a27a-04302542a2cc",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -500,
        -900
      ],
      "parameters": {
        "width": 2480,
        "height": 1100,
        "content": "## 2. Answer Correctness: Is the agent getting its facts correct?\n[Learn more about the Evaluations Trigger](https://docs.n8n.io/integrations/builtin/?utm_source=n8n_app&utm_medium=node_settings_modal"
      }
    },
    {
      "id": "2b3fe36c-4af9-4dec-bf0d-e9b6fe0386fb",
      "name": "Update Metrics",
      "type": "n8n-nodes-base.evaluation",
      "position": [
        1800,
        -320
      ]
    },
    {
      "id": "2c3b928e-db4c-42b7-b530-34ad3f6a1a04",
      "name": "Update Outputs",
      "type": "n8n-nodes-base.evaluation",
      "position": [
        1600,
        -320
      ]
    },
    {
      "id": "9de68866-994d-455e-af12-fb608a75341d",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1840,
        -600
      ],
      "parameters": {
        "width": 440,
        "height": 800,
        "content": "## Try It Out!\n### This n8n template demonstrates how to calculate the evaluation metric \"Correctness\" which in this scenario, measures the compares and classifies the agent's response against a set o"
      }
    },
    {
      "id": "5d3cbd9f-7cd9-4ff9-851c-e0b5b352302e",
      "name": "Get Embeddings",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        180,
        -500
      ]
    },
    {
      "id": "1da5f360-0e0f-4643-8236-8f55cc343655",
      "name": "GroundTruth to Items",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -20,
        -500
      ]
    },
    {
      "id": "e3c0673d-e80a-4f6f-a061-a9d92bfbb082",
      "name": "Get Embeddings1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        180,
        -680
      ]
    },
    {
      "id": "70688754-a777-464c-8b3b-f216018438e9",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        580,
        -500
      ]
    },
    {
      "id": "1b91219c-0e7a-4843-8f37-ee0160af2d2d",
      "name": "Remap Embeddings",
      "type": "n8n-nodes-base.set",
      "position": [
        380,
        -680
      ]
    },
    {
      "id": "d6844754-380d-4610-984e-a16042a9e239",
      "name": "Remap Embeddings1",
      "type": "n8n-nodes-base.set",
      "position": [
        380,
        -500
      ]
    },
    {
      "id": "8759c3ab-4d72-46f9-b969-339aba79b34f",
      "name": "Create Embeddings Result",
      "type": "n8n-nodes-base.merge",
      "position": [
        780,
        -500
      ]
    },
    {
      "id": "3acb5098-2703-4474-86da-d96f76350936",
      "name": "Calculate Similarity Score",
      "type": "n8n-nodes-base.code",
      "position": [
        980,
        -500
      ]
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Correctness Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Evaluation",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "Create Embeddings Result",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Examples1": {
      "ai_outputParser": [
        [
          {
            "node": "Correctness Classifier",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    },
    "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
          }
        ]
      ]
    },
    "Get Embeddings": {
      "main": [
        [
          {
            "node": "Remap Embeddings1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Outputs": {
      "main": [
        [
          {
            "node": "Update Metrics",
            "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": "Correctness Classifier",
            "type": "main",
            "index": 0
          },
          {
            "node": "Get Embeddings1",
            "type": "main",
            "index": 0
          },
          {
            "node": "GroundTruth to Items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Correctness Score": {
      "main": [
        [
          {
            "node": "Update Outputs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Correctness Classifier",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Remap Embeddings1": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate F1 Score": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "OpenAI Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "GroundTruth to Items": {
      "main": [
        [
          {
            "node": "Get Embeddings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Correctness Classifier": {
      "main": [
        [
          {
            "node": "Calculate F1 Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create Embeddings Result": {
      "main": [
        [
          {
            "node": "Calculate Similarity Score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Calculate Similarity Score": {
      "main": [
        [
          {
            "node": "Merge",
            "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
          }
        ]
      ]
    }
  }
}