3f92669f12
Promotes the prediction store-floor from the TAGGER_STORE_FLOOR env (default 0.05) to a DB-backed, Settings-UI-tunable ml_settings column (default 0.70). Storing every tag down to 0.05 from a ~10k-tag tagger is what grew image_record's TOAST to ~100 GB; the suggestion path already filters at 0.70 and the centroid/learned path covers lower-confidence preferred tags, so the sub-0.70 tail is redundant. Foundation for plan-task #764 (backfill + reclaim land next; this only changes the write gate for NEW imports). - ml_settings.tagger_store_floor (migration 0044, default 0.70) - tagger.Tagger.infer(store_floor=...); ml task passes settings.tagger_store_floor - ML admin GET/PATCH expose it; PATCH rejects a category suggestion threshold below the floor (nothing below the floor is stored, so the gap surfaces nothing) — server backstop for the UI slider clamp - Settings → ML: store-floor slider + caption; category sliders min-bound to it Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
52 lines
2.2 KiB
Python
52 lines
2.2 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
|
|
)
|
|
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()
|
|
)
|