| 12345678910111213141516171819202122232425262728 |
- from __future__ import annotations
- from typing import Any, Dict
- def compute_importance(cluster: Dict[str, Any]) -> float:
- """Compute an importance score for an already-enriched cluster.
- Preference: use LLM-derived signals when available.
- Heuristic blend:
- - consensus/coverage: sources + number of articles
- - signal strength: |sentimentScore| (LLM-derived)
- """
- sources = len(set(cluster.get("sources", [])))
- article_count = len(cluster.get("articles", []))
- sentiment_score = cluster.get("sentimentScore")
- if sentiment_score is None:
- sentiment_score = 0.0
- # Coverage term (kept conservative)
- coverage = 0.10 * sources + 0.01 * article_count
- # LLM signal term: higher magnitude sentiment => higher importance.
- signal = 0.60 * min(1.0, abs(float(sentiment_score)))
- score = coverage + signal
- return min(0.99, round(score, 2))
|