~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: remove reduntant comments
hashedvikingd9af32428741
diff --git a/web_search_engines/engines/search_engine_searxng.py b/web_search_engines/engines/search_engine_searxng.pyindex d06e7c331e..99111e7c6d 100644--- a/web_search_engines/engines/search_engine_searxng.py+++ b/web_search_engines/engines/search_engine_searxng.py@@ -77,18 +77,15 @@ class SearXNGSearchEngine(BaseSearchEngine):self.safe_search = safe_searchself.time_range = time_range- # Get delay from env var if provided, otherwise use parameterself.delay_between_requests = float(os.getenv("SEARXNG_DELAY", delay_between_requests))self.include_full_content = include_full_content- # Construct search URL if instance is availableif self.is_available:self.search_url = f"{self.instance_url}/search"logger.info(f"SearXNG engine initialized with instance: {self.instance_url}")logger.info(f"Rate limiting set to {self.delay_between_requests} seconds between requests")- # Initialize FullSearchResults for content retrievalself.full_search = FullSearchResults(llm=llm,web_search=self,@@ -99,7 +96,6 @@ class SearXNGSearchEngine(BaseSearchEngine):safesearch="Moderate" if safe_search == 1 else "Off" if safe_search == 0 else "Strict")- # Track last request time for rate limitingself.last_request_time = 0def _respect_rate_limit(self):@@ -107,14 +103,12 @@ class SearXNGSearchEngine(BaseSearchEngine):current_time = time.time()time_since_last_request = current_time - self.last_request_time- # If we haven't waited long enough since the last request+if time_since_last_request < self.delay_between_requests:- # Calculate how much longer we need to waitwait_time = self.delay_between_requests - time_since_last_requestlogger.info(f"Rate limiting: waiting {wait_time:.2f} seconds")time.sleep(wait_time)- # Update the last request timeself.last_request_time = time.time()def _get_search_results(self, query: str) -> List[Dict[str, Any]]:@@ -127,16 +121,13 @@ class SearXNGSearchEngine(BaseSearchEngine):Returns:List of search results from SearXNG"""- # If the engine is disabled, return empty resultsif not self.is_available:logger.warning("SearXNG engine is disabled (no instance URL provided)")return []try:- # Respect rate limitsself._respect_rate_limit()- # First get initial cookies by visiting home pageinitial_headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",@@ -150,7 +141,6 @@ class SearXNGSearchEngine(BaseSearchEngine):logger.warning(f"Failed to get initial cookies: {e}")cookies = None- # Basic parameters - using HTML formatparams = {"q": query,"categories": ",".join(self.categories),@@ -161,7 +151,6 @@ class SearXNGSearchEngine(BaseSearchEngine):"count": self.max_results}- # Add optional parameters if providedif self.engines:params["engines"] = ",".join(self.engines)@@ -178,7 +167,6 @@ class SearXNGSearchEngine(BaseSearchEngine):"Upgrade-Insecure-Requests": "1"}- # Send requestlogger.info(f"Sending request to SearXNG instance at {self.instance_url}")response = requests.get(self.search_url,@@ -188,32 +176,22 @@ class SearXNGSearchEngine(BaseSearchEngine):timeout=15)- # Check responseif response.status_code == 200:- # We need to parse HTML here since we're not getting JSONtry:- # Use a simple approach with string parsing as a fallback- # This is a simplified approach - in a production environment,- # a proper HTML parser (like BeautifulSoup) would be more robustfrom bs4 import BeautifulSoupsoup = BeautifulSoup(response.text, 'html.parser')results = []- # Find all result containers- result_elements = soup.select('.result-item') # Try the common SearXNG class+ result_elements = soup.select('.result-item')- # If we can't find results with the common class, try alternativesif not result_elements:result_elements = soup.select('.result')- # If we still can't find results, try more generic selectorsif not result_elements:result_elements = soup.select('article')- # If we still can't find anything, try the most generic approachif not result_elements:- # Log the classes found in the HTML to help debuglogger.debug(f"Classes found in HTML: {[c['class'] for c in soup.select('[class]') if 'class' in c.attrs][:10]}")result_elements = soup.select('div[id^="result"]')@@ -223,7 +201,6 @@ class SearXNGSearchEngine(BaseSearchEngine):if idx >= self.max_results:break- # Try different possible selectors for result componentstitle_element = (result_element.select_one('.result-title') orresult_element.select_one('.title') or@@ -246,7 +223,6 @@ class SearXNGSearchEngine(BaseSearchEngine):title = title_element.get_text(strip=True) if title_element else ""- # Get URL from the href attribute if available, otherwise from text contenturl = ""if url_element and url_element.has_attr('href'):url = url_element['href']@@ -255,11 +231,9 @@ class SearXNGSearchEngine(BaseSearchEngine):content = content_element.get_text(strip=True) if content_element else ""- # If we have a title element with href but no URL yet, use thatif not url and title_element and title_element.has_attr('href'):url = title_element['href']- # For debugginglogger.debug(f"Extracted result {idx}: title={title[:30]}..., url={url[:30]}..., content={content[:30]}...")# Add to results if we have at least a title or URL@@ -299,24 +273,20 @@ class SearXNGSearchEngine(BaseSearchEngine):Returns:List of preview dictionaries"""- # If the engine is disabled, return empty resultsif not self.is_available:logger.warning("SearXNG engine is disabled (no instance URL provided)")return []logger.info(f"Getting SearXNG previews for query: {query}")- # Get raw search resultsresults = self._get_search_results(query)if not results:logger.warning(f"No SearXNG results found for query: {query}")return []- # Format results as previewspreviews = []for i, result in enumerate(results):- # Extract relevant fieldstitle = result.get("title", "")url = result.get("url", "")content = result.get("content", "")@@ -344,26 +314,21 @@ class SearXNGSearchEngine(BaseSearchEngine):Returns:List of result dictionaries with full content"""- # If the engine is disabled, return input items unchangedif not self.is_available:return relevant_items- # Check if we should get full contentif hasattr(config, 'SEARCH_SNIPPETS_ONLY') and config.SEARCH_SNIPPETS_ONLY:logger.info("Snippet-only mode, skipping full content retrieval")return relevant_items- # Get full content using FullSearchResultslogger.info("Retrieving full webpage content")try:- # Use FullSearchResults to get full contentresults_with_content = self.full_search._get_full_content(relevant_items)return results_with_contentexcept Exception as e:logger.error(f"Error retrieving full content: {e}")- # Fall back to returning the items without full contentreturn relevant_itemsdef invoke(self, query: str) -> List[Dict[str, Any]]:@@ -381,22 +346,17 @@ class SearXNGSearchEngine(BaseSearchEngine):Returns:List of search result dictionaries"""- # If the engine is disabled, return empty resultsif not self.is_available:return []- # Save current max_resultsoriginal_max_results = self.max_resultstry:- # Override max_results if providedif max_results is not None:self.max_results = max_results- # Get raw search resultsresults = self._get_search_results(query)- # Format resultsformatted_results = []for result in results:formatted_results.append({@@ -408,7 +368,6 @@ class SearXNGSearchEngine(BaseSearchEngine):return formatted_resultsfinally:- # Restore original max_resultsself.max_results = original_max_results@staticmethod