You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RAG LLM评估中context precision/recall的上下文输入范围咨询

Ragas评估中Context Precision/Recall的retrieved_contexts参数取值说明
  • 核心结论:评估context precision(上下文精确率)或context recall(上下文召回率)时,仅传入检索器返回的原始内容(retrieved content)即可,不需要加入prompt instruction(规则描述指令)和chat history(对话历史)。

  • 原因解析:

    • Context Precision的本质是衡量「检索结果中对回答用户问题有用的内容占比」,聚焦的是检索环节的输出质量,prompt指令和对话历史属于LLM生成回答时的额外输入逻辑,和检索结果本身的相关性无关,不应混入评估指标。
    • Context Recall的核心是判断「检索结果是否覆盖了回答用户问题所需的全部关键信息」,同样只关注检索内容与问题、最终回答的匹配度,prompt和对话历史不影响检索内容的覆盖性判断。
  • 代码示例说明:
    你提供的代码中retrieved_contexts参数的用法是正确的,直接传入检索器返回的原始内容列表即可,示例如下:

    from ragas import SingleTurnSample
    from ragas.metrics import LLMContextPrecisionWithoutReference
    
    context_precision = LLMContextPrecisionWithoutReference(llm=evaluator_llm)
    
    sample = SingleTurnSample(
        user_input="Where is the Eiffel Tower located?",
        response="The Eiffel Tower is located in Paris.",
        retrieved_contexts=["The Eiffel Tower is located in Paris."],  # 仅传入检索器返回的原始内容
    )
    
    await context_precision.single_turn_ascore(sample)
    

内容的提问来源于stack exchange,提问作者Howie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 23:43:16