~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
feat: allow upgrading text-only documents to include PDF
LearningCircuit116e7f238e14
diff --git a/src/local_deep_research/research_library/routes/rag_routes.py b/src/local_deep_research/research_library/routes/rag_routes.pyindex aa2650b6d3..9862754c97 100644--- a/src/local_deep_research/research_library/routes/rag_routes.py+++ b/src/local_deep_research/research_library/routes/rag_routes.py@@ -1543,7 +1543,18 @@ def upload_to_collection(collection_id):)if existing_doc:- # Document exists, just add to collection+ # Document exists, check if we can upgrade to include PDF+ pdf_upgraded = False+ if (+ pdf_storage == "database"+ and pdf_storage_manager is not None+ ):+ pdf_upgraded = pdf_storage_manager.upgrade_to_pdf(+ document=existing_doc,+ pdf_content=file_content,+ session=db_session,+ )+# Check if already in collectionexisting_link = (db_session.query(DocumentCollection)@@ -1563,19 +1574,27 @@ def upload_to_collection(collection_id):chunk_count=0,)db_session.add(collection_link)+ status = "added_to_collection"+ if pdf_upgraded:+ status = "added_to_collection_pdf_upgraded"uploaded_files.append({"filename": existing_doc.filename,- "status": "added_to_collection",+ "status": status,"id": existing_doc.id,+ "pdf_upgraded": pdf_upgraded,})else:+ status = "already_in_collection"+ if pdf_upgraded:+ status = "pdf_upgraded"uploaded_files.append({"filename": existing_doc.filename,- "status": "already_in_collection",+ "status": status,"id": existing_doc.id,+ "pdf_upgraded": pdf_upgraded,})else: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.pyindex 43441e54d3..553932bc17 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@@ -328,3 +328,60 @@ class PDFStorageManager:except Exception:logger.exception(f"Failed to delete PDF for document {document.id}")return False++ def upgrade_to_pdf(+ self, document: Document, pdf_content: bytes, session: Session+ ) -> bool:+ """+ Upgrade a text-only document to include PDF storage.++ If document already has a PDF stored, returns False (no action needed).+ If document is text-only, adds the PDF blob and updates storage_mode.++ Args:+ document: Document model instance+ pdf_content: Raw PDF bytes+ session: Database session++ Returns:+ True if PDF was added, False if already had PDF or failed+ """+ # Only upgrade if document is currently text-only+ if document.storage_mode not in (None, "none"):+ logger.debug(+ f"Document {document.id} already has storage_mode={document.storage_mode}"+ )+ return False++ # Check if blob already exists (shouldn't happen, but be safe)+ existing_blob = (+ session.query(DocumentBlob)+ .filter_by(document_id=document.id)+ .first()+ )+ if existing_blob:+ logger.debug(f"Document {document.id} already has a blob")+ return False++ # Check file size+ file_size = len(pdf_content)+ if file_size > self.max_pdf_size_bytes:+ max_mb = self.max_pdf_size_bytes / (1024 * 1024)+ logger.warning(+ f"PDF size ({file_size / (1024 * 1024):.1f}MB) exceeds limit "+ f"({max_mb:.0f}MB), skipping upgrade"+ )+ return False++ try:+ # Add the PDF blob+ self._save_to_database(pdf_content, document, session)+ document.storage_mode = "database"+ document.file_path = None+ logger.info(f"Upgraded document {document.id} with PDF blob")+ return True+ except Exception:+ logger.exception(+ f"Failed to upgrade document {document.id} with PDF"+ )+ return False