~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
fix: centralize boolean type conversion for settings (#1276)
LearningCircuitcd52507742f8
diff --git a/src/local_deep_research/api/settings_utils.py b/src/local_deep_research/api/settings_utils.pyindex 8c1e7bf547..47719e2218 100644--- a/src/local_deep_research/api/settings_utils.py+++ b/src/local_deep_research/api/settings_utils.py@@ -330,3 +330,69 @@ def extract_setting_value(return setting["value"]return settingreturn default+++def to_bool(value: Any, default: bool = False) -> bool:+ """+ Convert a value to boolean, handling string representations.++ This is a standalone utility for converting any value to boolean,+ centralizing the string-to-boolean conversion logic that was+ previously scattered throughout the codebase.++ Handles truthy string representations that may come from:+ - API requests+ - Configuration files+ - SQLite (which lacks native boolean type)+ - Environment variables++ Args:+ value: The value to convert+ default: Default boolean if value is None++ Returns:+ Boolean value++ Examples:+ >>> to_bool("true")+ True+ >>> to_bool("yes")+ True+ >>> to_bool("1")+ True+ >>> to_bool("false")+ False+ >>> to_bool(1)+ True+ >>> to_bool(None, default=True)+ True+ """+ if isinstance(value, bool):+ return value+ if isinstance(value, str):+ return value.lower() in ("true", "1", "yes", "on", "enabled")+ if value is None:+ return default+ # For other types (int, etc.), use Python's bool conversion+ return bool(value)+++def extract_bool_setting(+ settings_snapshot: Dict[str, Any], key: str, default: bool = False+) -> bool:+ """+ Extract a boolean setting value from a settings snapshot.++ This is a convenience wrapper around extract_setting_value that+ handles string-to-boolean conversion.++ Args:+ settings_snapshot: Settings snapshot dict+ key: Setting key (e.g., "local_search_normalize_vectors")+ default: Default boolean value if not found++ Returns:+ Boolean value of the setting+ """+ value = extract_setting_value(settings_snapshot, key, default)+ return to_bool(value, default)diff --git a/src/local_deep_research/config/thread_settings.py b/src/local_deep_research/config/thread_settings.pyindex d5653e4c40..7f990fa186 100644--- a/src/local_deep_research/config/thread_settings.py+++ b/src/local_deep_research/config/thread_settings.py@@ -124,3 +124,44 @@ def get_setting_from_snapshot(raise NoSettingsContextError(f"No settings context available in thread for key '{key}'. All settings must be passed via settings_snapshot.")+++def get_bool_setting_from_snapshot(+ key,+ default=False,+ username=None,+ settings_snapshot=None,+ check_fallback_llm=False,+):+ """Get a boolean setting from snapshot, handling string conversion.++ This centralizes the string-to-boolean conversion logic for settings+ retrieved from snapshots. Handles various truthy string representations+ that may come from API requests, config files, or SQLite.++ Args:+ key: Setting key to retrieve+ default: Default boolean value if setting not found+ username: Username (unused, kept for backward compatibility)+ settings_snapshot: Optional settings snapshot dict+ check_fallback_llm: Whether to check LDR_USE_FALLBACK_LLM env var++ Returns:+ Boolean value of the setting+ """+ value = get_setting_from_snapshot(+ key,+ default,+ username=username,+ settings_snapshot=settings_snapshot,+ check_fallback_llm=check_fallback_llm,+ )++ if isinstance(value, bool):+ return value+ if isinstance(value, str):+ return value.lower() in ("true", "1", "yes", "on", "enabled")+ if value is None:+ return default+ # For other types (int, etc.), use Python's bool conversion+ return bool(value)diff --git a/src/local_deep_research/research_library/routes/rag_routes.py b/src/local_deep_research/research_library/routes/rag_routes.pyindex 43997a6779..050d293638 100644--- a/src/local_deep_research/research_library/routes/rag_routes.py+++ b/src/local_deep_research/research_library/routes/rag_routes.py@@ -100,16 +100,10 @@ def get_rag_service(collection_id: Optional[str] = None) -> LibraryRAGService:default_distance_metric = settings.get_setting("local_search_distance_metric", "cosine")- # Ensure normalize_vectors is a proper boolean (settings may return string)- raw_normalize = settings.get_setting("local_search_normalize_vectors", True)- if isinstance(raw_normalize, str):- default_normalize_vectors = raw_normalize.lower() in (- "true",- "1",- "yes",- )- else:- default_normalize_vectors = bool(raw_normalize)+ # Get normalize_vectors as a proper boolean+ default_normalize_vectors = settings.get_bool_setting(+ "local_search_normalize_vectors", True+ )default_index_type = settings.get_setting("local_search_index_type", "flat")# If collection_id provided, check for stored settings@@ -2140,17 +2134,9 @@ def _get_rag_service_for_thread(default_distance_metric = settings_manager.get_setting("local_search_distance_metric", "cosine")- raw_normalize = settings_manager.get_setting(+ default_normalize_vectors = settings_manager.get_bool_setting("local_search_normalize_vectors", True)- if isinstance(raw_normalize, str):- default_normalize_vectors = raw_normalize.lower() in (- "true",- "1",- "yes",- )- else:- default_normalize_vectors = bool(raw_normalize)default_index_type = settings_manager.get_setting("local_search_index_type", "flat")diff --git a/src/local_deep_research/research_library/services/library_rag_service.py b/src/local_deep_research/research_library/services/library_rag_service.pyindex 6e1d6dce3c..0923875a1a 100644--- a/src/local_deep_research/research_library/services/library_rag_service.py+++ b/src/local_deep_research/research_library/services/library_rag_service.py@@ -90,14 +90,9 @@ class LibraryRAGService:)self.distance_metric = distance_metric# Ensure normalize_vectors is always a proper boolean- if isinstance(normalize_vectors, str):- self.normalize_vectors = normalize_vectors.lower() in (- "true",- "1",- "yes",- )- else:- self.normalize_vectors = bool(normalize_vectors)+ from local_deep_research.api.settings_utils import to_bool++ self.normalize_vectors = to_bool(normalize_vectors, default=True)self.index_type = index_type# Use provided embedding manager or create a new onediff --git a/src/local_deep_research/web/services/settings_manager.py b/src/local_deep_research/web/services/settings_manager.pyindex 738e8c232e..0146381cb3 100644--- a/src/local_deep_research/web/services/settings_manager.py+++ b/src/local_deep_research/web/services/settings_manager.py@@ -288,6 +288,40 @@ class SettingsManager:# Return default if not foundreturn default+ def get_bool_setting(+ self, key: str, default: bool = False, check_env: bool = True+ ) -> bool:+ """+ Get a setting value as a boolean, handling string conversion.++ This centralizes the string-to-boolean conversion logic that was+ previously scattered throughout the codebase. Handles various+ truthy string representations that may come from:+ - API requests+ - Configuration files+ - SQLite (which lacks native boolean type)+ - Environment variables++ Args:+ key: Setting key+ default: Default boolean value if setting is not found+ check_env: If true, it will check the environment variable for+ this setting before reading from the DB.++ Returns:+ Boolean value of the setting+ """+ value = self.get_setting(key, default, check_env)++ if isinstance(value, bool):+ return value+ if isinstance(value, str):+ return value.lower() in ("true", "1", "yes", "on", "enabled")+ if value is None:+ return default+ # For other types (int, etc.), use Python's bool conversion+ return bool(value)+def set_setting(self, key: str, value: Any, commit: bool = True) -> bool:"""Set a setting value