~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: filter non-downloadable sources from Library to prevent pollution (#2627)
LearningCircuit1752fa19e857
diff --git a/src/local_deep_research/news/subscription_manager/scheduler.py b/src/local_deep_research/news/subscription_manager/scheduler.pyindex b0cc6d7973..1e06effd61 100644--- a/src/local_deep_research/news/subscription_manager/scheduler.py+++ b/src/local_deep_research/news/subscription_manager/scheduler.py@@ -784,15 +784,25 @@ class NewsScheduler:ResearchResource,)+ from ...research_library.utils import (+ is_downloadable_url,+ )+with DownloadService(username=username, password=password) as download_service:# Get all resources for this research (reuse existing db session)- resources = (+ all_resources = (db.query(ResearchResource).filter_by(research_id=research.id).all())+ # Filter: only process downloadable resources (academic/PDF)+ resources = [+ r+ for r in all_resources+ if is_downloadable_url(r.url)+ ]processed_count = 0for resource in resources:# We need to pass the password to the download servicediff --git a/src/local_deep_research/research_library/routes/library_routes.py b/src/local_deep_research/research_library/routes/library_routes.pyindex 6c47aa9835..0ebb054c33 100644--- a/src/local_deep_research/research_library/routes/library_routes.py+++ b/src/local_deep_research/research_library/routes/library_routes.py@@ -10,7 +10,6 @@ Provides web endpoints for:import jsonfrom io import BytesIOfrom pathlib import Path-from urllib.parse import urlparsefrom flask import (Blueprint,g,@@ -38,7 +37,12 @@ from ...library.download_management import ResourceFilterfrom ..services.download_service import DownloadServicefrom ..services.library_service import LibraryServicefrom ..services.pdf_storage_manager import PDFStorageManager-from ..utils import get_document_for_resource, handle_api_error+from ..utils import (+ get_document_for_resource,+ handle_api_error,+ is_downloadable_domain,+ is_downloadable_url,+)from ...utilities.db_utils import get_settings_managerfrom ...config.paths import get_library_directoryfrom ...web.exceptions import AuthenticationRequiredError@@ -63,98 +67,6 @@ def handle_web_api_exception(error):raise error-def is_downloadable_domain(url: str) -> bool:- """Check if URL is from a downloadable academic domain using proper URL parsing."""- try:- if not url:- return False-- parsed = urlparse(url.lower())- hostname = parsed.hostname or ""- path = parsed.path or ""- query = parsed.query or ""-- # Check for direct PDF files- if path.endswith(".pdf") or ".pdf?" in url.lower():- return True-- # List of downloadable academic domains- downloadable_domains = [- "arxiv.org",- "biorxiv.org",- "medrxiv.org",- "ncbi.nlm.nih.gov",- "pubmed.ncbi.nlm.nih.gov",- "europepmc.org",- "semanticscholar.org",- "researchgate.net",- "academia.edu",- "sciencedirect.com",- "springer.com",- "nature.com",- "wiley.com",- "ieee.org",- "acm.org",- "plos.org",- "frontiersin.org",- "mdpi.com",- "acs.org",- "rsc.org",- "tandfonline.com",- "sagepub.com",- "oxford.com",- "cambridge.org",- "bmj.com",- "nejm.org",- "thelancet.com",- "jamanetwork.com",- "annals.org",- "ahajournals.org",- "cell.com",- "science.org",- "pnas.org",- "elifesciences.org",- "embopress.org",- "journals.asm.org",- "microbiologyresearch.org",- "jvi.asm.org",- "genome.cshlp.org",- "genetics.org",- "g3journal.org",- "plantphysiol.org",- "plantcell.org",- "aspb.org",- "bioone.org",- "company-of-biologists.org",- "biologists.org",- "jeb.biologists.org",- "dmm.biologists.org",- "bio.biologists.org",- "doi.org",- "ssrn.com",- "openreview.net",- ]-- # Check if hostname matches any downloadable domain- for domain in downloadable_domains:- if hostname == domain or hostname.endswith("." + domain):- return True-- # Special case for PubMed which might appear in path- if "pubmed" in hostname or "/pubmed/" in path:- return True-- # Check for PDF in path or query parameters- if "/pdf/" in path or "type=pdf" in query or "format=pdf" in query:- return True-- return False-- except Exception as e:- logger.warning(f"Error parsing URL {url}: {e}")- return False--def get_authenticated_user_password(username: str, flask_session_id: str = None) -> str:@@ -671,7 +583,11 @@ def download_all_text():# Get all undownloaded resourceswith get_user_db_session(username) as session:# Get resources that don't have text files yet- resources = session.query(ResearchResource).all()+ all_resources = session.query(ResearchResource).all()+ # Filter to only downloadable resources (academic/PDF)+ resources = [+ r for r in all_resources if is_downloadable_url(r.url)+ ]# Filter resources that need text extractiontxt_path = Path(download_service.library_root) / "txt"diff --git a/src/local_deep_research/research_library/services/download_service.py b/src/local_deep_research/research_library/services/download_service.pyindex 9dec0dc4e4..0013ce02fe 100644--- a/src/local_deep_research/research_library/services/download_service.py+++ b/src/local_deep_research/research_library/services/download_service.py@@ -47,6 +47,7 @@ from ..utils import (get_document_for_resource,get_url_hash,get_absolute_path_from_settings,+ is_downloadable_url,)# Import our modular downloaders@@ -362,26 +363,11 @@ class DownloadService:return queueddef _is_downloadable(self, resource: ResearchResource) -> bool:- """Check if a resource is likely downloadable as PDF."""- url = resource.url.lower() if resource.url else ""-- # Check for PDF extensions- if url.endswith(".pdf"):- return True-- # Check for known academic sources with downloadable PDFs- downloadable_domains = [- "arxiv.org",- "biorxiv.org",- "medrxiv.org",- "ncbi.nlm.nih.gov/pmc", # PubMed Central has PDFs- "pubmed.ncbi.nlm.nih.gov", # Try to find PMC version- "semanticscholar.org",- "researchgate.net",- "academia.edu",- ]+ """Check if a resource is likely downloadable as PDF.- return any(domain in url for domain in downloadable_domains)+ Delegates to the consolidated is_downloadable_url() from utils.+ """+ return is_downloadable_url(resource.url)def download_resource(self, resource_id: int) -> Tuple[bool, Optional[str]]:"""@@ -1728,6 +1714,13 @@ class DownloadService:f"Recorded failed text extraction for document {doc.id}: {error}")else:+ # Defense-in-depth: don't create Library entries for non-downloadable URLs+ if not is_downloadable_url(resource.url):+ logger.debug(+ f"Skipping Library entry for non-downloadable: {resource.url}"+ )+ return+# Create a new Document for failed extraction# This enables tracking failures and retry capabilitysource_type_id = get_source_type_id(diff --git a/src/local_deep_research/research_library/utils/__init__.py b/src/local_deep_research/research_library/utils/__init__.pyindex f8a634f72e..4e69aa0fe1 100644--- a/src/local_deep_research/research_library/utils/__init__.py+++ b/src/local_deep_research/research_library/utils/__init__.py@@ -6,6 +6,7 @@ import subprocessimport sysfrom pathlib import Pathfrom typing import Optional+from urllib.parse import urlparsefrom flask import jsonifyfrom loguru import logger@@ -15,6 +16,113 @@ from ...database.models.library import Documentfrom ...security.path_validator import PathValidator+def is_downloadable_domain(url: str) -> bool:+ """Check if URL is from a downloadable academic domain using proper URL parsing."""+ try:+ if not url:+ return False++ parsed = urlparse(url.lower())+ hostname = parsed.hostname or ""+ path = parsed.path or ""+ query = parsed.query or ""++ # Check for direct PDF files+ if path.endswith(".pdf") or ".pdf?" in url.lower():+ return True++ # List of downloadable academic domains+ downloadable_domains = [+ "arxiv.org",+ "biorxiv.org",+ "medrxiv.org",+ "ncbi.nlm.nih.gov",+ "pubmed.ncbi.nlm.nih.gov",+ "europepmc.org",+ "semanticscholar.org",+ "researchgate.net",+ "academia.edu",+ "sciencedirect.com",+ "springer.com",+ "nature.com",+ "wiley.com",+ "ieee.org",+ "acm.org",+ "plos.org",+ "frontiersin.org",+ "mdpi.com",+ "acs.org",+ "rsc.org",+ "tandfonline.com",+ "sagepub.com",+ "oxford.com",+ "cambridge.org",+ "bmj.com",+ "nejm.org",+ "thelancet.com",+ "jamanetwork.com",+ "annals.org",+ "ahajournals.org",+ "cell.com",+ "science.org",+ "pnas.org",+ "elifesciences.org",+ "embopress.org",+ "journals.asm.org",+ "microbiologyresearch.org",+ "jvi.asm.org",+ "genome.cshlp.org",+ "genetics.org",+ "g3journal.org",+ "plantphysiol.org",+ "plantcell.org",+ "aspb.org",+ "bioone.org",+ "company-of-biologists.org",+ "biologists.org",+ "jeb.biologists.org",+ "dmm.biologists.org",+ "bio.biologists.org",+ "doi.org",+ "ssrn.com",+ "openreview.net",+ ]++ # Check if hostname matches any downloadable domain+ for domain in downloadable_domains:+ if hostname == domain or hostname.endswith("." + domain):+ return True++ # Special case for PubMed which might appear in path+ if "pubmed" in hostname or "/pubmed/" in path:+ return True++ # Check for PDF in path or query parameters+ if "/pdf/" in path or "type=pdf" in query or "format=pdf" in query:+ return True++ return False++ except Exception as e:+ logger.warning(f"Error parsing URL {url}: {e}")+ return False+++def is_downloadable_url(url: str) -> bool:+ """Check if a URL is downloadable (academic domain or direct PDF link).++ This is the single source of truth for downloadability checks.+ Combines domain checking with PDF extension/path detection.++ Args:+ url: The URL to check++ Returns:+ True if the URL is from a downloadable academic domain or is a direct PDF link+ """+ return is_downloadable_domain(url)++def get_document_for_resource(session, resource):"""Get Document for a ResearchResource.