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.

refactor: Address djpetti code review feedback on domain classification

LearningCircuitcc296c8a1e56
diff --git a/src/local_deep_research/domain_classifier/classifier.py b/src/local_deep_research/domain_classifier/classifier.py
index e369705c47..f778a1e1ce 100644
--- a/src/local_deep_research/domain_classifier/classifier.py
+++ b/src/local_deep_research/domain_classifier/classifier.py
@@ -35,9 +35,9 @@ DOMAIN_CATEGORIES = {
"Social & Community": [
"Social Network",
"Forum/Discussion",
- "Q&A Platform",
- "Blog Platform",
- "Personal Blog",
+ "Q&A Platform", # Question-and-answer focused sites (StackOverflow, Quora)
+ "Blog Platform", # Structured publishing platforms (Medium, WordPress.com)
+ "Personal Blog", # Individual author blogs
],
"Business & Commerce": [
"E-commerce",
@@ -137,9 +137,13 @@ class DomainClassifier:
) -> str:
"""Build prompt for LLM classification.
+ This method uses actual content samples (titles, previews) from the domain
+ rather than relying solely on domain name patterns, providing more
+ accurate classification based on actual site content.
+
Args:
domain: Domain to classify
- samples: Sample resources from the domain
+ samples: Sample resources from the domain (titles, URLs, content previews)
Returns:
Formatted prompt string
diff --git a/src/local_deep_research/domain_classifier/models.py b/src/local_deep_research/domain_classifier/models.py
index bff8b2d446..824713ff45 100644
--- a/src/local_deep_research/domain_classifier/models.py
+++ b/src/local_deep_research/domain_classifier/models.py
@@ -1,7 +1,7 @@
"""Database models for domain classification."""
-from sqlalchemy import Column, String, DateTime, Text, Float, Integer, Index
-from sqlalchemy.sql import func
+from sqlalchemy import Column, String, Text, Float, Integer, Index
+from sqlalchemy_utc import UtcDateTime, utcnow
from ..database.models import Base
@@ -20,8 +20,8 @@ class DomainClassification(Base):
sample_count = Column(
Integer, default=0
) # Number of resources used for classification
- created_at = Column(DateTime(timezone=True), server_default=func.now())
- updated_at = Column(DateTime(timezone=True), onupdate=func.now())
+ created_at = Column(UtcDateTime, default=utcnow())
+ updated_at = Column(UtcDateTime, default=utcnow(), onupdate=utcnow())
# Create index for faster lookups
__table_args__ = (Index("idx_domain_category", "domain", "category"),)
diff --git a/src/local_deep_research/web/routes/metrics_routes.py b/src/local_deep_research/web/routes/metrics_routes.py
index 021e2f0a13..e3f551c97c 100644
--- a/src/local_deep_research/web/routes/metrics_routes.py
+++ b/src/local_deep_research/web/routes/metrics_routes.py
@@ -28,266 +28,6 @@ from ..utils.templates import render_template_with_defaults
metrics_bp = Blueprint("metrics", __name__, url_prefix="/metrics")
-def classify_domain_smart(domain, title=None, content_preview=None):
- """
- Smart domain classification that uses multiple signals.
- Returns a dict with primary category and confidence scores for each category.
- """
- domain_lower = domain.lower()
-
- # Initialize scores for each category
- scores = {
- "academic": 0,
- "news": 0,
- "documentation": 0,
- "forum": 0,
- "blog": 0,
- "government": 0,
- "commercial": 0,
- "social": 0,
- "code": 0,
- "general": 0,
- }
-
- # Academic indicators
- academic_domains = {
- ".edu": 30,
- "arxiv.org": 50,
- "scholar.google": 40,
- "pubmed": 45,
- "jstor.org": 45,
- "sciencedirect": 40,
- "springer": 35,
- "nature.com": 40,
- "ieee.org": 40,
- "acm.org": 40,
- "researchgate": 35,
- "academia.edu": 35,
- "ncbi.nlm": 45,
- "plos.org": 40,
- "science.org": 40,
- ".ac.": 25,
- "university": 20,
- "journal": 15,
- "research": 10,
- }
-
- # News indicators
- news_domains = {
- "cnn.": 40,
- "bbc.": 40,
- "reuters": 40,
- "nytimes": 40,
- "wsj.": 40,
- "guardian": 35,
- "bloomberg": 35,
- "forbes": 30,
- "techcrunch": 30,
- "theverge": 30,
- "wired": 30,
- "arstechnica": 30,
- "news": 20,
- "daily": 15,
- "times": 10,
- "post": 10,
- "herald": 10,
- }
-
- # Documentation/Reference indicators
- doc_domains = {
- "wikipedia": 45,
- "docs.": 40,
- "documentation": 40,
- "readthedocs": 40,
- "gitbook": 35,
- "developer": 30,
- "api.": 30,
- "reference": 25,
- "guide": 20,
- "tutorial": 20,
- "manual": 20,
- "w3.org": 35,
- "mdn.mozilla": 40,
- "help.": 25,
- "support.": 20,
- }
-
- # Forum/Community indicators
- forum_domains = {
- "stackoverflow": 50,
- "reddit": 45,
- "stackexchange": 45,
- "quora": 40,
- "discourse": 35,
- "forum": 30,
- "community": 25,
- "discuss": 25,
- "answers": 20,
- "askubuntu": 40,
- "superuser": 40,
- }
-
- # Blog/Personal indicators
- blog_domains = {
- "medium.com": 40,
- "wordpress": 35,
- "blogspot": 35,
- "substack": 35,
- "dev.to": 35,
- "hashnode": 30,
- "ghost.io": 30,
- "blog": 25,
- "personal": 20,
- "portfolio": 15,
- }
-
- # Government/Official indicators
- gov_domains = {
- ".gov": 50,
- ".mil": 45,
- ".int": 40,
- "europa.eu": 35,
- "who.int": 40,
- "un.org": 40,
- "worldbank": 35,
- "imf.org": 35,
- ".gc.ca": 40,
- ".gov.uk": 40,
- ".gov.au": 40,
- }
-
- # Code/Repository indicators
- code_domains = {
- "github.com": 50,
- "gitlab": 45,
- "bitbucket": 45,
- "sourceforge": 40,
- "npm": 35,
- "pypi.org": 35,
- "crates.io": 35,
- "rubygems": 35,
- "packagist": 30,
- "nuget": 30,
- "maven": 30,
- }
-
- # Social Media indicators
- social_domains = {
- "twitter": 45,
- "x.com": 45,
- "facebook": 45,
- "linkedin": 45,
- "instagram": 40,
- "youtube": 40,
- "tiktok": 35,
- "pinterest": 35,
- "tumblr": 30,
- "discord": 30,
- "slack": 30,
- }
-
- # Commercial/Business indicators
- commercial_domains = {
- "amazon": 40,
- "ebay": 35,
- "shopify": 35,
- "store": 25,
- "shop": 25,
- "buy": 20,
- "sale": 20,
- ".com": 5,
- "product": 15,
- "service": 15,
- "pricing": 20,
- }
-
- # Calculate scores based on domain patterns
- domain_groups = [
- (academic_domains, "academic"),
- (news_domains, "news"),
- (doc_domains, "documentation"),
- (forum_domains, "forum"),
- (blog_domains, "blog"),
- (gov_domains, "government"),
- (code_domains, "code"),
- (social_domains, "social"),
- (commercial_domains, "commercial"),
- ]
-
- for patterns, category in domain_groups:
- for pattern, weight in patterns.items():
- if pattern in domain_lower:
- scores[category] += weight
-
- # Boost scores based on title/content if available
- if title:
- title_lower = title.lower()
- if any(
- word in title_lower
- for word in ["paper", "study", "analysis", "research"]
- ):
- scores["academic"] += 15
- if any(
- word in title_lower
- for word in ["breaking", "latest", "update", "report"]
- ):
- scores["news"] += 15
- if any(
- word in title_lower
- for word in ["how to", "guide", "tutorial", "documentation"]
- ):
- scores["documentation"] += 15
-
- # Find primary category
- max_score = max(scores.values())
- if max_score == 0:
- primary_category = "general"
- else:
- primary_category = max(scores, key=scores.get)
-
- # Normalize scores to percentages
- total_score = sum(scores.values()) or 1
- confidence_scores = {
- k: round(v / total_score * 100, 1) for k, v in scores.items()
- }
-
- # Create detailed categorization
- result = {
- "primary": primary_category,
- "confidence": confidence_scores,
- "top_categories": sorted(
- [
- (cat, score)
- for cat, score in confidence_scores.items()
- if score > 10
- ],
- key=lambda x: x[1],
- reverse=True,
- )[:3],
- }
-
- # Simplified category for backward compatibility
- # Map to our original 4 categories
- category_mapping = {
- "academic": "academic",
- "news": "news",
- "documentation": "reference",
- "government": "reference",
- "forum": "reference",
- "blog": "general",
- "code": "reference",
- "social": "general",
- "commercial": "general",
- "general": "general",
- }
-
- result["simple_category"] = category_mapping.get(
- primary_category, "general"
- )
-
- return result
-
-
def get_rating_analytics(period="30d", research_mode="all", username=None):
"""Get rating analytics for the specified period and research mode."""
try:
@@ -484,20 +224,8 @@ def get_link_analytics(period="30d", username=None):
temporal_data.get(date_str, 0) + 1
)
- # Categorize sources with smart classification
- classification = classify_domain_smart(
- domain, resource.title, resource.content_preview
- )
- simple_cat = classification["simple_category"]
-
- if simple_cat == "academic":
- academic_sources += 1
- elif simple_cat == "news":
- news_sources += 1
- elif simple_cat == "reference":
- reference_sources += 1
- else:
- general_sources += 1
+ # All sources are unclassified until LLM classifier processes them
+ general_sources += 1
# Track source type from metadata if available
if resource.source_type:
@@ -514,12 +242,11 @@ def get_link_analytics(period="30d", username=None):
if resource.title and resource.content_preview:
quality_metrics["with_both"] += 1
- # Track content type from classification
- if "primary" in classification:
- primary_cat = classification["primary"]
- content_types[primary_cat] = (
- content_types.get(primary_cat, 0) + 1
- )
+ # Content types will be available after LLM classification
+ # For now, mark as unclassified
+ content_types["unclassified"] = (
+ content_types.get("unclassified", 0) + 1
+ )
# Track domain co-occurrences for network visualization
research_id = resource.research_id