~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 parallel search engine with multi-level LLM relevance filtering
LearningCircuit8f543acc8594
diff --git a/src/local_deep_research/config/thread_settings.py b/src/local_deep_research/config/thread_settings.pyindex 477393247d..abb5580fab 100644--- a/src/local_deep_research/config/thread_settings.py+++ b/src/local_deep_research/config/thread_settings.py@@ -101,7 +101,16 @@ def get_setting_from_snapshot()return default- # Always raise the exception - callers should handle it explicitly if they want fallback behavior+ # If a default was provided, return it instead of raising an exception+ if default is not None:+ from loguru import logger++ logger.debug(+ f"Setting {key} not found in snapshot or context, using default: {default}"+ )+ return default++ # Only raise the exception if no default was providedraise NoSettingsContextError(f"No settings context available in thread for key '{key}'. All settings must be passed via settings_snapshot.")diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.jsonindex 98ee96b80c..f314793c16 100644--- a/src/local_deep_research/defaults/default_settings.json+++ b/src/local_deep_research/defaults/default_settings.json@@ -466,7 +466,7 @@"step": null,"type": "SEARCH","ui_element": "password",- "value": "ANTHROPIC_API_KEY",+ "value": "","visible": true},"llm.openai.api_key": {@@ -480,7 +480,7 @@"step": null,"type": "SEARCH","ui_element": "password",- "value": "OPENAI_API_KEY",+ "value": "","visible": true},"llm.openai_endpoint.api_key": {@@ -494,7 +494,7 @@"step": null,"type": "SEARCH","ui_element": "password",- "value": "OPENAI_ENDPOINT_API_KEY",+ "value": "","visible": true},"report.detailed_citations": {@@ -1438,7 +1438,7 @@"step": null,"type": "SEARCH","ui_element": "password",- "value": "BRAVE_API_KEY",+ "value": "","visible": true},"search.engine.web.brave.class_name": {@@ -1938,7 +1938,7 @@"step": null,"type": "SEARCH","ui_element": "password",- "value": "GOOGLE_PSE_API_KEY",+ "value": "","visible": true},"search.engine.web.google_pse.class_name": {@@ -2779,7 +2779,7 @@"step": null,"type": "SEARCH","ui_element": "password",- "value": "PUBMED_API_KEY",+ "value": "","visible": true},"search.engine.web.pubmed.class_name": {@@ -3562,7 +3562,7 @@"step": null,"type": "SEARCH","ui_element": "password",- "value": "SERP_API_KEY",+ "value": "","visible": true},"search.engine.web.serpapi.class_name": {@@ -4321,7 +4321,7 @@"step": null,"type": "SEARCH","ui_element": "password",- "value": "TAVILY_API_KEY",+ "value": "","visible": true},"search.engine.web.tavily.class_name": {diff --git a/src/local_deep_research/defaults/settings/search_engines/parallel.json b/src/local_deep_research/defaults/settings/search_engines/parallel.jsonnew file mode 100644index 0000000000..f71f82a4da--- /dev/null+++ b/src/local_deep_research/defaults/settings/search_engines/parallel.json@@ -0,0 +1,198 @@+{+ "search.engine.web.parallel.display_name": {+ "category": "parallel",+ "description": "Display name to use in the U.I. for this search engine.",+ "editable": false,+ "max_value": null,+ "min_value": null,+ "name": "Display Name",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "text",+ "value": "Parallel Search",+ "visible": true+ },+ "search.engine.web.parallel.description": {+ "category": "parallel",+ "description": "Human-readable description of the search engine.",+ "editable": false,+ "max_value": null,+ "min_value": null,+ "name": "Description",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "text",+ "value": "Executes multiple search engines in parallel and combines their results. Uses LLM to select the most appropriate engines for each query.",+ "visible": true+ },+ "search.engine.web.parallel.class_name": {+ "category": "parallel",+ "description": "Class name for the parallel search engine",+ "editable": true,+ "max_value": null,+ "min_value": null,+ "name": "Class Name",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "text",+ "value": "ParallelSearchEngine",+ "visible": true+ },+ "search.engine.web.parallel.module_path": {+ "category": "parallel",+ "description": "Module path for the parallel search engine",+ "editable": true,+ "max_value": null,+ "min_value": null,+ "name": "Module Path",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "text",+ "value": "local_deep_research.web_search_engines.engines.parallel_search_engine",+ "visible": true+ },+ "search.engine.web.parallel.default_params.max_engines_to_select": {+ "category": "parallel",+ "description": "Maximum number of search engines to select and run in parallel",+ "editable": true,+ "max_value": 10,+ "min_value": 1,+ "name": "Max Engines to Select",+ "options": null,+ "step": 1,+ "type": "SEARCH",+ "ui_element": "number",+ "value": 5,+ "visible": true+ },+ "search.engine.web.parallel.default_params.use_api_key_services": {+ "category": "parallel",+ "description": "Include search engines that require API keys",+ "editable": true,+ "max_value": null,+ "min_value": null,+ "name": "Use API Key Services",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "checkbox",+ "value": true,+ "visible": true+ },+ "search.engine.web.parallel.default_params.allow_local_engines": {+ "category": "parallel",+ "description": "⚠️ PRIVACY WARNING: Allow local/private document engines in parallel search. This may expose personal data from your documents to web search queries and LLMs. Only enable if you understand the privacy implications.",+ "editable": true,+ "max_value": null,+ "min_value": null,+ "name": "Allow Local Engines",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "checkbox",+ "value": false,+ "visible": true+ },+ "search.engine.web.parallel.default_params.enable_llm_relevance_filter": {+ "category": "parallel",+ "description": "Enable LLM-based relevance filtering to improve result quality by filtering out irrelevant results. This adds an extra LLM call but significantly improves result relevance.",+ "editable": true,+ "max_value": null,+ "min_value": null,+ "name": "Enable LLM Relevance Filter",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "checkbox",+ "value": true,+ "visible": true+ },+ "search.engine.web.parallel.reliability": {+ "category": "parallel",+ "description": "Reliability of the parallel search engine",+ "editable": true,+ "max_value": 1.0,+ "min_value": 0.0,+ "name": "Reliability",+ "options": null,+ "step": 0.05,+ "type": "SEARCH",+ "ui_element": "range",+ "value": 0.90,+ "visible": true+ },+ "search.engine.web.parallel.requires_api_key": {+ "category": "parallel",+ "description": "Whether this search engine requires an API key",+ "editable": true,+ "max_value": null,+ "min_value": null,+ "name": "Requires Api Key",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "checkbox",+ "value": false,+ "visible": true+ },+ "search.engine.web.parallel.requires_llm": {+ "category": "parallel",+ "description": "Whether this search engine requires an LLM for engine selection",+ "editable": true,+ "max_value": null,+ "min_value": null,+ "name": "Requires LLM",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "checkbox",+ "value": true,+ "visible": true+ },+ "search.engine.web.parallel.supports_full_search": {+ "category": "parallel",+ "description": "Whether this search engine supports full document search",+ "editable": true,+ "max_value": null,+ "min_value": null,+ "name": "Supports Full Search",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "checkbox",+ "value": false,+ "visible": true+ },+ "search.engine.web.parallel.strengths": {+ "category": "parallel",+ "description": "Strengths of this search engine",+ "editable": true,+ "max_value": null,+ "min_value": null,+ "name": "Strengths",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "json",+ "value": "[\"Comprehensive results from multiple sources\", \"Parallel execution for faster results\", \"Intelligent engine selection\", \"Automatic deduplication\", \"Combines strengths of all engines\"]",+ "visible": true+ },+ "search.engine.web.parallel.weaknesses": {+ "category": "parallel",+ "description": "Weaknesses of this search engine",+ "editable": true,+ "max_value": null,+ "min_value": null,+ "name": "Weaknesses",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "json",+ "value": "[\"Higher resource usage\", \"May hit rate limits on multiple engines\", \"Results may vary in quality\", \"Requires LLM for optimal selection\"]",+ "visible": true+ }+}diff --git a/src/local_deep_research/web_search_engines/engines/parallel_search_engine.py b/src/local_deep_research/web_search_engines/engines/parallel_search_engine.pynew file mode 100644index 0000000000..61b259f178--- /dev/null+++ b/src/local_deep_research/web_search_engines/engines/parallel_search_engine.py@@ -0,0 +1,650 @@+import json+import concurrent.futures+from typing import Any, Dict, List, Optional+from threading import Lock++from loguru import logger++from ...config.search_config import get_setting_from_snapshot+from ...utilities.thread_context import preserve_research_context+from ...web.services.socket_service import SocketIOService+from ..search_engine_base import BaseSearchEngine+from ..search_engine_factory import create_search_engine+++class ParallelSearchEngine(BaseSearchEngine):+ """+ Parallel search engine that executes multiple search engines simultaneously.+ Uses LLM to select appropriate engines based on query, then runs them all in parallel.+ """++ def __init__(+ self,+ llm,+ max_results: int = 10,+ use_api_key_services: bool = True,+ max_engines_to_select: int = 100, # Allow selecting all available engines+ allow_local_engines: bool = False, # Disabled by default for privacy+ include_generic_engines: bool = True, # Always include generic search engines+ max_filtered_results: Optional[int] = None,+ settings_snapshot: Optional[Dict[str, Any]] = None,+ programmatic_mode: bool = False,+ **kwargs,+ ):+ """+ Initialize the parallel search engine.++ Args:+ llm: Language model instance for query classification+ max_results: Maximum number of search results to return per engine+ use_api_key_services: Whether to include services that require API keys+ max_engines_to_select: Maximum number of engines to select for parallel execution+ allow_local_engines: Whether to include local/private engines (WARNING: May expose personal data to web)+ max_filtered_results: Maximum number of results to keep after filtering+ settings_snapshot: Settings snapshot for thread context+ programmatic_mode: If True, disables database operations and metrics tracking+ **kwargs: Additional parameters (ignored but accepted for compatibility)+ """+ super().__init__(+ llm=llm,+ max_filtered_results=max_filtered_results,+ max_results=max_results,+ settings_snapshot=settings_snapshot,+ programmatic_mode=programmatic_mode,+ )++ self.use_api_key_services = use_api_key_services+ self.max_engines_to_select = max_engines_to_select+ self.allow_local_engines = allow_local_engines+ self.include_generic_engines = include_generic_engines+ self.settings_snapshot = settings_snapshot++ # Enable LLM relevance filtering at parallel level to filter combined results+ self.enable_llm_relevance_filter = kwargs.get(+ "enable_llm_relevance_filter", True+ )++ # Cache for engine instances+ self.engine_cache = {}+ self.cache_lock = Lock()++ # Get available engines (excluding 'meta', 'auto', and 'parallel')+ self.available_engines = self._get_available_engines()+ logger.info(+ f"Parallel Search Engine initialized with {len(self.available_engines)} available engines: {', '.join(self.available_engines)}"+ )++ def _get_search_config(self) -> Dict[str, Any]:+ """Get search config from settings_snapshot"""+ if self.settings_snapshot:+ # Extract search engine configs from settings snapshot+ config_data = {}+ for key, value in self.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 config_data:+ config_data[engine_name] = {}+ remaining_key = (+ ".".join(parts[4:]) if len(parts) > 4 else ""+ )+ if remaining_key:+ config_data[engine_name][remaining_key] = (+ value.get("value")+ if isinstance(value, dict)+ else value+ )+ return config_data+ else:+ return {}++ def _get_available_engines(self) -> List[str]:+ """Get list of available engines based on is_public flag and API key availability"""+ import importlib++ available = []+ config_data = self._get_search_config()++ for name, config_ in config_data.items():+ # Skip meta, auto, and parallel engines (special engines)+ if name in ["meta", "auto", "parallel"]:+ continue++ # Try to get the engine class to check is_public flag+ try:+ # Load the engine class directly+ module_path = config_.get("module_path")+ class_name = config_.get("class_name")++ if not module_path or not class_name:+ logger.debug(+ f"Missing module_path or class_name for {name}"+ )+ continue++ # Import the module+ package = None+ if module_path.startswith("."):+ # This is a relative import+ package = "local_deep_research.web_search_engines"+ module = importlib.import_module(module_path, package=package)+ engine_class = getattr(module, class_name)++ # Check if engine is public or if local engines are allowed+ if hasattr(engine_class, "is_public"):+ if (+ not engine_class.is_public+ and not self.allow_local_engines+ ):+ logger.debug(f"Skipping local/private engine: {name}")+ continue+ elif (+ not engine_class.is_public and self.allow_local_engines+ ):+ logger.warning(+ f"Including local/private engine {name} - data may be exposed"+ )+ else:+ # No is_public flag - use old name-based detection as fallback+ if not self.allow_local_engines:+ if name.startswith("local") or name in [+ "paperless",+ "personal_notes",+ "project_docs",+ "research_papers",+ "elasticsearch",+ ]:+ logger.debug(+ f"Skipping suspected local engine (no is_public flag): {name}"+ )+ continue+ except Exception as e:+ logger.debug(f"Could not load engine class for {name}: {e}")+ # Skip engines we can't load+ continue++ # Skip engines that require API keys if we don't want to use them+ if (+ config_.get("requires_api_key", False)+ and not self.use_api_key_services+ ):+ logger.debug(+ f"Skipping {name} - requires API key and use_api_key_services is False"+ )+ continue++ # Skip engines that require API keys if the key is not available or empty+ if config_.get("requires_api_key", False):+ api_key = config_.get("api_key", "").strip()+ # Check for common placeholder values+ if (+ not api_key+ or api_key+ in ["", "None", "PLACEHOLDER", "YOUR_API_KEY_HERE"]+ or api_key.endswith(+ "_API_KEY"+ ) # Default placeholders like BRAVE_API_KEY+ or api_key.startswith("YOUR_")+ or api_key == "null"+ ):+ logger.debug(+ f"Skipping {name} - requires API key but none configured (found: {api_key[:20] if api_key else 'empty'})"+ )+ continue++ available.append(name)++ return available++ def _get_available_generic_engines(self) -> List[str]:+ """Get list of available generic search engines that pass API key checks"""+ import importlib++ generic_engines = []+ config_data = self._get_search_config()++ for name, config_ in config_data.items():+ # Skip if not in available engines (already filtered for API keys etc)+ if name not in self.available_engines:+ continue++ try:+ # Load the engine class to check is_generic flag+ module_path = config_.get("module_path")+ class_name = config_.get("class_name")++ if not module_path or not class_name:+ continue++ package = None+ if module_path.startswith("."):+ package = "local_deep_research.web_search_engines"+ module = importlib.import_module(module_path, package=package)+ engine_class = getattr(module, class_name)++ # Check if engine is generic+ if getattr(engine_class, "is_generic", False):+ generic_engines.append(name)+ logger.debug(f"Found generic engine: {name}")+ except Exception as e:+ logger.debug(f"Could not check if {name} is generic: {e}")++ return generic_engines++ def select_engines(self, query: str) -> List[str]:+ """+ Use LLM to select appropriate search engines based only on names.++ Args:+ query: The search query++ Returns:+ List of selected engine names+ """+ if not self.llm or not self.available_engines:+ logger.warning(+ "No LLM or no available engines, using all available"+ )+ return self.available_engines[: self.max_engines_to_select]++ try:+ # Get list of engines for LLM to select from (exclude generic ones if they'll be auto-added)+ engines_for_selection = self.available_engines.copy()+ generic_engines = []++ if self.include_generic_engines:+ generic_engines = self._get_available_generic_engines()+ # Remove generic engines from selection since they'll be added automatically+ engines_for_selection = [+ e for e in engines_for_selection if e not in generic_engines+ ]+ logger.debug(+ f"Excluding generic engines from LLM selection: {generic_engines}"+ )++ # If no specialized engines available, just return the generic ones+ if not engines_for_selection:+ logger.info(+ f"No specialized engines available, using generic engines: {generic_engines}"+ )+ return generic_engines++ # Create a simple prompt with just non-generic engine names+ engine_list = "\n".join(+ [+ f"[{i}] {name}"+ for i, name in enumerate(engines_for_selection)+ ]+ )++ logger.debug(f"Engines for LLM selection: {engines_for_selection}")++ prompt = f"""Query: {query}++Available search engines:+{engine_list}++Select the most appropriate search engines for this query. Return ONLY a JSON array of indices.+Example: [0, 2, 5]++Select up to {self.max_engines_to_select} engines that would best answer this query."""++ logger.debug("Sending prompt to LLM for engine selection")+ # Get LLM response+ response = self.llm.invoke(prompt)++ # Handle different response formats+ if hasattr(response, "content"):+ content = response.content.strip()+ else:+ content = str(response).strip()++ # Extract JSON array+ start_idx = content.find("[")+ end_idx = content.rfind("]")++ if start_idx >= 0 and end_idx > start_idx:+ array_text = content[start_idx : end_idx + 1]+ indices = json.loads(array_text)++ # Convert indices to engine names (from the filtered list)+ selected_engines = []+ for idx in indices:+ if isinstance(idx, int) and 0 <= idx < len(+ engines_for_selection+ ):+ selected_engines.append(engines_for_selection[idx])++ if selected_engines:+ # Add generic search engines (they were excluded from selection)+ if self.include_generic_engines:+ for engine in generic_engines:+ if engine not in selected_engines:+ selected_engines.append(engine)+ logger.debug(f"Added generic engine: {engine}")++ logger.info(f"Final selected engines: {selected_engines}")+ return selected_engines++ # Fallback if parsing fails - return generic engines plus some specialized ones+ logger.warning(+ "Failed to parse LLM response, using generic engines + top specialized"+ )+ result = (+ generic_engines.copy() if self.include_generic_engines else []+ )+ for engine in self.available_engines[: self.max_engines_to_select]:+ if engine not in result:+ result.append(engine)+ return result++ except Exception:+ logger.exception("Error selecting engines with LLM")+ # Fallback to using generic engines + available engines+ if self.include_generic_engines:+ generic_engines = self._get_available_generic_engines()+ result = generic_engines.copy()+ for engine in self.available_engines[+ : self.max_engines_to_select+ ]:+ if engine not in result:+ result.append(engine)+ return result+ return self.available_engines[: self.max_engines_to_select]++ def _get_engine_instance(+ self, engine_name: str+ ) -> Optional[BaseSearchEngine]:+ """Get or create an instance of the specified search engine"""+ with self.cache_lock:+ # Return cached instance if available+ if engine_name in self.engine_cache:+ return self.engine_cache[engine_name]++ # Create a new instance+ engine = None+ try:+ # Only pass parameters that all engines accept+ common_params = {+ "llm": self.llm,+ "max_results": self.max_results,+ }++ # Add max_filtered_results if specified+ if self.max_filtered_results is not None:+ common_params["max_filtered_results"] = (+ self.max_filtered_results+ )++ engine = create_search_engine(+ engine_name,+ settings_snapshot=self.settings_snapshot,+ programmatic_mode=self.programmatic_mode,+ **common_params,+ )++ # Enable filtering at child level to reduce results from each engine+ # We'll also filter at parallel level for combined results+ if engine:+ engine.enable_llm_relevance_filter = True+ logger.debug(+ f"Enabled LLM relevance filter for child engine: {engine_name}"+ )+ except Exception:+ logger.exception(+ f"Error creating engine instance for {engine_name}"+ )+ return None++ if engine:+ # Cache the instance+ self.engine_cache[engine_name] = engine++ return engine++ @preserve_research_context+ def _execute_single_engine(+ self, engine_name: str, query: str+ ) -> Dict[str, Any]:+ """+ Execute a single search engine and return results.++ Note: This method is decorated with @preserve_research_context to ensure+ rate limiting context is properly propagated to child threads.++ Args:+ engine_name: Name of the engine to execute+ query: The search query++ Returns:+ Dictionary with engine name and results or error+ """+ logger.info(f"Executing search on {engine_name}")++ engine = self._get_engine_instance(engine_name)+ if not engine:+ return {+ "engine": engine_name,+ "success": False,+ "error": f"Failed to initialize {engine_name}",+ "results": [],+ }++ try:+ # Run the engine properly through its run() method+ # This ensures proper filter application, context propagation, etc.+ results = engine.run(query)++ if results and len(results) > 0:+ logger.info(f"Got {len(results)} results from {engine_name}")+ return {+ "engine": engine_name,+ "success": True,+ "results": results,+ "count": len(results),+ }+ else:+ return {+ "engine": engine_name,+ "success": False,+ "error": "No results",+ "results": [],+ }++ except Exception as e:+ logger.exception(f"Error executing {engine_name}")+ return {+ "engine": engine_name,+ "success": False,+ "error": str(e),+ "results": [],+ }++ def _get_previews(self, query: str) -> List[Dict[str, Any]]:+ """+ Get preview information by executing selected engines in parallel.++ Args:+ query: The search query++ Returns:+ Combined list of preview dictionaries from all successful engines+ """+ # Select engines for this query+ selected_engines = self.select_engines(query)++ if not selected_engines:+ logger.warning("No engines selected")+ return []++ logger.info(+ f"PARALLEL_SEARCH: Executing {len(selected_engines)} engines in parallel: {', '.join(selected_engines)}"+ )++ # Emit socket event about selected engines+ try:+ SocketIOService().emit_socket_event(+ "parallel_search_started",+ {"engines": selected_engines, "query": query},+ )+ except Exception:+ logger.exception("Socket emit error (non-critical)")++ # Execute all engines in parallel+ all_results = []+ engine_results = {}++ with concurrent.futures.ThreadPoolExecutor(+ max_workers=len(selected_engines)+ ) as executor:+ # Submit all tasks+ future_to_engine = {+ executor.submit(+ self._execute_single_engine, engine_name, query+ ): engine_name+ for engine_name in selected_engines+ }++ # Collect results as they complete+ for future in concurrent.futures.as_completed(future_to_engine):+ engine_name = future_to_engine[future]+ try:+ result = future.result()+ engine_results[engine_name] = result++ if result["success"]:+ # Add source information to each result+ for item in result["results"]:+ item["search_engine"] = engine_name+ all_results.extend(result["results"])++ # Emit success event+ try:+ SocketIOService().emit_socket_event(+ "engine_completed",+ {+ "engine": engine_name,+ "success": True,+ "count": result["count"],+ },+ )+ except Exception:+ pass+ else:+ # Emit failure event+ try:+ SocketIOService().emit_socket_event(+ "engine_completed",+ {+ "engine": engine_name,+ "success": False,+ "error": result.get(+ "error", "Unknown error"+ ),+ },+ )+ except Exception:+ pass++ except Exception as e:+ logger.exception(f"Failed to get result from {engine_name}")+ engine_results[engine_name] = {+ "engine": engine_name,+ "success": False,+ "error": str(e),+ "results": [],+ }++ # Log summary+ successful_engines = [+ name for name, res in engine_results.items() if res["success"]+ ]+ failed_engines = [+ name for name, res in engine_results.items() if not res["success"]+ ]++ logger.info(+ f"PARALLEL_SEARCH_COMPLETE: {len(successful_engines)} succeeded, {len(failed_engines)} failed"+ )+ if successful_engines:+ logger.info(f"Successful engines: {', '.join(successful_engines)}")+ if failed_engines:+ logger.info(f"Failed engines: {', '.join(failed_engines)}")++ # Log sample result to understand structure+ if all_results:+ logger.debug(+ f"Sample result keys from first result: {list(all_results[0].keys())}"+ )+ logger.debug(f"Sample result: {str(all_results[0])[:500]}")++ logger.info(f"Total results from all engines: {len(all_results)}")++ # Store the engine results for potential use in _get_full_content+ self._engine_results = engine_results+ self._successful_engines = successful_engines++ return all_results++ def _get_full_content(+ self, relevant_items: List[Dict[str, Any]]+ ) -> List[Dict[str, Any]]:+ """+ Get full content for the relevant items.+ Since we ran multiple engines, we'll group items by their source engine+ and get full content from each engine for its own results.++ Args:+ relevant_items: List of relevant preview dictionaries++ Returns:+ List of result dictionaries with full content+ """+ # Check if we should get full content+ if get_setting_from_snapshot(+ "search.snippets_only",+ True,+ settings_snapshot=self.settings_snapshot,+ ):+ logger.info("Snippet-only mode, skipping full content retrieval")+ return relevant_items++ logger.info("Getting full content for relevant items")++ # Group items by their source engine+ items_by_engine = {}+ for item in relevant_items:+ engine_name = item.get("search_engine")+ if engine_name:+ if engine_name not in items_by_engine:+ items_by_engine[engine_name] = []+ items_by_engine[engine_name].append(item)++ # Get full content from each engine for its items+ all_full_content = []++ for engine_name, items in items_by_engine.items():+ engine = self._get_engine_instance(engine_name)+ if engine:+ try:+ logger.info(+ f"Getting full content from {engine_name} for {len(items)} items"+ )+ full_content = engine._get_full_content(items)+ all_full_content.extend(full_content)+ except Exception:+ logger.exception(+ f"Error getting full content from {engine_name}"+ )+ # Fall back to returning items without full content+ all_full_content.extend(items)+ else:+ # No engine available, return items as-is+ all_full_content.extend(items)++ return all_full_content++ def invoke(self, query: str) -> List[Dict[str, Any]]:+ """Compatibility method for LangChain tools"""+ return self.run(query)diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_arxiv.py b/src/local_deep_research/web_search_engines/engines/search_engine_arxiv.pyindex 9745543a76..ab8bfc32c4 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_arxiv.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_arxiv.py@@ -15,6 +15,11 @@ from ..search_engine_base import BaseSearchEngineclass ArXivSearchEngine(BaseSearchEngine):"""arXiv search engine implementation with two-phase approach"""+ # Mark as public search engine+ is_public = True+ # Not a generic search engine (specialized for academic papers)+ is_generic = False+def __init__(self,max_results: int = 10,@@ -57,6 +62,7 @@ class ArXivSearchEngine(BaseSearchEngine):# We deliberately do this filtering after relevancy checks,# because it is potentially quite slow.content_filters=content_filters,+ settings_snapshot=settings_snapshot,)self.max_results = max(self.max_results, 25)self.sort_by = sort_bydiff --git a/src/local_deep_research/web_search_engines/engines/search_engine_brave.py b/src/local_deep_research/web_search_engines/engines/search_engine_brave.pyindex bad190b1ae..22b7ecd039 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_brave.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_brave.py@@ -12,6 +12,11 @@ from ..search_engine_base import BaseSearchEngineclass BraveSearchEngine(BaseSearchEngine):"""Brave search engine implementation with two-phase approach"""+ # Mark as public search engine+ is_public = True+ # Mark as generic search engine (general web search)+ is_generic = True+def __init__(self,max_results: int = 10,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_ddg.py b/src/local_deep_research/web_search_engines/engines/search_engine_ddg.pyindex e4f3e1e93c..b0f431cfb3 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_ddg.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_ddg.py@@ -12,6 +12,11 @@ from .full_search import FullSearchResults # Import the FullSearchResults classclass DuckDuckGoSearchEngine(BaseSearchEngine):"""DuckDuckGo search engine implementation with two-phase retrieval"""+ # Mark as public search engine+ is_public = True+ # Mark as generic search engine (general web search)+ is_generic = True+def __init__(self,max_results: int = 10,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_github.py b/src/local_deep_research/web_search_engines/engines/search_engine_github.pyindex f4f53404fb..d7a791a895 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_github.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_github.py@@ -17,6 +17,9 @@ class GitHubSearchEngine(BaseSearchEngine):Provides search across GitHub repositories, code, issues, and users."""+ # Mark as public search engine+ is_public = True+def __init__(self,max_results: int = 15,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_google_pse.py b/src/local_deep_research/web_search_engines/engines/search_engine_google_pse.pyindex 4122757ea3..afefee309c 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_google_pse.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_google_pse.py@@ -14,6 +14,11 @@ from ..search_engine_base import BaseSearchEngineclass GooglePSESearchEngine(BaseSearchEngine):"""Google Programmable Search Engine implementation"""+ # Mark as public search engine+ is_public = True+ # Mark as generic search engine (general web search)+ is_generic = True+def __init__(self,max_results: int = 10,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_guardian.py b/src/local_deep_research/web_search_engines/engines/search_engine_guardian.pyindex 1d30619140..1cde118c9f 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_guardian.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_guardian.py@@ -14,6 +14,9 @@ from ..search_engine_base import BaseSearchEngineclass GuardianSearchEngine(BaseSearchEngine):"""Enhanced Guardian API search engine implementation with LLM query optimization"""+ # Mark as public search engine+ is_public = True+def __init__(self,max_results: int = 10,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py b/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.pyindex 425141f605..07270c7fa7 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_nasa_ads.py@@ -16,6 +16,9 @@ from ..search_engine_base import BaseSearchEngineclass NasaAdsSearchEngine(BaseSearchEngine):"""NASA ADS search engine for physics, astronomy, and astrophysics papers."""+ # Mark as public search engine+ is_public = True+def __init__(self,max_results: int = 25,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_openalex.py b/src/local_deep_research/web_search_engines/engines/search_engine_openalex.pyindex e09e599ba5..5f0d7f66c4 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_openalex.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_openalex.py@@ -16,6 +16,9 @@ from ..search_engine_base import BaseSearchEngineclass OpenAlexSearchEngine(BaseSearchEngine):"""OpenAlex search engine implementation with natural language query support."""+ # Mark as public search engine+ is_public = True+def __init__(self,max_results: int = 25,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.py b/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.pyindex 56126a3b55..bb3e6d276a 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_pubmed.py@@ -17,6 +17,9 @@ class PubMedSearchEngine(BaseSearchEngine):Provides efficient access to biomedical literature while minimizing API usage."""+ # Mark as public search engine+ is_public = True+def __init__(self,max_results: int = 10,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_searxng.py b/src/local_deep_research/web_search_engines/engines/search_engine_searxng.pyindex bd8dac8d42..984fe4c97f 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_searxng.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_searxng.py@@ -29,6 +29,11 @@ class SearXNGSearchEngine(BaseSearchEngine):rate limiting and single-instance approach."""+ # Mark as public search engine+ is_public = True+ # Mark as generic search engine (general web search)+ is_generic = True+def __init__(self,max_results: int = 15,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.py b/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.pyindex 71531154f7..1652b41d82 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_semantic_scholar.py@@ -17,6 +17,9 @@ class SemanticScholarSearchEngine(BaseSearchEngine):Provides efficient access to scientific literature across all fields."""+ # Mark as public search engine+ is_public = True+def __init__(self,max_results: int = 10,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_serpapi.py b/src/local_deep_research/web_search_engines/engines/search_engine_serpapi.pyindex f8d7b873b0..b95fd63775 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_serpapi.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_serpapi.py@@ -11,6 +11,11 @@ from ..search_engine_base import BaseSearchEngineclass SerpAPISearchEngine(BaseSearchEngine):"""Google search engine implementation using SerpAPI with two-phase approach"""+ # Mark as public search engine+ is_public = True+ # Mark as generic search engine (general web search via Google)+ is_generic = True+def __init__(self,max_results: int = 10,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_tavily.py b/src/local_deep_research/web_search_engines/engines/search_engine_tavily.pyindex b6c28ce781..1411147623 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_tavily.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_tavily.py@@ -12,6 +12,11 @@ from ..search_engine_base import BaseSearchEngineclass TavilySearchEngine(BaseSearchEngine):"""Tavily search engine implementation with two-phase approach"""+ # Mark as public search engine+ is_public = True+ # Mark as generic search engine (general web search)+ is_generic = True+def __init__(self,max_results: int = 10,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_wayback.py b/src/local_deep_research/web_search_engines/engines/search_engine_wayback.pyindex 304998aba5..7ac6e8ca04 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_wayback.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_wayback.py@@ -16,6 +16,9 @@ class WaybackSearchEngine(BaseSearchEngine):Provides access to historical versions of web pages"""+ # Mark as public search engine+ is_public = True+def __init__(self,max_results: int = 10,diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_wikipedia.py b/src/local_deep_research/web_search_engines/engines/search_engine_wikipedia.pyindex 4c48fb8bda..c33e7f283f 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_wikipedia.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_wikipedia.py@@ -11,6 +11,9 @@ from ..search_engine_base import BaseSearchEngineclass WikipediaSearchEngine(BaseSearchEngine):"""Wikipedia search engine implementation with two-phase approach"""+ # Mark as public search engine+ is_public = True+def __init__(self,max_results: int = 10,diff --git a/src/local_deep_research/web_search_engines/search_engine_base.py b/src/local_deep_research/web_search_engines/search_engine_base.pyindex 01d72a9eca..660059eb82 100644--- a/src/local_deep_research/web_search_engines/search_engine_base.py+++ b/src/local_deep_research/web_search_engines/search_engine_base.py@@ -38,6 +38,10 @@ class BaseSearchEngine(ABC):Handles common parameters and implements the two-phase search approach."""+ # Class attribute to indicate if this engine searches public internet sources+ # Should be overridden by subclasses - defaults to False for safety+ is_public = False+def __init__(self,llm: Optional[BaseLLM] = None,@@ -232,12 +236,30 @@ class BaseSearchEngine(ABC):previews = preview_filter.filter_results(previews, query)# Step 2: Filter previews for relevance with LLM- # TEMPORARILY DISABLED: Skip LLM relevance filtering- filtered_items = previews- logger.info(- f"LLM relevance filtering disabled - returning all {len(previews)} previews"+ # Check if LLM relevance filtering should be enabled+ enable_llm_filter = getattr(+ self, "enable_llm_relevance_filter", False)+ if enable_llm_filter and self.llm:+ logger.info(+ f"Applying LLM relevance filter to {len(previews)} previews"+ )+ filtered_items = self._filter_for_relevance(previews, query)+ logger.info(+ f"LLM filter kept {len(filtered_items)} of {len(previews)} results"+ )+ else:+ filtered_items = previews+ if not enable_llm_filter:+ logger.debug(+ f"LLM relevance filtering disabled - returning all {len(previews)} previews"+ )+ elif not self.llm:+ logger.debug(+ f"No LLM available for relevance filtering - returning all {len(previews)} previews"+ )+# Step 3: Get full content for filtered itemsif self.search_snippets_only:logger.info("Returning snippet-only results as per config")@@ -356,20 +378,23 @@ class BaseSearchEngine(ABC):# Set a reasonable limit on context lengthcurrent_date = datetime.now(UTC).strftime("%Y-%m-%d")- prompt = f"""Analyze these search results and provide a ranked list of the most relevant ones.+ prompt = f"""Analyze these search results and select the most relevant ones for the query.++Query: "{query}"+Current date: {current_date}-IMPORTANT: Evaluate and rank based on these criteria (in order of importance):-1. Timeliness - current/recent information as of {current_date}-2. Direct relevance to query: "{query}"-3. Source reliability (prefer official sources, established websites)-4. Factual accuracy (cross-reference major claims)+Criteria for selection (in order of importance):+1. Relevance - directly addresses the query topic+2. Quality - from reputable sources or contains substantive information+3. Recency - prefer recent information when relevantSearch results to evaluate:{json.dumps(previews, indent=2)}-Return ONLY a JSON array of indices (0-based) ranked from most to least relevant.-Include ONLY indices that meet ALL criteria, with the most relevant first.-Example response: [4, 0, 2]+Return a JSON array of indices (0-based) for results that are relevant to the query.+Include results that are reasonably relevant, not just perfect matches.+Aim to include diverse perspectives if available.+Example response: [4, 0, 2, 7, 11]Respond with ONLY the JSON array, no other text."""