优化 paper2figure 相关论文检索与参考图元数据流程#61
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
本 PR 聚焦优化 paper2figure 工作流的前半段链路:将“相关论文”从本地 PDF stub 切换为基于 AI4Scholar 的动态检索(含 query planner、缓存与可选 embedding 重排),并将参考图收集升级为保留更丰富 MinerU 元数据的 reference figure items,以便后续 framework spec / figure prompt 生成使用更完整上下文。
Changes:
- 新增 AI4Scholar 检索工具(paper_search)+ query planner prompt,并重写 related_papers 支持动态检索、去重、cache 合并与可选 rerank(保持旧
get_topk_related_papers()调用接口)。 - 新增 SQLite paper cache(paper_cache)与 embedding reranker(paper_reranker),支持缓存论文 metadata/embedding 并在 text API 可用时对候选论文重排。
- 新增 reference_figures,从 MinerU zip 解析结果中收集 framework-like 参考图并保留
image_id/paper_title/paper_rank/caption/visual_summary/zip_url/page_idx等元数据;工作流切换到使用该新收集逻辑,并补充对应单元测试。
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/tests/test_paper2figure_related_papers.py | 覆盖动态检索、配置读取、cache/rerank、debug artifacts 等行为的单测 |
| backend/tests/test_paper2figure_reference_figures.py | 覆盖 reference figure 元数据保留与拷贝输出保留关键字段的单测 |
| backend/tests/test_paper2figure_figure_options.py | 更新 workflow 中参考图收集函数的 monkeypatch 目标以匹配新实现 |
| backend/src/modules/paper2figure/workflow.py | figure workflow 从旧图片提取切换为 metadata-rich reference figure collection |
| backend/src/modules/paper2figure/utils/workflow_helpers.py | copy_framework_items_to_output() 返回类型放宽并保留更多参考图 metadata 字段 |
| backend/src/modules/paper2figure/utils/related_papers.py | 动态 related paper 检索主逻辑:query planning、搜索、去重、cache 合并、rerank、选取 PDF |
| backend/src/modules/paper2figure/utils/reference_figures.py | 新增 reference figure 收集与元数据抽取逻辑 |
| backend/src/modules/paper2figure/utils/paper_search.py | 新增 AI4Scholar paper search:字段规范化与 PDF URL 归一化 |
| backend/src/modules/paper2figure/utils/paper_reranker.py | 新增 embedding reranker:向量缓存与相似度排序 |
| backend/src/modules/paper2figure/utils/paper_cache.py | 新增 SQLite 缓存:论文 metadata 与 embedding 存取 |
| backend/src/modules/paper2figure/utils/init.py | 导出新增 utils:reference_figures 与 related paper debug/records APIs |
| backend/src/modules/paper2figure/prompts.py | 新增 query planner prompt 构造函数 |
| backend/src/modules/paper2figure/config.py | 新增 AI4Scholar 与 related paper retrieval 配置读取(复用 config.yaml / env) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+76
to
+83
| if self.cache is not None: | ||
| self.cache.upsert_embedding( | ||
| title=str(papers[index].get("title", "") or ""), | ||
| paper=papers[index], | ||
| embedding_model=self.embedding_model, | ||
| embedding_text=str(papers[index].get("_embedding_text", "") or ""), | ||
| embedding=vector, | ||
| ) |
| embedding=vector, | ||
| ) | ||
|
|
||
| return [[float(value) for value in (vector or [])] for vector in cached_vectors] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
本 PR 优化了 paper2figure 中“相关论文检索 -> MinerU 解析 -> 参考图筛选 -> figure prompt/image 生成”的前半段链路。
原流程中相关论文主要依赖本地 PDF stub,用于临时跑通流程;本 PR 将其替换为动态检索方案,并补充了参考图 metadata 的保留,使后续 framework spec / figure prompt 生成能够利用更完整的参考图上下文。
主要改动
config.yaml/ 环境变量体系,不引入独立settings.py。related_papers.py,支持动态检索、去重、cache 合并、可选 rerank、PDF URL 选择,并保留旧的get_topk_related_papers()调用接口。collect_related_paper_debug()和get_topk_related_paper_records(),便于后续调试和扩展。reference_figures.py,从 MinerU zip 解析结果中收集 framework-like 参考图。image_id、paper_title、paper_rank、caption、visual_summary、zip_url、page_idx等 metadata。copy_framework_items_to_output()复制筛选后的参考图时保留 metadata。