Skip to content

feat(cs_feed): 论文关联 PaperTopic + 触发引用 auto_link - #51

Merged
Color2333 merged 1 commit into
mainfrom
feat/cs-feed-topic-link
Jul 18, 2026
Merged

feat(cs_feed): 论文关联 PaperTopic + 触发引用 auto_link#51
Color2333 merged 1 commit into
mainfrom
feat/cs-feed-topic-link

Conversation

@Color2333

Copy link
Copy Markdown
Owner

背景

cs_feed 按分类抓取论文后只 upsert_paper无 PaperTopic 关联、无 _bg_auto_link。后果:

  • cs_feed 论文进不了主题侧边栏文件夹、topic 图谱视图(citation network/deep-trace/similarity map)、topic 统计
  • 归入"未分类"文件夹;推荐排序 20% 劣势(无 topic boost);日报归 uncategorized 桶
  • 论文间引用关系只靠后续 sync_incremental 补,不触发 auto_link

修复

每分类建一个 disabled topic + 关联 + auto_link

  • 命名约定:topic name=csfeed:{category_code}(如 csfeed:cs.AI),query=cat:{category_code}enabled=False
  • enabled=False 防 topic_dispatch 重复抓取topic_dispatch_job 只选 enabled=True 的 topic(main.py list_topics(enabled_only=True)),所以 cs_feed topic 永不被 topic_dispatch 抓取,仅 cs_feed_dispatch 负责 → 零重复抓取
  • disabled topic 仍出现在侧边栏list_topics(enabled_only=False) 默认显示全部;get_folder_stats.by_topic INNER JOIN PaperTopic 统计,不过滤 enabled、只显示有论文的 topic → cs_feed 抓取后该 topic 即可见

改动

  1. packages/ai/cs_feed_orchestrator.py run():抓取循环 upsert_paper 后调 _link_cs_papers_to_topic(按 category_code upsert_topic 幂等 + link_to_topic uq_paper_topic 兜底幂等);抓取后补 _trigger_auto_link(复用 paper_pipelines._auto_link_pool 有界线程池,与 ingest_arxiv 对齐)
  2. apps/api/routers/cs_feeds.py 手动 fetch_category:同步加 link + auto_link,保持两入口一致
  3. 两 helper 设为 @staticmethod(不依赖实例状态,路由可直接调,免实例化 TokenBucket)

验证

  • ruff / format 全通过
  • pytest:58 passed, 2 skipped(新增 TestCSFeedTopicLink 3 项:建 disabled topic + 关联、幂等无重复行、分类隔离)
  • 运行时验证:topic enabled=False + query=cat:cs.AI;2 篇关联;重复关联仍 2 篇(幂等);cs.AI=2 / cs.LG=1 分类隔离

部署影响

  • 无新迁移、无新增配置项
  • cs_feed 抓取后会自动建 topic(disabled)+ 关联 + auto_link,无需手动操作
  • 已有历史 cs_feed 论文(在库无 topic)不在本轮回填范围——只对新抓取的关联;如需回填可后续单独跑脚本

不做(诚实标注)

  • 历史论文回填关联:避免大改 + 数据回填混在一起,留后续
  • cs_feed topic 的 CollectionAction 记录:非图谱/统计必需,留后续
  • 不改 enabled 语义、不改 topic_dispatch、不改前端

此前 cs_feed 按分类抓取论文后只 upsert_paper,无 PaperTopic 关联、
无 _bg_auto_link。后果:cs_feed 论文进不了主题侧边栏文件夹、topic
图谱视图、topic 统计;归入"未分类";推荐排序 20% 劣势;日报归
uncategorized 桶;论文间引用关系只靠后续 sync 补。

修复:
- 每分类建一个 disabled topic(name=csfeed:{code}, query=cat:{code},
  enabled=False)。enabled=False 防 topic_dispatch 重复抓取同一分类
  (topic_dispatch 只选 enabled=True),仅 cs_feed_dispatch 负责。
  disabled topic 仍出现在侧边栏(list_topics 不过滤 enabled,
  get_folder_stats INNER JOIN PaperTopic 统计有论文的 topic)。
- CSFeedOrchestrator.run() 抓取循环加 _link_cs_papers_to_topic,
  按 category_code upsert_topic(幂等)+ link_to_topic(uq_paper_topic
  兜底幂等)。
- 抓取后补 _trigger_auto_link,复用 paper_pipelines._auto_link_pool
  有界线程池,与 ingest_arxiv 对齐。
- 手动 fetch_category 端点同步加 link + auto_link,保持两入口一致。
- 两个 helper 设为 staticmethod(不依赖实例状态,路由可直接调)。

测试:新增 TestCSFeedTopicLink 3 项(建 disabled topic + 关联、
幂等无重复行、分类隔离),全套 58 passed。
@github-actions

Copy link
Copy Markdown

🔍 OpenCode PR Review Required

这是一个受保护的分支,merge 前需要进行 code review。

请运行以下命令进行 OpenCode review:

/oc review https://github.com/Color2333/PaperMind/pull/$PR_NUM

或者在 PR 页面评论 /oc 来触发 OpenCode review。


This is an automated reminder from PR Review Gate.

@Color2333
Color2333 merged commit a4e26eb into main Jul 18, 2026
2 checks passed
@Color2333
Color2333 deleted the feat/cs-feed-topic-link branch July 18, 2026 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant