Skip to content

feat(enrichment): alias-aware scoring — auto-confirm non-Latin-primary artists - #772

Merged
byrongamatos merged 7 commits into
mainfrom
feat/mb-alias-scoring
Jul 4, 2026
Merged

byrongamatos merged 7 commits into
mainfrom
feat/mb-alias-scoring

Conversation

@ChrisBeWithYou

@ChrisBeWithYou ChrisBeWithYou commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Stacks on #771 (base = feat/mb-loose-search-fallback; retarget to main once #771 merges).

Problem

The loose-search fallback (#771) makes a recording stored under a Japanese primary name (大橋純子) findable via its romanized alias. But the scorer still compared the reference ("Junko Ohashi") against the candidate's primary name only → artist similarity 0 → below AUTO_ARTIST_MIN, so these could only ever appear as manual candidates (score ~0.5), never auto-fill on the Refresh pass.

Fix

  • mb_match.cand_artist_sim — best similarity over the candidate's primary name and its artist_aliases (romanized/alternate names). score_candidate and classify both use it, so an alias match clears the per-field artist floor.
  • _mb_artist_aliases(id) — fetches an artist's aliases via /ws/2/artist/{id}?inc=aliases, process-cached (a one-artist discography costs a single request). Raises on transport failure so a pass pauses cleanly (nothing cached on failure).
  • _alias_enrich — attaches aliases only to promising near-misses (title already agrees, primary artist doesn't), bounded by _ALIAS_ENRICH_MAX=3. A normal pass (artist already matches, or no ref artist) spends zero extra requests. Wired into both the auto-matcher (_enrich_one) and the manual search proxy (ranking).

Verified live

search loose-only (#771) + alias scoring
Junko Ohashi / Telephone Number → 大橋純子 score 0.5 (manual only) score 1.0, ranked #1, auto-confirmable
AC/DC / Highway to Hell 1.0 1.0, no alias lookup (unchanged)

Tests

cand_artist_sim uses aliases; an alias lifts a title-matching candidate from non-auto to auto; _mb_artist_aliases fetches + caches (+ rejects a non-UUID id without fetching); and an end-to-end _background_enrich auto-matches a Japanese-primary candidate through the alias.

Note / possible follow-up

The stored canonical artist is MB's primary (大橋純子). If preferring the romanized display is wanted, a small display-precedence tweak (prefer a romanized alias / the pack's own value) can follow — the match + album/year/art/MBID all resolve correctly regardless.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • MusicBrainz matching now recognizes alternate artist names, including romanized and other aliases, improving match quality for multilingual releases.
    • Manual search results are ranked using these alias-aware matches for better candidate suggestions.
  • Bug Fixes

    • Improved auto-detection and review gating for releases where the track title matches but the artist appears under a different spelling or script.
    • Reduced missed matches for recordings with equivalent artist names across languages.

ChrisBeWithYou and others added 2 commits July 4, 2026 15:03
…ists)

The MB text search used a strict field-phrase query
(`recording:"<title>" AND artist:"<artist>"`). A field phrase only matches
MusicBrainz's *primary* artist/title — it never searches ALIASES — so a
recording stored under a non-Latin primary name (大橋純子) whose romanized
form ("Junko Ohashi") is only an alias returns ZERO results, even though MB
has it. Whole swaths of a community library (e.g. romanized J-pop / city-pop
charts) were unsearchable.

- `build_recording_query(..., loose=True)` drops the field scoping + phrases
  for plain AND-ed term groups (`(telephone number) AND (junko ohashi)`),
  which searches the whole document incl. aliases.
- `_mb_search_recordings` runs the strict query first (unchanged, high
  precision) and only on an EMPTY result retries once with the loose query —
  so mainstream matches are untouched and the extra throttled request is spent
  only on a miss. Results are re-scored by rank_candidates, so recall goes up
  without lowering match quality (auto-accept still needs the per-field floors).

Verified live: "Junko Ohashi / Telephone Number" and "Anri / Windy Summer"
(both 0 under the strict query) now surface the real records; "AC/DC /
Highway to Hell" still hits strict at score 1.0 with no loose retry.

Follow-up (separate): alias-aware SCORING so these can auto-confirm, not just
appear as manual candidates.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… artists)

Builds on the loose-search fallback: that surfaces a recording stored under a
Japanese primary name (大橋純子) via its romanized alias, but the SCORER still
compared the reference ("Junko Ohashi") against the primary only → artist
similarity 0 → below the auto floor, so it could only ever be a manual
candidate, never an auto-fill.

- mb_match: `cand_artist_sim` takes the best similarity over the candidate's
  primary name AND its `artist_aliases`; score_candidate + classify use it.
- server: `_mb_artist_aliases(id)` fetches an artist's aliases (one throttled
  lookup, process-cached — a one-artist discography costs ONE request) and
  `_alias_enrich` attaches them ONLY to promising near-misses (title agrees,
  primary artist doesn't) so a normal pass spends zero extra requests. Wired
  into both the auto-matcher (_enrich_one) and the manual search proxy.

Verified live: "Junko Ohashi / Telephone Number" → 大橋純子 candidate goes from
score 0.5 (loose-only) to 1.0 (auto-confirmable), ranked #1; "AC/DC / Highway
to Hell" unchanged at 1.0 with no alias lookup.

Stacks on #771 (feat/mb-loose-search-fallback).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5519ddf7-1fa5-45cf-a635-f7d208376587

📥 Commits

Reviewing files that changed from the base of the PR and between 18c4e22 and c5d8396.

📒 Files selected for processing (4)
  • lib/mb_match.py
  • server.py
  • tests/test_mb_enrichment.py
  • tests/test_mb_match.py

📝 Walkthrough

Walkthrough

Adds alias-aware artist similarity scoring, alias fetching and attachment in MusicBrainz enrichment/search flows, and tests covering alias-based matching and cache behavior.

Changes

Alias-aware artist matching

Layer / File(s) Summary
Alias-aware similarity and enrichment wiring
lib/mb_match.py, server.py
Adds cand_artist_sim to compare a reference artist against a candidate’s primary name and aliases, updates scoring/classification to use it, and wires cached MusicBrainz alias lookup plus selective alias attachment into enrichment and manual search ranking.
Alias scoring and enrichment tests
tests/test_mb_enrichment.py, tests/test_mb_match.py
Adds tests for alias fetch caching, UUID rejection, alias-driven enrichment matching, and alias-aware similarity/classification behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mb-alias-scoring

Comment @coderabbitai help to get the list of available commands.

…fallback

# Conflicts:
#	lib/mb_match.py
#	server.py
…nto feat/mb-alias-scoring

# Conflicts:
#	server.py
@byrongamatos

Copy link
Copy Markdown
Contributor

Review + fix pass (Claude Code) — stacked on #771. Logic is correct: cand_artist_sim maxes over primary + aliases (early-break at 1.0); _mb_artist_aliases is process-cached, UUID-guarded, and raises on a network failure so nothing is cached on failure (verified _mb_http_get raises for network-shaped errors, returns None only on 404); _alias_enrich only enriches title-matching / primary-artist-missing near-misses, bounded to _ALIAS_ENRICH_MAX; and the auto-matcher's propagated EnrichTransportError rides the existing try/except → break around _enrich_one (pauses the pass cleanly), while the manual search swallows it as a nicety.

Fixed (integration): synced the updated #771 base (which now carries merged #758 + #764) and resolved the server.py conflicts — routing _enrich_one's search/enrich/rank through ref instead of row so alias scoring also uses #764's filename-artist seed, and keeping #758's duration corroboration in the manual search. 60 mb tests green. Still needs a retarget to main once #771 lands (as your PR body notes). (Codex second-opinion rate-limited — manual + test-backed.)

byrongamatos and others added 3 commits July 5, 2026 01:04
The loose fallback dropped the strict path's -secondarytype:Live filter, so a
studio chart whose strict query missed could fall back to — and, since
score_candidate doesn't penalize live takes, auto-confirm — a live-only
recording. Apply the same live gate to the loose query (skipped only when the
source title is itself a live take).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
# Conflicts:
#	tests/test_mb_enrichment.py
#	tests/test_mb_match.py
@byrongamatos
byrongamatos changed the base branch from feat/mb-loose-search-fallback to main July 4, 2026 23:11
@byrongamatos
byrongamatos merged commit 74cff4e into main Jul 4, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants