osint-dashboard/alembic/versions/012_article_scores.py
hermes-backend 853e87b7c5 feat(summarizer): score articles in the map phase, brief only the important ones
The map prompt now grades every article 0-100 against an explicit rubric as
the first line of its block; the summarizer parses Score:, falls back to the
Importance: label when the line is missing, ranks blocks best-first and passes
only score >= SUMMARY_MIN_SCORE (capped at SUMMARY_TOP_N) to the reduce phase.

- new pure helpers in intel.py: parse_map_scores(), select_graded(), join_blocks()
- reduce prompts drop the 'fill the brief with minor incidents and crime'
  filler instructions and the 'fill ticker with medium then low' clause
- new article_scores table (ensure_tables + alembic 012) persists every grade
  with selected/summary_id/model so thresholds can be tuned from data
- SUMMARY_MIN_SCORE (60), SUMMARY_TOP_N (12), SUMMARY_FALLBACK_TOP (3) env knobs
2026-11-13 21:47:30 -05:00

39 lines
1 KiB
Python

"""article_scores: per-article map-phase grades for threshold tuning
Revision ID: 012_article_scores
Revises: 011_geofence_alerts_fence
Create Date: 2026-11-13
"""
from alembic import op
revision = "012_article_scores"
down_revision = "011_geofence_alerts_fence"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.execute(
"""
CREATE TABLE IF NOT EXISTS article_scores (
article_id INTEGER NOT NULL,
summary_id INTEGER,
score INTEGER NOT NULL,
category TEXT,
selected BOOLEAN NOT NULL,
model TEXT,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (article_id, created_at)
)
"""
)
op.execute(
"CREATE INDEX IF NOT EXISTS ix_article_scores_summary "
"ON article_scores (summary_id)"
)
def downgrade() -> None:
op.execute("DROP INDEX IF EXISTS ix_article_scores_summary")
op.execute("DROP TABLE IF EXISTS article_scores")