Skip to content

feat(tools): Improve tool search ranking with stemming, synonyms, and a ranking test - #2898

Merged
dcramer merged 5 commits into
mainfrom
feat/tool-search-ranking-cases
Nov 7, 2026
Merged

dcramer merged 5 commits into
mainfrom
feat/tool-search-ranking-cases

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Part of #2893: adds the ranking test from recommendation 6, plus ranking fixes.

Ranking test. tool-search-ranking.test.ts builds the real catalog: core tools plus the GitHub and memory plugins, through createApp and createPiAgentTools. 31 queries must rank the fitting tool first, and 2 queries with no fitting tool must return nothing. The queries are written from the tool descriptions. Each test compares its whole table, so one failure shows every query that regressed.

Ranking fixes:

  • The stemmer now also removes -ed, -ing, and a final e, on both the query and the tool text. Before this, "closing a pull request" ranked getPullRequest first and "closing an issue" ranked createIssue first, because the update tools say "closed".
  • Tool descriptions get a weaker BM25 length penalty (b = 0.3; the other fields keep 0.75). Long descriptions add usage guidance, not topics. Before this, "remember something" ranked listMemories above createMemory only because the createMemory description is long.
  • Common action words now match their synonyms: fetch/get, edit/update, reply/comment, unsubscribe/stop, and similar. A word and its synonyms share one document frequency: the count of tools that contain any of the words. If each synonym had its own, a rare synonym such as "read" would outscore a common exact word such as "get". A synonym match scores 0.6 of an exact match. The weight applies after BM25 saturation, because field weights make most matches saturate. The words are generic English, so they apply to MCP tools too.
  • Queries expand pr, repo, and msg. Tool text is not expanded, because most GitHub tools have a repo parameter.

The test fails on main and passes with this change. The related search, adapter, and Code Mode tests pass.

Known gaps:

  • Queries that no tool fits can still return weak matches, for example "create repository" → createIssue. A cutoff on the share of the query that a tool matches did not help. Any threshold that dropped the weak matches also dropped correct ones.
  • "what do you remember" now ranks createMemory above listMemories. Stop words reduce it to "remember", so either tool can be right.

Refs #2893

via @dcramer.

--

View Session [Sentry]

@vercel

vercel Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 7, 2026 7:35pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 7, 2026
@sentry-junior sentry-junior Bot changed the title fix(tools): Fold verb endings and soften description length in tool search feat(tools): Improve tool search ranking with stemming, synonyms, and a ranking test Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

8 screenshot changes — 8 changed · 0 added · 0 removed

Review screenshots in Frameshift

Conversation Attachment · Desktop
Conversation Attachment · Desktop
Changed
Conversation Captured Memories Popover · Desktop
Conversation Captured Memories Popover · Desktop
Changed
Conversation Details Watched Linked Work · Desktop
Conversation Details Watched Linked Work · Desktop
Changed
Conversation Details Watched Linked Work · Mobile
Conversation Details Watched Linked Work · Mobile
Changed
Conversation Event Log Virtual · Desktop
Conversation Event Log Virtual · Desktop
Changed
Conversation Long Transcript Touch · Mobile
Conversation Long Transcript Touch · Mobile
Changed
Show 2 more changed screenshots
Conversation Stop Active · Mobile
Conversation Stop Active · Mobile
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

sentry-junior Bot and others added 3 commits November 7, 2026 19:17
…earch

Fold -ed, -ing, and a final e so "closing" matches "closed". Use a
weaker BM25 length penalty on tool descriptions, because long
descriptions add usage guidance, not topics.

Add a ranking test over the real catalog of core tools plus the GitHub
and memory plugins.

Refs #2893

Co-Authored-By: David Cramer <[email protected]>
Treat common action words such as fetch/get, edit/update, and
reply/comment as one BM25 term with a 0.6 weight for the synonym, as
Lucene's SynonymQuery does. Expand pr, repo, and msg in queries.

Refs #2893

Co-Authored-By: David Cramer <[email protected]>
Field weights make most term frequencies saturate, so a weight applied
to term frequency gave a synonym match the same score as an exact
match. "add a comment to an issue" nearly tied commentOnIssue with
createIssue (add -> create), and the catalog on main flipped it.

Refs #2893
@sentry-junior
sentry-junior Bot force-pushed the feat/tool-search-ranking-cases branch from 5d85321 to d4677d2 Compare November 7, 2026 19:22
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: medium PR risk score: medium labels Nov 7, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d4677d2. Configure here.

…ch ranking

A description such as "For issues, use github_commentOnIssue" made
github_commentOnPullRequest match issue queries. Ranking now skips
description sentences that name another catalog tool.
Stemming folds the noun "files" onto the verb "file", so file queries
expanded to create, add, and write.
@dcramer
dcramer merged commit 3dcf111 into main Nov 7, 2026
45 checks passed
@dcramer
dcramer deleted the feat/tool-search-ranking-cases branch November 7, 2026 19:44
dcramer added a commit that referenced this pull request Nov 7, 2026
…ol fits (#2903)

Next step on #2893, after #2898.

**Action and object from tool names.** `searchTools` splits each tool
name (camelCase or snake_case, without the source prefix) into an action
word and object words: `commentOnIssue` and `create_issue` give
"comment"/"create" and "issue". When the query matches the action
(synonyms count) and the object, the score goes up by as much as 2x.
This works for any plugin or MCP tool, and plugins don't need to add
anything.

**No guess when nothing fits.** If one tool has the query's action and
another has its object, but no tool has both, search returns no tools
and a `note`. "create repository" used to return `createIssue`. Any
empty search now has the note.

**Crowded ranking test.** It adds a fake `tracker` plugin with
`create_issue`, `get_issue` and `comment_on_issue`, set up through the
real plugin wiring. The new cases check:
- with `source`, the right plugin's tool ranks first
- without `source`, a provider name in the query picks the tool
- without either, the GitHub and Tracker tools tie for the top 2

The two-step source selection planned next should fix that last case.

| Query | Before | After |
| --- | --- | --- |
| "create repository" (github) | `createIssue` | nothing + note |
| "create repository" (any source) | `createIssue`,
`tracker_create_issue`, … | nothing + note |
| "edit a memory" (any source) | `createMemory` | nothing + note |
| "get pull request diff" (github) | `submitPullRequestReview` |
`getPullRequest` |

All new cases come from tool descriptions.

<!-- junior-request-attribution:start -->
via @dcramer.
<!-- junior-request-attribution:end -->

<!-- junior-session-footer:start -->
<!-- junior-conversation-id:agent%3Ac153e1c8612191d35fbd9fa76faa8da2 -->

--

[View
Session](https://junior-prod.sentry.dev/conversations/agent%3Ac153e1c8612191d35fbd9fa76faa8da2)
[[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3Ac153e1c8612191d35fbd9fa76faa8da2/?project=4510944073809921)

<!-- junior-session-footer:end -->

Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Co-authored-by: David Cramer <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – junior-docs — eceee021 Deployed Nov 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant