369e3de684
Video tag noise root cause: frames were a FIXED count (6) max-pooled — a tag firing on one frame survived at peak confidence, and a fixed count under-samples long multi-scene videos so real scene-local tags looked like noise. Redesign (operator-steered): - Sample at a fixed CADENCE — one frame every `video_frame_interval_seconds` (default 4) across the 5–95% window — so a tag's frame-presence reflects real screen time independent of video length. Capped at `video_max_frames` (default 64): a long video stretches the spacing instead of exploding into hundreds of inferences, bounding per-video cost on the single ml-worker (per-frame ffmpeg timeout also cut 60s→30s). - Aggregate with `_aggregate_video_predictions`: keep a tag only if it appears in >= `video_min_tag_frames` sampled frames (≈ that many × interval seconds on screen — duration-independent noise rejection), with confidence = MEAN over the frames it appears in (not max). Clamps the threshold to the sample count so a 1–2-frame short video still tags. - All three knobs are DB-backed ml_settings (migration 0053), patchable via /api/ml/settings + sliders in the ML settings card — replaces the VIDEO_ML_FRAMES env var (product-not-project). Tests: aggregation drops one-frame noise + means corroborated tags + clamps on short videos; settings round-trip + min>max validation. Replaced the _maxpool_predictions unit test. NOTE: this is the QUALITY half of #747. The perf half — the ml-worker runs CPU-only — is GPU enablement, tracked separately in #872. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
67 lines
3.0 KiB
Python
67 lines
3.0 KiB
Python
"""MLSettings — single-row table holding ML pipeline tunables."""
|
||
|
||
from datetime import datetime
|
||
|
||
from sqlalchemy import CheckConstraint, DateTime, Float, Integer, String, func
|
||
from sqlalchemy.orm import Mapped, mapped_column
|
||
|
||
from .base import Base
|
||
|
||
|
||
class MLSettings(Base):
|
||
__tablename__ = "ml_settings"
|
||
# Bare name — Base.metadata's naming convention prepends ck_<table>_,
|
||
# producing the final ck_ml_settings_singleton (matches migration 0003).
|
||
__table_args__ = (CheckConstraint("id = 1", name="singleton"),)
|
||
|
||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||
suggestion_threshold_character: Mapped[float] = mapped_column(
|
||
Float, nullable=False, default=0.70
|
||
)
|
||
# Default raised 0.50 → 0.70 on 2026-06-02 — operator-flagged 0.50
|
||
# surfaced too many low-confidence picks; 0.70 keeps the rail
|
||
# signal-rich while still surfacing more than the original 0.95
|
||
# which hid almost everything. Operator-tunable via Settings → ML.
|
||
suggestion_threshold_general: Mapped[float] = mapped_column(
|
||
Float, nullable=False, default=0.70
|
||
)
|
||
centroid_similarity_threshold: Mapped[float] = mapped_column(
|
||
Float, nullable=False, default=0.55
|
||
)
|
||
# Ingest floor: tagger predictions below this confidence are not stored
|
||
# (tagger.Tagger.infer). Default 0.70 — the suggestion path already
|
||
# filters at 0.70 and the centroid/learned path covers low-confidence
|
||
# preferred tags, so the sub-0.70 tail is redundant weight (it had
|
||
# bloated image_record's TOAST to ~100 GB; plan-task #764). Operator-
|
||
# tunable via Settings → ML; must stay ≤ the suggestion thresholds.
|
||
tagger_store_floor: Mapped[float] = mapped_column(
|
||
Float, nullable=False, default=0.70
|
||
)
|
||
min_reference_images: Mapped[int] = mapped_column(
|
||
Integer, nullable=False, default=5
|
||
)
|
||
# Video tagging (#747). Sample one frame every N seconds (fixed CADENCE, not a
|
||
# fixed count) so a tag's frame-presence reflects real screen time regardless
|
||
# of video length; cap the total so a long video can't explode into hundreds
|
||
# of inferences (the cadence stretches past the cap). A tag is kept only if it
|
||
# appears in >= video_min_tag_frames sampled frames (≈ that many × interval
|
||
# seconds on screen) — duration-independent noise rejection. Operator-tunable.
|
||
video_frame_interval_seconds: Mapped[float] = mapped_column(
|
||
Float, nullable=False, default=4.0
|
||
)
|
||
video_max_frames: Mapped[int] = mapped_column(
|
||
Integer, nullable=False, default=64
|
||
)
|
||
video_min_tag_frames: Mapped[int] = mapped_column(
|
||
Integer, nullable=False, default=3
|
||
)
|
||
tagger_model_version: Mapped[str] = mapped_column(
|
||
String(128), nullable=False, default="camie-tagger-v2"
|
||
)
|
||
embedder_model_version: Mapped[str] = mapped_column(
|
||
String(128), nullable=False, default="siglip-so400m-patch14-384"
|
||
)
|
||
updated_at: Mapped[datetime] = mapped_column(
|
||
DateTime(timezone=True), nullable=False, server_default=func.now()
|
||
)
|