~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
feat: add BrowseComp benchmark support for optimization
LearningCircuita22453ac1511
diff --git a/examples/optimization/browsecomp_optimization.py b/examples/optimization/browsecomp_optimization.pynew file mode 100755index 0000000000..b25eddc5d4--- /dev/null+++ b/examples/optimization/browsecomp_optimization.py@@ -0,0 +1,104 @@+#!/usr/bin/env python+"""+Parameter Optimization Using BrowseComp Benchmark for Local Deep Research.++This script demonstrates optimizing research parameters using the BrowseComp benchmark+for higher quality evaluation.++Usage:+ # Install dependencies with PDM+ cd /path/to/local-deep-research+ pdm install++ # Run the script with PDM+ pdm run python examples/optimization/browsecomp_optimization.py+"""++import os+import sys+import json+import logging+from datetime import datetime++# Add the src directory to the Python path+project_root = os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))+sys.path.insert(0, os.path.join(project_root, 'src'))++# Import the optimization functionality+from local_deep_research.benchmarks.optimization import (+ optimize_parameters,+ optimize_for_quality,+ optimize_for_speed,+)++# Configure logging to see progress+logging.basicConfig(+ level=logging.INFO,+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'+)+logger = logging.getLogger(__name__)++def main():+ # Create timestamp for unique output directory+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")+ output_dir = os.path.join("examples", "optimization", "results", f"browsecomp_opt_{timestamp}")+ os.makedirs(output_dir, exist_ok=True)++ print(f"Starting BrowseComp optimization - results will be saved to {output_dir}")++ # Define a simple parameter space for demonstration+ param_space = {+ "iterations": {+ "type": "int",+ "low": 1,+ "high": 3,+ "step": 1,+ },+ "questions_per_iteration": {+ "type": "int",+ "low": 1,+ "high": 3,+ "step": 1,+ },+ "search_strategy": {+ "type": "categorical",+ "choices": ["rapid", "standard", "parallel"],+ },+ }++ # Run optimization with BrowseComp benchmark+ # Using a small number of trials and examples for demonstration+ print("\n=== Running balanced optimization with BrowseComp benchmark ===")+ balanced_params, balanced_score = optimize_parameters(+ query="Climate change effects on biodiversity",+ param_space=param_space,+ output_dir=output_dir,+ n_trials=3, # Small number for demo purposes+ search_tool="searxng",+ benchmark_type="browsecomp", # Specify BrowseComp benchmark+ )++ print(f"Best balanced parameters: {balanced_params}")+ print(f"Best balanced score: {balanced_score:.4f}")++ # Save optimization results+ summary = {+ "timestamp": timestamp,+ "benchmark_type": "browsecomp",+ "balanced": {+ "parameters": balanced_params,+ "score": float(balanced_score)+ }+ }++ with open(os.path.join(output_dir, "browsecomp_optimization_summary.json"), "w") as f:+ json.dump(summary, f, indent=2)++ print(f"\nDemo complete! Results saved to {output_dir}/browsecomp_optimization_summary.json")+ print(f"Recommended parameters for BrowseComp: {balanced_params}")++ print("\nNote: For actual optimizations, we recommend increasing n_trials to at least 20.")+ print("This demo runs with minimal trials to demonstrate the functionality quickly.")++if __name__ == "__main__":+ main()\ No newline at end of filediff --git a/src/local_deep_research/benchmarks/optimization/api.py b/src/local_deep_research/benchmarks/optimization/api.pyindex df541f94f3..49474c26af 100644--- a/src/local_deep_research/benchmarks/optimization/api.py+++ b/src/local_deep_research/benchmarks/optimization/api.py@@ -29,6 +29,7 @@ def optimize_parameters(optimization_metrics: Optional[List[str]] = None,metric_weights: Optional[Dict[str, float]] = None,progress_callback: Optional[Callable[[int, int, Dict], None]] = None,+ benchmark_type: str = "simpleqa",) -> Tuple[Dict[str, Any], float]:"""Optimize parameters for Local Deep Research.@@ -48,6 +49,7 @@ def optimize_parameters(optimization_metrics: List of metrics to optimize (default: ["quality", "speed"])metric_weights: Dictionary of weights for each metricprogress_callback: Optional callback for progress updates+ benchmark_type: Type of benchmark to use ("simpleqa" or "browsecomp")Returns:Tuple of (best_parameters, best_score)@@ -67,6 +69,7 @@ def optimize_parameters(optimization_metrics=optimization_metrics,metric_weights=metric_weights,progress_callback=progress_callback,+ benchmark_type=benchmark_type,)# Run optimization@@ -81,6 +84,7 @@ def optimize_for_speed(provider: Optional[str] = None,search_tool: Optional[str] = None,progress_callback: Optional[Callable[[int, int, Dict], None]] = None,+ benchmark_type: str = "simpleqa",) -> Tuple[Dict[str, Any], float]:"""Optimize parameters with a focus on speed performance.@@ -93,6 +97,7 @@ def optimize_for_speed(provider: LLM providersearch_tool: Search engine to useprogress_callback: Optional callback for progress updates+ benchmark_type: Type of benchmark to use ("simpleqa" or "browsecomp")Returns:Tuple of (best_parameters, best_score)@@ -131,6 +136,7 @@ def optimize_for_speed(metric_weights=metric_weights,optimization_metrics=["speed", "quality"],progress_callback=progress_callback,+ benchmark_type=benchmark_type,)@@ -142,6 +148,7 @@ def optimize_for_quality(provider: Optional[str] = None,search_tool: Optional[str] = None,progress_callback: Optional[Callable[[int, int, Dict], None]] = None,+ benchmark_type: str = "simpleqa",) -> Tuple[Dict[str, Any], float]:"""Optimize parameters with a focus on result quality.@@ -154,6 +161,7 @@ def optimize_for_quality(provider: LLM providersearch_tool: Search engine to useprogress_callback: Optional callback for progress updates+ benchmark_type: Type of benchmark to use ("simpleqa" or "browsecomp")Returns:Tuple of (best_parameters, best_score)@@ -171,6 +179,7 @@ def optimize_for_quality(metric_weights=metric_weights,optimization_metrics=["quality", "speed"],progress_callback=progress_callback,+ benchmark_type=benchmark_type,)@@ -182,6 +191,7 @@ def optimize_for_efficiency(provider: Optional[str] = None,search_tool: Optional[str] = None,progress_callback: Optional[Callable[[int, int, Dict], None]] = None,+ benchmark_type: str = "simpleqa",) -> Tuple[Dict[str, Any], float]:"""Optimize parameters with a focus on resource efficiency.@@ -194,6 +204,7 @@ def optimize_for_efficiency(provider: LLM providersearch_tool: Search engine to useprogress_callback: Optional callback for progress updates+ benchmark_type: Type of benchmark to use ("simpleqa" or "browsecomp")Returns:Tuple of (best_parameters, best_score)@@ -211,6 +222,7 @@ def optimize_for_efficiency(metric_weights=metric_weights,optimization_metrics=["quality", "speed", "resource"],progress_callback=progress_callback,+ benchmark_type=benchmark_type,)diff --git a/src/local_deep_research/benchmarks/optimization/optuna_optimizer.py b/src/local_deep_research/benchmarks/optimization/optuna_optimizer.pyindex c9638b1156..6623465a26 100644--- a/src/local_deep_research/benchmarks/optimization/optuna_optimizer.py+++ b/src/local_deep_research/benchmarks/optimization/optuna_optimizer.py@@ -24,7 +24,7 @@ from optuna.visualization import (plot_slice,)-from local_deep_research.benchmarks import run_simpleqa_benchmark+from local_deep_research.benchmarks import run_browsecomp_benchmark, run_simpleqa_benchmarkfrom local_deep_research.benchmarks.efficiency.speed_profiler import SpeedProfiler# Local Deep Research imports@@ -50,14 +50,16 @@ def evaluate_benchmark_quality(system_config: Dict[str, Any],num_examples: int = 10,output_dir: Optional[str] = None,+ benchmark_type: str = "simpleqa",) -> Dict[str, float]:"""- Evaluate quality using SimpleQA benchmark.+ Evaluate quality using a benchmark.Args:system_config: Configuration parameters to evaluatenum_examples: Number of benchmark examples to useoutput_dir: Directory to save results (temporary if None)+ benchmark_type: Type of benchmark to use ("simpleqa" or "browsecomp")Returns:Dictionary with benchmark metrics@@ -81,14 +83,23 @@ def evaluate_benchmark_quality("provider": system_config.get("provider"),}- # Run benchmark- logger.info(f"Running SimpleQA benchmark with {num_examples} examples")- benchmark_results = run_simpleqa_benchmark(- num_examples=num_examples,- output_dir=output_dir,- search_config=search_config,- run_evaluation=True,- )+ # Run specified benchmark+ if benchmark_type.lower() == "browsecomp":+ logger.info(f"Running BrowseComp benchmark with {num_examples} examples")+ benchmark_results = run_browsecomp_benchmark(+ num_examples=num_examples,+ output_dir=output_dir,+ search_config=search_config,+ run_evaluation=True,+ )+ else: # Default to SimpleQA+ logger.info(f"Running SimpleQA benchmark with {num_examples} examples")+ benchmark_results = run_simpleqa_benchmark(+ num_examples=num_examples,+ output_dir=output_dir,+ search_config=search_config,+ run_evaluation=True,+ )# Extract key metricsmetrics = benchmark_results.get("metrics", {})@@ -98,11 +109,17 @@ def evaluate_benchmark_quality(return {"accuracy": accuracy,"quality_score": accuracy, # Map accuracy directly to quality score+ "benchmark_type": benchmark_type,}except Exception as e:logger.error(f"Error in benchmark evaluation: {str(e)}")- return {"accuracy": 0.0, "quality_score": 0.0, "error": str(e)}+ return {+ "accuracy": 0.0,+ "quality_score": 0.0,+ "error": str(e),+ "benchmark_type": benchmark_type,+ }finally:# Clean up temporary directory if we created it@@ -141,6 +158,7 @@ class OptunaOptimizer:optimization_metrics: Optional[List[str]] = None,metric_weights: Optional[Dict[str, float]] = None,progress_callback: Optional[Callable[[int, int, Dict], None]] = None,+ benchmark_type: str = "simpleqa",):"""Initialize the optimizer.@@ -159,6 +177,7 @@ class OptunaOptimizer:optimization_metrics: List of metrics to optimize (default: ["quality", "speed"])metric_weights: Dictionary of weights for each metricprogress_callback: Optional callback for progress updates+ benchmark_type: Type of benchmark to use ("simpleqa" or "browsecomp")"""self.base_query = base_queryself.output_dir = output_dir@@ -172,6 +191,7 @@ class OptunaOptimizer:self.optimization_metrics = optimization_metrics or ["quality", "speed"]self.metric_weights = metric_weights or {"quality": 0.6, "speed": 0.4}self.progress_callback = progress_callback+ self.benchmark_type = benchmark_type# Normalize weights to sum to 1.0total_weight = sum(self.metric_weights.values())@@ -490,12 +510,13 @@ class OptunaOptimizer:"provider": self.provider,}- # Evaluate quality using benchmark+ # Evaluate quality using specified benchmark type# Use a small number of examples for efficiencyquality_results = evaluate_benchmark_quality(system_config=system_config,num_examples=5, # Small number for optimization efficiencyoutput_dir=os.path.join(self.output_dir, "benchmark_temp"),+ benchmark_type=self.benchmark_type,)# Stop timing@@ -592,6 +613,7 @@ class OptunaOptimizer:"provider": self.provider,"search_tool": self.search_tool,"metric_weights": self.metric_weights,+ "benchmark_type": self.benchmark_type,},f,indent=2,@@ -1012,6 +1034,7 @@ def optimize_parameters(optimization_metrics: Optional[List[str]] = None,metric_weights: Optional[Dict[str, float]] = None,progress_callback: Optional[Callable[[int, int, Dict], None]] = None,+ benchmark_type: str = "simpleqa",) -> Tuple[Dict[str, Any], float]:"""Optimize parameters for Local Deep Research.@@ -1031,6 +1054,7 @@ def optimize_parameters(optimization_metrics: List of metrics to optimize (default: ["quality", "speed"])metric_weights: Dictionary of weights for each metricprogress_callback: Optional callback for progress updates+ benchmark_type: Type of benchmark to use ("simpleqa" or "browsecomp")Returns:Tuple of (best_parameters, best_score)@@ -1050,6 +1074,7 @@ def optimize_parameters(optimization_metrics=optimization_metrics,metric_weights=metric_weights,progress_callback=progress_callback,+ benchmark_type=benchmark_type,)# Run optimization@@ -1064,6 +1089,7 @@ def optimize_for_speed(provider: Optional[str] = None,search_tool: Optional[str] = None,progress_callback: Optional[Callable[[int, int, Dict], None]] = None,+ benchmark_type: str = "simpleqa",) -> Tuple[Dict[str, Any], float]:"""Optimize parameters with a focus on speed performance.@@ -1076,6 +1102,7 @@ def optimize_for_speed(provider: LLM providersearch_tool: Search engine to useprogress_callback: Optional callback for progress updates+ benchmark_type: Type of benchmark to use ("simpleqa" or "browsecomp")Returns:Tuple of (best_parameters, best_score)@@ -1114,6 +1141,7 @@ def optimize_for_speed(metric_weights=metric_weights,optimization_metrics=["speed", "quality"],progress_callback=progress_callback,+ benchmark_type=benchmark_type,)@@ -1125,6 +1153,7 @@ def optimize_for_quality(provider: Optional[str] = None,search_tool: Optional[str] = None,progress_callback: Optional[Callable[[int, int, Dict], None]] = None,+ benchmark_type: str = "simpleqa",) -> Tuple[Dict[str, Any], float]:"""Optimize parameters with a focus on result quality.@@ -1137,6 +1166,7 @@ def optimize_for_quality(provider: LLM providersearch_tool: Search engine to useprogress_callback: Optional callback for progress updates+ benchmark_type: Type of benchmark to use ("simpleqa" or "browsecomp")Returns:Tuple of (best_parameters, best_score)@@ -1154,4 +1184,5 @@ def optimize_for_quality(metric_weights=metric_weights,optimization_metrics=["quality", "speed"],progress_callback=progress_callback,+ benchmark_type=benchmark_type,)