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.

Get cacheing for journal quality scores to work.

Daniel Petti2b51494d0c49
diff --git a/src/local_deep_research/advanced_search_system/filters/journal_reputation_filter.py b/src/local_deep_research/advanced_search_system/filters/journal_reputation_filter.py
index e5dde600a2..e5db4b01be 100644
--- a/src/local_deep_research/advanced_search_system/filters/journal_reputation_filter.py
+++ b/src/local_deep_research/advanced_search_system/filters/journal_reputation_filter.py
@@ -1,4 +1,7 @@
import logging
+import time
+import traceback
+from datetime import timedelta
from typing import Any, Dict, List, Optional
from langchain_core.language_models.chat_models import BaseChatModel
@@ -6,7 +9,8 @@ from methodtools import lru_cache
from ...config.llm_config import get_llm
from ...search_system import AdvancedSearchSystem
-from ...utilities.db_utils import get_db_setting
+from ...utilities.db_utils import get_db_session, get_db_setting
+from ...web.database.models import Journal
from ...web_search_engines.search_engine_factory import create_search_engine
from .base_filter import BaseFilter
@@ -32,6 +36,7 @@ class JournalReputationFilter(BaseFilter):
reliability_threshold: int | None = None,
max_context: int | None = None,
exclude_non_published: bool | None = None,
+ quality_reanalysis_period: timedelta | None = None,
):
"""
Args:
@@ -44,6 +49,8 @@ class JournalReputationFilter(BaseFilter):
LLM when assessing journal reliability.
exclude_non_published: If true, it will exclude any results that
don't have an associated journal publication.
+ quality_reanalysis_period: Period at which to update journal
+ quality assessments.
"""
super().__init__(model)
@@ -62,10 +69,17 @@ class JournalReputationFilter(BaseFilter):
get_db_setting("search.journal_reputation.max_context", 3000)
)
self.__exclude_non_published = exclude_non_published
- if self.__exclude_non_published:
+ if self.__exclude_non_published is None:
self.__exclude_non_published = bool(
get_db_setting("search.journal_reputation.exclude_non_published", False)
)
+ self.__quality_reanalysis_period = quality_reanalysis_period
+ if self.__quality_reanalysis_period is None:
+ self.__quality_reanalysis_period = timedelta(
+ days=int(
+ get_db_setting("search.journal_reputation.reanalysis_period", 365)
+ )
+ )
# SearXNG is required so we can search the open web for reputational
# information.
@@ -82,6 +96,8 @@ class JournalReputationFilter(BaseFilter):
questions_per_iteration=3,
)
+ self.__db_session = get_db_session()
+
@classmethod
def create_default(
cls, model: BaseChatModel | None = None, *, engine_name: str
@@ -173,9 +189,34 @@ class JournalReputationFilter(BaseFilter):
return max(min(reputation_score, 10), 1)
+ def __add_journal_to_db(self, *, name: str, quality: int) -> None:
+ """
+ Saves the journal quality information to the database.
+
+ Args:
+ name: The name of the journal.
+ quality: The quality assessment for the journal.
+
+ """
+ journal = self.__db_session.query(Journal).filter_by(name=name).first()
+ if journal is not None:
+ journal.quality = quality
+ journal.quality_model = self.model.name
+ journal.quality_analysis_time = int(time.time())
+ else:
+ journal = Journal(
+ name=name,
+ quality=quality,
+ quality_model=self.model.name,
+ quality_analysis_time=int(time.time()),
+ )
+ self.__db_session.add(journal)
+
+ self.__db_session.commit()
+
def __check_result(self, result: Dict[str, Any]) -> bool:
"""
- Checks a single result to see if the journal is reputable.
+ Performs a search to determine the reputability of a result journal..
Args:
result: The result to check.
@@ -195,14 +236,34 @@ class JournalReputationFilter(BaseFilter):
# Basic filtering: sometimes the journal ref includes volume and page
# information.
journal_name = journal_name.split(",")[0]
+ journal_name = journal_name.split("volume")[0]
+
+ # Check the database first.
+ journal = self.__db_session.query(Journal).filter_by(name=journal_name).first()
+ if (
+ journal is not None
+ and (time.time() - journal.quality_analysis_time)
+ < self.__quality_reanalysis_period.total_seconds()
+ ):
+ logger.debug(f"Found existing reputation for {journal_name} in database.")
+ return journal.quality >= self.__threshold
# Evaluate reputation.
try:
- return self.__analyze_journal_reputation(journal_name) >= self.__threshold
+ quality = self.__analyze_journal_reputation(journal_name)
+ # Save to the database.
+ self.__add_journal_to_db(name=journal_name, quality=quality)
+ return quality >= self.__threshold
except ValueError:
# The LLM behaved weirdly. In this case, we will just assume it's
# okay.
return True
def filter_results(self, results: List[Dict], query: str, **kwargs) -> List[Dict]:
- return list(filter(self.__check_result, results))
+ try:
+ return list(filter(self.__check_result, results))
+ except Exception as e:
+ logger.error(
+ f"Journal quality filtering failed: {e}, {traceback.format_exc()}"
+ )
+ return results
diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.json
index 80b4954a32..fe5f771b44 100644
--- a/src/local_deep_research/defaults/default_settings.json
+++ b/src/local_deep_research/defaults/default_settings.json
@@ -677,7 +677,34 @@
"step": null,
"type": "SEARCH",
"ui_element": "checkbox",
- "value": 3000,
+ "value": false,
+ "visible": true
+ },
+ "search.journal_reputation.reanalysis_period": {
+ "category": "journal_quality_filter_parameters",
+ "description": "Period at which to re-check the quality of journals.",
+ "editable": true,
+ "max_value": null,
+ "min_value": null,
+ "name": "Quality Reanalysis Period",
+ "options": [
+ {
+ "label": "Yearly",
+ "value": "365"
+ },
+ {
+ "label": "Every 6 Months",
+ "value": "182"
+ },
+ {
+ "label": "Every Month",
+ "value": "30"
+ }
+ ],
+ "step": null,
+ "type": "SEARCH",
+ "ui_element": "select",
+ "value": "265",
"visible": true
},
"search.snippets_only": {
diff --git a/src/local_deep_research/web/database/migrations.py b/src/local_deep_research/web/database/migrations.py
index 1a154861f2..6a576eb335 100644
--- a/src/local_deep_research/web/database/migrations.py
+++ b/src/local_deep_research/web/database/migrations.py
@@ -3,7 +3,7 @@ import logging
from sqlalchemy import inspect
from ..services.settings_manager import SettingsManager
-from .models import Base, Setting
+from .models import Base, Journal, Setting
logger = logging.getLogger(__name__)
@@ -44,6 +44,10 @@ def run_migrations(engine, db_session=None):
logger.info("Creating settings table")
Base.metadata.create_all(engine, tables=[Setting.__table__])
+ if not inspector.has_table(Journal.__tablename__):
+ logger.info("Creating journals table.")
+ Base.metadata.create_all(engine, tables=[Journal.__table__])
+
# Import existing settings from files
if db_session:
import_default_settings_file(db_session)
diff --git a/src/local_deep_research/web/database/models.py b/src/local_deep_research/web/database/models.py
index 7edffbaaff..c151a68926 100644
--- a/src/local_deep_research/web/database/models.py
+++ b/src/local_deep_research/web/database/models.py
@@ -9,6 +9,7 @@ from sqlalchemy import (
Float,
ForeignKey,
Integer,
+ Sequence,
String,
Text,
UniqueConstraint,
@@ -115,3 +116,22 @@ class Setting(Base):
)
__table_args__ = (UniqueConstraint("key", name="uix_settings_key"),)
+
+
+class Journal(Base):
+ """
+ Database model for storing information about academic journals.
+ """
+
+ __tablename__ = "journals"
+
+ id = Column(Integer, Sequence("journal_id_seq"), primary_key=True, index=True)
+
+ # Name of the journal
+ name = Column(String(255), nullable=False, unique=True, index=True)
+ # Quality score of the journal
+ quality = Column(Integer, nullable=True)
+ # Model that was used to generate the quality score.
+ quality_model = Column(String(255), nullable=True, index=True)
+ # Time at which the quality was last analyzed.
+ quality_analysis_time = Column(Integer, nullable=False)