chrysopedia/backend/pipeline/highlight_schemas.py
jlightner 289e707799 feat: Added HighlightCandidate ORM model, Alembic migration 019, and Py…
- "backend/models.py"
- "alembic/versions/019_add_highlight_candidates.py"
- "backend/pipeline/highlight_schemas.py"

GSD-Task: S04/T01
2026-04-04 05:30:36 +00:00

51 lines
2.1 KiB
Python

"""Pydantic schemas for highlight detection pipeline.
Covers scoring breakdown, candidate responses, and batch result summaries.
"""
from __future__ import annotations
import uuid
from datetime import datetime
from pydantic import BaseModel, Field
class HighlightScoreBreakdown(BaseModel):
"""Per-dimension score breakdown for a highlight candidate.
Each field is a float in [0, 1] representing the normalized score
for that scoring dimension.
"""
duration_score: float = Field(description="Score based on moment duration (sweet-spot curve)")
content_density_score: float = Field(description="Score based on transcript richness / word density")
technique_relevance_score: float = Field(description="Score based on content_type and plugin mentions")
position_score: float = Field(description="Score based on temporal position within the video")
uniqueness_score: float = Field(description="Score based on title/topic distinctness among siblings")
engagement_proxy_score: float = Field(description="Proxy engagement signal from summary quality/length")
plugin_diversity_score: float = Field(description="Score based on breadth of plugins/tools mentioned")
class HighlightCandidateResponse(BaseModel):
"""API response schema for a single highlight candidate."""
id: uuid.UUID
key_moment_id: uuid.UUID
source_video_id: uuid.UUID
score: float = Field(ge=0.0, le=1.0, description="Composite highlight score")
score_breakdown: HighlightScoreBreakdown
duration_secs: float = Field(ge=0.0, description="Duration of the key moment in seconds")
status: str = Field(description="One of: candidate, approved, rejected")
created_at: datetime
model_config = {"from_attributes": True}
class HighlightBatchResult(BaseModel):
"""Summary of a highlight scoring batch run for one video."""
video_id: uuid.UUID
candidates_created: int = Field(ge=0, description="Number of new candidates inserted")
candidates_updated: int = Field(ge=0, description="Number of existing candidates re-scored")
top_score: float = Field(ge=0.0, le=1.0, description="Highest score in this batch")