Skip to content

SiliconEinstein/Paper2tools

Repository files navigation

Paper2Tools v2

从大规模论文推理链中自动发现研究模式,经 Agent Skills 提炼为可执行工作流与 ARM 复现包,并支持工作流 / 思维链检索。

项目概述

Paper2Tools v2 以 TOS 上的 reasoning chain(推理链) 为起点:

  1. Step1:向量化 + 语义聚类,结果写入 LanceDB
  2. Step2:按簇选链、从 TOS 下载语料,生成 Workflower 输入目录与任务脚本
  3. Agent Skills:提取工作流元数据 → 生成 ARM 代码与测试
  4. Step3:对工作流建索引,并提供 workflow 检索 / 思维链检索 API

历史能力(LLM 工具注入 XML、旧版 workflow 抽取、代码自动生成、成对评判等)已移至 archived_steps/,不再走当前主 CLI。

端到端流程

TOS (paper_ocr/)
  ├─ xml/*_reasoning_chain.xml
  └─ md/*.md
       ↓
Step1:向量化 + 聚类 → LanceDB
  ├─ 加载推理链(依赖外部包 staged_lance)
  ├─ DashScope Embedding(text-embedding-v4)
  ├─ Agglomerative 等(见 src/step1/cluster/)
  └─ 输出:Lance chain_embeddings + cluster_metadata、cluster_summary_{domain}.json
       ↓
Step2:Workflow 目录准备
  ├─ 从 Lance 按 domain / 簇规模 / 相似度筛选 cluster
  ├─ 下载 md/、xml/,写入 selected_chains.json
  └─ 输出:data/{domain}/workflows/cluster_{id}/、run_workflows.sh、workflow_tasks.json
       ↓
Workflower_v2(Agent Skill,人工在 Cursor 中执行)
  └─ workflow/workflow_metadata.json、papers_metadata.json
       ↓
Workflow2Code(Agent Skill)
  └─ ARM/(plan、code、dataset、result、trace)
       ↓
Step3:检索
  ├─ build_index — 扫描 workflow 目录建 Lance 索引
  ├─ search — 多路召回 + 可选 LLM 重排(workflow 库)
  └─ chain_search — ByteHouse 思维链多路召回(对外 API)

检索编排类 Skill(QuestionRefiner → WorkflowSearch → ChainSearch)见 skills/LKMRetrievalOrchestrator/

快速开始

环境准备

pip install -r requirements.txt

# 运行完整流水线通常还需(未全部写入 requirements.txt):
pip install openai litellm tenacity tos python-dotenv
# Step1 数据加载依赖外部包:
pip install staged_lance

# 可选:GPU 聚类见 requirements-gpu.txt
# 可选:ChartQA MVP 校验需 jsonschema

在项目根目录配置 .env(勿提交 Git):

# TOS
TOS_ACCESS_KEY=...
TOS_SECRET_KEY=...
TOS_BUCKET=paper-ocr
TOS_ENDPOINT=tos-cn-beijing.volces.com
TOS_REGION=cn-beijing

# Embedding(Step1 / Step3)
API_URL=https://dashscope.aliyuncs.com/compatible-mode/v1/embeddings
ACCESS_KEY=...                    # 或 DASHSCOPE_API_KEY

# LLM(Skills / Step3 重排)
GPUGEEK_API_KEY=...
GPUGEEK_API_BASE=https://api.gpugeek.com/v1
LITELLM_PROXY_API_BASE=...
LITELLM_PROXY_API_KEY=...

# 思维链检索 Step3 chain_search(可选)
LKM_BYTEHOUSE_HOST=...
LKM_BYTEHOUSE_USER=...
LKM_BYTEHOUSE_PASSWORD=...
LKM_BYTEHOUSE_DATABASE=...

CLI 主入口

# Step1:向量化 + 聚类
python -m src.main --step 1 --config configs/step1_config.yaml

# 超导领域
python -m src.main --step 1 --config configs/step1_superconductivity_config.yaml

# 随机 5 万条采样(测试用)
python -m src.main --step 1 --config configs/step1_random50k_config.yaml

# Step2:选簇 + 下载语料 + 生成 Workflower 任务目录
python -m src.main --step 2 --config configs/step2_config.yaml

# Step3:建 workflow 索引
python -m src.main --step 3 --config configs/step3_config.yaml --action build_index

# Step3:workflow 检索
python -m src.main --step 3 --config configs/step3_config.yaml \
  --action search --query "qRT-PCR validation workflow" --top-k 5

# Step3:思维链检索(ByteHouse)
python -m src.main --step 3 --config configs/step3_config.yaml \
  --action chain_search --query "超导磁阻测量工作流" --top-k 5

Step3 常用参数

参数 说明
--action build_index / search / chain_search
--query 检索文本(search / chain_search)
--top-k 返回条数,默认 5
--domain 领域过滤
--table chain_search 表名,默认 lkm_reasoning_chain_embeddings_v2
--strict-routes chain_search 任一路由失败则报错(默认允许降级)

辅助脚本

# 关键词精确检索 → paper_id 频次 → TOS 下载 Top30 md
python scripts/run_tool_keyword_pipeline.py --keyword spades --slug spades

# 重写 research_questions_50_samples 为紧凑评测 schema
python scripts/migrate_samples_schema.py

Agent Skills

Step2 产出目录(含 selected_chains.jsonmd/xml/)下,于 Cursor / Claude Code 加载对应 SKILL.md 执行:

Skill 用途
Workflower_v2/ 推荐:可提取性判断 → 选链 → workflow_metadata.json / papers_metadata.json
Workflow2Code/ ARM 题目、代码、测试与迭代
Workflower/ 早期三阶段:LaTeX 综述、决策树
Workflower_LLM/ 脚本化三阶段 LLM 批处理(01_fast_analyzer.py 等)
WorkflowChallenger/ 基于 workflow 生成半开放挑战题与阅卷手册
QuestionRefiner/ 多轮澄清研究问题,产出检索 query
WorkflowSearchEntry/ 编排 Step3 workflow search
ChainSearchEntry/ 编排 Step3 chain_search
LKMRetrievalOrchestrator/ 端到端:Refiner → WorkflowSearch → ChainSearch

辅助:skills/generate_schema.py(GAIA schema)、skills/batch_generate_schemas.sh

项目结构

paper2tools_v2/
├── src/
│   ├── main.py             # CLI 入口
│   ├── step1/              # 向量化、聚类、Lance 元数据
│   ├── step2/              # 选簇、TOS 下载、Workflow 目录与任务脚本
│   ├── step3/              # workflow 索引 / search / chain_search
│   ├── db/                 # LanceDB 封装
│   ├── models/             # LLM Provider(GPUGEEK / LiteLLM)
│   └── common/
├── skills/                 # Agent Skills(见上表)
├── configs/                # step1/2/3、domain_journals、LLM 模型映射
├── prompts/                # 归档 LLM prompt 模板
├── data/                   # 本地语料与产物(大文件见 .gitignore)
├── archived_steps/         # 历史 step2/3/3.5/4 实现
├── experiments/chartqa_mvp/  # ChartQA JSON Schema MVP
├── scripts/                # 关键词检索、样本 schema 迁移等
├── tests/                  # step1 + common 单元测试
├── docs/                   # 本地报告与图表
├── STEP1_REDESIGN.md
├── STEP2_DESIGN.md
├── requirements.txt
├── requirements-gpu.txt    # cuML GPU 聚类说明
└── monitor_pipeline.sh     # 监控 logs/full_pipeline.log

各 Step 输出说明

Step1

  • LanceDB:data/lance_db/chain_embeddingscluster_metadata
  • 摘要:data/{domain}/step1_output/cluster_summary_{domain}.json
  • 不在此步生成 selected_chains.jsonmd/xml/(由 Step2 完成)

Step2

data/{domain}/workflows/
├── cluster_{id}/
│   ├── selected_chains.json
│   ├── md/
│   └── xml/
├── run_workflows.sh
└── workflow_tasks.json

Workflower_v2

cluster_{id}/workflow/
├── workflow_metadata.json
├── papers_metadata.json
├── workflow_visualization.html
└── stage1_extractability_judgment.json   # 等中间产物(可选)

Workflow2Code / ARM

ARM/
├── plan/
├── code/
├── dataset/
├── result/
└── trace/

本地数据与领域

领域 domain key 仓库内示例
生物信息学 bioinformatics data/bioinformatics/step1_output/
超导 superconductivity data/Superconductivity/(含 workflows_top50/、ARM)
材料科学 materials_science step1_output/
环境科学 environmental_science step1_output/
数学 mathematics step1_output/
流体力学 fluid_mechanics step1_output/

期刊列表:configs/domain_journals.yaml
其他:data/research_questions_50_samples/(评测问题)、data/tool_top30_highfreq_papers/(工具关键词 Top30)。

配置文件

文件 用途
configs/step1_config.yaml 默认 Step1(bioinformatics)
configs/step1_superconductivity_config.yaml 超导 Step1
configs/step1_random50k_config.yaml 随机 5 万条采样
configs/step2_config.yaml 选簇、TOS 下载、输出目录
configs/step3_config.yaml 索引路径、召回权重、ByteHouse
configs/domain_journals.yaml 各领域期刊
configs/config.yaml LLM 模型名映射

Step1 支持 runtime.skip_vectorization: true 复用已有 Lance 向量。

技术栈

  • 向量化:DashScope text-embedding-v4(维度见各 step 配置,常用 512 / 1024)
  • 聚类:Agglomerative(主 pipeline)、KMeans / HDBSCAN / UMAP(src/step1/cluster/
  • 向量库:LanceDB;Step3 chain_search 用 ByteHouse
  • LLM:GPUGEEK / LiteLLM Proxy
  • 对象存储:Volcengine TOS
  • Agent:Cursor Skills

测试

pytest tests/

当前测试覆盖 Step1 与 common;Step2/3 历史测试在 archived_steps/

归档与遗留

路径 说明
archived_steps/step2/ 旧 Step2:LLM 工具提取 + XML enrich
archived_steps/step3/ 旧 Step3:LLM 抽取 workflow JSON
archived_steps/step3_5/ workflow → 可执行 Python
archived_steps/step4/ workflow 成对评判、消融
run_batch_judge_workflows.py 依赖已归档的 workflow_judge当前不可用

相关文档

  • STEP1_REDESIGN.mdSTEP2_DESIGN.md — 分阶段设计
  • .claude/CLAUDE.md.claude/TRACE.md — 项目约定与开发日志
  • experiments/chartqa_mvp/README.md — ChartQA MVP
  • 聚类语料示例:starbilibili/workflow_cluster_raw

License

MIT(仓库根目录暂未附带 LICENSE 文件)

About

从论文中抽取工具信息

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors