文章目录
1 总体目标 / Overall Goal
ZH:构建一个“论文检索 + 推理”知识库服务,支持用户上传 PDF/LATEX 源码后,秒级检索并获得基于内容的问答、摘要、引用等功能。
EN: Build a “paper-RAG” service where users upload PDF/LaTeX, then get sub-second search plus content-grounded QA, summaries, and citations.
2 数据管线 / Data Pipeline
阶段 | 关键动作 (ZH) | Key Steps (EN) |
---|---|---|
采集 | S3/GCS 触发 RAGFlow ingest |
Trigger ragflow ingest on S3/GCS events |
解析 | ① PDF→markdown ② LaTeX→AST→markdown;补 bib 引用 |
Parse PDF→md; LaTeX→AST→md; keep bib entries |
分块 | 400–800 tokens;公式单独切块并转为 $\LaTeX$ 字符串 |
Chunk 400–800 tokens; isolate formulas |
元数据 | title, authors, year, doi, venue, sec_title |
Rich metadata for filters |
嵌入 | MCP-Embed service;BGE-Large-zh-v1.5 for CN/EN;可热插入 MiniLM、Llama-Embed | MCP-Embed; hot-swappable embedders |
索引 | Infinity DB:Dense + BM25,enable_hybrid=true |
Hybrid index in Infinity DB |
3 检索策略 / Retrieval Strategy
ZH
- Stage-1 召回
- BM25:速命中关键词(算法名、公式编号)。
- Dense:Cosine k=40 捕获语义同义。
- 融合:
score = 0.3·BM25 + 0.7·Dense
,动态调参。 - 精排:BGE-Reranker-v2;如 GPU 紧张降为 MiniLM-L6。
EN
- Recall via BM25 & dense cosine (k = 40).
- Score fusion with 0.3 / 0.7 weights (tunable).
- Re-rank top-50 using BGE-Reranker-v2 (fallback MiniLM).
4 服务切分 / Service Decomposition
微服务 | 作用 (ZH) | Latency SLA | Endpoint |
---|---|---|---|
MCP-Embed | 文本→向量 | ≤ 20 ms | /embed |
MCP-Search | Hybrid 检索+精排 | ≤ 60 ms | /search |
MCP-Memory | 用户长/短期 KV | ≤ 5 ms | /memory/{uid} |
MCP-Summarise | 论文长文摘要 | ≤ 3 s (async) | /summarise |
5 Agent & Prompt 设计 / Agent & Prompt
SYSTEM: 你是论文助手,只能基于检索结果回答。
TOOLS:
search_papers(query:str, top_k:int=20)
cite(paper_id:str, span:str)
CONTEXT:
{retrieved_chunks}
QUESTION:
{user_query}
GUIDELINES:
1. 如需更多资料务必调用 search_papers。
2. 引用时用 (Author, Year) 并列出 span。
- 多轮 Function Calling:模型看不到答案→触发
search_papers
→检索结果以function
消息注入→模型生成最终答复。 - Memory 写回:把对话摘要、兴趣主题存
MCP-Memory
,下轮预填。 - Chunk 过长:先走 LLM map-reduce 压缩,保证 < 8 K tokens 上下文。
6 核心功能 / Core Features
- 语义搜索 / Semantic Search
- 基于内容的问答 (RAG-QA)
- 自动摘要 & 中英对照翻译
- 引用追踪 (click-to-source spans)
- 相似论文推荐(Dense Only 模式)
7 评测与监控 / Evaluation & Monitoring
指标 | 工具 | 频率 |
---|---|---|
nDCG@10 (BEIR-SciDocs) | nightly auto-eval | 每晚 |
Faithfulness (QAG) | Prompt-ed Llama-3 judge | 每晚 |
Latency P95 | Prometheus + Grafana | 实时 |
GPU 使用率 | NVML exporter | 实时 |
8 面试亮点 / Interview Selling Points
ZH
- 端到端视角:能说清数据→检索→Agent→监控整链路。
- 可替换组件:Embed/Rerank/LLM 全部热插拔,体现工程弹性。
- 效能权衡:给出双检索、融合权重、GPU 回退策略,说明你懂成本。
EN
- E2E vision: articulate full pipeline from ingestion to monitoring.
- Pluggability: swap embedders, rerankers and LLMs—design for change.
- Cost-latency trade-offs: hybrid search, dynamic weights, GPU fallback.
总结 / Wrap-up
我会先用 RAGFlow 搭建混合索引,MCP 服务封装嵌入与检索,Agent 通过 Function Calling 串起工具,实现秒级论文检索及推理;再用监控与评测闭环调优。这样既满足现阶段功能,也给后续模型或业务升级留足弹性。