fix(search): score symbols on the query's identifier, not the whole question#853
Merged
Merged
Conversation
…uestion
A hybrid query is prose wrapped around an identifier ("where is X defined").
Both symbol and hybrid mode handed the raw query to `search_symbols_single`,
but that scorer ranks on token overlap, so the question's prose tokens
compete as if they were symbol names.
Live, on this repo:
search_codebase("filter_dicts_by_key")
-> mode=symbol, exact_match=true, `_helpers.py::filter_dicts_by_key` at rank 1
search_codebase("where is filter_dicts_by_key defined")
-> mode=hybrid, exact_match=false, and the note
"No indexed symbol exactly matches 'filter_dicts_by_key'"
The claim is false: the symbol is indexed at `_helpers.py:532`. What ranked
instead was `is_ci` (matching the token "is") and `FilterRegistry.get`
(matching "filter"). The real symbol never entered the result window, so
`_has_exact_symbol` saw no match and the response asserted the symbol was
absent from the index.
That is the worst shape of wrong: the tool is most confident exactly where it
is wrong, and an agent that believes it stops looking for a symbol that is
right there.
`_identifier_candidates` already extracted the identifier at the call site
below, but only to compute the `exact` flag; it never reached the search.
This scores symbols on the extracted identifiers when the query is hybrid,
and leaves symbol mode (already a bare identifier) and identifier-free
queries on the raw text.
The test asserts the query the scorer receives rather than the resulting
ranking: a fixture small enough to unit-test carries no decoys for the
identifier to lose to, so an end-to-end assertion passes against the bug.
Verified to fail without the change and pass with it.
|
✅ Health: 7.6 (unchanged) 📋 At a glance Files & modules (2)
🩹 Review priority (files here with the most recent bug-fix history — defects cluster, so review these first)
🔎 More signals (2)🔥 Hotspots touched (2)
🔗 Hidden coupling (1 file)
📊 Full report · ⭐ Star Repowise · 📥 Install bot · Last updated 2026-07-15 15:52 UTC |
RaghavChamadiya
approved these changes
Jul 15, 2026
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.
The bug
A hybrid query is prose wrapped around an identifier ("where is X defined").
Both symbol and hybrid mode handed the raw query to
search_symbols_single,but that scorer ranks on token overlap, so the question's prose tokens compete
as if they were symbol names.
Live, on this repo:
The claim is false. The symbol is indexed at
_helpers.py:532. What rankedinstead was
is_ci(matching the token "is") andFilterRegistry.get(matching "filter"). The real symbol never entered the result window, so
_has_exact_symbolsaw no match among the returned symbols and the responseasserted the symbol was absent from the index.
That is the worst shape of wrong: the tool is most confident exactly where it
is wrong, and an agent that believes "this symbol is not indexed" stops looking
for something that is right there.
The fix
_identifier_candidatesalready extracted the identifier at the call sitebelow, but only to compute the
exactflag; it never reached the search. Thisscores symbols on the extracted identifiers when the query is hybrid, and
leaves symbol mode (already a bare identifier) and identifier-free queries on
the raw text.
Testing
tests/unit/server/mcp/test_search.py: 42 passed.The new test asserts the query the scorer receives rather than the resulting
ranking. A fixture small enough to unit-test carries no decoys for the
identifier to lose to, so an end-to-end assertion on rank passes against the
bug. Verified to fail without the change (
symbol scorer got prose, not the identifier: ['where is AuthService defined']) and pass with it.