codebase-memory-mcp icon indicating copy to clipboard operation
codebase-memory-mcp copied to clipboard

search_graph BM25: label filter applies after the FTS5 candidate window

Open DeusData opened this issue 2 months ago • 4 comments

The label filter on the BM25 path is applied after the 2000-row FTS5 candidate window (BM25_INNER_LIMIT, src/mcp/mcp.c ~3778; inner query ~4073), not inside candidate selection.

Effect: when a query token is common but the requested label is rare among its matches, the matching rows of that label can fall outside the window. The response then reports total_relation: gte / candidate_window_saturated, but can contain 0 rows, even though matching nodes exist.

Possible fix: filter on the label column of nodes_fts inside the FTS MATCH itself (or pre-select candidates per label), so the window is filled with rows of the requested label only.

Test: index a fixture where one token matches more than 2000 nodes of one label and a few of another; query with the rare label and assert those rows come back.

Found while reconciling #2159 / #2148 (fixed in 1a342553).

DeusData avatar Sep 27 '26 22:09 DeusData

Hi, I've opened #2423 for this.

The label now goes into the FTS5 MATCH itself ((<tokens>) AND label : "<Label>"), so the 2000 row candidate window only fills with rows of the requested label. The existing n.label = ? check stays as the exact filter, and the count query and saturation probe use the same match string, so total and candidate_window_saturated describe the filtered window.

Two regression tests are included, one of which reproduces the issue (2001 Functions crowding out 3 Classes, which returns 0 rows on current main). Full suite and lint-ci pass locally. The PR description has details on a small ranking safeguard.

Happy to adjust anything.

harshitaajoshi avatar Sep 28 '26 20:09 harshitaajoshi

Thank you for opening #2423 and for the rare-label crowding regression. The count and saturation semantics are useful parts of the proposed change, alongside the returned rows. I have no new verified review or landing status to report in this issue.

DeusData avatar Oct 19 '26 22:10 DeusData

Thank you for your patience and the filtered-window regression in #2423. Count/saturation behavior remains part of the maintainer review. Sorry for the delay; I’ll follow up soon.

DeusData avatar Oct 25 '26 17:10 DeusData

Fixed by #2423 (merge commit b956413eb49b): the label filter now selects the BM25 candidate window instead of trimming it, so a label that is rare among a common token's matches is returned in full, and total / candidate_window_saturated describe the label-scoped window. Thank you @harshitaajoshi for the fix and the regression test.

DeusData avatar Oct 28 '26 01:10 DeusData