Candidate dedup and provenance

From pdl-openair/OpenAIR · View interactive version

Candidate dedup and provenance is an AI agent skill from the GitHub repository pdl-openair/OpenAIR. 对多源检索返回的元数据候选集进行去重,保留最优版本(按引用数、年份、arXiv PDF 优先级), 合并 provenance 标记每条文献被多少个检索源命中。 在 academic-source-retrieval-skill 之后、candidate-source-scoring 之前运行。

How to use this skill

Skill file

Candidate Dedup and Provenance

概述

候选文献去重与来源标记 Skill 负责对多源检索返回的元数据候选集进行去重,保留最优版本,并标记每条文献被多少个检索源命中(provenance)。

能力边界

做什么

不做什么

输入

{
  "metadata_candidates": [
    {
      "candidate_id": "openalex_W1234567890",
      "dedupe_key": "doi:10.1016/j.jpowsour.2023.233456",
      "normalized_title": "fast charging lithium ion batteries",
      "external_ids": {
        "doi": "10.1016/j.jpowsour.2023.233456",
        "arxiv_id": null,
        "openalex_id": "W1234567890"
      },
      "title": "Fast Charging Lithium-Ion Batteries",
      "abstract": "...",
      "authors": ["Zhang, Wei", "Li, Ming"],
      "year": 2023,
      "venue": "Journal of Power Sources",
      "doi": "10.1016/j.jpowsour.2023.233456",
      "citation_count": 45,
      "source_name": "openalex",
      "matched_query": "fast charging lithium ion battery",
      "provenance": [
        {
          "source_name": "openalex",
          "matched_query": "fast charging lithium ion battery",
          "query_index": 0,
          "source_result_index": 0,
          "source_rank": 1,
          "retrieved_at": "2026-05-26T12:00:00Z",
          "retrieval_mode": "expanded_query_variant"
        }
      ]
    }
  ]
}

兼容性:输入 schema 与 academic-source-retrieval-skill 输出完全兼容。

输出

{
  "deduped_candidates": [
    {
      "candidate_id": "openalex_W1234567890",
      "dedupe_key": "doi:10.1016/j.jpowsour.2023.233456",
      "normalized_title": "fast charging lithium ion batteries",
      "title": "Fast Charging Lithium-Ion Batteries",
      "year": 2023,
      "citation_count": 45,
      "matched_source_count": 2,
      "dedup_reason": "higher_citations",
      "provenance": [
        {
          "source_name": "openalex",
          "matched_query": "fast charging lithium ion battery",
          "retrieved_at": "2026-05-26T12:00:00Z"
        },
        {
          "source_name": "semantic_scholar",
          "matched_query": "rapid charge Li-ion cell",
          "retrieved_at": "2026-05-26T12:01:00Z"
        }
      ]
    }
  ],
  "dedup_report": {
    "input_count": 150,
    "output_count": 87,
    "duplicates_removed": 63,
    "multi_source_candidates": 23,
    "dedup_keys_used": {
      "doi": 45,
      "arxiv_id": 12,
      "openalex_id": 18,
      "normalized_title": 12
    }
  }
}

去重逻辑

1. 去重键优先级

本 Skill 会先规范化外部标识,再按以下优先级生成稳定去重键:

dedupe_key = DOI > arXiv ID > existing cross-source title key > OpenAlex ID > legacy dedupe_key > normalized_title hash

说明:

2. 版本选择规则

当多个候选映射到同一 dedupe_key 时,按以下规则保留最优版本:

  1. 引用数优先:citation_count 更高者
  2. 年份优先:引用数相同时,year 更新者
  3. arXiv PDF 优先:引用数和年份都相同时,优先保留有 arXiv PDF 直链的版本
  4. 先到先得:以上都相同时,保留第一个遇到的版本

3. Provenance 合并

迁移来源

源仓库:OpenTrajectory

源文件:literature_merge_filter.py

源函数:merge_candidates() (L25-57)

核心逻辑:

def merge_candidates(groups: list[list[LiteratureCandidate]]) -> list[LiteratureCandidate]:
    best: dict[str, LiteratureCandidate] = {}
    sources_by_key: dict[str, set[str]] = {}

    for group in groups:
        for c in group:
            k = c.dedupe_key.lower()
            sources_by_key.setdefault(k, set()).add(c.source_backend)

            if k not in best:
                best[k] = c
                continue

            o = best[k]
            oc, nc = o.citation_count or 0, c.citation_count or 0
            oy, ny = o.year or 0, c.year or 0

            # 保留引用更多或年份更新的版本
            if nc > oc or (nc == oc and ny > oy):
                best[k] = c
            elif nc == oc and ny == oy and "arxiv.org/pdf" in c.pdf_url:
                best[k] = c

    # 标记多源命中数
    for k, c in best.items():
        n = len(sources_by_key.get(k, {c.source_backend}))
        c.extra["matched_source_count"] = str(n)

    return sorted(best.values(), key=lambda x: (-(x.citation_count or 0), -(x.year or 0)))

测试覆盖

Fixture 场景

  1. DOI 重复:同一 DOI 被 OpenAlex 和 Semantic Scholar 返回,保留引用数更高的版本
  2. 标题归一化重复:无 DOI 的文献,通过 normalized_title 去重
  3. 多源命中:同一文献被 3 个检索源命中,matched_source_count = 3
  4. 年份优先:引用数相同时,保留更新的版本
  5. arXiv PDF 优先:引用数和年份都相同时,保留有 arXiv PDF 的版本

回放测试

下游 Skill

本 Skill 的输出可供以下下游 Skill 使用:

运行时要求

状态

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.