Files
AIclinicalresearch/docs/03-业务模块/ASL-AI智能文献/05-开发记录
HaHafeng 4c6eaaecbf feat(dc): Implement Postgres-Only async architecture and performance optimization
Summary:
- Implement async file upload processing (Platform-Only pattern)
- Add parseExcelWorker with pg-boss queue
- Implement React Query polling mechanism
- Add clean data caching (avoid duplicate parsing)
- Fix pivot single-value column tuple issue
- Optimize performance by 99 percent

Technical Details:

1. Async Architecture (Postgres-Only):
   - SessionService.createSession: Fast upload + push to queue (3s)
   - parseExcelWorker: Background parsing + save clean data (53s)
   - SessionController.getSessionStatus: Status query API for polling
   - React Query Hook: useSessionStatus (auto-serial polling)
   - Frontend progress bar with real-time feedback

2. Performance Optimization:
   - Clean data caching: Worker saves processed data to OSS
   - getPreviewData: Read from clean data cache (0.5s vs 43s, -99 percent)
   - getFullData: Read from clean data cache (0.5s vs 43s, -99 percent)
   - Intelligent cleaning: Boundary detection + ghost column/row removal
   - Safety valve: Max 3000 columns, 5M cells

3. Bug Fixes:
   - Fix pivot column name tuple issue for single value column
   - Fix queue name format (colon to underscore: asl:screening -> asl_screening)
   - Fix polling storm (15+ concurrent requests -> 1 serial request)
   - Fix QUEUE_TYPE environment variable (memory -> pgboss)
   - Fix logger import in PgBossQueue
   - Fix formatSession to return cleanDataKey
   - Fix saveProcessedData to update clean data synchronously

4. Database Changes:
   - ALTER TABLE dc_tool_c_sessions ADD COLUMN clean_data_key VARCHAR(1000)
   - ALTER TABLE dc_tool_c_sessions ALTER COLUMN total_rows DROP NOT NULL
   - ALTER TABLE dc_tool_c_sessions ALTER COLUMN total_cols DROP NOT NULL
   - ALTER TABLE dc_tool_c_sessions ALTER COLUMN columns DROP NOT NULL

5. Documentation:
   - Create Postgres-Only async task processing guide (588 lines)
   - Update Tool C status document (Day 10 summary)
   - Update DC module status document
   - Update system overview document
   - Update cloud-native development guide

Performance Improvements:
- Upload + preview: 96s -> 53.5s (-44 percent)
- Filter operation: 44s -> 2.5s (-94 percent)
- Pivot operation: 45s -> 2.5s (-94 percent)
- Concurrent requests: 15+ -> 1 (-93 percent)
- Complete workflow (upload + 7 ops): 404s -> 70.5s (-83 percent)

Files Changed:
- Backend: 15 files (Worker, Service, Controller, Schema, Config)
- Frontend: 4 files (Hook, Component, API)
- Docs: 4 files (Guide, Status, Overview, Spec)
- Database: 4 column modifications
- Total: ~1388 lines of new/modified code

Status: Fully tested and verified, production ready
2025-12-22 21:30:31 +08:00
..

ASL模块开发记录

本目录记录ASLAI智能文献筛选模块的完整开发历程。


📁 文档索引

Week 1 完成报告2025-11-18

文档 内容 重要性
今日工作总结.md 2025-11-18全天工作总结
两步测试完整报告.md 国内外模型对比 + 三种风格测试
卒中数据泛化测试报告.md 最初的泛化能力测试
Prompt设计与测试完成报告.md Prompt v1.0.0测试
Week1完成报告.md Week 1开发完成总结

🎯 核心发现

1. 根本问题确认

准确率不高的根本原因 = AI与人类对边界情况的理解差异

不是:

  • 模型智商不够
  • Prompt设计不好
  • 宽松/严格程度不对

而是:

  • 纳排标准存在隐含规则
  • 边界情况定义不明确
  • AI无法猜测用户真实意图

2. 解决方案

短期方案(已实现)

三种筛选风格:

  • 宽松模式:初筛使用,宁可多纳入
  • 标准模式:常规使用,平衡准确率
  • 严格模式:精筛使用,宁可错杀

状态: 后端完成,前端待开发


中期方案(推荐)

用户自定义边界情况:

  1. 用户输入PICOS + 纳排标准
  2. LLM分析生成20种边界情况
  3. 用户确认每种情况的处理方式
  4. 系统生成定制化Prompt

优点: 消除AI与人类理解差异


长期方案V1.0+🔮

Few-shot学习:

  • 从用户纠正中学习
  • 持续优化准确率
  • 个性化Prompt

📊 测试数据

模型性能对比

模型 准确率 一致率 速度 JSON稳定性
DeepSeek-V3 + Qwen-Max 40% 60% 16秒 100%
GPT-4o + Claude-4.5 0%* 80% 10秒 20%

*因JSON格式错误导致失败

筛选风格对比

风格 准确率 召回率 精确率
标准模式 60% 0% 100%
宽松模式 20% 50% 0%
严格模式 未测试 - -

🚀 下一步计划

本周任务

  1. 前端开发:筛选风格选择器
  2. API集成传递style参数
  3. 扩大测试20篇真实数据
  4. 用户培训:三种风格使用场景

Week 2任务

  1. 设计边界情况确认UI
  2. 实现LLM边界情况生成
  3. 用户确认流程开发
  4. 定制化Prompt生成

📝 快速链接

测试脚本

  • backend/scripts/test-stroke-screening.ts - 标准模式测试
  • backend/scripts/test-stroke-screening-lenient.ts - 宽松模式测试
  • backend/scripts/test-stroke-screening-international-models.ts - 模型对比
  • backend/scripts/test-json-parser.ts - JSON解析器测试

Prompt文件

  • backend/prompts/asl/screening/v1.1.0-lenient.txt - 宽松Prompt
  • backend/prompts/asl/screening/v1.1.0-standard.txt - 标准Prompt
  • backend/prompts/asl/screening/v1.1.0-strict.txt - 严格Prompt

核心代码

  • backend/src/modules/asl/schemas/screening.schema.ts - Prompt生成
  • backend/src/modules/asl/services/llmScreeningService.ts - 筛选服务
  • backend/src/common/utils/jsonParser.ts - JSON解析器

💡 重要提示

  1. JSON解析器已修复 - 支持中文引号自动转换
  2. 三种风格已实现 - 后端完成,前端待开发
  3. 根本问题已确认 - 需要用户自定义边界情况

更新日期: 2025-11-18
维护人: AI Assistant
版本: v1.0