# 滚动更新功能使用指南 **更新日期**: 2026-01-08 **版本**: v2.1.1 --- ## ✅ 新增功能 ### 滚动更新(Rolling Update) 在长时间评估过程中,每完成一个问题就立即更新结果文件,而不是等待所有问题评估完成后再保存。 **优势**: - ✅ 实时查看评估进度 - ✅ 防止评估中断导致数据丢失 - ✅ 支持评估过程中随时查看结果 - ✅ 原子写入保证文件完整性 --- ## 🚀 快速开始 ### 基本用法 ```bash # 启用滚动更新 python scripts/evaluate_with_config.py \ --system zht-excel \ --disable answer_correctness \ --output data/results/rolling_update ``` **输出文件**: - `data/results/rolling_update_positive.json` - 正向用例结果(滚动更新) - `data/results/rolling_update_negative.json` - 负向用例结果(滚动更新) --- ## 📊 文件格式 ### 初始状态(评估开始) ```json { "evaluation_start": "2026-01-08T12:00:00", "status": "in_progress", "total_questions": 10, "completed_questions": 0, "metrics_used": ["context_precision", "context_recall", "faithfulness", "answer_relevance"], "results": [] } ``` ### 评估进行中(已完成 3 个问题) ```json { "evaluation_start": "2026-01-08T12:00:00", "status": "in_progress", "total_questions": 10, "completed_questions": 3, "metrics_used": ["context_precision", "context_recall", "faithfulness", "answer_relevance"], "last_updated": "2026-01-08T12:15:30", "results": [ { "question_id": "q001", "category": "简单检索", "type": "positive", "scores": { "context_precision": 0.8000, "context_recall": 1.0000, "faithfulness": 0.7500, "answer_relevance": 0.9000 } }, { "question_id": "q002", "category": "简单检索", "type": "positive", "scores": { "context_precision": 0.8500, "context_recall": 0.9000, "faithfulness": 0.8000, "answer_relevance": 0.8500 } }, { "question_id": "q003", "category": "复杂检索", "type": "positive", "scores": { "context_precision": 0.7000, "context_recall": 0.8000, "faithfulness": 0.7000, "answer_relevance": 0.7500 } } ] } ``` ### 评估完成 ```json { "evaluation_start": "2026-01-08T12:00:00", "status": "completed", "evaluation_end": "2026-01-08T12:50:00", "total_questions": 10, "completed_questions": 10, "metrics_used": ["context_precision", "context_recall", "faithfulness", "answer_relevance"], "last_updated": "2026-01-08T12:50:00", "results": [ // ... 所有10个问题的结果 ] } ``` --- ## 💡 使用场景 ### 场景 1:长时间评估 **问题**:评估 8 个系统 × 15 个问题 = 120 个问题,需要 6+ 小时 **解决方案**:启用滚动更新,随时查看进度 ```bash python scripts/evaluate_with_config.py \ --system zht-excel \ --disable answer_correctness \ --output data/results/long_evaluation ``` **好处**: - 每完成一个问题(约 3 分钟)就更新一次文件 - 可以随时查看已完成的评估结果 - 即使评估中断,已保存的结果不会丢失 --- ### 场景 2:实时监控 **问题**:需要实时了解评估进度和结果 **解决方案**:使用文件监控工具实时查看更新 ```bash # Linux/Mac 使用 watch 命令 watch -n 10 'cat data/results/rolling_update_positive.json | jq ".completed_questions, .results[-1]"' # Windows 使用 PowerShell while($true) { Get-Content data/results/rolling_update_positive.json | ConvertFrom-Json | Select-Object completed_questions, @{Name="last_result"; Expression={$_.results[-1]}}; Start-Sleep -Seconds 10 } ``` --- ### 场景 3:断点续评 **问题**:评估过程中意外中断(断电、网络问题等) **解决方案**:从已完成的结果继续 ```python # 读取已完成的评估结果 import json with open('data/results/rolling_update_positive.json', 'r', encoding='utf-8') as f: data = json.load(f) completed_count = data['completed_questions'] total_count = data['total_questions'] print(f"已完成: {completed_count}/{total_count}") # 可以基于已完成的结果继续评估(需要自行实现续评逻辑) ``` --- ## 🔧 技术实现 ### 原子写入保证 ```python # 1. 更新报告内容 report['completed_questions'] = completed report['results'] = results report['last_updated'] = datetime.now().isoformat() # 2. 原子写入:先写临时文件 temp_file = output_file + '.tmp' with open(temp_file, 'w', encoding='utf-8') as f: json.dump(report, f, ensure_ascii=False, indent=2) # 3. 重命名临时文件(原子操作) Path(temp_file).replace(output_file) ``` **优势**: - 避免写入过程中断导致文件损坏 - 使用临时文件 + 重命名确保原子性 - 即使写入失败,原文件仍然完整 --- ## 📝 完整示例 ### 示例 1:快速评估 + 滚动更新 ```bash python scripts/evaluate_with_config.py \ --system zht-excel \ --disable answer_correctness \ --output data/results/test_rolling ``` **配置**: - 系统:zht-excel - 模式:快速评估(禁用 answer_correctness) - 滚动更新:启用 - 预估时间:48分钟(15问题) **输出**: ``` 评估配置 ================================================================================ 系统: zht-excel 并行: 启用 日志: 启用 滚动更新: 启用 禁用的指标: answer_correctness 输出文件: data/results/test_rolling - 正向用例: data/results/test_rolling_positive.json - 负向用例: data/results/test_rolling_negative.json ================================================================================ ``` --- ### 示例 2:极速评估 + 滚动更新 + 禁用日志 ```bash python scripts/evaluate_with_config.py \ --system zht-excel \ --enable context_precision faithfulness answer_relevance \ --no-logging \ --output data/results/fast_rolling ``` **配置**: - 系统:zht-excel - 模式:极速评估(仅3个核心指标) - 日志:禁用 - 滚动更新:启用 - 预估时间:15分钟(15问题) --- ### 示例 3:完整评估 + 滚动更新 ```bash python scripts/evaluate_with_config.py \ --system zht-excel \ --output data/results/full_rolling ``` **配置**: - 系统:zht-excel - 模式:完整评估(所有5个指标) - 滚动更新:启用 - 预估时间:125分钟(15问题) --- ## ⚠️ 注意事项 ### 1. 文件覆盖 如果输出文件已存在,将会被覆盖! ```bash # 建议使用时间戳避免覆盖 --output data/results/eval_$(date +%Y%m%d_%H%M%S) ``` ### 2. 磁盘空间 滚动更新会产生临时文件,确保有足够磁盘空间。 ### 3. 性能影响 滚动更新每次都会重写整个文件,对于大量问题可能有轻微性能影响。 **影响**: - 每次更新耗时:< 0.1 秒 - 对总耗时影响:几乎可以忽略 ### 4. 结果格式 滚动更新产生的文件格式与标准报告格式不同: - 标准报告:包含 `metadata` 和 `results` 结构 - 滚动更新:直接包含评估数据和状态信息 --- ## 🎯 最佳实践 ### 1. 长时间评估必用 ```bash # 评估时间 > 1 小时,强烈建议启用滚动更新 python scripts/evaluate_with_config.py \ --system zht-excel \ --disable answer_correctness \ --output data/results/long_eval ``` ### 2. 使用有意义的文件名 ```bash # 好的文件名 --output data/results/zht-excel-fast-$(date +%Y%m%d) # 不好的文件名 --output data/results/test ``` ### 3. 定期备份 ```bash # 评估完成后备份结果 cp data/results/rolling_update_positive.json data/results/backup/positive_$(date +%Y%m%d_%H%M%S).json ``` ### 4. 监控磁盘空间 ```bash # 检查磁盘空间 df -h # 清理旧结果 rm data/results/old_*.json ``` --- ## 📚 相关文档 - **性能优化**: `docs/OPTIMIZATION_SUMMARY.md` - **禁用指标指南**: `docs/DISABLE_METRICS_GUIDE.md` - **并行优化**: `docs/PARALLEL_OPTIMIZATION.md` --- ## ✅ 总结 ### 核心优势 1. ⚡ **实时查看**:每完成一个问题就更新结果 2. 🛡️ **数据安全**:原子写入防止文件损坏 3. 🔄 **断点续评**:评估中断可以从已完成结果继续 4. 📊 **实时监控**:支持外部工具监控评估进度 ### 立即开始 ```bash # 最简单的方式 python scripts/evaluate_with_config.py \ --system zht-excel \ --disable answer_correctness \ --output data/results/my_evaluation ``` --- **版本**: v2.1.1 **状态**: ✅ 已完成并可用 **推荐**: 长时间评估(> 1小时)时启用滚动更新 **性能影响**: 几乎可以忽略(< 0.1秒/次)