fix(search): return matches when the tool catalog is small#202
Merged
Conversation
Tool search ranked results with TF-IDF, which scores a term at zero when it appears in every tool (log(N/N) = 0). In small catalogs — a single-integration deployment, or an org whose policy narrows the visible tools down to a handful — every query term is effectively universal, so every candidate scored zero and was filtered out. Search returned nothing even when the query clearly matched a tool. Smooth the IDF weight (log(N/df) + 1) so a matched term always contributes a positive score while keeping the existing relative ranking (rarer terms still outrank common ones). Adds unit coverage for the single-tool and shared-word cases plus an end-to-end search test that asserts a small catalog surfaces its matching tools. 💘 Generated with Crush Assisted-by: Crush:claude-opus-4-8
acmacalister
approved these changes
Jul 10, 2026
acmacalister
left a comment
Collaborator
There was a problem hiding this comment.
Clean PR — CI/status checks are passing and I didn't find any blocking issues. LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Tool search ranks candidates with TF-IDF. Plain IDF (
log(N/df)) is zero for any term that appears in every tool —log(N/N) = 0. In a small catalog every query term is effectively universal, so all candidates score zero, get filtered by thescore > 0cut, and search returns nothing even when the query obviously matches a tool.This bites two real deployments:
Fix
Smooth the IDF weight to
log(N/df) + 1. A matched term now always contributes a positive floor, so a matching tool is never dropped. The+1is a constant shift, so relative ranking is unchanged — a rarer term still outranks a common one.Tests
computeIDFkeeps universal words positive (single-tool corpus, word shared by all tools).handleSearchon a one-tool and a two-tool catalog returns the matching tools. Both new tests were confirmed to fail on the old formula and pass with the fix../serversuite + race detector +golangci-lintclean.💘 Generated with Crush