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: use PDFStorageManager.has_pdf() for citation PDF links

LearningCircuit01dbe11ba5f0
diff --git a/src/local_deep_research/research_library/services/pdf_storage_manager.py b/src/local_deep_research/research_library/services/pdf_storage_manager.py
index 553932bc17..272b0c0373 100644
--- a/src/local_deep_research/research_library/services/pdf_storage_manager.py
+++ b/src/local_deep_research/research_library/services/pdf_storage_manager.py
@@ -136,6 +136,44 @@ class PDFStorageManager:
logger.debug(f"No PDF available for document {document.id}")
return None
+ def has_pdf(self, document: Document, session: Session) -> bool:
+ """
+ Check if PDF is available without loading the actual bytes.
+
+ Args:
+ document: Document model instance
+ session: Database session
+
+ Returns:
+ True if PDF is available (in database or filesystem)
+ """
+ # Must be a PDF file type
+ if document.file_type != "pdf":
+ return False
+
+ # Check database first (has blob?)
+ from ...database.models.library import DocumentBlob
+
+ has_blob = (
+ session.query(DocumentBlob.id)
+ .filter_by(document_id=document.id)
+ .first()
+ is not None
+ )
+ if has_blob:
+ return True
+
+ # Check filesystem
+ if document.file_path and document.file_path not in (
+ "metadata_only",
+ "text_only_not_stored",
+ ):
+ file_path = self.library_root / document.file_path
+ if file_path.exists():
+ return True
+
+ return False
+
def _infer_storage_mode(self, document: Document) -> str:
"""
Infer storage mode for documents without explicit mode set.
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_collection.py b/src/local_deep_research/web_search_engines/engines/search_engine_collection.py
index 72322aafc6..6047edbd1f 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_collection.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_collection.py
@@ -10,6 +10,7 @@ from loguru import logger
from .search_engine_library import LibraryRAGSearchEngine
from ...research_library.services.library_rag_service import LibraryRAGService
from ...database.models.library import RAGIndex, Document
+from ...research_library.services.pdf_storage_manager import PDFStorageManager
from ...database.session_context import get_user_db_session
@@ -250,7 +251,14 @@ class CollectionSearchEngine(LibraryRAGSearchEngine):
with get_user_db_session(self.username) as session:
document = session.query(Document).filter_by(id=doc_id).first()
if document:
- if document.file_type == "pdf" and document.file_path:
+ # Use PDFStorageManager to check if PDF available
+ from pathlib import Path
+
+ library_root = (
+ Path.home() / ".local-deep-research" / "library"
+ )
+ pdf_manager = PDFStorageManager(library_root, "auto")
+ if pdf_manager.has_pdf(document, session):
return f"/library/document/{doc_id}/pdf"
return f"/library/document/{doc_id}/txt"
except Exception as e:
diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_library.py b/src/local_deep_research/web_search_engines/engines/search_engine_library.py
index 8ec2f2dc44..265487356d 100644
--- a/src/local_deep_research/web_search_engines/engines/search_engine_library.py
+++ b/src/local_deep_research/web_search_engines/engines/search_engine_library.py
@@ -13,6 +13,7 @@ from ...research_library.services.library_service import LibraryService
from ...config.thread_settings import get_setting_from_snapshot
from ...utilities.llm_utils import get_server_url
from ...database.models.library import RAGIndex, Document
+from ...research_library.services.pdf_storage_manager import PDFStorageManager
from ...database.session_context import get_user_db_session
@@ -239,11 +240,18 @@ class LibraryRAGSearchEngine(BaseSearchEngine):
.first()
)
if document:
- # Prefer PDF if available, otherwise TXT
- if (
- document.file_type == "pdf"
- and document.file_path
- ):
+ # Use PDFStorageManager to check if PDF available
+ from pathlib import Path
+
+ library_root = (
+ Path.home()
+ / ".local-deep-research"
+ / "library"
+ )
+ pdf_manager = PDFStorageManager(
+ library_root, "auto"
+ )
+ if pdf_manager.has_pdf(document, session):
document_url = (
f"/library/document/{doc_id}/pdf"
)