fix(cli): stop rendering raw FTS score as nonsensical percentages in query (#1045) (#1052)

`codegraph query` printed `(score * 100)%` next to each hit, but `score`
is an unbounded BM25/FTS relevance magnitude (relative-ranking only), so
it rendered as values like "12042%" that made the output look broken.

Results already arrive in rank order, so drop the score from the
human-readable output entirely — matching the MCP search tool, which
shows no score. The raw `score` stays in `--json` for programmatic
sorting/thresholding. Also corrects the SearchResult.score doc comment,
which wrongly claimed a 0-1 range. Adds an end-to-end regression test.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Colby Mchenry
2026-06-28 22:01:47 -05:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 0d331b9017
commit 4b58a6d2d0
4 changed files with 78 additions and 4 deletions
+6 -3
View File
@@ -964,15 +964,18 @@ program
} else {
console.log(chalk.bold(`\nSearch Results for "${search}":\n`));
// Results arrive already ranked by relevance, so the order conveys
// it. We don't print the raw score: it's an unbounded BM25/FTS value
// (relative-ranking only), and the old `(score * 100)%` rendered it
// as nonsensical percentages like "12042%" (#1045). The MCP search
// tool likewise shows no score. Raw `score` stays in --json output.
for (const result of results) {
const node = result.node;
const location = `${node.filePath}:${node.startLine}`;
const score = chalk.dim(`(${(result.score * 100).toFixed(0)}%)`);
console.log(
chalk.cyan(node.kind.padEnd(12)) +
chalk.white(node.name) +
' ' + score
chalk.white(node.name)
);
console.log(chalk.dim(` ${location}`));
if (node.signature) {
+6 -1
View File
@@ -398,7 +398,12 @@ export interface SearchResult {
/** Matching node */
node: Node;
/** Relevance score (0-1) */
/**
* Relevance score for relative ranking only — higher is more relevant.
* NOT normalized and NOT a 0-1 fraction: the FTS path returns an unbounded
* BM25 magnitude (often in the tens or hundreds), while the fuzzy/exact
* paths return ~0-1. Use it to order results, not as an absolute percentage.
*/
score: number;
/** Matched text snippets for highlighting */