~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
Fix f-string linting issues in benchmark
LearningCircuit4f7580f93dad
diff --git a/examples/benchmarks/claude_grading/README.md b/examples/benchmarks/claude_grading/README.mdindex 1f578680aa..5d536b1f6d 100644--- a/examples/benchmarks/claude_grading/README.md+++ b/examples/benchmarks/claude_grading/README.md@@ -40,4 +40,4 @@ Results are saved in the `benchmark_results` directory with comprehensive metric- Accuracy scores- Processing times- Grading confidence-- Detailed evaluation reports\ No newline at end of file+- Detailed evaluation reportsdiff --git a/examples/benchmarks/claude_grading/__init__.py b/examples/benchmarks/claude_grading/__init__.pyindex 724f6ab992..bfc0c79343 100644--- a/examples/benchmarks/claude_grading/__init__.py+++ b/examples/benchmarks/claude_grading/__init__.py@@ -1,6 +1,6 @@"""Claude API Grading Benchmark Module-This module provides tools for benchmarking search strategies+This module provides tools for benchmarking search strategieswith proper grading through Claude API integration.-"""\ No newline at end of file+"""diff --git a/examples/benchmarks/claude_grading/benchmark.py b/examples/benchmarks/claude_grading/benchmark.pyindex 042bb513a6..201c9f2466 100755--- a/examples/benchmarks/claude_grading/benchmark.py+++ b/examples/benchmarks/claude_grading/benchmark.py@@ -38,11 +38,12 @@ logging.basicConfig()logger = logging.getLogger(__name__)+def setup_grading_config():"""Create a custom evaluation configuration that uses the local databasefor API keys and specifically uses Claude 3 Sonnet for grading.-+Returns:Dict containing the evaluation configuration"""@@ -53,29 +54,33 @@ def setup_grading_config():print(f"Error importing database utilities: {e}")print("Current sys.path:", sys.path)return None-+# Create config that uses Claude 3 Sonnet via Anthropic directly# This will use the API key from the database# Only use parameters that get_llm() acceptsevaluation_config = {- "model_name": "claude-3-sonnet-20240229", # Correct Anthropic model name+ "model_name": "claude-3-sonnet-20240229", # Correct Anthropic model name"provider": "anthropic", # Use Anthropic directly"temperature": 0, # Zero temp for consistent evaluation}-+# Check if anthropic API key is available in the databasetry:anthropic_key = get_db_setting("llm.anthropic.api_key")if anthropic_key:- print("Found Anthropic API key in database, will use Claude 3 Sonnet for grading")+ print(+ "Found Anthropic API key in database, will use Claude 3 Sonnet for grading"+ )else:print("Warning: No Anthropic API key found in database")print("Checking for alternative providers...")-+# Try OpenRouter as a fallbackopenrouter_key = get_db_setting("llm.openai_endpoint.api_key")if openrouter_key:- print("Found OpenRouter API key, will use OpenRouter with Claude 3 Sonnet")+ print(+ "Found OpenRouter API key, will use OpenRouter with Claude 3 Sonnet"+ )evaluation_config = {"model_name": "anthropic/claude-3-sonnet-20240229", # OpenRouter format"provider": "openai_endpoint",@@ -84,13 +89,14 @@ def setup_grading_config():}except Exception as e:print(f"Error checking for API keys: {e}")-+return evaluation_config+def run_benchmark(strategy="source_based", iterations=1, examples=5):"""Run a comprehensive benchmark evaluation of a specific strategy configuration.-+Args:strategy: Search strategy to evaluate (default: source_based)iterations: Number of iterations for the strategy (default: 1)@@ -98,28 +104,34 @@ def run_benchmark(strategy="source_based", iterations=1, examples=5):"""# Import the benchmark componentstry:+ from local_deep_research.benchmarks.evaluators.browsecomp import (+ BrowseCompEvaluator,+ )+ from local_deep_research.benchmarks.evaluators.composite import (+ CompositeBenchmarkEvaluator,+ )from local_deep_research.benchmarks.evaluators.simpleqa import SimpleQAEvaluator- from local_deep_research.benchmarks.evaluators.browsecomp import BrowseCompEvaluator- from local_deep_research.benchmarks.evaluators.composite import CompositeBenchmarkEvaluatorfrom local_deep_research.config.llm_config import get_llmexcept ImportError as e:print(f"Error importing benchmark components: {e}")print("Current sys.path:", sys.path)return-+# Set up custom grading configurationevaluation_config = setup_grading_config()if not evaluation_config:- print("Failed to setup evaluation configuration, proceeding with default config")-+ print(+ "Failed to setup evaluation configuration, proceeding with default config"+ )+# Patch the graders module to use our local get_llmtry:# This ensures we use the local get_llm function that accesses the databaseimport local_deep_research.benchmarks.graders as graders-+# Store the original function for referenceoriginal_get_evaluation_llm = graders.get_evaluation_llm-+# Define a new function that uses our local get_llm directlydef custom_get_evaluation_llm(custom_config=None):"""@@ -127,24 +139,27 @@ def run_benchmark(strategy="source_based", iterations=1, examples=5):"""if custom_config is None:custom_config = evaluation_config-+print(f"Getting evaluation LLM with config: {custom_config}")return get_llm(**custom_config)-+# Replace the function with our custom versiongraders.get_evaluation_llm = custom_get_evaluation_llm- print("Successfully patched graders.get_evaluation_llm to use local get_llm function")-+ print(+ "Successfully patched graders.get_evaluation_llm to use local get_llm function"+ )+except Exception as e:print(f"Error patching graders module: {e}")import traceback+traceback.print_exc()-+# Create timestamp for outputtimestamp = datetime.now().strftime("%Y%m%d_%H%M%S")output_dir = os.path.join("benchmark_results", f"claude_grading_{timestamp}")os.makedirs(output_dir, exist_ok=True)-+config = {"search_strategy": strategy,"iterations": iterations,@@ -154,9 +169,11 @@ def run_benchmark(strategy="source_based", iterations=1, examples=5):"search_tool": "searxng", # Specify SearXNG search engine"timeout": 10, # Very short timeout to speed up the demo}-+# Run SimpleQA benchmark- print(f"\n=== Running SimpleQA benchmark with {strategy} strategy, {iterations} iterations ===")+ print(+ f"\n=== Running SimpleQA benchmark with {strategy} strategy, {iterations} iterations ==="+ )simpleqa_start = time.time()try:@@ -168,7 +185,7 @@ def run_benchmark(strategy="source_based", iterations=1, examples=5):simpleqa_results = simpleqa.evaluate(config,num_examples=examples,- output_dir=os.path.join(output_dir, "simpleqa")+ output_dir=os.path.join(output_dir, "simpleqa"),)simpleqa_duration = time.time() - simpleqa_start@@ -178,15 +195,19 @@ def run_benchmark(strategy="source_based", iterations=1, examples=5):# Save resultsimport json+with open(os.path.join(output_dir, "simpleqa_results.json"), "w") as f:json.dump(simpleqa_results, f, indent=2)except Exception as e:print(f"Error during SimpleQA evaluation: {e}")import traceback+traceback.print_exc()# Run BrowseComp benchmark- print(f"\n=== Running BrowseComp benchmark with {strategy} strategy, {iterations} iterations ===")+ print(+ f"\n=== Running BrowseComp benchmark with {strategy} strategy, {iterations} iterations ==="+ )browsecomp_start = time.time()try:@@ -198,7 +219,7 @@ def run_benchmark(strategy="source_based", iterations=1, examples=5):browsecomp_results = browsecomp.evaluate(config,num_examples=examples,- output_dir=os.path.join(output_dir, "browsecomp")+ output_dir=os.path.join(output_dir, "browsecomp"),)browsecomp_duration = time.time() - browsecomp_start@@ -212,22 +233,23 @@ def run_benchmark(strategy="source_based", iterations=1, examples=5):except Exception as e:print(f"Error during BrowseComp evaluation: {e}")import traceback+traceback.print_exc()# Run composite benchmark- print(f"\n=== Running Composite benchmark with {strategy} strategy, {iterations} iterations ===")+ print(+ f"\n=== Running Composite benchmark with {strategy} strategy, {iterations} iterations ==="+ )composite_start = time.time()try:# Create composite evaluator with benchmark weights (without evaluation_config parameter)benchmark_weights = {"simpleqa": 0.5, "browsecomp": 0.5}- composite = CompositeBenchmarkEvaluator(- benchmark_weights=benchmark_weights- )+ composite = CompositeBenchmarkEvaluator(benchmark_weights=benchmark_weights)composite_results = composite.evaluate(- config,- num_examples=examples,- output_dir=os.path.join(output_dir, "composite")+ config,+ num_examples=examples,+ output_dir=os.path.join(output_dir, "composite"),)composite_duration = time.time() - composite_start@@ -240,51 +262,68 @@ def run_benchmark(strategy="source_based", iterations=1, examples=5):except Exception as e:print(f"Error during composite evaluation: {e}")import traceback+traceback.print_exc()-+# Generate summary- print(f"\n=== Evaluation Summary ===")+ print("\n=== Evaluation Summary ===")print(f"Strategy: {strategy}")print(f"Iterations: {iterations}")print(f"Examples: {examples}")print(f"Results saved to: {output_dir}")-+# If we patched the graders module, restore the original function- if 'original_get_evaluation_llm' in locals():+ if "original_get_evaluation_llm" in locals():graders.get_evaluation_llm = original_get_evaluation_llmprint("Restored original graders.get_evaluation_llm function")-+return {- "simpleqa": simpleqa_results if 'simpleqa_results' in locals() else None,- "browsecomp": browsecomp_results if 'browsecomp_results' in locals() else None,- "composite": composite_results if 'composite_results' in locals() else None,+ "simpleqa": simpleqa_results if "simpleqa_results" in locals() else None,+ "browsecomp": browsecomp_results if "browsecomp_results" in locals() else None,+ "composite": composite_results if "composite_results" in locals() else None,}+def main():# Parse command line argumentsimport argparse- parser = argparse.ArgumentParser(description="Run benchmark with Claude API grading")- parser.add_argument("--strategy", type=str, default="source_based",- help="Strategy to evaluate (default: source_based)")- parser.add_argument("--iterations", type=int, default=1,- help="Number of iterations (default: 1)")- parser.add_argument("--examples", type=int, default=5,- help="Number of examples to evaluate (default: 5)")-++ parser = argparse.ArgumentParser(+ description="Run benchmark with Claude API grading"+ )+ parser.add_argument(+ "--strategy",+ type=str,+ default="source_based",+ help="Strategy to evaluate (default: source_based)",+ )+ parser.add_argument(+ "--iterations", type=int, default=1, help="Number of iterations (default: 1)"+ )+ parser.add_argument(+ "--examples",+ type=int,+ default=5,+ help="Number of examples to evaluate (default: 5)",+ )+args = parser.parse_args()-- print(f"Starting benchmark of {args.strategy} strategy with {args.iterations} iterations")++ print(+ "Starting benchmark of {} strategy with {} iterations".format(+ args.strategy, args.iterations+ )+ )print(f"Evaluating with {args.examples} examples")-+# Run the evaluationresults = run_benchmark(- strategy=args.strategy,- iterations=args.iterations,- examples=args.examples+ strategy=args.strategy, iterations=args.iterations, examples=args.examples)-+# Return success if at least one benchmark completedreturn 0 if any(results.values()) else 1+if __name__ == "__main__":- sys.exit(main())\ No newline at end of file+ sys.exit(main())diff --git a/examples/benchmarks/claude_grading/run_benchmark.sh b/examples/benchmarks/claude_grading/run_benchmark.shindex 9eda9cbb0f..8eb1d17245 100755--- a/examples/benchmarks/claude_grading/run_benchmark.sh+++ b/examples/benchmarks/claude_grading/run_benchmark.sh@@ -26,4 +26,4 @@ echo "Results will be saved to: $OUTPUT_DIR"pdm run timeout 86400 python -m examples.benchmarks.claude_grading.benchmark "$@"echo "Benchmark complete or timed out."-echo "Check $OUTPUT_DIR for results."\ No newline at end of file+echo "Check $OUTPUT_DIR for results."