這很重要
本文中標示為 (預覽) 的項目目前處於公開預覽狀態。 此預覽版本沒有服務等級協定,不建議將其用於生產工作負載。 可能不支援特定功能,或可能已經限制功能。 如需詳細資訊,請參閱 Microsoft Azure 預覽版增補使用條款。
備註
本文件指的是 Microsoft Foundry(新) 入口網站。
Retrieval-Augmented 生成 (RAG) 系統會嘗試產生與接地文件一致的最相關答案,以回應使用者的查詢。 使用者的查詢會觸發在基礎文件語料庫中進行搜尋,為 AI 模型產生回應提供基礎上下文。
請務必評估:
這些評估者聚焦於三個面向:
- 擷取結果與使用者查詢的相關性:如果您有查詢特定文件相關性的標籤,請使用 Document Retrieval ,或查詢相關性判斷 (qrels) 以取得更準確的測量。 如果您只有擷取的內容,但沒有這類標籤,且對不太精細的測量有較高的容錯 ,請使用 擷取。
- 產生的回應相對於基礎文件的一致性:如果您想要在我們的開放原始碼大型語言模型判斷 (LLM-judge) 提示中自訂基礎的定義,請使用 Groundedness 。 如果您想要一個簡單的定義,請使用 Groundedness Pro 。
- 查詢最終回應的相關性:如果您沒有基本事實,請使用 Relevance 。 如果您有基本事實並且不希望您的回應錯過關鍵資訊,請使用 回應完整性 。
| 評估者 | 最佳做法 | 在以下情況下使用 | 目標 | 輸入 | 輸出 |
|---|---|---|---|---|---|
| 文件檢索(預覽) | 流程評估 | 檢索品質是 RAG 的瓶頸,而你有查詢相關性標籤(ground truth)來提供精確的搜尋品質指標,用於除錯和參數優化 | 透過比較檢索文件與真實標籤來衡量搜尋品質指標(Fidelity、NDCG、XDCG、最大相關性、漏洞) |
retrieval_ground_truth、retrieval_documents |
綜合:Fidelity、NDCG、XDCG、Max Relevance、Holes(含通過/不通過) |
| Retrieval | 流程評估 | 你想評估檢索出的上下文的文本品質,但你沒有確切的事實 | 衡量擷取的上下文區塊與使用 LLM 判定器處理查詢的相關性 | 查詢、上下文 | 二元:根據門檻(1-5 等級)進行通過/不通過 |
| Groundedness | 系統評估 | 你需要一個全面的接地定義,能配合代理輸入,並帶著你自己的 GPT 模型作為 LLM 評審 | 衡量生成的回應與所給情境的契合度,且不需捏造內容(精確度方面) | 查詢、情境、回應 | 二元:根據門檻(1-5 等級)進行通過/不通過 |
| Groundedness Pro(預覽版) | 系統評估 | 你需要由 Azure AI 內容安全驅動的嚴格接地定義,並使用我們的服務模型 | 利用 Azure AI 內容安全服務偵測回應是否嚴格符合上下文 | 查詢、情境、回應 | 二元:真/假 |
| Relevance | 系統評估 | 你想評估 RAG 回應對問題的回應程度,但沒有實地真相 | 衡量回應對查詢的準確性、完整性及直接相關性 | 查詢,回應 | 二元:根據門檻(1-5 等級)進行通過/不通過 |
| 回應完整性(預覽) | 系統評估 | 你要確保 RAG 回應不會漏掉你那個真實資訊中的關鍵資訊(回憶面向) | 衡量回應涵蓋預期資訊與實際資訊的完整性 | 回應,實地真相 | 二元:根據門檻(1-5 等級)進行通過/不通過 |
將 接地性 與 回應完整性 視為:
- 接地則著重於回應的 精確 度。 它不包含接地語境以外的內容。
- 回應完整性著重於 回應的回憶 面向。 與預期的回應或實地資訊相比,它不會遺漏關鍵資訊。
AI 輔助評估工具的模型設定
為了在下列程式碼片段中參考,除了 Groundedness Pro 之外,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"),
)
評估工具模型支援
評估者支援 AzureOpenAI 或 OpenAI 推理模型 ,以及 LLM 判斷的非推理模型,視評估者而定:
| Evaluators | 推理模型作為法官 (例如:來自 Azure OpenAI / OpenAI 的 o 系列模型) | 非推理模型作為 Judge(例如:gpt-4.1、gpt-4o) | 若要啟用 |
|---|---|---|---|
IntentResolution、TaskAdherence、ToolCallAccuracy、ResponseCompleteness、Coherence、Fluency、Similarity、Groundedness、Retrieval、Relevance |
Supported | Supported | 在初始化評估工具時設定其他參數is_reasoning_model=True |
| 其他評估者 | 不支援 | Supported | -- |
對於需要精細推理的複雜評估,請使用強有力的推理模型,例如 4.1-mini 在推理效能與成本效益之間取得平衡。
Retrieval
由於其在 RAG 中扮演上游角色,檢索品質至關重要。 如果檢索品質不佳且回應需要語料庫特定的知識,語言模型就較不可能給出令人滿意的答案。
RetrievalEvaluator 使用語言模型測量檢索結果的 文字質量 ,無需基本事實,也稱為 查詢相關性判斷。
此方法相較 DocumentRetrievalEvaluator於 , ndcg後者衡量 、 xdcg、 及 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. ",
)
擷取輸出
數值分數基於李克特量表(整數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 推理模型 ,以及非推理模型作為 LLM 評審。 對於需要精細推理的複雜評估,請使用強有力的推理模型,例如 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 搜尋標籤標 Sanity 缺少查詢相關性判斷或基本事實的文件數目
- 若要在稱為 參數掃描的案例中最佳化 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."
)
接地輸出
數字分數採用李克特量表(整數 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
}
根據性專業版
AI 系統可能會產生無關的回應,或在特定語境外捏造內容。 由 Azure AI 內容安全驅動, GroundednessProEvaluator 能檢查生成的文字回應是否準確且符合特定情境,並用於檢索增強生成問答情境。 它確保回答緊貼上下文以回答問題,避免猜測或捏造。 它輸出二進位標籤。
基礎性 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."
)
基礎性 Pro 輸出
標籤欄位回傳時,回應中的所有內容都完全基於上下文,True否則則回傳False。 使用理由欄位來了解分數背後的判斷。
{
"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."
)
相關性輸出
數字分數採用李克特量表(整數 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."
)
回應完整性輸出
李克特量表上的數字分數(整數 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."
}