Open
【11月贡献大赛-缺陷修复】fix/docs: deduplicate Recall@k hits in eval_retrieval.py (#4106) #7331
【11月贡献大赛-缺陷修复】fix/docs: deduplicate Recall@k hits in eval_retrieval.py (#4106) #7331
Open
Sophie LeeAdd on 4 hours ago
Sophie Lee
Sophie Lee
4 hours ago

Fixes #4106

问题与根因

skills/deployment/npu-embedding-retrieval/scripts/eval_retrieval.py 中 evaluate() 使用列表推导 hits = [doc for doc in ranked if doc in rel_set] 统计前 k 名命中的相关文档,当排名结果中同一相关文档 ID 重复出现时(如多路召回合并或同文档多片段切分场景),len(hits) 会重复计数而分母 len(rel_set) 按唯一相关文档数计算,导致 recall@k 超过 1.0(例如单相关文档重复出现时输出 2.0)。

改动说明

  • skills/deployment/npu-embedding-retrieval/scripts/eval_retrieval.py:
    • evaluate() 中改用集合推导 hits = {doc for doc in ranked if doc in rel_set} 对前 k 名命中文档按 ID 去重;
    • 保留 ranked = (runs.get(q) or [])[:k] 的原始切片口径,重复项占据的原始名次保留、k 以外的命中不向前补位,且同时兼容缺失/None 排名输入;
    • MRR、Hit Rate@k 语义及输出格式保持不变。
  • skills/deployment/npu-embedding-retrieval/references/retrieval_eval_guide.md:
    • 补充 Recall@k 前 k 名去重及不补位口径说明。
  • skills/deployment/npu-embedding-retrieval/tests/test_eval_retrieval.py:
    • 新增 6 个离线 CPU 回归测试(无重复基线、重复命中去重、名次保留不补位、部分命中分母、空/缺失排名、CLI 端到端与缺失文件退出码 1)。

本地验证结果

在 G:\openatom\wt-agy-4106(CPU 离线环境,纯 Python 标准库)执行:

  1. python -m pytest -v skills/deployment/npu-embedding-retrieval/tests/test_eval_retrieval.py -> 6 passed in 2.54s
  2. python -m unittest -v skills/deployment/npu-embedding-retrieval/tests/test_eval_retrieval.py -> Ran 6 tests in 2.844s (OK)
  3. 复现脚本验证:['d', 'x'] 与 ['d', 'd'] 在 k=2 下均输出 recall@k: 1.0, mrr: 1.0, hit_rate@k: 1.0。
likedislike
Merge blocked
ascend-robot
ascend-robotCollaborators
4 hours ago Comments:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.


PR Approval Progress

⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)

Module Approval Details

module lgtm status approve status
sig-model-agent ❌ (0/2)(You can also ask: 顾梦沁, 林泽毅, 刘磊, shaos-governance, 花新宇) ❌ (0/1)(You can also ask: 焦泽昱, 陈少宏, 顾梦沁, 刘磊, 王岩)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

DoubleCore, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
Sophie Lee
Sophie Lee
4 hours ago Comments:

/label add bug

likedislike
ascend-robotascend-robotCollaborators
4 hours ago Added label: ascend-cla/yes
Sophie Lee
Sophie Lee
4 hours ago Comments:

/label add fix

likedislike
Sophie Lee
Sophie Lee
4 hours ago Comments:

/label add document

likedislike
Sophie Lee
Sophie Lee
4 hours ago Comments:

/check-cla

likedislike
ascend-robotascend-robotCollaborators
4 hours ago Removed label: ascend-cla/yes
ascend-robotascend-robotCollaborators
4 hours ago Added label: ascend-cla/yes
ascend-robot
ascend-robotCollaborators
4 hours ago Comments:

CLA检查已通过,详情可参考这里

likedislike