~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
added arxiv search
LearningCircuitdf7c73a72fcd
diff --git a/config.py b/config.pyindex b29060616f..8ac8242870 100644--- a/config.py+++ b/config.py@@ -7,7 +7,7 @@ from dotenv import load_dotenvfrom web_search_engines.full_serp_search_results_old import FullSerpAPISearchResults # Added import for SerpAPI classfrom web_search_engines.full_search import FullSearchResults-+from web_search_engines.search_engine_arxiv import ArXivSearchEnginefrom web_search_engines.search_engine_ddg import DuckDuckGoSearchEnginefrom web_search_engines.search_engine_wikipedia import WikipediaSearchEnginefrom web_search_engines.search_engine_serpapi import SerpAPISearchEngine@@ -47,7 +47,7 @@ SEARCH_LANGUAGE = "English"OUTPUT_DIR = "research_outputs"# Choose search tool: "serp" or "duckduckgo" (serp requires API key)-search_tool = "wiki" # Change this variable to switch between search tools+search_tool = "arxiv" # Change this variable to switch between search toolsdef get_llm(model_name=DEFAULT_MODEL, temperature=DEFAULT_TEMPERATURE):@@ -89,6 +89,15 @@ def get_search():elif "wiki" in search_tool.lower():wiki = WikipediaSearchEngine(max_results=3, include_content=SEARCH_SNIPPETS_ONLY)return wiki+ elif "arxiv" in search_tool.lower():+ # Create and return an instance of ArXivSearchEngine+ arxiv_engine = ArXivSearchEngine(+ max_results=MAX_SEARCH_RESULTS,+ sort_by="relevance", # Options: 'relevance', 'lastUpdatedDate', 'submittedDate'+ sort_order="descending",+ include_full_text=SEARCH_SNIPPETS_ONLY+ )+ return arxiv_engineelse:search_engine = DuckDuckGoSearchEngine(max_results=MAX_SEARCH_RESULTS,diff --git a/requirements.txt b/requirements.txtindex 50661fbe7e..ab046f71f5 100644--- a/requirements.txt+++ b/requirements.txt@@ -16,4 +16,7 @@ flask-cors>=3.0.10flask-socketio>=5.1.1sqlalchemy>=1.4.23# SerpAPI-google-search-results\ No newline at end of file+google-search-results+wikipedia+arxiv>=1.4.3+PyPDF2>=2.0.0 # Optional - for extracting text from PDFs if needed\ No newline at end of filediff --git a/web_search_engines/search_engine_arxiv.py b/web_search_engines/search_engine_arxiv.pynew file mode 100644index 0000000000..9c709fd7de--- /dev/null+++ b/web_search_engines/search_engine_arxiv.py@@ -0,0 +1,173 @@+import arxiv+from typing import Dict, List, Any, Optional+from web_search_engines.search_engine_base import BaseSearchEngine+++class ArXivSearchEngine(BaseSearchEngine):+ """arXiv search engine implementation"""++ def __init__(self,+ max_results: int = 10,+ sort_by: str = "relevance",+ sort_order: str = "descending",+ include_full_text: bool = False,+ download_dir: Optional[str] = None):+ """+ Initialize the arXiv search engine.++ Args:+ max_results: Maximum number of search results+ sort_by: Sorting criteria ('relevance', 'lastUpdatedDate', or 'submittedDate')+ sort_order: Sort order ('ascending' or 'descending')+ include_full_text: Whether to include full paper content in results (downloads PDF)+ download_dir: Directory to download PDFs to (if include_full_text is True)+ """+ self.max_results = max_results+ self.sort_by = sort_by+ self.sort_order = sort_order+ self.include_full_text = include_full_text+ self.download_dir = download_dir++ # Map sort parameters to arxiv package parameters+ self.sort_criteria = {+ 'relevance': arxiv.SortCriterion.Relevance,+ 'lastUpdatedDate': arxiv.SortCriterion.LastUpdatedDate,+ 'submittedDate': arxiv.SortCriterion.SubmittedDate+ }++ self.sort_directions = {+ 'ascending': arxiv.SortOrder.Ascending,+ 'descending': arxiv.SortOrder.Descending+ }++ def run(self, query: str) -> List[Dict[str, Any]]:+ print("""Execute a search using arXiv""")+ try:+ # Configure the search client+ sort_criteria = self.sort_criteria.get(self.sort_by, arxiv.SortCriterion.Relevance)+ sort_order = self.sort_directions.get(self.sort_order, arxiv.SortOrder.Descending)++ # Create the search client+ client = arxiv.Client()++ # Create the search query+ search = arxiv.Search(+ query=query,+ max_results=self.max_results,+ sort_by=sort_criteria,+ sort_order=sort_order+ )++ # Process results+ results = []+ for paper in client.results(search):+ # Basic paper information+ result = {+ "title": paper.title,+ "link": paper.entry_id, # arXiv URL+ "pdf_url": paper.pdf_url,+ "authors": [author.name for author in paper.authors],+ "published": paper.published.strftime("%Y-%m-%d") if paper.published else None,+ "updated": paper.updated.strftime("%Y-%m-%d") if paper.updated else None,+ "categories": paper.categories,+ "summary": paper.summary,+ "comment": paper.comment,+ "journal_ref": paper.journal_ref,+ "doi": paper.doi+ }++ # Download and extract text if requested+ if self.include_full_text and self.download_dir:+ try:+ # Download the paper+ paper_path = paper.download_pdf(dirpath=self.download_dir)+ result["pdf_path"] = str(paper_path)++ # Here you could add PDF text extraction+ # For example using PyPDF2, pdfplumber, or other PDF libraries+ # This would require additional dependencies++ except Exception as e:+ print(f"Error downloading paper {paper.title}: {e}")+ result["pdf_path"] = None++ results.append(result)++ return results++ except Exception as e:+ print(f"Error during arXiv search: {e}")+ return []++ def get_paper_details(self, arxiv_id: str) -> Dict[str, Any]:+ """+ Get detailed information about a specific arXiv paper.++ Args:+ arxiv_id: arXiv ID of the paper (e.g., '2101.12345')++ Returns:+ Dictionary with paper information+ """+ try:+ # Create the search client+ client = arxiv.Client()++ # Search for the specific paper+ search = arxiv.Search(id_list=[arxiv_id], max_results=1)++ # Get the paper+ papers = list(client.results(search))+ if not papers:+ return {}++ paper = papers[0]++ # Return the paper details+ return {+ "title": paper.title,+ "link": paper.entry_id,+ "pdf_url": paper.pdf_url,+ "authors": [author.name for author in paper.authors],+ "published": paper.published.strftime("%Y-%m-%d") if paper.published else None,+ "updated": paper.updated.strftime("%Y-%m-%d") if paper.updated else None,+ "categories": paper.categories,+ "summary": paper.summary,+ "comment": paper.comment,+ "journal_ref": paper.journal_ref,+ "doi": paper.doi+ }++ except Exception as e:+ print(f"Error getting paper details: {e}")+ return {}++ def search_by_author(self, author_name: str, max_results: Optional[int] = None) -> List[Dict[str, Any]]:+ """+ Search for papers by a specific author.++ Args:+ author_name: Name of the author+ max_results: Maximum number of results (defaults to self.max_results)++ Returns:+ List of papers by the author+ """+ max_results = max_results or self.max_results+ query = f"au:\"{author_name}\""+ return self.run(query)++ def search_by_category(self, category: str, max_results: Optional[int] = None) -> List[Dict[str, Any]]:+ """+ Search for papers in a specific arXiv category.++ Args:+ category: arXiv category (e.g., 'cs.AI', 'physics.optics')+ max_results: Maximum number of results (defaults to self.max_results)++ Returns:+ List of papers in the category+ """+ max_results = max_results or self.max_results+ query = f"cat:{category}"+ return self.run(query)\ No newline at end of file