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.

feat: implement configurable PDF and text storage for Research Library

LearningCircuita90f7a3e4781
diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.json
index 93849d3132..151d4938d7 100644
--- a/src/local_deep_research/defaults/default_settings.json
+++ b/src/local_deep_research/defaults/default_settings.json
@@ -5247,7 +5247,7 @@
},
"research_library.storage_path": {
"category": "research_library",
- "description": "Base path for storing research library documents",
+ "description": "Base path for storing research library documents. Each user will have their own subdirectory unless shared library is enabled.",
"editable": true,
"max_value": null,
"min_value": null,
@@ -5259,18 +5259,46 @@
"value": "~/Documents/LocalDeepResearch/Library",
"visible": true
},
- "research_library.path_locked": {
+ "research_library.shared_library": {
"category": "research_library",
- "description": "If true, prevents users from changing the library storage path through the UI",
- "editable": false,
+ "description": "⚠️ WARNING: When enabled, all users share the same library directory. Documents from all users will be visible to each other. Only enable in trusted environments.",
+ "editable": true,
"max_value": null,
"min_value": null,
- "name": "Lock Library Path",
+ "name": "Shared Library Mode",
"options": null,
"step": null,
"type": "APP",
"ui_element": "checkbox",
"value": false,
- "visible": false
+ "visible": true
+ },
+ "research_library.enable_pdf_storage": {
+ "category": "research_library",
+ "description": "⚠️ PRIVACY WARNING: PDFs will be stored unencrypted on disk, exposing your research interests to anyone with filesystem access. Only enable if you need PDF files for external tools.",
+ "editable": true,
+ "max_value": null,
+ "min_value": null,
+ "name": "Enable PDF Storage",
+ "options": null,
+ "step": null,
+ "type": "APP",
+ "ui_element": "checkbox",
+ "value": false,
+ "visible": true
+ },
+ "research_library.enable_txt_storage": {
+ "category": "research_library",
+ "description": "⚠️ PRIVACY WARNING: Text files will be stored unencrypted on disk for RAG/ChromaDB integration. This exposes document contents to anyone with filesystem access.",
+ "editable": true,
+ "max_value": null,
+ "min_value": null,
+ "name": "Enable Text File Storage",
+ "options": null,
+ "step": null,
+ "type": "APP",
+ "ui_element": "checkbox",
+ "value": false,
+ "visible": true
}
}
diff --git a/src/local_deep_research/defaults/research_library/library_settings.json b/src/local_deep_research/defaults/research_library/library_settings.json
index bab9cd67de..fbe2798375 100644
--- a/src/local_deep_research/defaults/research_library/library_settings.json
+++ b/src/local_deep_research/defaults/research_library/library_settings.json
@@ -2,15 +2,27 @@
"research_library": {
"storage_path": {
"value": "~/Documents/LocalDeepResearch/Library",
- "description": "Base path for storing research library documents. Can be overridden by RESEARCH_LIBRARY_STORAGE_PATH environment variable.",
+ "description": "Base path for storing research library documents. Each user will have their own subdirectory unless shared library is enabled.",
"type": "string",
"env_var": "RESEARCH_LIBRARY_STORAGE_PATH"
},
- "path_locked": {
+ "shared_library": {
"value": false,
- "description": "If true, prevents users from changing the library storage path through the UI. Can be overridden by RESEARCH_LIBRARY_PATH_LOCKED environment variable.",
+ "description": "When enabled, all users share the same library directory. Documents from all users will be visible to each other.",
"type": "boolean",
- "env_var": "RESEARCH_LIBRARY_PATH_LOCKED"
+ "env_var": "RESEARCH_LIBRARY_SHARED_LIBRARY"
+ },
+ "enable_pdf_storage": {
+ "value": false,
+ "description": "Enable storing PDF files on disk. PDFs will be unencrypted and expose research interests.",
+ "type": "boolean",
+ "env_var": "RESEARCH_LIBRARY_ENABLE_PDF_STORAGE"
+ },
+ "enable_txt_storage": {
+ "value": false,
+ "description": "Enable storing text files on disk for RAG/ChromaDB. Text files will be unencrypted.",
+ "type": "boolean",
+ "env_var": "RESEARCH_LIBRARY_ENABLE_TXT_STORAGE"
}
}
}
diff --git a/src/local_deep_research/research_library/services/download_service.py b/src/local_deep_research/research_library/services/download_service.py
index b68f88ac44..bbaf055a0e 100644
--- a/src/local_deep_research/research_library/services/download_service.py
+++ b/src/local_deep_research/research_library/services/download_service.py
@@ -414,22 +414,36 @@ class DownloadService:
logger.info(f"Download failed with reason: {error_msg}")
return False, error_msg
- # Save file
- file_path = self._save_pdf(resource, pdf_content)
+ # Check if PDF storage is enabled
+ enable_pdf_storage = self.settings.get_setting(
+ "research_library.enable_pdf_storage", False
+ )
# Update tracker
import hashlib
tracker.file_hash = hashlib.sha256(pdf_content).hexdigest()
- # Store only relative path
- tracker.file_path = str(
- Path(file_path).relative_to(self.library_root)
- )
- tracker.file_name = Path(file_path).name
tracker.file_size = len(pdf_content)
tracker.is_downloaded = True
tracker.downloaded_at = datetime.now(UTC)
+ # Only save PDF file if storage is enabled
+ if enable_pdf_storage:
+ # Save file
+ file_path = self._save_pdf(resource, pdf_content)
+ # Store only relative path
+ tracker.file_path = str(
+ Path(file_path).relative_to(self.library_root)
+ )
+ tracker.file_name = Path(file_path).name
+ else:
+ # PDF storage disabled - only store metadata
+ tracker.file_path = None
+ tracker.file_name = None
+ logger.info(
+ "PDF storage disabled - only storing metadata and text"
+ )
+
# Update attempt with success info
attempt.succeeded = True
@@ -471,7 +485,10 @@ class DownloadService:
attempt.succeeded = True
attempt.bytes_downloaded = len(pdf_content)
- logger.info(f"Successfully downloaded: {file_path}")
+ if enable_pdf_storage:
+ logger.info(f"Successfully downloaded: {tracker.file_path}")
+ else:
+ logger.info(f"Successfully extracted text from: {resource.url}")
return True, None
except Exception as e:
@@ -584,15 +601,26 @@ class DownloadService:
self, resource: ResearchResource, text: str
) -> Optional[str]:
"""
- Save extracted text to disk in txt folder.
+ Save extracted text to disk in txt folder if text storage is enabled.
Args:
resource: The research resource
text: Extracted text content
Returns:
- Absolute path to saved text file or None if save fails
+ Absolute path to saved text file or None if storage disabled or save fails
"""
+ # Check if text file storage is enabled
+ enable_txt_storage = self.settings.get_setting(
+ "research_library.enable_txt_storage", False
+ )
+
+ if not enable_txt_storage:
+ logger.info(
+ "Text file storage disabled - text will only be stored in database"
+ )
+ return None
+
try:
# Generate filename similar to PDF but with .txt extension
domain = urlparse(resource.url).netloc.replace(".", "_")
@@ -1217,19 +1245,21 @@ class DownloadService:
Absolute path to saved text file or None if save fails
"""
try:
- # First save the file to disk
+ # Try to save the file to disk (returns None if storage disabled)
text_path = self._save_text(resource, text)
- if not text_path:
- return None
- # Calculate file metadata
+ # Calculate file metadata (needed for database even if no file)
file_size = len(text.encode("utf-8"))
text_hash = hashlib.sha256(text.encode("utf-8")).hexdigest()
word_count = len(text.split())
character_count = len(text)
- # Get relative path from library root
- relative_path = Path(text_path).relative_to(self.library_root)
+ # Get relative path from library root (if file was saved)
+ relative_path = (
+ str(Path(text_path).relative_to(self.library_root))
+ if text_path
+ else None
+ )
# Check if record exists
text_doc = (
@@ -1241,7 +1271,9 @@ class DownloadService:
if text_doc:
# Update existing record
text_doc.text_hash = text_hash
- text_doc.file_path = str(relative_path)
+ text_doc.file_path = (
+ relative_path # Can be None if storage disabled
+ )
text_doc.file_size = file_size
text_doc.character_count = character_count
text_doc.word_count = word_count
@@ -1251,6 +1283,8 @@ class DownloadService:
text_doc.extraction_error = None
text_doc.extracted_at = datetime.now(UTC)
text_doc.document_id = pdf_document_id
+ # Store text content in database
+ text_doc.text_content = text
# Set quality based on method
if extraction_method == "native_api":
@@ -1270,7 +1304,7 @@ class DownloadService:
document_id=pdf_document_id,
text_hash=text_hash,
original_url=resource.url,
- file_path=str(relative_path),
+ file_path=relative_path, # Can be None if storage disabled
file_size=file_size,
character_count=character_count,
word_count=word_count,
@@ -1281,13 +1315,17 @@ class DownloadService:
extraction_quality="high"
if extraction_method == "native_api"
else "medium",
+ text_content=text, # Store text content in database
)
session.add(text_doc)
- logger.info(
- f"Saved text file to database and disk: {relative_path}"
- )
- return text_path
+ if text_path:
+ logger.info(f"Saved text to database and disk: {relative_path}")
+ else:
+ logger.info(
+ "Saved text to database only (file storage disabled)"
+ )
+ return text_path # Return path even if None (caller handles it)
except Exception:
logger.exception("Error saving text file with DB")
diff --git a/src/local_deep_research/research_library/utils/__init__.py b/src/local_deep_research/research_library/utils/__init__.py
index d1364d3657..12f473a24d 100644
--- a/src/local_deep_research/research_library/utils/__init__.py
+++ b/src/local_deep_research/research_library/utils/__init__.py
@@ -28,15 +28,13 @@ def get_library_storage_path(username: str) -> Path:
Uses the settings system which respects environment variable overrides:
- research_library.storage_path: Base path for library storage
- - research_library.path_locked: If true, prevents UI from showing path config
-
- Always adds username subdirectory for multi-user isolation.
+ - research_library.shared_library: If true, all users share the same directory
Args:
username: The username
Returns:
- Path to the user's library storage directory
+ Path to the library storage directory
"""
from ...utilities.db_utils import get_settings_manager
@@ -50,10 +48,20 @@ def get_library_storage_path(username: str) -> Path:
)
).expanduser()
- # Always add username subdirectory for user isolation in multi-user environments
- base_dir = base_path / username
- base_dir.mkdir(parents=True, exist_ok=True)
- return base_dir
+ # Check if shared library mode is enabled
+ shared_library = settings.get_setting(
+ "research_library.shared_library", False
+ )
+
+ if shared_library:
+ # Shared mode: all users use the same directory
+ base_path.mkdir(parents=True, exist_ok=True)
+ return base_path
+ else:
+ # Default: user isolation with subdirectories
+ user_dir = base_path / username
+ user_dir.mkdir(parents=True, exist_ok=True)
+ return user_dir
def open_file_location(file_path: str) -> bool: