~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: add backend support for three-mode download (PDF/text+RAG/text-only)
LearningCircuit262eac6f8f6a
diff --git a/src/local_deep_research/research_library/routes/library_routes.py b/src/local_deep_research/research_library/routes/library_routes.pyindex 87e68bac77..71cfea9a80 100644--- a/src/local_deep_research/research_library/routes/library_routes.py+++ b/src/local_deep_research/research_library/routes/library_routes.py@@ -690,10 +690,10 @@ def download_bulk():queue_item.resource_id)else: # text_with_files or text_only- # TODO: Update download_as_text to accept save_files parameter- # For now, always saves files (text_with_files behavior)+ # Pass save_files=True for text_with_files, False for text_only+ save_files = mode == "text_with_files"result = download_service.download_as_text(- queue_item.resource_id+ queue_item.resource_id, save_files=save_files)# Handle new tuple return formatdiff --git a/src/local_deep_research/research_library/services/download_service.py b/src/local_deep_research/research_library/services/download_service.pyindex 3979650685..c3bdf44fe9 100644--- a/src/local_deep_research/research_library/services/download_service.py+++ b/src/local_deep_research/research_library/services/download_service.py@@ -685,12 +685,15 @@ class DownloadService:logger.exception("Failed to save text file")return None- def download_as_text(self, resource_id: int) -> Tuple[bool, Optional[str]]:+ def download_as_text(+ self, resource_id: int, save_files: bool = False+ ) -> Tuple[bool, Optional[str]]:"""Download resource and save as text file only.Args:resource_id: ID of the resource to download+ save_files: Whether to save .txt files to disk (True) or DB-only (False)Returns:Tuple of (success, error_message)@@ -772,19 +775,24 @@ class DownloadService:pdf_content = f.read()text = self._extract_text_from_pdf(pdf_content)if text:- text_path = self._save_text_with_db(- resource,- text,- session,- extraction_method="pdf_extraction",- extraction_source="pdfplumber",- pdf_document_id=pdf_document.id,- )- if text_path:+ try:+ text_path = self._save_text_with_db(+ resource,+ text,+ session,+ extraction_method="pdf_extraction",+ extraction_source="pdfplumber",+ pdf_document_id=pdf_document.id,+ save_files=save_files,+ )+ # Success! text_path may be None (DB-only) or a path (DB + file)session.commit()return True, None- else:- return False, "Failed to save text file"+ except Exception as e:+ logger.exception(+ f"Failed to save text for resource {resource.id}"+ )+ return False, f"Failed to save text: {str(e)}"except Exception:logger.exception(f"Failed to extract text from existing PDF: {pdf_path}"@@ -819,18 +827,23 @@ class DownloadService:extraction_source = "pubmed_api"# Save text file with database record- text_path = self._save_text_with_db(- resource,- text,- session,- extraction_method=extraction_method,- extraction_source=extraction_source,- )- if text_path:+ try:+ text_path = self._save_text_with_db(+ resource,+ text,+ session,+ extraction_method=extraction_method,+ extraction_source=extraction_source,+ save_files=save_files,+ )+ # Success! text_path may be None (DB-only) or a path (DB + file)session.commit()return True, None- else:- return False, "Failed to save text file"+ except Exception as e:+ logger.exception(+ f"Failed to save text for resource {resource.id}"+ )+ return False, f"Failed to save text: {str(e)}"# Fallback: Download PDF temporarily (in memory only) and extract textlogger.info(f"Falling back to PDF extraction for: {resource.url}")@@ -849,18 +862,25 @@ class DownloadService:text = self._extract_text_from_pdf(result.content)if text:# Save text file with database record- text_path = self._save_text_with_db(- resource,- text,- session,- extraction_method="pdf_extraction",- extraction_source="pdfplumber_fallback",- )- if text_path:+ # Returns file path if saved to disk, None if DB-only mode+ # Raises exception if save fails+ try:+ text_path = self._save_text_with_db(+ resource,+ text,+ session,+ extraction_method="pdf_extraction",+ extraction_source="pdfplumber_fallback",+ save_files=save_files,+ )+ # Success! text_path may be None (DB-only) or a path (DB + file)session.commit()return True, None- else:- return False, "Failed to save text file"+ except Exception as e:+ logger.exception(+ f"Failed to save text for resource {resource.id}"+ )+ return False, f"Failed to save text: {str(e)}"else:# Record failed extractionself._record_failed_text_extraction(@@ -1233,6 +1253,7 @@ class DownloadService:extraction_method: str,extraction_source: str,pdf_document_id: Optional[int] = None,+ save_files: bool = True,) -> Optional[str]:"""Save extracted text to disk and database.@@ -1244,13 +1265,14 @@ class DownloadService:extraction_method: How the text was extractedextraction_source: Specific tool/API usedpdf_document_id: ID of PDF document if extracted from PDF+ save_files: Whether to save .txt files to disk (True) or DB-only (False)Returns:Absolute path to saved text file or None if save fails"""try:- # Try to save the file to disk (returns None if storage disabled)- text_path = self._save_text(resource, text)+ # Try to save the file to disk (returns None if storage disabled or save_files=False)+ text_path = self._save_text(resource, text) if save_files else None# Calculate file metadata (needed for database even if no file)file_size = len(text.encode("utf-8"))@@ -1329,11 +1351,11 @@ class DownloadService:logger.info("Saved text to database only (file storage disabled)")- return text_path # Return path even if None (caller handles it)+ return text_path # Return path if saved to disk, None if DB-onlyexcept Exception:logger.exception("Error saving text file with DB")- return None+ raise # Re-raise so caller can handle the errordef _create_text_document_record(self,