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.

refactor: extract blob existence check into helper method

LearningCircuitfdac3371408e
diff --git a/src/local_deep_research/research_library/services/library_service.py b/src/local_deep_research/research_library/services/library_service.py
index ba91f6b0be..10baf478c8 100644
--- a/src/local_deep_research/research_library/services/library_service.py
+++ b/src/local_deep_research/research_library/services/library_service.py
@@ -40,6 +40,15 @@ class LibraryService:
"""Initialize library service for a user."""
self.username = username
+ def _has_blob_in_db(self, session, document_id: str) -> bool:
+ """Check if a PDF blob exists in the database for a document."""
+ return (
+ session.query(DocumentBlob.document_id)
+ .filter_by(document_id=document_id)
+ .first()
+ is not None
+ )
+
def _is_arxiv_url(self, url: str) -> bool:
"""Check if URL is from arXiv domain."""
try:
@@ -281,13 +290,7 @@ class LibraryService:
# Check if PDF is available (filesystem OR database)
has_pdf = bool(file_absolute_path)
if not has_pdf and doc.storage_mode == "database":
- # Verify blob actually exists in database
- has_pdf = (
- session.query(DocumentBlob.document_id)
- .filter_by(document_id=doc.id)
- .first()
- is not None
- )
+ has_pdf = self._has_blob_in_db(session, doc.id)
has_text_db = bool(doc.text_content) # Text now in Document
# Use DocumentCollection from query results
@@ -583,13 +586,7 @@ class LibraryService:
and doc.file_path != "text_only_not_stored"
)
if not has_pdf and doc.storage_mode == "database":
- # Verify blob actually exists in database
- has_pdf = (
- session.query(DocumentBlob.document_id)
- .filter_by(document_id=doc.id)
- .first()
- is not None
- )
+ has_pdf = self._has_blob_in_db(session, doc.id)
return {
"id": doc.id,