feat(summarizer): collapse syndicated duplicate stories before selection #55

Merged
sirius merged 1 commit from wt/t_b3af1cb0 into master 2026-11-14 03:16:28 +00:00
Owner

What

Syndicated wire copies are collapsed before the score threshold and SUMMARY_TOP_N cap, so the slot budget buys distinct stories instead of station copies.

Follow-up to #54. Measured defect on summary id=6: 21 graded articles, 9 distinct titles, 12 selected blocks that were only two stories (Trump-Xi-Putin summit carried by 7 Hearst domains, FAA ground stop by 6).

Changes

  • news/summerizer/intel.py: pure dedupe_blocks(blocks, *, similarity=0.85, enabled=True) plus normalize_title / title_similarity.
    • normalise: lowercase, strip a short digit-free trailing source suffix ( - KCCI, | CNN, - AP), keep [a-z0-9 ], collapse whitespace;
    • same story when normalised titles are equal or word-set Jaccard / word-sequence difflib ratio >= SUMMARY_DEDUPE_SIMILARITY;
    • highest score wins the group (ties -> earliest position); star clustering against the representative, no transitive chaining;
    • never merges differing (both-set) category values, and never merges titles that disagree on a number (wire copy is verbatim);
    • empty/None input, missing/NULL titles and malformed blocks never raise.
  • news/summerizer/summarizer.py: dedupe graded before select_graded(), one log line 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 - duplicates get selected=false and duplicate_of = surviving article_id.
  • article_scores.duplicate_of INTEGER NULL: ensure_tables() DDL + alembic 013 (upgrade and downgrade verified against Postgres 16).
  • .env.example + docs/news.md: both knobs documented in the grading paragraph and config table.

Verification

  • Root suite: 347 passed, 18 skipped (same as master).
  • cd news/summerizer && pytest tests -q: 78 -> 106 passed (+28 new in tests/test_dedupe.py).
  • Replay of the observed case as a unit test: the 21 blocks of summary id=6 collapse to 9, and with min_score=60, top_n=12 select 2 (scores [95, 75]).
  • Scratch Postgres replay of the same 21 blocks (ensure_tables() + persist_article_scores()):
dedupe 21 -> 9 (kept 9, duplicates 12)
selected 2/9 distinct (scores=[95, 75])
article_scores persisted rows=21 selected=2 duplicates=12 summary_id=6

 score | selected | duplicate_of | article_id
-------+----------+--------------+------------
    95 | t        |              |      17263
    95 | f        |        17263 |      18546
    95 | f        |        17263 |      18550
    92 | f        |        17263 |      17272
    92 | f        |        17263 |      17291
    92 | f        |        17263 |      18205
    92 | f        |        17263 |      18297
    75 | t        |              |      23748
    75 | f        |        23748 |      24029
    60 | f        |        23748 |      22643
    60 | f        |        23748 |      22664
    60 | f        |        23748 |      22683
    60 | f        |        23748 |      23708
    55 | f        |              |      23943
    55 | f        |        23748 |      24087
    45 | f        |              |      21227
    30 | f        |              |      16888
     5 | f        |              |      17414
     5 | f        |              |      22376
     5 | f        |              |      22427
     5 | f        |              |      23026
(21 rows)

Premise note (measured, not assumed)

I ran the heuristic over the 500 most recent live titles (24h feed mix) and inspected every merged group. Two false-merge classes appeared and both are now vetoed by the digit-free-suffix / numbers-differ rules: ... - Part 1 vs ... - Part 2 (wiseye.org) and horoscope boilerplate variants.

The horoscope class still merges at 0.85 (identical 16-word template, one sign word different) - it is noise (score 5, never selected), and SUMMARY_DEDUPE_SIMILARITY=0.96 removes it at the cost of one real variant (...across U.S.... copy at 0.889). No editorially significant story merged at 0.85 in this sample: every true syndication cluster scored 0.970-1.000. Default left at 0.85 per spec; raising it is a ConfigMap-only change.

Merge policy: do not merge - operator merges, rebuilds osint-news-summarizer, pins the sha in sirius/homek8s, then re-runs a forced interval.

## What Syndicated wire copies are collapsed **before** the score threshold and `SUMMARY_TOP_N` cap, so the slot budget buys distinct stories instead of station copies. Follow-up to #54. Measured defect on summary id=6: 21 graded articles, 9 distinct titles, 12 selected blocks that were only two stories (Trump-Xi-Putin summit carried by 7 Hearst domains, FAA ground stop by 6). ## Changes - `news/summerizer/intel.py`: pure `dedupe_blocks(blocks, *, similarity=0.85, enabled=True)` plus `normalize_title` / `title_similarity`. - normalise: lowercase, strip a short digit-free trailing source suffix (` - KCCI`, ` | CNN`, ` - AP`), keep `[a-z0-9 ]`, collapse whitespace; - same story when normalised titles are equal or word-set Jaccard / word-sequence `difflib` ratio >= `SUMMARY_DEDUPE_SIMILARITY`; - highest score wins the group (ties -> earliest position); star clustering against the representative, no transitive chaining; - never merges differing (both-set) `category` values, and never merges titles that disagree on a number (wire copy is verbatim); - empty/None input, missing/NULL titles and malformed blocks never raise. - `news/summerizer/summarizer.py`: dedupe `graded` before `select_graded()`, one log line `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 - duplicates get `selected=false` and `duplicate_of` = surviving `article_id`. - `article_scores.duplicate_of INTEGER NULL`: `ensure_tables()` DDL + alembic **013** (upgrade and downgrade verified against Postgres 16). - `.env.example` + `docs/news.md`: both knobs documented in the grading paragraph and config table. ## Verification - Root suite: **347 passed, 18 skipped** (same as master). - `cd news/summerizer && pytest tests -q`: **78 -> 106 passed** (+28 new in `tests/test_dedupe.py`). - Replay of the observed case as a unit test: the 21 blocks of summary id=6 collapse to **9**, and with `min_score=60, top_n=12` select **2** (scores `[95, 75]`). - Scratch Postgres replay of the same 21 blocks (`ensure_tables()` + `persist_article_scores()`): ``` dedupe 21 -> 9 (kept 9, duplicates 12) selected 2/9 distinct (scores=[95, 75]) article_scores persisted rows=21 selected=2 duplicates=12 summary_id=6 score | selected | duplicate_of | article_id -------+----------+--------------+------------ 95 | t | | 17263 95 | f | 17263 | 18546 95 | f | 17263 | 18550 92 | f | 17263 | 17272 92 | f | 17263 | 17291 92 | f | 17263 | 18205 92 | f | 17263 | 18297 75 | t | | 23748 75 | f | 23748 | 24029 60 | f | 23748 | 22643 60 | f | 23748 | 22664 60 | f | 23748 | 22683 60 | f | 23748 | 23708 55 | f | | 23943 55 | f | 23748 | 24087 45 | f | | 21227 30 | f | | 16888 5 | f | | 17414 5 | f | | 22376 5 | f | | 22427 5 | f | | 23026 (21 rows) ``` ## Premise note (measured, not assumed) I ran the heuristic over the 500 most recent live titles (24h feed mix) and inspected every merged group. Two false-merge classes appeared and both are now vetoed by the digit-free-suffix / numbers-differ rules: `... - Part 1` vs `... - Part 2` (wiseye.org) and horoscope boilerplate variants. The horoscope class still merges at 0.85 (identical 16-word template, one sign word different) - it is noise (score 5, never selected), and `SUMMARY_DEDUPE_SIMILARITY=0.96` removes it at the cost of one real variant (`...across U.S....` copy at 0.889). No editorially significant story merged at 0.85 in this sample: every true syndication cluster scored 0.970-1.000. Default left at **0.85** per spec; raising it is a ConfigMap-only change. Merge policy: **do not merge** - operator merges, rebuilds `osint-news-summarizer`, pins the sha in `sirius/homek8s`, then re-runs a forced interval.
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.
sirius merged commit d04ddc9afa into master 2026-11-14 03:16:28 +00:00
sirius deleted branch wt/t_b3af1cb0 2026-11-14 03:16:28 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
sirius/osint-dashboard!55
No description provided.