~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
clean up and reduced relevance of guardian
LearningCircuit22dcebb7b3e5
diff --git a/full_duck_duck_go_search_results.py b/full_duck_duck_go_search_results.pydeleted file mode 100644index 0c9b0b7719..0000000000--- a/full_duck_duck_go_search_results.py+++ /dev/null@@ -1,148 +0,0 @@-import justext-from langchain_community.tools import DuckDuckGoSearchResults-from langchain.document_loaders import AsyncChromiumLoader, AsyncHtmlLoader-from langchain.document_transformers import BeautifulSoupTransformer-from langchain_core.language_models import BaseLLM-from typing import List, Dict-import json, os-from utilities import remove_think_tags-from datetime import datetime-import config--class FullDuckDuckGoSearchResults:- def __init__(- self,- llm: BaseLLM, # Add LLM parameter- output_format: str = "list",- language: str = "English",- max_results: int = 10,- region: str = "wt-wt",- time: str = "y",- safesearch: str = "Moderate",- ):- self.llm = llm- self.output_format = output_format- self.language = language- self.max_results = max_results- self.region = region- self.time = time- self.safesearch = safesearch- os.environ["USER_AGENT"] = "Local Deep Research/1.0"-- self.ddg_search = DuckDuckGoSearchResults(- output_format=output_format,- max_results=self.max_results,- region=self.region,- time=self.time,- safesearch=self.safesearch,- )- self.bs_transformer = BeautifulSoupTransformer()- self.tags_to_extract = ["p", "div", "span"]-- def check_urls(self, results: List[Dict], query: str) -> List[Dict]:- if not results:- return results-- # Prepare the prompt for URL evaluation- urls_text = "\n".join(- [- f"URL: {r.get('link', '')}\n"- f"Title: {r.get('title', '')}\n"- f"Snippet: {r.get('snippet', '')}\n"- for r in results- ]- )- print(urls_text)- now = datetime.now()- current_time = now.strftime("%Y-%m-%d")- prompt = f"""ONLY Return a JSON array. The response contains no letters. Evaluate these URLs for:- 1. Timeliness (today: {current_time})- 2. Factual accuracy (cross-reference major claims)- 3. Source reliability (prefer official company websites, established news outlets)- 4. Direct relevance to query: {query}-- For each source, analyze:- - Publication date (if available)- - Author/organization credibility- - Whether claims are supported by other reliable sources- - Primary vs secondary source status-- URLs to evaluate:- {urls_text}-- Return a JSON array of indices (0-based) for sources that meet ALL criteria.- ONLY Return a JSON array of indices (0-based) and nothing else. No letters.- Example response: \n[0, 2, 4]\n\n"""-- try:- # Get LLM's evaluation- response = self.llm.invoke(prompt)- # print(response)- good_indices = json.loads(remove_think_tags(response.content))-- # Return only the results with good URLs- return [r for i, r in enumerate(results) if i in good_indices]- except Exception as e:- print(f"URL filtering error: {e}")- return []-- def remove_boilerplate(self, html: str) -> str:- if not html or not html.strip():- return ""- paragraphs = justext.justext(html, justext.get_stoplist(self.language))- cleaned = "\n".join([p.text for p in paragraphs if not p.is_boilerplate])- return cleaned-- def run(self, query: str):- nr_full_text = 0- # Step 1: Get search results from DuckDuckGo- search_results = self.ddg_search.invoke(query)- #print(type(search_results))- if not isinstance(search_results, list):- raise ValueError("Expected the search results in list format.")-- # Step 2: Filter URLs using LLM- if config.QUALITY_CHECK_DDG_URLS:- filtered_results = self.check_urls(search_results, query)- else:- filtered_results = search_results-- # Extract URLs from filtered results- urls = [result.get("link") for result in filtered_results if result.get("link")]- print(urls)- if not urls:- print("\n === NO VALID LINKS ===\n")- return []-- # Step 3: Download the full HTML pages for filtered URLs- loader = AsyncHtmlLoader(urls)- html_docs = loader.load()-- # Step 4: Process the HTML using BeautifulSoupTransformer- full_docs = self.bs_transformer.transform_documents(- html_docs, tags_to_extract=self.tags_to_extract- )-- # Step 5: Remove boilerplate from each document- url_to_content = {}- for doc in full_docs:- nr_full_text = nr_full_text + 1- source = doc.metadata.get("source")- if source:- cleaned_text = self.remove_boilerplate(doc.page_content)- url_to_content[source] = cleaned_text-- # Attach the cleaned full content to each filtered result- for result in filtered_results:- link = result.get("link")- result["full_content"] = url_to_content.get(link, None)-- print("FULL SEARCH WITH FILTERED URLS")- print("Full text retrieved: ", nr_full_text)- return filtered_results-- def invoke(self, query: str):- return self.run(query)-- def __call__(self, query: str):- return self.invoke(query)diff --git a/web_search_engines/engines/full_serp_search_results_old.py b/web_search_engines/engines/full_serp_search_results_old.pydeleted file mode 100644index bdeac65bf8..0000000000--- a/web_search_engines/engines/full_serp_search_results_old.py+++ /dev/null@@ -1,168 +0,0 @@-import os-import json-import justext-from langchain_community.utilities import SerpAPIWrapper-from langchain_community.document_loaders import AsyncChromiumLoader-from langchain_community.document_transformers import BeautifulSoupTransformer-from langchain_core.language_models import BaseLLM-from typing import List, Dict-from datetime import datetime-from utilities import remove_think_tags-import config--#Define Google Language Codes-LANGUAGE_CODE_MAPPING = {- "english": "en",- "spanish": "es",- "chinese": "zh",- "hindi": "hi",- "french": "fr",- "arabic": "ar",- "bengali": "bn",- "portuguese": "pt",- "russian": "ru",-}---class FullSerpAPISearchResults:- def __init__(- self,- llm: BaseLLM,- serpapi_api_key: str, # <-- Add this parameter explicitly!- language: str = "English",- max_results: int = 10,- region: str = "us",- time_period: str = "y",- safesearch: str = "active",- ):- self.llm = llm- self.language = language- self.max_results = max_results- self.region = region- self.time_period = time_period- self.safesearch = safesearch-- os.environ["USER_AGENT"] = "Local Deep Research/1.0"-- self.serp_search = SerpAPIWrapper(- serpapi_api_key=serpapi_api_key, # <-- Pass API Key here!- params={- "engine": "google",- "hl": LANGUAGE_CODE_MAPPING.get(self.language.lower()),- "gl": self.region,- "safe": self.safesearch.lower(),- "tbs": f"qdr:{self.time_period}",- "num": self.max_results,- }- )-- self.bs_transformer = BeautifulSoupTransformer()- self.tags_to_extract = ["p", "div", "span"]-- def check_urls(self, results: List[Dict], query: str) -> List[Dict]:- if not results:- return results-- urls_text = "\n".join(- [- f"URL: {r.get('link', '')}\n"- f"Title: {r.get('title', '')}\n"- f"Snippet: {r.get('snippet', '')}\n"- for r in results- ]- )-- now = datetime.now().strftime("%Y-%m-%d")- prompt = f"""ONLY Return a JSON array. The response contains no letters. Evaluate these URLs for:- 1. Timeliness (today: {now})- 2. Factual accuracy (cross-reference major claims)- 3. Source reliability (prefer official company websites, established news outlets)- 4. Direct relevance to query: {query}-- URLs to evaluate:- {urls_text}-- Return a JSON array of indices (0-based) for sources that meet ALL criteria.- ONLY Return a JSON array of indices (0-based) and nothing else. No letters.- Example response:\n[0, 2, 4]\n\n"""-- try:- response = self.llm.invoke(prompt)- good_indices = json.loads(remove_think_tags(response.content))- return [r for i, r in enumerate(results) if i in good_indices]- except Exception as e:- print(f"URL filtering error: {e}")- return []-- def remove_boilerplate(self, html: str) -> str:- if not html or not html.strip():- return ""- paragraphs = justext.justext(html, justext.get_stoplist(self.language))- cleaned = "\n".join([p.text for p in paragraphs if not p.is_boilerplate])- return cleaned-- def run(self, query: str):-- serp_results_raw = self.serp_search.results(query).get("organic_results", [])- search_results = [- {- "title": res.get("title"),- "link": res.get("link"),- "snippet": res.get("snippet"),- }- for res in serp_results_raw[:self.max_results]- if res.get("link")- ]--- if config.QUALITY_CHECK_DDG_URLS:- filtered_results = self.check_urls(search_results, query)- else:- filtered_results = search_results--- urls = [result["link"] for result in filtered_results if result["link"]]--- if not urls:- print("\n === NO VALID LINKS ===\n")- return []--- loader = AsyncChromiumLoader(urls)-- html_docs = loader.load()--- full_docs = self.bs_transformer.transform_documents(- html_docs, tags_to_extract=self.tags_to_extract- )--- url_to_content = {}-- for doc in full_docs:-- source_url = doc.metadata.get("source")-- if source_url:- cleaned_text = self.remove_boilerplate(doc.page_content)- url_to_content[source_url] = cleaned_text--- for result in filtered_results:-- link_url = result["link"]-- result["full_content"] = url_to_content.get(link_url)--- return filtered_results-- def invoke(self, query: str):-- return self.run(query)-- def __call__(self, query: str):-- return self.invoke(query)\ No newline at end of filediff --git a/web_search_engines/search_engines_config.py b/web_search_engines/search_engines_config.pyindex 6b862c89c0..86a017fc25 100644--- a/web_search_engines/search_engines_config.py+++ b/web_search_engines/search_engines_config.py@@ -73,13 +73,13 @@ SEARCH_ENGINES = {"full_search_module": "web_search_engines.engines.full_serp_search_results_old","full_search_class": "FullSerpAPISearchResults"},- # The Guardian search engine+ # The Guardian search engine - search seem to often provide irrelevant results."guardian": {"module_path": "web_search_engines.engines.search_engine_guardian","class_name": "GuardianSearchEngine","requires_api_key": True,"api_key_env": "GUARDIAN_API_KEY",- "reliability": 0.85,+ "reliability": 0.5,"strengths": ["news articles", "current events", "opinion pieces", "journalism","UK and global news", "political analysis"],"weaknesses": ["primarily focused on news", "limited historical content pre-1999"],