Conversation
📝 WalkthroughWalkthroughAdds the ChangesBM25 tool ranking
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
src/services/tools/Bm25Ranker.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. src/services/tools/__tests__/Bm25Ranker.spec.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. src/services/tools/types.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/services/tools/Bm25Ranker.ts`:
- Around line 88-90: Update the tokenize function to treat underscores as
separators alongside the existing non-word delimiters, so underscore-separated
tool names produce individual terms. Add a regression test covering matching an
underscore-separated name such as create_issue against separate query terms.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 92e64eac-ea6c-4124-88e9-9ff7e5e059ce
📒 Files selected for processing (3)
src/services/tools/Bm25Ranker.tssrc/services/tools/__tests__/Bm25Ranker.spec.tssrc/services/tools/types.ts
| function tokenize(value: string): string[] { | ||
| return value.toLowerCase().split(/\W+/).filter(Boolean) | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
node - <<'NODE'
console.log("create_issue".split(/\W+/).filter(Boolean))
console.log("create issue".split(/\W+/).filter(Boolean))
NODERepository: Zoo-Code-Org/Zoo-Code
Length of output: 200
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
# Locate the ranker implementation and inspect its surrounding code.
fd -a 'Bm25Ranker\.ts$' . | sed 's#^\./##'
echo '--- outline ---'
ast-grep outline src/services/tools/Bm25Ranker.ts --view expanded || true
echo '--- relevant file excerpt ---'
sed -n '1,140p' src/services/tools/Bm25Ranker.ts
echo '--- tests mentioning Bm25Ranker/tokenize ---'
rg -n "Bm25Ranker|tokenize|build.*Index|rank\\(" src -g '*.ts' -g '*.tsx' | head -200Repository: Zoo-Code-Org/Zoo-Code
Length of output: 6696
🏁 Script executed:
#!/usr/bin/env bash
set -euo pipefail
echo '--- Bm25Ranker spec excerpt ---'
sed -n '1,110p' src/services/tools/__tests__/Bm25Ranker.spec.tsRepository: Zoo-Code-Org/Zoo-Code
Length of output: 2736
Split underscore-separated tool names into terms.
The ranked content uses the same tokenize() helper, but \W treats _ as part of a word. A tool named create_issue indexes under create_issue, while the query create issue only produces create and issue, so it cannot match that name. Include _ in the separator expression and add a regression test for an underscore-separated tool name.
Proposed fix
function tokenize(value: string): string[] {
- return value.toLowerCase().split(/\W+/).filter(Boolean)
+ return value.toLowerCase().split(/[\W_]+/).filter(Boolean)
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function tokenize(value: string): string[] { | |
| return value.toLowerCase().split(/\W+/).filter(Boolean) | |
| } | |
| function tokenize(value: string): string[] { | |
| return value.toLowerCase().split(/[\W_]+/).filter(Boolean) | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/services/tools/Bm25Ranker.ts` around lines 88 - 90, Update the tokenize
function to treat underscores as separators alongside the existing non-word
delimiters, so underscore-separated tool names produce individual terms. Add a
regression test covering matching an underscore-separated name such as
create_issue against separate query terms.
Related GitHub Issue
Relates to #575
Description
Adds a dependency-free, pure-JavaScript BM25 ranker as the always-available baseline for MCP tool search. This PR is limited to the foundational ranker described in issue #575; it does not implement downstream routing or threshold-gating work.
Implementation
ToolDoctype withserverName,toolName, anddescriptionfields.Rankerinterface withrank(query, items, k)returning the top-rankedToolDocresults.k1 = 1.5andb = 0.75, with no external npm dependencies.rank()call and rebuilds it only when the input array reference changes.k, empty descriptions, and stable input ordering for equal scores.Tests and Validation
ktruncation, stable tie ordering, case-insensitive punctuation-aware tokenization, empty descriptions, and reference-based index rebuilding.cd src && npx vitest run services/tools/__tests__/Bm25Ranker.spec.tsSummary by CodeRabbit
New Features
Bug Fixes