📝 Ragas评估四个常用指标解析笔记

评估环境

  • 大语言模型:qwen3-max
  • 嵌入模型:text-embedding-v4

四个核心评估指标的prompt指令判定标准实际输出示例


一、Faithfulness(忠实度)

📌 核心概念

检查答案中的每个陈述是否都能从给定的上下文中找到依据,防止模型"凭空捏造"。

🔧 Prompt指令

instruction = "Given a question and an answer, analyze the complexity of each sentence in the answer. Break down each sentence into one or more fully understandable statements. Ensure that no pronouns are used in any statement. Format the outputs in JSON."

📊 判定标准

  • attributed: 1 = 该陈述可以在上下文中找到依据
  • attributed: 0 = 该陈述无法在上下文中找到依据

🔍 实际输出示例

{
    "classifications": [
        {
            "statement": "有三种方式:1、通过中央显示屏,设置座椅加热强度或关闭座椅加热功能,\n    在中央显示屏中点击座椅进入座椅加热控制界面,可在“关-低-中-高”之间循环。",
            "reason": "上下文指出驾驶员/乘客侧座椅加热可以通过中央显示屏控制,有三个强度级别,可在'关-低-中-高'之间循环。它还提到了通过中央显示屏进入座椅加热控制界面。",
            "attributed": 1
        },
        {
            "statement": "2、登录Lynk & Co App,按下前排座椅加热图标图标可以打开/关闭前排座椅加热。",
            "reason": "上下文明确提到使用Lynk & Co App通过按下相应图标来打开/关闭前排座椅加热。",
            "attributed": 1
        },
        {
            "statement": "3、在中央显示屏中唤起空调控制界面然后点击舒适选项,降低座椅加热时间。",
            "reason": "上下文提到了设置前排座椅加热时间以及通过空调控制界面访问'舒适'选项,但并未说明此操作会降低加热时间;它仅描述了如何访问控制。'降低座椅加热时间'这一说法在上下文中没有依据。",
            "attributed": 0
        }
    ]
}

💡 判定解读

前两个陈述✅被判为1,因为上下文明确支持;第三个❌被判为0,因为上下文只说可以"设置"加热时间,没说可以"降低"——忠实度要求精确匹配,而非大致意思对即可


二、Answer Relevancy(答案相关性)

📌 核心概念

根据答案反向生成可能的问题,并评估生成的问题与原始问题的匹配程度,同时判断答案是否"非承诺性"(含糊其辞)。

🔧 Prompt指令

instruction = """Generate a question for the given answer and Identify if answer is noncommittal. Give noncommittal as 1 if the answer is noncommittal and 0 if the answer is committal. A noncommittal answer is one that is evasive, vague, or ambiguous. For example, "I don't know" or "I'm not sure" are noncommittal answers"""

📊 判定标准

  • noncommittal: 1 = 答案含糊其辞(如"我不知道"、“我不确定”)
  • noncommittal: 0 = 答案明确具体(提供了实质性信息)

🔍 实际输出示例

{
    "question": "如何调节前排座椅加热以避免座椅过热?",
    "noncommittal": 0
}

⚠️ 我遇到的问题

LLM温度配置为0,导致大模型生成了3个一样的问题,我试着调整温度到0.7时,有两个一样,一个不一样,具体的原理还没搞清,可能是ragas提示词,也可能就是大模型温度问题:

[
    {
        "question": "如何调节前排座椅加热以避免座椅过热?",
        "noncommittal": 0
    },
    {
        "question": "如何调节前排座椅加热以避免座椅过热?",
        "noncommittal": 0
    },
    {
        "question": "如何调节前排座椅加热以避免座椅过热?",
        "noncommittal": 0
    }
]

三、Context Precision(上下文精确度)

📌 核心概念

评估检索到的单个上下文片段对于得出答案是否有用——如果给我这个上下文,我能得出这个答案吗?

🔧 Prompt指令

instruction: str = 'Given question, answer and context verify if the context was useful in arriving at the given answer. Give verdict as "1" if useful and "0" if not with json output.'

📊 判定标准

  • verdict: 1 = 该上下文对得出答案有用(能支持完整答案)
  • verdict: 0 = 该上下文对得出答案没用(只能支持部分或完全不相关)

✅ 判定为1的完整示例

问题

座椅太热怎么办?

答案

有三种方式:1、通过中央显示屏,设置座椅加热强度或关闭座椅加热功能,
在中央显示屏中点击座椅进入座椅加热控制界面,可在“关-低-中-高”之间循环。
2、登录Lynk & Co App,按下前排座椅加热图标图标可以打开/关闭前排座椅加热。
3、在中央显示屏中唤起空调控制界面然后点击舒适选项,设置座椅加热时间。

上下文

您可以使用中央显示屏设置驾驶员/乘客侧座椅加热强度或关闭座椅加热功能。
在中央显示屏中,点击[座椅]图标,进入驾驶员侧座椅加热控制界面,
座椅加热强度可在“关-低-中-高”之间循环。您也可以登录Lynk & Co App,
按下前排座椅加热图标打开/关闭前排座椅加热。在中央显示屏中唤起空调控制界面,
点击舒适选项,可以设置前排座椅加热时间。

LLM评估输出

{
    "reason": "The provided context contains all three methods mentioned in the answer: (1) adjusting seat heating via the central display with intensity levels cycling through 'off-low-medium-high', (2) using the Lynk & Co App to turn on/off front seat heating, and (3) accessing the climate control interface and comfort option to set the heating time. The context fully supports each component of the answer, providing sufficient information to arrive at the complete given answer.",
    "verdict": 1
}

中文翻译

{
    "reason": "所提供的上下文包含了答案中提到的所有三种方法:(1)通过中央显示屏调节座椅加热,强度可在'关-低-中-高'之间循环,(2)使用Lynk & Co App打开/关闭前排座椅加热,(3)通过空调控制界面和舒适选项设置加热时间。上下文完全支持答案的每个组成部分,提供了足够的信息来得出完整的给定答案。",
    "verdict": 1
}

❌ 判定为0的示例(来自你的实际输出)

{
    "reason": "The provided context mentions adjusting or turning off the front seat heating via the central display, which aligns with part of the answer. However, the answer includes additional methods (using the Lynk & Co App and adjusting through the climate control interface) that are not mentioned in the context. Since the context only partially supports the answer and does not provide all necessary information to fully arrive at the given answer, it is not fully useful.",
    "verdict": 0
}

中文翻译

{
    "reason": "所提供的上下文提到了通过中央显示屏调节或关闭前排座椅加热,这与答案的部分内容一致。然而,答案还包含了上下文中未提及的其他方法(使用领克手机应用程序和通过空调控制界面进行调节)。由于上下文仅部分支持答案,并未提供完整得出给定答案所需的全部信息,因此它不是完全有用的。",
    "verdict": 0
}

💡 判定解读对比

判定 上下文覆盖情况 原因
verdict: 1 ✅ 完整覆盖三种方法 上下文包含中央显示屏、App、空调界面全部三种方法
verdict: 0 ❌ 只覆盖中央显示屏方法 上下文缺少App和空调界面方法,不足以得出完整答案

关键区别:上下文精确度要求上下文必须能支持完整答案,而不是部分内容。即使上下文包含了部分正确信息,只要不足以得出完整答案,就会被判为0。


四、Context Recall(上下文召回率)

📌 核心概念

检查答案中的信息是否都能从上下文中找到依据——与Faithfulness类似,但角度不同:Faithfulness看答案是否基于上下文,Context Recall看上下文是否覆盖了答案。

🔧 Prompt指令

instruction: str = "Given a context, and an answer, analyze each sentence in the answer and classify if the sentence can be attributed to the given context or not. Use only 'Yes' (1) or 'No' (0) as a binary classification. Output json with reason."

📊 判定标准

  • attributed: 1 = 该陈述可以归因于上下文(被"召回")
  • attributed: 0 = 该陈述无法归因于上下文

🔍 实际输出示例

{
    "classifications": [
        {
            "statement": "有三种方式:1、通过中央显示屏...",
            "reason": "The context states that the driver/passenger side seat heating can be controlled via the central display...",
            "attributed": 1
        },
        {
            "statement": "2、登录Lynk & Co App...",
            "reason": "The context explicitly mentions using the Lynk & Co App...",
            "attributed": 1
        },
        {
            "statement": "3、在中央显示屏中唤起空调控制界面...",
            "reason": "The context...does not state that this action lowers the heating time...",
            "attributed": 0
        }
    ]
}

五、四个指标对比总结

指标 评估对象 判定标准 你的示例中为什么被判0/1
Faithfulness 答案中的每个陈述 1=有上下文支持
0=无上下文支持
第3条说"降低"加热时间,但上下文只说可以"设置" → 0
Answer Relevancy 整个答案 1=含糊其辞
0=明确具体
你的答案提供了三种具体方法 → noncommittal=0
Context Precision 单个上下文片段 1=对得出答案有用
0=没用
完整上下文:三种方法都支持 → 1
部分上下文:只支持中央显示屏 → 0
Context Recall 答案中的每个陈述 1=可归因于上下文
0=不可归因
与Faithfulness相同的问题——"降低"一词无依据 → 0
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐