~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
add: SearXNG integration
hashedviking1ef4d9aec19a
diff --git a/web_search_engines/engines/search_engine_searxng.py b/web_search_engines/engines/search_engine_searxng.pyindex 90119445af..d06e7c331e 100644--- a/web_search_engines/engines/search_engine_searxng.py+++ b/web_search_engines/engines/search_engine_searxng.py@@ -136,12 +136,26 @@ class SearXNGSearchEngine(BaseSearchEngine):# Respect rate limitsself._respect_rate_limit()- # Basic parameters+ # First get initial cookies by visiting home page+ initial_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",+ "Accept-Language": "en-US,en;q=0.9"+ }++ try:+ initial_response = requests.get(self.instance_url, headers=initial_headers, timeout=10)+ cookies = initial_response.cookies+ except Exception as e:+ logger.warning(f"Failed to get initial cookies: {e}")+ cookies = None++ # Basic parameters - using HTML formatparams = {"q": query,"categories": ",".join(self.categories),"language": self.language,- "format": "json",+ "format": "html", # Use HTML format instead of JSON"pageno": 1,"safesearch": self.safe_search,"count": self.max_results@@ -154,10 +168,14 @@ class SearXNGSearchEngine(BaseSearchEngine):if self.time_range:params["time_range"] = self.time_range- # Basic browser-like headers+ # Browser-like headersheaders = {- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",- "Accept": "application/json",+ "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",+ "Accept-Language": "en-US,en;q=0.9",+ "Referer": self.instance_url + "/",+ "Connection": "keep-alive",+ "Upgrade-Insecure-Requests": "1"}# Send request@@ -166,18 +184,102 @@ class SearXNGSearchEngine(BaseSearchEngine):self.search_url,params=params,headers=headers,- timeout=10+ cookies=cookies,+ timeout=15)# Check responseif response.status_code == 200:+ # We need to parse HTML here since we're not getting JSONtry:- data = response.json()- results = data.get("results", [])- logger.info(f"SearXNG returned {len(results)} results")+ # 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 robust+ from bs4 import BeautifulSoup++ soup = BeautifulSoup(response.text, 'html.parser')+ results = []++ # Find all result containers+ result_elements = soup.select('.result-item') # Try the common SearXNG class++ # If we can't find results with the common class, try alternatives+ if not result_elements:+ result_elements = soup.select('.result')++ # If we still can't find results, try more generic selectors+ if not result_elements:+ result_elements = soup.select('article')++ # If we still can't find anything, try the most generic approach+ if not result_elements:+ # Log the classes found in the HTML to help debug+ logger.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"]')++ logger.info(f"Found {len(result_elements)} search result elements")++ for idx, result_element in enumerate(result_elements):+ if idx >= self.max_results:+ break++ # Try different possible selectors for result components+ title_element = (+ result_element.select_one('.result-title') or+ result_element.select_one('.title') or+ result_element.select_one('h3') or+ result_element.select_one('a[href]')+ )++ url_element = (+ result_element.select_one('.result-url') or+ result_element.select_one('.url') or+ result_element.select_one('a[href]')+ )++ content_element = (+ result_element.select_one('.result-content') or+ result_element.select_one('.content') or+ result_element.select_one('.snippet') or+ result_element.select_one('p')+ )++ title = title_element.get_text(strip=True) if title_element else ""++ # Get URL from the href attribute if available, otherwise from text content+ url = ""+ if url_element and url_element.has_attr('href'):+ url = url_element['href']+ elif url_element:+ url = url_element.get_text(strip=True)++ content = content_element.get_text(strip=True) if content_element else ""++ # If we have a title element with href but no URL yet, use that+ if not url and title_element and title_element.has_attr('href'):+ url = title_element['href']++ # For debugging+ logger.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+ if title or url:+ results.append({+ "title": title,+ "url": url,+ "content": content,+ "engine": "searxng",+ "category": "general"+ })++ logger.info(f"SearXNG returned {len(results)} results from HTML parsing")return results- except json.JSONDecodeError:- logger.error("Failed to decode JSON response from SearXNG")++ except ImportError:+ logger.error("BeautifulSoup not available for HTML parsing")+ return []+ except Exception as e:+ logger.error(f"Error parsing HTML results: {str(e)}")return []else:logger.error(f"SearXNG returned status code {response.status_code}")diff --git a/web_search_engines/search_engines_config.py b/web_search_engines/search_engines_config.pyindex d240650e4c..8f590747ae 100644--- a/web_search_engines/search_engines_config.py+++ b/web_search_engines/search_engines_config.py@@ -76,15 +76,15 @@ SEARCH_ENGINES = {"searxng": {"module_path": "web_search_engines.engines.search_engine_searxng","class_name": "SearXNGSearchEngine",- "requires_api_key": True, # Changed to True to indicate requirement- "api_key_env": "SEARXNG_INSTANCE", # Environment variable contains instance URL+ "requires_api_key": False, # Changed to False to use config value instead+ "api_key_env": "SEARXNG_INSTANCE", # Will still check environment but not required"reliability": 0.7,"strengths": ["privacy-focused", "metasearch capability", "no tracking","combines multiple engines", "ethical usage", "respects rate limits"],"weaknesses": ["requires self-hosted instance", "disabled without configuration"],"default_params": {"max_results": 15,- "instance_url": None, # Default to None, will use env var or be disabled+ "instance_url": "http://localhost:8080", # Default to localhost"categories": ["general"],"engines": None,"language": "en",