OpenViking icon indicating copy to clipboard operation
OpenViking copied to clipboard

feat(benchmark): Add VikingBot testing to RAG benchmark

Open sponge225 opened this issue 7 months ago • 3 comments

Description

本 PR 将 VikingBot 测试添加到了 OpenViking benchmark/RAG 框架中,并添加了自定义 prompt 配置功能,同时优化了执行流程。

  • VikingBot 集成 :添加 VikingBot 测试功能,支持代理式 RAG 评估
  • 自定义 Prompt 配置 :添加 prompt 和 base_instruction 两个配置项,让用户可以灵活自定义 bot 的 prompt
  • 执行流程拆分 :将 --step gen 拆分为 ingest (数据导入)和 gen (RAG 生成)两个独立步骤
  • 断点续传功能 :添加 resume/checkpoint 机制,支持在 gen 和 eval 阶段断点续传
  • Bot 专用配置文件 :为所有数据集添加 bot 专用配置文件示例(位于 config/bot/ 目录下)

Related Issue

Type of Change

  • [ ] Bug fix (non-breaking change that fixes an issue)
  • [ ] New feature (non-breaking change that adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] Documentation update
  • [ ] Refactoring (no functional changes)
  • [ ] Performance improvement
  • [ ] Test update

Changes Made

新增

  • benchmark/RAG/src/core/checkpoint.py - 检查点管理器,支持断点续传
  • benchmark/RAG/src/vikingbot_runner.py - VikingBot 运行器,支持自定义 prompt
  • benchmark/RAG/config/bot/locomo_bot_config.yaml - Locomo 数据集 bot 配置
  • benchmark/RAG/config/bot/qasper_bot_config.yaml - Qasper 数据集 bot 配置
  • benchmark/RAG/config/bot/financebench_bot_config.yaml - FinanceBench 数据集 bot 配置
  • benchmark/RAG/config/bot/syllabusqa_bot_config.yaml - SyllabusQA 数据集 bot 配置 修改
  • benchmark/RAG/run.py - 更新命令行参数和执行流程
  • benchmark/RAG/src/pipeline.py - 拆分执行流程,添加 resume 支持
  • benchmark/RAG/config/*.yaml - 更新标准配置文件
  • benchmark/RAG/README.md - 更新英文文档
  • benchmark/RAG/README_zh.md - 更新中文文档

Testing

  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] New and existing unit tests pass locally with my changes
  • [ ] I have tested this on the following platforms:
    • [ ] Linux
    • [ ] macOS
    • [ ] Windows

Checklist

  • [ ] My code follows the project's coding style
  • [ ] I have performed a self-review of my code
  • [ ] I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] My changes generate no new warnings
  • [ ] Any dependent changes have been merged and published

Screenshots (if applicable)

Additional Notes

功能详情

  1. VikingBot 自定义 Prompt

    • prompt :完全自定义 prompt,支持 {question} 占位符
    • base_instruction :自定义基础指令,保持默认结构
    • 向后兼容:不配置时使用默认 prompt
  2. 执行流程拆分

    • --step ingest :只执行数据导入
    • --step gen :只执行 RAG 生成
    • --step eval :只执行评估
    • --step del :只执行数据删除
    • --step all :执行所有步骤(向后兼容)
    • 删除了 skip_ingestion 配置项
  3. 断点续传功能

    • 支持 --step gen 和 --step eval 两个阶段
    • 自动保存进度到 benchmark_checkpoint.json
    • 配置哈希验证,防止错误的实验结果覆盖

更多详细内容以及使用示例请参考readme文档

sponge225 avatar Apr 15 '26 07:04 sponge225

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Apr 15 '26 07:04 CLAassistant

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🏅 Score: 70
🧪 No relevant tests
🔒 No security concerns identified
✅ No TODO sections
🔀 Multiple PR themes

Sub-PR theme: Add checkpoint/resume functionality and split steps into ingest/gen

Relevant files:

  • benchmark/RAG/src/core/checkpoint.py
  • benchmark/RAG/src/pipeline.py
  • benchmark/RAG/run.py
  • benchmark/RAG/README.md
  • benchmark/RAG/README_zh.md

Sub-PR theme: Add VikingBot integration and custom prompt configuration

Relevant files:

  • benchmark/RAG/src/vikingbot_runner.py
  • benchmark/RAG/src/pipeline.py
  • benchmark/RAG/config/bot/
  • benchmark/RAG/README.md
  • benchmark/RAG/README_zh.md

⚡ Recommended focus areas for review

API Key Environment Variable Regression

The LLM client setup no longer supports the api_key_env_var configuration option, which previously allowed loading the API key from an environment variable. This breaks existing configurations that rely on environment variables for API keys.

if args.step in ["all", "gen", "eval"]:
    api_key = config['llm'].get('api_key', '')
    if not api_key:
        logger.warning("No API Key found in config or environment variables!")
    llm_client = LLMClientWrapper(config=config['llm'], api_key=api_key)
Performance Regression in Generation Stage

The generation stage now uses a serial loop instead of ThreadPoolExecutor for non-VikingBot mode, which reduces parallelism and increases execution time for standard RAG tasks.

if remaining_tasks:
    pbar = tqdm(total=len(tasks), desc="Generating Answers", unit="task", initial=len(completed_tasks))
    for task in remaining_tasks:
        try:
            res = self._process_generation_task(task)
            results_map[res['_global_index']] = res
            completed_tasks.add(res['_global_index'])
            self.checkpoint_manager.update_completed_tasks("generation", completed_tasks, len(tasks))
            self._save_partial_results(results_map)
        except Exception as e:
            self.logger.error(f"Generation failed for task {task['id']}: {e}")
            self.monitor.worker_end(success=False)
        pbar.set_postfix(self.monitor.get_status_dict())
        pbar.update(1)
    pbar.close()

github-actions[bot] avatar Apr 15 '26 07:04 github-actions[bot]

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Stop server only with VikingBot

Only stop the OpenViking server if we actually used VikingBot (i.e., when
use_vikingbot is true in the config). This avoids unnecessary server restarts when
using standard RAG.

benchmark/RAG/src/pipeline.py [112-176]

 def run_generation_only(self):
     """Step 2: Generation (Retrieve -> Generate)"""
     self.logger.info(">>> Stage: Generation")
+    use_vikingbot = self.config['execution'].get('use_vikingbot', False)
     try:
         samples = self.adapter.load_and_transform()    
         tasks = self._prepare_tasks(samples)
         results_map = {}
          
         completed_tasks: Set[int] = set()
         if self.resume:
             completed_tasks = self.checkpoint_manager.get_completed_tasks("generation")
             if completed_tasks:
                 self.logger.info(f"Resuming from checkpoint. {len(completed_tasks)} tasks already completed.")
                 if os.path.exists(self.generated_file):
                     with open(self.generated_file, "r", encoding="utf-8") as f:
                         saved_data = json.load(f)
                         for result in saved_data.get("results", []):
                             results_map[result["_global_index"]] = result
         
         remaining_tasks = [task for task in tasks if task["id"] not in completed_tasks]
         self.logger.info(f"Total tasks: {len(tasks)}, Remaining: {len(remaining_tasks)}")
         
         if remaining_tasks:
             pbar = tqdm(total=len(tasks), desc="Generating Answers", unit="task", initial=len(completed_tasks))
             for task in remaining_tasks:
                 try:
                     res = self._process_generation_task(task)
                     results_map[res['_global_index']] = res
                     completed_tasks.add(res['_global_index'])
                     self.checkpoint_manager.update_completed_tasks("generation", completed_tasks, len(tasks))
                     self._save_partial_results(results_map)
                 except Exception as e:
                     self.logger.error(f"Generation failed for task {task['id']}: {e}")
                     self.monitor.worker_end(success=False)
                 pbar.set_postfix(self.monitor.get_status_dict())
                 pbar.update(1)
             pbar.close()
         else:
             self.logger.info("All tasks already completed!")
         
         sorted_results = [results_map[i] for i in sorted(results_map.keys())]
         dataset_name = self.config.get('dataset_name', 'UnknownDataset')
         save_data = {
             "summary": {"dataset": dataset_name, "total_queries": len(sorted_results)},
             "results": sorted_results
         }
         total = len(sorted_results)
         if total > 0:
             self._update_report({
                     "Query Efficiency (Average Per Query)": {
                         "Average Retrieval Time (s)": sum(r['retrieval']['latency_sec'] for r in sorted_results) / total,
                         "Average Input Tokens": sum(r['token_usage'].get('total_input_tokens', 0) for r in sorted_results) / total,
                         "Average Output Tokens": sum(r['token_usage'].get('llm_output_tokens', 0) for r in sorted_results) / total,
                         "Average Retrieval Embedding Tokens": sum(r['token_usage'].get('retrieval_embedding_tokens', 0) for r in sorted_results) / total,
                     }
                 }
             )
         with open(self.generated_file, "w", encoding="utf-8") as f:
             json.dump(save_data, f, indent=2, ensure_ascii=False)
         
         self.checkpoint_manager.delete_checkpoint()
     finally:
-        # 确保在 generation 阶段结束后停止 ov 服务
-        self.logger.info("Generation stage completed, stopping OpenViking server...")
-        stop_openviking_server()
+        # 仅在使用 VikingBot 时停止 ov 服务
+        if use_vikingbot:
+            self.logger.info("Generation stage completed, stopping OpenViking server...")
+            stop_openviking_server()
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly modifies the code to only stop the OpenViking server when VikingBot is actually used, avoiding unnecessary operations in standard RAG mode.

Low

github-actions[bot] avatar Apr 15 '26 07:04 github-actions[bot]