feat(asl): Implement full-text screening core LLM service and validation system (Day 1-3)

Core Components:
- PDFStorageService with Dify/OSS adapters
- LLM12FieldsService with Nougat-first + dual-model + 3-layer JSON parsing
- PromptBuilder for dynamic prompt assembly
- MedicalLogicValidator with 5 rules + fault tolerance
- EvidenceChainValidator for citation integrity
- ConflictDetectionService for dual-model comparison

Prompt Engineering:
- System Prompt (6601 chars, Section-Aware strategy)
- User Prompt template (PICOS context injection)
- JSON Schema (12 fields constraints)
- Cochrane standards (not loaded in MVP)

Key Innovations:
- 3-layer JSON parsing (JSON.parse + json-repair + code block extraction)
- Promise.allSettled for dual-model fault tolerance
- safeGetFieldValue for robust field extraction
- Mixed CN/EN token calculation

Integration Tests:
- integration-test.ts (full test)
- quick-test.ts (quick test)
- cached-result-test.ts (fault tolerance test)

Documentation Updates:
- Development record (Day 2-3 summary)
- Quality assurance strategy (full-text screening)
- Development plan (progress update)
- Module status (v1.1 update)
- Technical debt (10 new items)

Test Results:
- JSON parsing success rate: 100%
- Medical logic validation: 5/5 passed
- Dual-model parallel processing: OK
- Cost per PDF: CNY 0.10

Files: 238 changed, 14383 insertions(+), 32 deletions(-)
Docs: docs/03-涓氬姟妯″潡/ASL-AI鏅鸿兘鏂囩尞/05-寮€鍙戣褰?2025-11-22_Day2-Day3_LLM鏈嶅姟涓庨獙璇佺郴缁熷紑鍙?md
This commit is contained in:
2025-11-22 22:18:17 +08:00
parent 8eef9e0544
commit beb7f7f559
238 changed files with 20718 additions and 31 deletions

View File

@@ -839,3 +839,4 @@ export default ScreeningResults;
**开始时间**:待定

View File

@@ -0,0 +1,223 @@
# 全文复筛开发计划 - 更新说明
> **更新日期**2025-11-22
> **版本**V1.1
> **更新原因**:基于质量保障策略讨论,优化技术方案
---
## 📊 核心变更总结
### 1⃣ **提取策略:全文一次性 + Prompt工程优化**
**决策**:采用全文一次性输入策略,而非分段提取
**理由**
- ✅ 实现复杂度低2周 vs 3周
- ✅ 快速验证可行性
- ✅ Nougat结构化已降低大模型负担
- ✅ 先进的Prompt工程可以减轻Lost in the Middle
**核心优化**
1. **Nougat优先**英文论文用Nougat提取结构化Markdown
2. **Section-Aware Prompting**引导LLM逐章节处理
3. **Few-shot案例库**:特别强调"信息在中间位置"的案例
4. **JSON Schema约束**:强制证据链 + 处理日志 + 自我验证
---
### 2⃣ **模型选择DeepSeek-V3 + Qwen3-Max**
**变更**:从 GPT-4o + Claude-4.5 改为 DeepSeek-V3 + Qwen3-Max
**理由**
- ✅ 成本友好¥0.06/篇 vs ¥0.10/篇节省40%
- ✅ 通用能力层已支持
- ✅ 中文文献友好
- ✅ MVP阶段优先验证可行性而非追求极致准确率
---
### 3⃣ **质量保障Cochrane标准 + 医学逻辑验证**
**新增服务**
1. **MedicalLogicValidator**(医学逻辑验证)
- RCT必须有随机化
- 双盲研究必须说明盲法
- 样本量与基线数据一致性
- 等...共5条规则
2. **EvidenceChainValidator**(证据链验证)
- 强制原文引用≥50字
- 位置信息(章节、段落)
- 处理日志验证
3. **ConflictDetectionService**(增强)
- 基于Cochrane标准的严重程度分级
- 关键字段特殊处理
---
### 4⃣ **Prompt模板结构化分层**
**新目录结构**
```
prompts/
├── system_prompt.md # System PromptSection-Aware
├── user_prompt_template.md # User Prompt模板
├── cochrane_standards/ # Cochrane标准描述分字段
│ ├── 随机化方法.md
│ ├── 盲法.md
│ ├── 结果完整性.md
│ └── ...共12个
└── few_shot_examples/ # Few-shot医学案例库
├── 高质量RCT.md
├── 质量不足案例.md
└── 信息在中间位置案例.md # ← 特别重要
```
---
### 5⃣ **开发周期2周 + MVP验证3天**
**调整**
- Week 1-2开发保持2周
- Week 3Day 11-13MVP验证 + 条件升级决策
**MVP验证关键**
- 测试10-15篇人工标注论文
- 评估准确率目标≥85%
- 如果<80%,升级为混合策略(关键字段分段提取)
---
### 6⃣ **数据库设计增强**
**新增字段**
- `promptVersion`Prompt版本号
- `extractionMethod`'nougat' | 'pymupdf'
- `structuredFormat`:是否为结构化格式
- `processingLog`:处理日志(验证逐章节处理)
- `logicValidation`:医学逻辑验证结果
- `evidenceComplete`:证据链是否完整
- `conflictSeverity`:冲突严重程度
- `reviewPriority`:复核优先级
---
## 🎯 关键技术要点
### Prompt工程核心策略
#### 1. Section-Aware Prompting
```markdown
⚠️ 重要本文是完整全文约20,000字请按章节逐步处理。
## 处理流程(必须遵守):
### Step 1: 章节定位
快速浏览全文识别关键章节Abstract、Methods、Results...
### Step 2: 分字段提取
对于每个字段:
1. 标注预期位置
2. 定位到章节
3. **逐段仔细阅读**(不要跳过中间)
4. 提取信息
5. 记录引用和位置
⚠️ 特别注意:
- Methods和Results在中间位置最容易遗漏
- 这些章节很长,请分段阅读
### Step 3: 交叉验证
回到全文,搜索关键词,确认无遗漏
```
#### 2. Few-shot案例重点信息在中间
```markdown
### 案例1信息在Methods中间段落易遗漏
全文19,500字
- Methods4,000字
- 第1段研究设计概述
- 第2段入排标准
- **第3段随机化方法** ← 关键!在中间
- 第4段盲法
- ...
正确做法✅:逐段阅读,不跳过
错误示例❌:只看开头和结尾,跳过中间
```
#### 3. JSON Schema强制约束
```json
{
"processing_log": {
"sections_reviewed": ["Abstract", "Methods", "Results", "Tables"],
"paragraphs_read_per_section": {
"Methods": 7, // 必须≥3
"Results": 5 // 必须≥3
},
"middle_sections_attention": true // 必须关注中间
},
"verification": {
"keywords_searched": ["randomization", "blinding", "ITT"],
"reread_count": 2, // 至少重读1次
"found_missed_info": false
}
}
```
---
## 📈 预期效果
| 指标 | 目标 | 验证方法 |
|------|------|----------|
| **准确率MVP** | ≥ 85% | 人工标注10-15篇测试 |
| **Methods章节准确率** | ≥ 83% | 分章节评估 |
| **Results章节准确率** | ≥ 83% | 分章节评估 |
| **证据链完整性** | 100% | 自动检查 |
| **医学逻辑验证** | 100% | 规则引擎检查 |
| **成本** | ≤ ¥0.06/篇 | 实际消耗统计 |
| **处理时间** | ≤ 3分钟/篇 | 性能测试 |
---
## 🚀 条件升级路径
如果MVP准确率<80%,升级为**混合策略**
```
关键字段3个→ 分段提取
- 随机化方法Methods
- 盲法Methods
- 结果完整性Results + Figures
其他字段9个→ 保持全文提取
- 研究设计、研究人群、干预措施等
开发增量:+1周
预期准确率90%+
```
---
## 📚 相关文档
- [全文复筛质量保障策略](../02-技术设计/08-全文复筛质量保障策略.md)
- [标题摘要初筛质量保障策略](../02-技术设计/06-质量保障与可追溯策略.md)
- [数据库设计](../02-技术设计/01-数据库设计.md)
- [API设计规范](../02-技术设计/02-API设计规范.md)
---
**更新日志**
- 2025-11-22: V1.1 - 基于质量保障讨论,确定全文一次性+Prompt优化策略
- 2025-11-22: V1.0 - 初始版本