feat(suggestions): user-managed blocklist for noisy auto-tags

Adds a tag_suggestion_blocklist table + service-layer filter so the
user can permanently suppress specific canonical tag names from the
suggestion stream (WD14 anatomy/composition tags like '1girl',
'breasts', 'nipples' that aren't useful for the discoverability use
case this app targets).

Data model
  - migration k26042201: tag_suggestion_blocklist(name TEXT PK, created_at)
  - model TagSuggestionBlocklistEntry

Service
  - tag_suggestions._blocklisted_names() snapshots the current set
  - get_suggestions filters merged results before grouping, so both
    WD14- and embedding-sourced suggestions respect the blocklist
  - get_bulk_suggestions inherits the filter via its per-image call
    to get_suggestions

API
  - GET  /api/suggestions/blocklist           -> {ok, names}
  - POST /api/suggestions/blocklist           -> add one
  - POST /api/suggestions/blocklist/delete    -> remove one
  - POST /api/suggestions/blocklist/bulk      -> replace the whole list
    (backs the settings textarea save button)

UI
  - modal suggestion chip gets a third action button (⊘) alongside
    accept (✓) / reject (✕). Clicking it adds the name to the
    blocklist, logs a rejection for ML feedback on this image, and
    sweeps every chip on the page carrying that same name.
  - Settings -> Maintenance -> Suggestion blocklist section with a
    monospaced textarea (one name per line) + Save. Loads current
    entries on mount.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-23 08:41:44 -04:00
parent 3f11dcdc6c
commit a510665a17
7 changed files with 269 additions and 0 deletions
+16
View File
@@ -102,6 +102,14 @@ def _existing_tag_names() -> set[str]:
return {row[0] for row in db.session.query(Tag.name).all()}
def _blocklisted_names() -> set[str]:
"""User-managed set of canonical names that must never be surfaced as
suggestions. Stored in tag_suggestion_blocklist; matched exactly against
the post-canonicalization suggestion name."""
from app.models import TagSuggestionBlocklistEntry
return {row[0] for row in db.session.query(TagSuggestionBlocklistEntry.name).all()}
def _wd14_suggestions(image_id: int, cfg: dict, already: set[str]) -> list[dict]:
@@ -227,6 +235,14 @@ def get_suggestions(
_embedding_tag_suggestions(image_id, cfg, already),
)
# Drop any name the user has blocklisted (e.g. anatomy/composition noise
# from WD14 like '1girl', 'breasts'). Applied after merge so it hides
# the suggestion regardless of whether WD14 or embedding-similarity
# surfaced it.
blocklist = _blocklisted_names()
if blocklist:
merged = [s for s in merged if s['name'] not in blocklist]
if existing_all is None:
existing_all = _existing_tag_names()