bug: Dataset run scores aggregate across reruns when reusing the same run name

用户在 Langfuse(self-hosted, v3.157.0)中创建数据集,并使用 Python SDK(3.14.5)通过 itemclient.run 等 API 对数据集进行多次评测。每次评测都使用同一个 run name(例如 "eval-run-1" ),导致在 Langfuse

bug: Dataset run scores aggregate across reruns when reusing the same run name

bug: Dataset run scores aggregate across reruns when reusing the same run name

快速结论:在 Langfuse 中对同一数据集多次使用相同的 run name 进行评测时,UI 中显示的每条数据项(item)对应的是最新一次的 traces,但分数的聚合结果却包含了所有历史执行中的 scores,导致数据看上去“堆叠”或夸大。优先排查是否在重复使用固定的 run name。

问题场景

用户在 Langfuse(self-hosted, v3.157.0)中创建数据集,并使用 Python SDK(3.14.5)通过 itemclient.run 等 API 对数据集进行多次评测。每次评测都使用同一个 run name(例如 "eval-run-1"),导致在 Langfuse UI 中查看该 run 时,每条数据项的最新 trace 是正常的,但 run 级别的分数聚合包含了所有历史执行的数据。

报错原文

When I run a dataset evaluation multiple times using the same run name, the Langfuse UI shows one run whose traces look like they belong to the latest execution (per item), but scores for that run appear to include results from earlier executions as well. Aggregates can look inflated or "stacked" (e.g. more score entries or blended values than match what you see for the current traces).

原因分析

Langfuse 中 dataset run 的名称在 (datasetId, projectId, name) 上存在唯一约束,因此如果重复使用同一个 run name,不会创建新的 run,而是返回已有的 run 并向其中添加新的 dataset run items。核心问题在于 traces 和 scores 的查询逻辑不一致

  • Traces 有去重:查询时按 created_at DESC 排序,并使用 LIMIT 1 BY,因此每个数据集 item 只显示最新一次的 trace。
  • Scores 没有去重:分数聚合时,会关联所有历史上绑定到同一个 dataset_run_id 的 traces,而不按 created_at 过滤,导致旧 traces 的 scores 仍然参与计算,造成“堆叠”效果。

环境排查

  • 确认 Langfuse 版本(self-hosted v3.157.0)
  • 确认 Python SDK 版本(3.14.5)
  • 检查是否在代码中硬编码了固定的 run name(如 "eval-run-1"

解决步骤

  1. 立即缓解措施:每次执行使用唯一的 run name。例如在 run name 后面添加时间戳或版本号(如 "eval-run-1-2026-04-28""eval-run-1-v2")。这样可以确保每次评测都创建一个新的 dataset_run_id,从而完全隔离 traces 和 scores。
  2. 长期修复方向:如果这是你希望修复的 bug,可以关注 Langfuse 的代码仓库。问题出在 getDatasetRunsTableInternal()getTraceScoresForDatasetRuns 的分数聚合逻辑中——需要对 scores 的 join 也应用与 traces 类似的 created_at 去重逻辑。

验证方法

使用唯一的 run name 重新执行评测后,在 Langfuse UI 中查看该 run,确认每条数据项的 trace 与分数数量一致,且 run 级别的聚合分数与最新执行的 traces 对应,不再包含历史数据。

参考来源

langfuse/langfuse #13022

GamsGo AI

AI 工具推荐

想把多个 AI 模型放在一个入口?

GamsGo AI 集成 ChatGPT、DeepSeek、Gemini、Claude、Midjourney、Veo 等常用模型,适合写作、绘图、视频和日常 AI 工作流。

了解 GamsGo AI

推广链接:通过此链接购买,我可能获得佣金,不影响你的价格。

celebrityanime
celebrityanime
文章: 13050

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注