~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: Refactor meta search engine for improved error handling and query processing
hashedviking3f1888118049
diff --git a/src/local_deep_research/web_search_engines/engines/meta_search_engine.py b/src/local_deep_research/web_search_engines/engines/meta_search_engine.pyindex a6ee9b9699..3058d2cf41 100644--- a/src/local_deep_research/web_search_engines/engines/meta_search_engine.py+++ b/src/local_deep_research/web_search_engines/engines/meta_search_engine.py@@ -89,69 +89,82 @@ class MetaSearchEngine(BaseSearchEngine):def analyze_query(self, query: str) -> List[str]:"""- Use the LLM to analyze the query and return a ranked list of- recommended search engines to try+ Analyze the query to determine the best search engines to use.++ Args:+ query: The search query++ Returns:+ List of search engine names sorted by suitability"""- if not self.available_engines:- logger.warning("No search engines available")- return []- engine_descriptions = []- for name in self.available_engines:- try:- description = (- f"- {name.upper()}: Good for {', '.join(SEARCH_ENGINES[name]['strengths'][:3])}. "- f"Weaknesses: {', '.join(SEARCH_ENGINES[name]['weaknesses'][:2])}. "- f"Reliability: "- f"{SEARCH_ENGINES[name]['reliability'] * 100:.0f}%"- )- engine_descriptions.append(description)- except KeyError as e:- logger.error(f"Missing key for engine {name}: {e}")- # Add a basic description for engines with missing configuration- engine_descriptions.append(- f"- {name.upper()}: General purpose search engine."+ try:+ # Check if the LLM is available to help select engines+ if not self.llm:+ logger.warning(+ "No LLM available for query analysis, using default engines")- except Exception as e:- logger.error(f"Error processing engine {name}: {e}")- engine_descriptions.append(- f"- {name.upper()}: General purpose search engine."+ # Return engines sorted by reliability+ return sorted(+ self.available_engines,+ key=lambda x: SEARCH_ENGINES.get(x, {}).get("reliability", 0),+ reverse=True,)- engine_descriptions = "\n".join(engine_descriptions)+ # Create a prompt that outlines the available search engines and their strengths+ engines_info = []+ for engine_name in self.available_engines:+ try:+ if engine_name in SEARCH_ENGINES:+ strengths = SEARCH_ENGINES[engine_name].get(+ "strengths", "General search"+ )+ weaknesses = SEARCH_ENGINES[engine_name].get(+ "weaknesses", "None specified"+ )+ description = SEARCH_ENGINES[engine_name].get(+ "description", engine_name+ )+ engines_info.append(+ f"- {engine_name}: {description}\n Strengths: {strengths}\n Weaknesses: {weaknesses}"+ )+ except KeyError as e:+ logger.error(f"Missing key for engine {engine_name}: {str(e)}")- prompt = f"""Analyze this search query and rank the available search engines in order of most to least appropriate for answering it.+ prompt = f"""You are a search query analyst. Consider this search query:-Query: "{query}"+QUERY: {query}-Available search engines:-{engine_descriptions}+I have these search engines available:+{chr(10).join(engines_info)}-Consider:-1. The nature of the query (factual, academic, product-related, news, etc.)-2. The strengths and weaknesses of each engine-3. The reliability of each engine+Determine which search engines would be most appropriate for answering this query.+First analyze the nature of the query (factual, scientific, code-related, etc.)+Then select the 1-3 most appropriate search engines for this type of query.-Return ONLY a comma-separated list of search engine names in your recommended order. Example: "wikipedia,arxiv,duckduckgo"-Do not include any engines that are not listed above. Only return the comma-separated list, nothing else."""+Output ONLY a comma-separated list of the search engine names in order of most appropriate to least appropriate.+Example output: wikipedia,arxiv,github"""- # Get response from LLM- try:+ # Get analysis from LLMresponse = self.llm.invoke(prompt)- content = response.content.strip()- # Parse the response into a list of engine names- engine_names = [name.strip().lower() for name in content.split(",")]+ # Handle different response formats+ if hasattr(response, "content"):+ content = response.content.strip()+ else:+ content = str(response).strip()- # Filter out any invalid engine names- valid_engines = [- name for name in engine_names if name in self.available_engines- ]+ # Extract engine names+ valid_engines = []+ for engine_name in content.split(","):+ cleaned_name = engine_name.strip().lower()+ if cleaned_name in self.available_engines:+ valid_engines.append(cleaned_name)# If no valid engines were returned, use default order based on reliabilityif not valid_engines:valid_engines = sorted(self.available_engines,- key=lambda x: SEARCH_ENGINES[x]["reliability"],+ key=lambda x: SEARCH_ENGINES.get(x, {}).get("reliability", 0),reverse=True,)@@ -161,7 +174,7 @@ Do not include any engines that are not listed above. Only return the comma-sepa# Fall back to reliability-based orderingreturn sorted(self.available_engines,- key=lambda x: SEARCH_ENGINES[x]["reliability"],+ key=lambda x: SEARCH_ENGINES.get(x, {}).get("reliability", 0),reverse=True,)