feat(summarizer): collapse syndicated wire copies before selection
The map phase grades every article, but a single wire story arrives from
many station domains with an identical headline (the measured run selected
12 blocks that were only two stories, then produced a ticker with five
summit rows and one FAA row). Dedupe now runs before the threshold/cap, so
SUMMARY_TOP_N buys distinct stories.
- intel.py: pure `dedupe_blocks(blocks, *, similarity, enabled)` plus
`normalize_title` / `title_similarity`. Titles are lowercased, punctuation
flattened and a short digit-free trailing source suffix (" - KCCI",
" | CNN", " — AP") dropped; blocks match on equal normalised titles or
word-set Jaccard / word-sequence difflib ratio >= similarity (default
0.85). Best score wins the group (ties -> earliest), matching is against
the representative only (no transitive chaining), and differing categories
or differing numbers never merge. Blocks now carry their article title.
- summarizer.py: dedupe graded blocks before select_graded() and log
`dedupe 21 -> 9 (kept 9, duplicates 12)`; SUMMARY_DEDUPE=0 skips it,
SUMMARY_DEDUPE_SIMILARITY tunes it. persist_article_scores() still writes
one row per graded article, with duplicates selected=false and
duplicate_of pointing at the surviving article id.
- article_scores.duplicate_of INTEGER NULL in ensure_tables() and alembic
013 (upgrade/downgrade verified against Postgres 16).
- docs/news.md + .env.example document both knobs.
Replaying the observed summary id=6 (21 graded, 9 distinct titles) now keeps
9 and, at min_score=60/top_n=12, selects 2 — the 11 dropped copies that
scored >= 60 are stored selected=false with a duplicate_of pointer.
This commit is contained in:
parent
fa745ee3f7
commit
d40244900e
6 changed files with 757 additions and 11 deletions
17
docs/news.md
17
docs/news.md
|
|
@ -89,6 +89,21 @@ promotes an item above its score. Every graded article is persisted to
|
|||
`article_scores` (score, category, selected, model, summary_id) so the operator
|
||||
can tune the thresholds against real data.
|
||||
|
||||
Syndicated wire copy is collapsed **before** the threshold and cap, so
|
||||
`SUMMARY_TOP_N` counts distinct stories instead of stations: the same headline
|
||||
carried by seven Hearst domains is one story, not seven. Titles are normalised
|
||||
first (lowercase, punctuation flattened, a trailing ` - KCCI` / ` | CNN` /
|
||||
` — AP` source suffix dropped when it is short and digit-free), then two blocks
|
||||
are the same story when the normalised titles are equal or at least
|
||||
`SUMMARY_DEDUPE_SIMILARITY` similar (default 0.85; word-set Jaccard or
|
||||
word-sequence `difflib` ratio). The highest-scoring copy represents the story
|
||||
(ties → earliest); differing `category` values and titles that disagree on any
|
||||
number are never merged. Duplicates are still written to `article_scores` with
|
||||
`selected=false` and `duplicate_of` = the surviving `article_id`, so nothing is
|
||||
lost for tuning. `SUMMARY_DEDUPE=0` disables dedupe entirely; raising
|
||||
`SUMMARY_DEDUPE_SIMILARITY` toward 0.95 makes it stricter. Dedupe is pure string
|
||||
work — no extra LLM call.
|
||||
|
||||
## Keys and Settings
|
||||
|
||||
- **`NOUS_API_KEY`** — paste in the dashboard **Keys** UI (`api_keys` /
|
||||
|
|
@ -270,6 +285,8 @@ map. `summary_en` lands in `article_summaries.summary_text`.
|
|||
| `SUMMARY_TOP_N` | `12` | Max blocks passed to the reduce phase (best score first). |
|
||||
| `SUMMARY_FALLBACK_TOP` | `3` | Blocks used when nothing clears `SUMMARY_MIN_SCORE`; `0` = empty DATA. |
|
||||
| `SUMMARY_FALLBACK_MIN_SCORE` | `40` | Score floor for the fallback set; below it the reduce phase gets empty DATA. |
|
||||
| `SUMMARY_DEDUPE` | `1` | Collapse syndicated wire copies before selection; `0` skips dedupe entirely. |
|
||||
| `SUMMARY_DEDUPE_SIMILARITY` | `0.85` | Normalised-title similarity at which two blocks count as the same story (1.0 = verbatim only). |
|
||||
| `SUMMARY_WINDOW_MINUTES` | `15` | How far back the summarizer looks for new articles (window is `(now - N, now]`; future-dated rows are ignored). |
|
||||
| `NEWS_SCRAPE_INTERVAL_S` | `10` | Pause after each crawl before the next (scraper is otherwise continuous). |
|
||||
| `NEWS_SUMMARIZE_INTERVAL_S` | `900` | Seconds between analyst runs (default 15 min). |
|
||||
|
|
|
|||
Loading…
Reference in a new issue