你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Retrieval-Augmented 代(RAG)评估程序

重要

本文中标记了“(预览版)”的项目目前为公共预览版。 此预览版未提供服务级别协议,不建议将其用于生产工作负载。 某些功能可能不受支持或者受限。 有关详细信息,请参阅 Microsoft Azure 预览版补充使用条款

注释

本文档引用 Microsoft Foundry (经典) 门户。

🔄如果使用新门户,请切换到 Microsoft Foundry (new) 文档

注释

本文档指 Microsoft Foundry (新) 门户。

Retrieval-Augmented 生成 (RAG) 系统尝试生成与地面文档一致的最相关的答案,以响应用户的查询。 用户的查询在地面文档的语料库中触发搜索检索,以便为 AI 模型提供地面上下文以生成响应。

评估非常重要:

这些评估者侧重于三个方面:

  • 检索结果与用户查询的相关性:如果具有特定于查询的文档相关性的标签,请使用 文档检索 ,或者查询相关性判断(qrels)进行更准确的度量。 如果只有检索的上下文,但没有此类标签,并且对更细粒度的度量具有更高的容忍度,请使用 检索
  • 与基础文档相关的生成的响应的一致性:如果要自定义开源大型语言模型判断(LLM-judge)提示中基础性的定义,请使用 “基础 性”。 如果需要简单的定义,请使用 Groundedness Pro
  • 最终响应与查询的相关性:如果没有基本事实,请使用 相关性 。 如果有基本事实,并且不希望响应错过关键信息,请使用 响应完整性
计算器 最佳做法 使用时 目的 输入 输出
文档检索(预览版) 进程评估 检索质量是 RAG 的瓶颈,并且具有用于调试和参数优化的精确搜索质量指标的查询相关性标签(地面真相) 通过比较检索到的文档与地面真相标签来度量搜索质量指标(Fidelity、NDCG、XDCG、Max Relevance、Holes) retrieval_ground_truthretrieval_documents 复合:保真度、NDCG、XDCG、最大相关性、孔(通过/失败)
Retrieval 进程评估 你想要评估检索上下文的文本质量,但你没有基本事实 度量检索的上下文区块与使用 LLM 法官处理查询的相关性 查询、上下文 二进制:基于阈值传递/失败(1-5 缩放)
Groundedness 系统评估 你需要一个圆润的基础性定义,它适用于代理输入,并自带 GPT 模型作为 LLM 判断 测量生成的响应与给定上下文的对齐程度(精度方面) 查询、上下文、响应 二进制:基于阈值传递/失败(1-5 缩放)
基础专业版 (预览版) 系统评估 你需要由 Azure AI 内容安全提供支持的严格基础定义,并使用我们的服务模型 使用 Azure AI 内容安全服务检测响应是否与上下文严格一致 查询、上下文、响应 二进制:True/False
Relevance 系统评估 你希望评估 RAG 响应解决查询的方式,但没有基本事实 度量对查询的响应的准确性、完整性和直接相关性 查询、响应 二进制:基于阈值传递/失败(1-5 缩放)
响应完整性(预览版) 系统评估 你想要确保 RAG 响应不会错过关键信息(召回方面)从地面真相 衡量响应与地面真相相比,响应的完全涵盖预期信息的方式 响应,基本事实 二进制:基于阈值传递/失败(1-5 缩放)

基础性和响应完整性视为:

  • 基础性侧重于响应的 精度 方面。 它不包含在地面上下文之外的内容。
  • 响应完整性侧重于响应的 召回 方面。 与预期的响应或基本事实相比,它不会错过关键信息。

AI 辅助评估器的模型配置

为了在以下代码片段中参考,AI 辅助质量评估器(除了“基础性专业”除外)使用 LLM 判断的模型配置:

import os
from azure.ai.evaluation import AzureOpenAIModelConfiguration
from dotenv import load_dotenv
load_dotenv()

model_config = AzureOpenAIModelConfiguration(
    azure_endpoint=os.environ["AZURE_ENDPOINT"],
    api_key=os.environ.get("AZURE_API_KEY"),
    azure_deployment=os.environ.get("AZURE_DEPLOYMENT_NAME"),
    api_version=os.environ.get("AZURE_API_VERSION"),
)

计算器模型支持

评估程序支持 LLM 判断的 AzureOpenAI 或 OpenAI 推理模型 和非推理模型,具体取决于评估者:

Evaluators 推理模型作为法官 (示例:Azure OpenAI /OpenAI 中的 o 系列模型) 非推理模型作为法官 (示例: gpt-4.1, gpt-4o) 若要为
IntentResolutionTaskAdherenceToolCallAccuracyResponseCompletenessCoherenceFluencySimilarityGroundednessRetrievalRelevance Supported Supported 在初始化计算器时设置其他参数is_reasoning_model=True
其他计算器 不支持 Supported --

对于需要优化推理的复杂评估,请使用强大的推理模型,例如 4.1-mini 推理性能和成本效益的平衡。

Retrieval

由于它在 RAG 中的上游角色,检索质量至关重要。 如果检索质量差且响应需要特定于语料库的知识,则语言模型不太可能提供令人满意的答案。 RetrievalEvaluator 使用语言模型测量检索结果 的文本质量 ,而无需基本事实,也称为 查询相关性判断

与需要实况的DocumentRetrievalEvaluatorndcgxdcg经典信息检索指标相比fidelity,此方法增加了价值。 此指标侧重于上下文区块与处理查询的相关性,以及如何在列表顶部显示最相关的上下文区块。 上下文区块编码为字符串。

检索示例

from azure.ai.evaluation import RetrievalEvaluator

retrieval = RetrievalEvaluator(model_config=model_config, threshold=3)
retrieval(
    query="Where was Marie Curie born?", 
    context="Background: 1. Marie Curie was born in Warsaw. 2. Marie Curie was born on November 7, 1867. 3. Marie Curie is a French scientist. ",
)

检索输出

数值分数基于 Likert 刻度(整数 1 到 5),其中更高的分数表示性能更好。 给定数值阈值(已设置默认值),计算器还会在分数 = 阈值时输出>,否则将失败。 原因字段解释了分数高或低的原因。

{
    "retrieval": 5.0,
    "gpt_retrieval": 5.0,
    "retrieval_reason": "The context contains relevant information that directly answers the query about Marie Curie's birthplace, with the most pertinent information placed at the top. Therefore, it fits the criteria for a high relevance score.",
    "retrieval_result": "pass",
    "retrieval_threshold": 3
}

系统评估

系统评估侧重于评估 RAG 系统中生成的响应的相关性、基础性和响应完整性。 这些评估程序有助于确保基于提供的上下文和用户查询,AI 生成的内容准确、相关且完整。

例子

进程评估

进程评估评估 RAG 系统中文档检索过程的质量。 检索步骤对于为语言模型提供相关上下文至关重要,因此评估其有效性可确保 RAG 系统生成准确且上下文适当的响应。

示例:

AI 辅助评估程序的评估器模型支持

对于 AI 辅助评估程序,请根据评估程序使用 Azure OpenAI 或 OpenAI 推理模型 和非推理模型。 对于需要优化推理的复杂评估,请使用强大的推理模型,例如 gpt-5-mini 推理性能、成本和效率的平衡。

系统和进程评估示例

from dotenv import load_dotenv
import os
import json
import time
from pprint import pprint

from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from openai.types.evals.create_eval_jsonl_run_data_source_param import (
    CreateEvalJSONLRunDataSourceParam,
    SourceFileContent,
    SourceFileContentContent,
)


load_dotenv()


endpoint = os.environ[
    "AZURE_AI_PROJECT_ENDPOINT"
]  # Sample : https://<account_name>.services.ai.azure.com/api/projects/<project_name>
model_deployment_name = os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "")  # Sample : gpt-4o-mini

with DefaultAzureCredential() as credential:
    with AIProjectClient(
        endpoint=endpoint, credential=credential
    ) as project_client:
        print("Creating an OpenAI client from the AI Project client")

        client = project_client.get_openai_client()

        data_source_config = {
            "type": "custom",
            "item_schema": {
                "type": "object",
                "properties": {
                    "context": {"type": "string"},
                    "query": {"type": "string"},
                    "response": {"type": "string"},
                    "ground_truth": {"type": "string"},
                },
                "required": ["response"] # see example below for specific input requirements
            },
            "include_sample_schema": True,
        }

        testing_criteria = [
            # System evaluation criteria
            {
                "type": "azure_ai_evaluator",
                "name": "groundedness",
                "evaluator_name": "builtin.groundedness",
                "initialization_parameters": {
                    "deployment_name": f"{model_deployment_name}",
                    # "is_reasoning_model": True # if you use an AOAI reasoning model
                },
                "data_mapping": {
                    "context": "{{item.context}}",
                    "query": "{{item.query}}",
                    "response": "{{item.response}}"
                },
            },
            {
                "type": "azure_ai_evaluator",
                "name": "relevance",
                "evaluator_name": "builtin.relevance",
                "initialization_parameters": {
                    "deployment_name": f"{model_deployment_name}",
                    # "is_reasoning_model": True # if you use an AOAI reasoning model        
                },
                "data_mapping": {
                    "query": "{{item.query}}",
                    "response": "{{item.response}}",
                },
            },
            {
                "type": "azure_ai_evaluator",
                "name": "response_completeness",
                "evaluator_name": "builtin.response_completeness",
                "initialization_parameters": {
                    "deployment_name": f"{model_deployment_name}",
                    # "is_reasoning_model": True # if you use an AOAI reasoning model        
                },
                "data_mapping": {
                    "response": "{{item.response}}",
                    "ground_truth": "{{item.ground_truth}}",
                },
            },
            # Process evaluation criteria
            {
                "type": "azure_ai_evaluator",
                "name": "retrieval",
                "evaluator_name": "builtin.retrieval",
                "initialization_parameters": {
                    "deployment_name": f"{model_deployment_name}",
                    # "is_reasoning_model": True # if you use an AOAI reasoning model
                },
                "data_mapping": {
                    "context": "{{item.context}}",
                    "query": "{{item.query}}",
                },
            },
        ]

        print("Creating Eval Group")
        eval_object = client.evals.create(
            name="Test Groundedness Evaluator with inline data",
            data_source_config=data_source_config,
            testing_criteria=testing_criteria,
        )
        print(f"Eval Group created")

        print("Get Eval Group by Id")
        eval_object_response = client.evals.retrieve(eval_object.id)
        print("Eval Run Response:")
        pprint(eval_object_response)

        query = "What is the cheapest available tent of Contoso Outdoor?"
        context = (
            "Contoso Outdoor is a leading retailer specializing in outdoor gear and equipment. "
            "Contoso Product Catalog: 1. tent A - $99.99, lightweight 2-person tent; 2. tent B - $149.99, 4-person family tent; tent C - $199.99, durable 6-person expedition tent."
        )
        response = "The cheapest available tent is tent A, priced at $99.99."
        ground_truth = "The cheapest available tent is tent A, priced at $99.99."

        print("Creating Eval Run with Inline Data")
        eval_run_object = client.evals.runs.create(
            eval_id=eval_object.id,
            name="inline_data_run",
            metadata={"team": "eval-exp", "scenario": "inline-data-v1"},
            data_source=CreateEvalJSONLRunDataSourceParam(
                type="jsonl",
                source=SourceFileContent(
                    type="file_content",
                    content=[
                        SourceFileContentContent(
                            item={
                                "context": context,
                                "response": response,
                                "query": query,
                                "ground_truth": ground_truth
                            }
                        )
                    ]
                ),
            ),
        )

        print(f"Eval Run created")
        pprint(eval_run_object)

        print("Get Eval Run by Id")
        eval_run_response = client.evals.runs.retrieve(run_id=eval_run_object.id, eval_id=eval_object.id)
        print("Eval Run Response:")
        pprint(eval_run_response)

        print("\n\n----Eval Run Output Items----\n\n")

        while True:
            run = client.evals.runs.retrieve(run_id=eval_run_response.id, eval_id=eval_object.id)
            if run.status == "completed" or run.status == "failed":
                output_items = list(client.evals.runs.output_items.list(run_id=run.id, eval_id=eval_object.id))
                pprint(output_items)
                print(f"Eval Run Status: {run.status}")
                print(f"Eval Run Report URL: {run.report_url}")
                break
            time.sleep(5)
            print("Waiting for eval run to complete...")

文档检索

由于它在 RAG 中的上游角色,检索质量至关重要。 检索质量不佳可降低语言模型提供令人满意的答案的可能性,尤其是在响应需要特定于语料库的知识时。 用于 DocumentRetrievalEvaluator 评估检索质量并优化 RAG 的搜索参数。

由于它在 RAG 中的上游角色,检索质量非常重要。 如果检索质量不佳,并且响应需要特定于语料库的知识,则语言模型提供令人满意的答案的可能性较小。 最精确的度量是使用 document_retrieval 计算器来评估检索质量并优化 RAG 的搜索参数。

  • 文档检索计算器度量 RAG 如何从文档存储中检索正确的文档。 作为对具有基本事实的 RAG 方案的复合计算器,它计算用于调试 RAG 管道的有用搜索质量指标的列表:

    Metric Category Description
    Fidelity 搜索保真度 前 n 个检索的区块如何反映给定查询的内容:从数据集中已知良好文档总数返回的优秀文档数
    NDCG 搜索 NDCG 排名对列表顶部所有相关项的理想顺序有多好
    XDCG 搜索 XDCG 无论对其他索引文档的评分如何,结果在 top-k 文档中有多好
    最大相关性 N 搜索最大相关性 top-k 区块中的最大相关性
    Holes 搜索标签健全性 缺少查询相关性判断或基本事实的文档数
  • 若要在名为 参数扫描的方案中优化 RAG,可以使用这些指标来校准搜索参数以获得最佳的 RAG 结果。 为不同的搜索参数(例如搜索算法(矢量、语义)、top_k和区块大小生成检索结果。 然后,用于 DocumentRetrievalEvaluator 标识产生最高检索质量的参数。
  • 若要在名为 参数扫描的方案中优化 RAG,可以使用这些指标来校准搜索参数以获得最佳的 RAG 结果。 为各种搜索参数(例如搜索算法(矢量、语义)、top_k和想要测试的区块大小等各种搜索参数生成不同的检索结果。 然后,用于 document_retrieval 查找产生最高检索质量的搜索参数。

文档检索示例

from azure.ai.evaluation import DocumentRetrievalEvaluator

# These query_relevance_labels are given by your human- or LLM-judges.
retrieval_ground_truth = [
    {
        "document_id": "1",
        "query_relevance_label": 4
    },
    {
        "document_id": "2",
        "query_relevance_label": 2
    },
    {
        "document_id": "3",
        "query_relevance_label": 3
    },
    {
        "document_id": "4",
        "query_relevance_label": 1
    },
    {
        "document_id": "5",
        "query_relevance_label": 0
    },
]
# The min and max of the label scores are inputs to document retrieval evaluator
ground_truth_label_min = 0
ground_truth_label_max = 4

# These relevance scores come from your search retrieval system
retrieved_documents = [
    {
        "document_id": "2",
        "relevance_score": 45.1
    },
    {
        "document_id": "6",
        "relevance_score": 35.8
    },
    {
        "document_id": "3",
        "relevance_score": 29.2
    },
    {
        "document_id": "5",
        "relevance_score": 25.4
    },
    {
        "document_id": "7",
        "relevance_score": 18.8
    },
]

document_retrieval_evaluator = DocumentRetrievalEvaluator(
    # Specify the ground truth label range
    ground_truth_label_min=ground_truth_label_min, 
    ground_truth_label_max=ground_truth_label_max,
    # Optionally override the binarization threshold for pass/fail output
    ndcg_threshold = 0.5,
    xdcg_threshold = 50.0,
    fidelity_threshold = 0.5,
    top1_relevance_threshold = 50.0,
    top3_max_relevance_threshold = 50.0,
    total_retrieved_documents_threshold = 50,
    total_ground_truth_documents_threshold = 50
)
document_retrieval_evaluator(retrieval_ground_truth=retrieval_ground_truth, retrieved_documents=retrieved_documents)   

from dotenv import load_dotenv
import os
import json
import time
from pprint import pprint

from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from openai.types.evals.create_eval_jsonl_run_data_source_param import (
    CreateEvalJSONLRunDataSourceParam,
    SourceFileContent,
    SourceFileContentContent,
)


load_dotenv()

endpoint = os.environ.get(
    "AZURE_AI_PROJECT_ENDPOINT", ""
)  # Sample : https://<account_name>.services.ai.azure.com/api/projects/<project_name>

with DefaultAzureCredential() as credential:

    with AIProjectClient(
        endpoint=endpoint, credential=credential
    ) as project_client:

        print("Creating an OpenAI client from the AI Project client")

        client = project_client.get_openai_client()

        data_source_config = {
            "type": "custom",
            "item_schema": {
                "type": "object",
                "properties": {
                    "retrieved_documents": {"type": "array", "items": {"type": "object"}},
                    "retrieval_ground_truth": {"type": "array", "items": {"type": "object"}}
                },
                "required": ["retrieved_documents", "retrieval_ground_truth"],
            },
            "include_sample_schema": True,
        }

        testing_criteria = [
            {
                "type": "azure_ai_evaluator",
                "name": "document_retrieval",
                "evaluator_name": "builtin.document_retrieval",
                "initialization_parameters": {
                    # The min and max of the retrieval_ground_truth scores are required inputs to document retrieval evaluator
                    "ground_truth_label_min": 1, "ground_truth_label_max": 5
                },
                "data_mapping": {
                    "retrieval_ground_truth": "{{item.retrieval_ground_truth}}", 
                    "retrieval_documents": "{{item.retrieved_documents}}"
                },
            }
        ]

        print("Creating Eval Group")
        eval_object = client.evals.create(
            name="Test Task Navigation Efficiency Evaluator with inline data",
            data_source_config=data_source_config,
            testing_criteria=testing_criteria,
        )
        print(f"Eval Group created")

        print("Get Eval Group by Id")
        eval_object_response = client.evals.retrieve(eval_object.id)
        print("Eval Run Response:")
        pprint(eval_object_response)


        # Score each retrieval from a user's query by your human experts or LLM-judges such as relevance.
        retrieval_ground_truth = [
            {
                "document_id": "1",
                "query_relevance_label": 4
            },
            {
                "document_id": "2",
                "query_relevance_label": 2
            },
            {
                "document_id": "3",
                "query_relevance_label": 3
            },
            {
                "document_id": "4",
                "query_relevance_label": 1
            },
            {
                "document_id": "5",
                "query_relevance_label": 0
            },
        ]

        # These relevance scores for each retrieval chunk come from your search retrieval system
        retrieved_documents = [
            {
                "document_id": "2",
                "relevance_score": 45.1
            },
            {
                "document_id": "6",
                "relevance_score": 35.8
            },
            {
                "document_id": "3",
                "relevance_score": 29.2
            },
            {
                "document_id": "5",
                "relevance_score": 25.4
            },
            {
                "document_id": "7",
                "relevance_score": 18.8
            },
        ]

        print("Creating Eval Run with Inline Data")
        eval_run_object = client.evals.runs.create(
            eval_id=eval_object.id,
            name="document_retrieval_inline_data_run",
            metadata={"team": "eval-exp", "scenario": "inline-data-v1"},
            data_source=CreateEvalJSONLRunDataSourceParam(
                type="jsonl",
                source=SourceFileContent(
                    type="file_content",
                    content=[
                        SourceFileContentContent(
                            item={"retrieval_ground_truth": retrieval_ground_truth, "retrieved_documents": retrieved_documents}
                        )
                    ],
                ),
            ),
        )

        print(f"Eval Run created")
        pprint(eval_run_object)

        print("Get Eval Run by Id")
        eval_run_response = client.evals.runs.retrieve(run_id=eval_run_object.id, eval_id=eval_object.id)
        print("Eval Run Response:")
        pprint(eval_run_response)

        print("\n\n----Eval Run Output Items----\n\n")

        while True:
            run = client.evals.runs.retrieve(run_id=eval_run_response.id, eval_id=eval_object.id)
            if run.status == "completed" or run.status == "failed":
                output_items = list(client.evals.runs.output_items.list(run_id=run.id, eval_id=eval_object.id))
                pprint(output_items)
                print(f"Eval Run Status: {run.status}")
                print(f"Eval Run Report URL: {run.report_url}")
                break
            time.sleep(5)
            print("Waiting for eval run to complete...")

文档检索输出

所有数值分数都有 high_is_better=True,除了 holesholes_ratio,还有 high_is_better=False。 对于数值阈值(默认值为 3),如果分数大于或等于阈值,则计算器输出 传递 ,否则 将失败

{
    "ndcg@3": 0.6461858173,
    "xdcg@3": 37.7551020408,
    "fidelity": 0.0188438199,
    "top1_relevance": 2,
    "top3_max_relevance": 2,
    "holes": 30,
    "holes_ratio": 0.6000000000000001,
    "holes_higher_is_better": False,
    "holes_ratio_higher_is_better": False,
    "total_retrieved_documents": 50,
    "total_groundtruth_documents": 1565,
    "ndcg@3_result": "pass",
    "xdcg@3_result": "pass",
    "fidelity_result": "fail",
    "top1_relevance_result": "fail",
    "top3_max_relevance_result": "fail",
    # Omitting more fields ...
}
{
    "ndcg@3": 0.6461858173,
    "xdcg@3": 37.7551020408,
    "fidelity": 0.0188438199,
    "top1_relevance": 2,
    "top3_max_relevance": 2,
    "holes": 30,
    "holes_ratio": 0.6000000000000001,
    "holes_higher_is_better": False,
    "holes_ratio_higher_is_better": False,
    "total_retrieved_documents": 50,
    "total_groundtruth_documents": 1565,
    "ndcg@3_result": "pass",
    "xdcg@3_result": "pass",
    "fidelity_result": "fail",
    "top1_relevance_result": "fail",
    "top3_max_relevance_result": "fail",
    # Omitting more fields ...
}

Groundedness

评估响应与上下文的关系非常重要。 AI 模型可能会捏造内容或生成不相关的响应。 GroundednessEvaluator 度量生成的响应与给定上下文、基础源的对齐程度,并且不会在给定上下文之外捏造内容。

此指标捕获与地面源的响应对齐 的精度 方面。 较低的分数意味着响应与查询无关,或者捏造上下文之外的不准确内容。 此指标是 ResponseCompletenessEvaluator互补的,它捕获响应与预期响应的 召回 方面。

基础性示例

from azure.ai.evaluation import GroundednessEvaluator

groundedness = GroundednessEvaluator(model_config=model_config, threshold=3)
groundedness(
    query="Is Marie Curie is born in Paris?", 
    context="Background: 1. Marie Curie is born on November 7, 1867. 2. Marie Curie is born in Warsaw.",
    response="No, Marie Curie is born in Warsaw."
)

地面输出

数值分数以 Likert 刻度(整数 1 到 5)表示。 分数越高越好。 给定数值阈值(默认值为 3),如果分数大于或等于阈值,则计算器输出 传递 ,否则 将失败 。 使用原因字段了解分数高或低的原因。

{
    "groundedness": 5.0,  
    "gpt_groundedness": 5.0,
    "groundedness_reason": "The RESPONSE accurately answers the QUERY by confirming that Marie Curie was born in Warsaw, which is supported by the CONTEXT. It does not include any irrelevant or incorrect information, making it a complete and relevant answer. Thus, it deserves a high score for groundedness.",
    "groundedness_result": "pass", 
    "groundedness_threshold": 3
}

有据性 Pro

AI 系统可以在给定上下文之外生成不相关的响应或捏造内容。 由 Azure AI 内容安全提供支持, GroundednessProEvaluator 检查生成的文本响应是否准确且与给定上下文一致,在检索扩充的生成问答方案中。 它确保响应严格遵循上下文来回答查询,避免猜测或捏造。 它输出二进制标签。

Groundedness Pro 示例

from azure.ai.evaluation import GroundednessProEvaluator
from azure.identity import DefaultAzureCredential
import os
from dotenv import load_dotenv
load_dotenv()

# Using Microsoft Foundry Hub
azure_ai_project = {
    "subscription_id": os.environ.get("AZURE_SUBSCRIPTION_ID"),
    "resource_group_name": os.environ.get("AZURE_RESOURCE_GROUP"),
    "project_name": os.environ.get("AZURE_PROJECT_NAME"),
}

groundedness_pro = GroundednessProEvaluator(azure_ai_project=azure_ai_project), 
groundedness_pro(
    query="Is Marie Curie is born in Paris?", 
    context="Background: 1. Marie Curie is born on November 7, 1867. 2. Marie Curie is born in Warsaw.",
    response="No, Marie Curie is born in Warsaw."
)

Groundedness Pro 输出

如果响应中的所有内容完全位于上下文中,则标签字段返回 TrueFalse 否则返回。 使用原因字段详细了解分数背后的判断。

{
    "groundedness_pro_reason": "All Contents are grounded",
    "groundedness_pro_label": True
}

Relevance

AI 模型可以生成与用户查询无关的响应。 评估最终响应非常重要。 若要解决此问题,请使用 RelevanceEvaluator它来衡量响应处理查询的效率。 它基于查询评估响应的准确性、完整性和直接相关性。 更高的分数意味着更好的相关性。

相关性示例

from azure.ai.evaluation import RelevanceEvaluator

relevance = RelevanceEvaluator(model_config=model_config, threshold=3)
relevance(
    query="Is Marie Curie is born in Paris?", 
    response="No, Marie Curie is born in Warsaw."
)

相关性输出

数值分数以 Likert 刻度(整数 1 到 5)表示。 分数越高越好。 给定数值阈值(默认值为 3),如果分数大于或等于阈值,则计算器输出 传递 ,否则 将失败 。 原因字段可帮助你了解分数高或低的原因。

{
    "relevance": 4.0,
    "gpt_relevance": 4.0, 
    "relevance_reason": "The RESPONSE accurately answers the QUERY by stating that Marie Curie was born in Warsaw, which is correct and directly relevant to the question asked.",
    "relevance_result": "pass", 
    "relevance_threshold": 3
}

响应完整性

AI 系统可以在给定上下文之外捏造内容或生成无关的响应。 给定地面真实响应, ResponseCompletenessEvaluator 捕获响应的 召回 方面与预期响应保持一致。 此计算器补充, GroundednessEvaluator它捕获与地面源的 响应对齐的精度 方面。

响应完整性示例

from azure.ai.evaluation import ResponseCompletenessEvaluator

response_completeness = ResponseCompletenessEvaluator(model_config=model_config, threshold=3)
response_completeness(
    response="Based on the retrieved documents, the shareholder meeting discussed the operational efficiency of the company and financing options.",
    ground_truth="The shareholder meeting discussed the compensation package of the company's CEO."
)

响应完整性输出

Likert 刻度的数字分数(整数 1 到 5)。 分数越高越好。 给定数值阈值(默认值为 3),如果评分 = 阈值或>,计算器也会输出传递。 使用原因字段了解分数高或低的原因。

{
    "response_completeness": 1,
    "response_completeness_result": "fail",
    "response_completeness_threshold": 3,
    "response_completeness_reason": "The response does not contain any relevant information from the ground truth, which specifically discusses the CEO's compensation package. Therefore, it is considered fully incomplete."
}