Skip to content

~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.

fix: address djpetti's review feedback on downloaders

LearningCircuit3c40507417ad
diff --git a/src/local_deep_research/research_library/downloaders/openalex.py b/src/local_deep_research/research_library/downloaders/openalex.py
index e884186e30..9e05110737 100644
--- a/src/local_deep_research/research_library/downloaders/openalex.py
+++ b/src/local_deep_research/research_library/downloaders/openalex.py
@@ -102,18 +102,16 @@ class OpenAlexDownloader(BaseDownloader):
Returns:
Work ID (e.g., W123456789) or None if not found
"""
- # Pattern to extract work ID (W followed by digits)
- patterns = [
- r"openalex\.org/works/(W\d+)", # /works/W123456789
- r"openalex\.org/(W\d+)", # Direct /W123456789
- ]
-
- for pattern in patterns:
- match = re.search(pattern, url)
- if match:
- return match.group(1)
+ # Use urlparse for more robust URL handling (handles query strings, fragments)
+ parsed = urlparse(url)
+ if not parsed.netloc or "openalex.org" not in parsed.netloc:
+ return None
- return None
+ # Extract work ID from path (W followed by digits)
+ # Handles /works/W123 or /W123
+ path = parsed.path
+ match = re.search(r"(?:/works/)?(W\d+)", path)
+ return match.group(1) if match else None
def _get_pdf_url(self, work_id: str) -> Optional[str]:
"""
@@ -204,11 +202,12 @@ class OpenAlexDownloader(BaseDownloader):
logger.warning(f"OpenAlex API error: {response.status_code}")
return None
- except (
- requests.exceptions.RequestException,
- ValueError,
- KeyError,
- TypeError,
- ):
+ except requests.exceptions.RequestException:
logger.exception("Failed to query OpenAlex API")
return None
+ except ValueError:
+ # JSON decode errors are expected runtime errors
+ logger.exception("Failed to parse OpenAlex API response")
+ return None
+ # Note: KeyError and TypeError are not caught - they indicate programming
+ # bugs that should propagate for debugging
diff --git a/src/local_deep_research/research_library/downloaders/semantic_scholar.py b/src/local_deep_research/research_library/downloaders/semantic_scholar.py
index f32231717c..0b6ecd6895 100644
--- a/src/local_deep_research/research_library/downloaders/semantic_scholar.py
+++ b/src/local_deep_research/research_library/downloaders/semantic_scholar.py
@@ -99,18 +99,16 @@ class SemanticScholarDownloader(BaseDownloader):
Returns:
Paper ID (hash) or None if not found
"""
- # Pattern to extract paper ID (40 character hex hash)
- patterns = [
- r"semanticscholar\.org/paper/([a-f0-9]{40})", # Direct ID
- r"semanticscholar\.org/paper/[^/]+/([a-f0-9]{40})", # With title slug
- ]
-
- for pattern in patterns:
- match = re.search(pattern, url)
- if match:
- return match.group(1)
+ # Use urlparse for more robust URL handling (handles query strings, fragments)
+ parsed = urlparse(url)
+ if not parsed.netloc or "semanticscholar.org" not in parsed.netloc:
+ return None
- return None
+ # Extract paper ID from path (40 character hex hash)
+ # Handles /paper/{hash} or /paper/{title}/{hash}
+ path = parsed.path
+ match = re.search(r"/paper/(?:[^/]+/)?([a-f0-9]{40})", path)
+ return match.group(1) if match else None
def _get_pdf_url(self, paper_id: str) -> Optional[str]:
"""
@@ -166,11 +164,12 @@ class SemanticScholarDownloader(BaseDownloader):
)
return None
- except (
- requests.exceptions.RequestException,
- ValueError,
- KeyError,
- TypeError,
- ):
+ except requests.exceptions.RequestException:
logger.exception("Failed to query Semantic Scholar API")
return None
+ except ValueError:
+ # JSON decode errors are expected runtime errors
+ logger.exception("Failed to parse Semantic Scholar API response")
+ return None
+ # Note: KeyError and TypeError are not caught - they indicate programming
+ # bugs that should propagate for debugging
diff --git a/src/local_deep_research/web_search_engines/search_engine_factory.py b/src/local_deep_research/web_search_engines/search_engine_factory.py
index 810689d53e..9e8e3ba6a5 100644
--- a/src/local_deep_research/web_search_engines/search_engine_factory.py
+++ b/src/local_deep_research/web_search_engines/search_engine_factory.py
@@ -87,6 +87,11 @@ def create_search_engine(
# Check if engine_name might be a display label instead of a config key
# Display labels have format: "{icon} {base_name} ({category})"
# e.g., "🔬 OpenAlex (Scientific)"
+ # NOTE: This fallback is deprecated - callers should pass config keys directly
+ logger.warning(
+ f"Engine '{engine_name}' not found in config - attempting display label fallback. "
+ "This is deprecated; callers should pass the config key directly."
+ )
# Try to extract the base name from the label
# To avoid ReDoS, we use string operations instead of regex