~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
Merge branch 'dev' into feature/document-scheduler-integration
LearningCircuitfc29f11afcfb
diff --cc src/local_deep_research/research_library/services/download_service.pyindex 440b300f77,6feb279560..a436d5acfd--- a/src/local_deep_research/research_library/services/download_service.py+++ b/src/local_deep_research/research_library/services/download_service.py@@@ -933,115 -853,60 +933,85 @@@ class DownloadService)return False, f"Failed to save text: {str(e)}"- # Fallback: Download PDF temporarily (in memory only) and extract text- logger.info(f"Falling back to PDF extraction for: {resource.url}")+ # Fallback: Download PDF to memory only and extract text (no disk storage)+ logger.info(+ f"[TEXT_EXTRACTION] API text extraction failed, falling back to in-memory PDF download for: {resource.url}"+ )+ logger.info(+ "[TEXT_EXTRACTION] PDF will be processed in memory only - no disk storage"+ )- # Download PDF to memory only using requests (no file system operations)- try:- import requests-- headers = {- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"- }-- # Convert arXiv abstract URL to PDF URL if needed- pdf_url = resource.url- if "arxiv.org/abs/" in resource.url:- # Convert: http://arxiv.org/abs/2401.03055v1 -> https://arxiv.org/pdf/2401.03055v1.pdf- pdf_url = (- resource.url.replace("/abs/", "/pdf/").replace(- "http://", "https://"- )- + ".pdf"- )- logger.info(- f"[TEXT_EXTRACTION] Converting arXiv URL: {resource.url} -> {pdf_url}"- )-- response = requests.get(pdf_url, headers=headers, timeout=30)- response.raise_for_status()-- # Verify it's a PDF- content_type = response.headers.get("Content-Type", "")- logger.debug(- f"[TEXT_EXTRACTION] Response content type: {content_type}"- )- logger.debug(- f"[TEXT_EXTRACTION] Response headers: {dict(response.headers)}"- )- logger.debug(- f"[TEXT_EXTRACTION] Response status: {response.status_code}"- # Use the downloader directly without tracker++ # Use downloader to get PDF content+ downloader = self._get_downloader(resource.url)- if not downloader:- downloader = GenericDownloader(timeout=30)-- result = downloader.download_with_result(- resource.url, ContentType.PDF- )++ if downloader:++ result = downloader.download_with_result(++ resource.url, ContentType.PDF+ )- logger.debug(f"[TEXT_EXTRACTION] Response URL: {response.url}")- if not content_type.startswith("application/pdf"):- logger.warning(- f"[TEXT_EXTRACTION] URL didn't return PDF content: {content_type}, status: {response.status_code}, final URL: {response.url}"- )- # Check if we got redirected to an HTML page- if "text/html" in content_type:- if result.is_success and result.content:- # Extract text from PDF (without saving the PDF)- text = self.extract_text_from_pdf(result.content)- if text:- # Save text file with database record- # 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,++ if result.is_success and result.content:++ # Extract text from PDF (without saving the PDF)++ text = self._extract_text_from_pdf(result.content)++ if text:++ # Save text file with database record++ # 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()++ logger.info(++ f"[TEXT_EXTRACTION] ✓ SUCCESS: Extracted text from '{resource.title[:50]}...' | {resource.url}"++ )++ return True, None++ 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:+ logger.warning(- "[TEXT_EXTRACTION] Got HTML instead of PDF - likely arXiv abstract page"- )- # Log first few characters of content for debugging- content_preview = (- response.text[:200]- if hasattr(response, "text")- else str(response.content[:200])++ f"[TEXT_EXTRACTION] Failed to extract text from PDF for: {resource.url}"+ )- logger.debug(- f"[TEXT_EXTRACTION] Content preview: {content_preview}"++ error_msg = "PDF text extraction returned empty text"++ self._record_failed_text_extraction(+ session,- extraction_method="pdf_extraction",- extraction_source="pdfplumber_fallback",- save_files=save_files,++ resource,++ error=error_msg,)- raise Exception("Not a PDF file")-- # Extract text from PDF in memory- pdf_content = response.content- text = self._extract_text_from_pdf(pdf_content)-- if text:- # Save text to database only (no file storage)- text_path = self._save_text_with_db(- resource,- text,- session,- extraction_method="pdf_extraction",- extraction_source="in_memory_fallback",- save_files=save_files, # This determines if .txt files are saved- )- # Success! text_path may be None (DB-only) or a path (DB + file)- session.commit()- logger.info(- f"[TEXT_EXTRACTION] ✓ SUCCESS: Extracted text from '{resource.title[:50]}...' | {resource.url}"- )- return True, None- # Success! text_path may be None (DB-only) or a path (DB + file)+ session.commit()- return True, None- except Exception as e:- logger.exception(- f"Failed to save text for resource {resource.id}"- )- return False, f"Failed to save text: {str(e)}"++ return False, error_msgelse:- # Record failed extraction++ # Download failed++ error_msg = result.skip_reason or "Failed to download PDF"+ logger.warning(- f"[TEXT_EXTRACTION] Failed to extract text from in-memory PDF for: {resource.url}"++ f"[TEXT_EXTRACTION] ✗ FAILED: Could not download PDF for '{resource.title[:50]}...' | {resource.url} | Error: {error_msg}"+ )- raise Exception("PDF text extraction returned empty text")-- except Exception as e:- logger.warning(- f"[TEXT_EXTRACTION] In-memory PDF download/extraction failed for {resource.url}: {e}"- )-- # For both RAG and file modes, mark as failed if PDF extraction fails- # This is a genuine error that should be tracked for potential retry+ self._record_failed_text_extraction(+ session,+ resource,- error="Failed to extract text from PDF",++ error=f"PDF download failed: {error_msg}",+ )+ session.commit()- return False, "Failed to extract text from PDF"++ return False, f"PDF extraction failed: {error_msg}"+ else:- # Record failed download++ error_msg = "No compatible downloader found"+ logger.warning(- f"[TEXT_EXTRACTION] ✗ FAILED: Could not extract text from '{resource.title[:50]}...' | {resource.url} | Error: {e}"++ f"[TEXT_EXTRACTION] ✗ FAILED: {error_msg} for '{resource.title[:50]}...' | {resource.url}"+ )self._record_failed_text_extraction(session,resource,- error=f"In-memory PDF extraction failed: {str(e)}",- error=result.skip_reason or "Failed to download content",++ error=error_msg,)session.commit()- return False, f"PDF extraction failed: {str(e)}"- return False, result.skip_reason or "Failed to download content"++ return False, error_msgdef _get_downloader(self, url: str):"""