Skip to content

~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.

Resolve merge conflicts with main

LearningCircuitdcbf43fbc0d8
diff --cc tests/web_search_engines/test_search_engine_factory.py
index fd3cba8eeb,5bf7bbc4c4..6d9c100a2d
--- a/tests/web_search_engines/test_search_engine_factory.py
+++ b/tests/web_search_engines/test_search_engine_factory.py
@@@ -448,97 -478,244 +448,156 @@@ class TestGetSearch
assert result is None
+ def test_get_search_adds_region_params(self):
+ """get_search adds region parameters for supported engines."""
+ from src.local_deep_research.web_search_engines.search_engine_factory import (
+ get_search,
+ )
+
+ mock_llm = Mock()
+
+ settings_snapshot = {
+ "search.max_results": {"value": 10},
+ }
+
+ with patch(
+ "src.local_deep_research.web_search_engines.search_engine_factory.create_search_engine"
+ ) as mock_create:
+ mock_create.return_value = Mock()
+
+ get_search(
+ search_tool="duckduckgo",
+ llm_instance=mock_llm,
+ max_results=10,
+ region="uk",
+ safe_search=True,
+ settings_snapshot=settings_snapshot,
+ )
+
+ # Check that region was passed
+ call_kwargs = mock_create.call_args[1]
+ assert call_kwargs.get("region") == "uk"
+ assert call_kwargs.get("safe_search") is True
+
+ def test_get_search_adds_language_params(self):
+ """get_search adds language parameters for supported engines."""
+ from src.local_deep_research.web_search_engines.search_engine_factory import (
+ get_search,
+ )
+
+ mock_llm = Mock()
+
+ settings_snapshot = {
+ "search.max_results": {"value": 10},
+ }
+
+ with patch(
+ "src.local_deep_research.web_search_engines.search_engine_factory.create_search_engine"
+ ) as mock_create:
+ mock_create.return_value = Mock()
+
+ get_search(
+ search_tool="brave",
+ llm_instance=mock_llm,
+ max_results=10,
+ search_language="German",
+ settings_snapshot=settings_snapshot,
+ )
+
+ call_kwargs = mock_create.call_args[1]
+ assert call_kwargs.get("search_language") == "German"
+
-class TestSearchEngineConfig:
- """Tests for search_config function."""
+class TestFullSearchWrapper:
+ """Tests for _create_full_search_wrapper function."""
- def test_search_config_with_settings_snapshot(self):
- """Load config from settings snapshot."""
- from src.local_deep_research.web_search_engines.search_engines_config import (
- search_config,
- )
-
- settings_snapshot = {
- "search.engine.web.wikipedia.module_path": {
- "value": ".engines.search_engine_wikipedia"
- },
- "search.engine.web.wikipedia.class_name": {
- "value": "WikipediaSearchEngine"
- },
- "search.engine.auto": {"value": {}},
- }
+ def test_wrapper_returns_base_on_missing_config(self):
+ """Test wrapper returns base engine when config missing."""
+ mock_base_engine = Mock()
+ config = {}
+ engine_name = "test_engine"
- config = search_config(settings_snapshot=settings_snapshot)
+ if engine_name not in config:
+ result = mock_base_engine
+ else:
+ result = None
- assert isinstance(config, dict)
- assert "auto" in config
+ assert result == mock_base_engine
- def test_search_config_includes_auto(self):
- """Config includes auto engine."""
- from src.local_deep_research.web_search_engines.search_engines_config import (
- search_config,
- )
-
- # The settings snapshot should have the proper nested structure
+ def test_wrapper_config_extraction(self):
+ """Test config extraction from settings snapshot."""
settings_snapshot = {
- "search.engine.web": {}, # Empty dict, not {"value": {}}
- "search.engine.auto": {
- "key": "value"
- }, # Direct dict, not nested under "value"
+ "search.engine.web.serpapi.api_key": {"value": "test-key"},
+ "search.engine.web.serpapi.class_name": {"value": "SerpApiSearch"},
}
- config = search_config(settings_snapshot=settings_snapshot)
-
- assert "auto" in config
-
-
-class TestExtractPerEngineConfig:
- """Tests for _extract_per_engine_config function."""
-
- def test_extract_flat_config(self):
- """Extract flat configuration."""
- from src.local_deep_research.web_search_engines.search_engines_config import (
- _extract_per_engine_config,
- )
-
- raw = {
- "wikipedia.module_path": ".engines.search_engine_wikipedia",
- "wikipedia.class_name": "WikipediaSearchEngine",
- "arxiv.module_path": ".engines.search_engine_arxiv",
- }
-
- result = _extract_per_engine_config(raw)
-
- assert "wikipedia" in result
- assert "arxiv" in result
- assert (
- result["wikipedia"]["module_path"]
- == ".engines.search_engine_wikipedia"
- )
- assert result["wikipedia"]["class_name"] == "WikipediaSearchEngine"
-
- def test_extract_nested_config(self):
- """Extract nested configuration."""
- from src.local_deep_research.web_search_engines.search_engines_config import (
- _extract_per_engine_config,
- )
-
- raw = {
- "wikipedia.default_params.max_results": 10,
- "wikipedia.default_params.timeout": 30,
- }
-
- result = _extract_per_engine_config(raw)
-
- assert "wikipedia" in result
- assert "default_params" in result["wikipedia"]
- assert result["wikipedia"]["default_params"]["max_results"] == 10
- assert result["wikipedia"]["default_params"]["timeout"] == 30
-
- def test_extract_mixed_config(self):
- """Extract mixed flat and nested configuration."""
- from src.local_deep_research.web_search_engines.search_engines_config import (
- _extract_per_engine_config,
- )
-
- raw = {
- "wikipedia.module_path": ".engines.search_engine_wikipedia",
- "wikipedia.default_params.max_results": 10,
- "simple_key": "simple_value",
+ web_engines = {}
+ for key, value in settings_snapshot.items():
+ if key.startswith("search.engine.web."):
+ parts = key.split(".")
+ if len(parts) >= 4:
+ engine_name = parts[3]
+ if engine_name not in web_engines:
+ web_engines[engine_name] = {}
+ remaining_key = (
+ ".".join(parts[4:]) if len(parts) > 4 else ""
+ )
+ if remaining_key:
+ web_engines[engine_name][remaining_key] = (
+ value.get("value")
+ if isinstance(value, dict)
+ else value
+ )
+
+ assert "serpapi" in web_engines
+ assert web_engines["serpapi"]["api_key"] == "test-key"
+
+
+class TestParameterFiltering:
+ """Tests for parameter filtering logic."""
+
+ def test_filter_unsupported_params(self):
+ """Test filtering of unsupported parameters."""
+ engine_init_params = [
+ "self",
+ "max_results",
+ "api_key",
+ "settings_snapshot",
+ ]
+ all_params = {
+ "max_results": 20,
+ "api_key": "test-key",
+ "unsupported_param": "value",
+ "another_unsupported": "value2",
}
- result = _extract_per_engine_config(raw)
-
- assert "wikipedia" in result
- assert "simple_key" in result
- assert result["simple_key"] == "simple_value"
-
-
-class TestLLMRelevanceFilter:
- """Tests for LLM relevance filter configuration."""
-
- def test_scientific_engine_enables_filter(self):
- """Scientific engines auto-enable LLM filtering."""
- from src.local_deep_research.web_search_engines.search_engine_factory import (
- create_search_engine,
- )
-
- mock_llm = Mock()
-
- settings_snapshot = {
- "search.max_results": {"value": 10},
+ filtered_params = {
+ k: v for k, v in all_params.items() if k in engine_init_params[1:]
}
- with patch(
- "src.local_deep_research.web_search_engines.search_engine_factory.search_config"
- ) as mock_config:
- mock_config.return_value = {
- "arxiv": {
- "module_path": ".engines.search_engine_arxiv",
- "class_name": "ArxivSearchEngine",
- "requires_api_key": False,
- "default_params": {},
- }
- }
+ assert "max_results" in filtered_params
+ assert "api_key" in filtered_params
+ assert "unsupported_param" not in filtered_params
+ assert "another_unsupported" not in filtered_params
- result = create_search_engine(
- engine_name="arxiv",
- llm=mock_llm,
- settings_snapshot=settings_snapshot,
- )
-
- # ArXiv is scientific, should have LLM filtering enabled if LLM present
- if result is not None and hasattr(
- result, "enable_llm_relevance_filter"
- ):
- # Scientific engines should enable filter when LLM is present
- assert result.enable_llm_relevance_filter is True
-
- def test_skip_relevance_filter_global_setting(self):
- """Global skip_relevance_filter overrides engine settings."""
- from src.local_deep_research.web_search_engines.search_engine_factory import (
- create_search_engine,
- )
+ def test_add_settings_snapshot_to_params(self):
+ """Test adding settings_snapshot to params if accepted."""
+ engine_init_params = ["self", "max_results", "settings_snapshot"]
+ filtered_params = {"max_results": 20}
+ settings_snapshot = {"test": "value"}
- mock_llm = Mock()
+ if "settings_snapshot" in engine_init_params[1:] and settings_snapshot:
+ filtered_params["settings_snapshot"] = settings_snapshot
- settings_snapshot = {
- "search.max_results": {"value": 10},
- "search.skip_relevance_filter": {"value": True},
- }
+ assert "settings_snapshot" in filtered_params
- with patch(
- "src.local_deep_research.web_search_engines.search_engine_factory.search_config"
- ) as mock_config:
- mock_config.return_value = {
- "arxiv": {
- "module_path": ".engines.search_engine_arxiv",
- "class_name": "ArxivSearchEngine",
- "requires_api_key": False,
- "default_params": {},
- }
- }
+ def test_add_programmatic_mode_to_params(self):
+ """Test adding programmatic_mode to params if accepted."""
+ engine_init_params = ["self", "max_results", "programmatic_mode"]
+ filtered_params = {"max_results": 20}
+ programmatic_mode = True
- result = create_search_engine(
- engine_name="arxiv",
- llm=mock_llm,
- settings_snapshot=settings_snapshot,
- )
+ if "programmatic_mode" in engine_init_params[1:]:
+ filtered_params["programmatic_mode"] = programmatic_mode
- # With global skip, filter should be disabled
- if result is not None and hasattr(
- result, "enable_llm_relevance_filter"
- ):
- assert result.enable_llm_relevance_filter is False
+ assert filtered_params["programmatic_mode"] is True