Skip to content

fix: use exact tag matching for model gallery tag filtering#9041

Open
majiayu000 wants to merge 1 commit intomudler:masterfrom
majiayu000:fix/issue-8775-exact-tag-filtering
Open

fix: use exact tag matching for model gallery tag filtering#9041
majiayu000 wants to merge 1 commit intomudler:masterfrom
majiayu000:fix/issue-8775-exact-tag-filtering

Conversation

@majiayu000
Copy link
Contributor

Fixes #8775

Problem

When browsing the model gallery by tag (e.g. clicking "ASR"), unrelated models are returned. The root cause is in core/gallery/gallery.go where Search() joins all tags into a single comma-separated string and uses strings.Contains() for matching. This means searching for "asr" matches any model whose joined tag string contains that substring — for example, "image-diffusers" matches because the joined string contains "asr" as a substring.

Fix

  1. core/gallery/gallery.go — Added FilterByTag() method that does exact case-insensitive comparison (strings.EqualFold) against individual tags instead of substring matching on a joined string.

  2. core/http/routes/ui_api.go — Added tag query parameter to GET /api/models and GET /api/backends. When tag is provided, FilterByTag() is used for exact matching. The existing term parameter continues to work as before for fuzzy text search.

  3. core/http/react-ui/src/pages/Models.jsx — Filter button clicks now send ?tag= instead of ?term=, so tag selections use exact matching while the search box continues to use fuzzy search.

  4. core/gallery/gallery_test.go — Added tests for FilterByTag() covering exact match, case insensitivity, substring non-match (key regression: model with tag "image-diffusers" must NOT match filter "asr"), empty results, and multiple matches.

The Search() method uses strings.Contains() on comma-joined tags,
causing substring false positives (e.g., "asr" matching "image-diffusers").

Add FilterByTag() method that checks each tag with strings.EqualFold()
for exact, case-insensitive matching. Add 'tag' query parameter to
/api/models and /api/backends endpoints. Update the React frontend to
send filter selections as 'tag' instead of 'term'.

Closes mudler#8775

Signed-off-by: majiayu000 <1835304752@qq.com>
@netlify
Copy link

netlify bot commented Mar 17, 2026

Deploy Preview for localai ready!

Name Link
🔨 Latest commit 2117f80
🔍 Latest deploy log https://app.netlify.com/projects/localai/deploys/69b90e654c28290008fce304
😎 Deploy Preview https://deploy-preview-9041--localai.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@majiayu000 majiayu000 marked this pull request as ready for review March 17, 2026 08:29
Copy link
Owner

@mudler mudler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good, thanks!

@mudler
Copy link
Owner

mudler commented Mar 18, 2026

rebase is needed @majiayu000

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.

Search by a specific tag in the model gallery returns unrelated models without the specified tag

2 participants