Skip to content

fix(search): return matches when the tool catalog is small#202

Merged
daltoniam merged 1 commit into
mainfrom
fix/search-idf-zero-floor
Jul 10, 2026
Merged

fix(search): return matches when the tool catalog is small#202
daltoniam merged 1 commit into
mainfrom
fix/search-idf-zero-floor

Conversation

@daltoniam

Copy link
Copy Markdown
Owner

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 the score > 0 cut, and search returns nothing even when the query obviously matches a tool.

This bites two real deployments:

  • a gateway configured with a single integration (or a handful of tools), and
  • a multi-tenant host whose per-user policy narrows the visible catalog down to a few tools.

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 +1 is a constant shift, so relative ranking is unchanged — a rarer term still outranks a common one.

Tests

  • Unit: computeIDF keeps universal words positive (single-tool corpus, word shared by all tools).
  • End-to-end: handleSearch on 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.
  • Full ./server suite + race detector + golangci-lint clean.

💘 Generated with Crush

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 acmacalister left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Clean PR — CI/status checks are passing and I didn't find any blocking issues. LGTM.

@daltoniam daltoniam merged commit 33e08fb into main Jul 10, 2026
5 checks passed
@daltoniam daltoniam deleted the fix/search-idf-zero-floor branch July 10, 2026 00:30
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