From 19374f2d340df14c0273b1381c1ad2390b0157d9 Mon Sep 17 00:00:00 2001 From: harshitaajoshi Date: Mon, 28 Sep 2026 15:02:38 -0500 Subject: [PATCH 1/2] fix(mcp): apply search_graph label filter inside the BM25 candidate window (#2386) Signed-off-by: harshitaajoshi --- src/mcp/mcp.c | 68 ++++++++++++++++++--- tests/test_mcp.c | 150 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 211 insertions(+), 7 deletions(-) diff --git a/src/mcp/mcp.c b/src/mcp/mcp.c index 03741e23a7..60cef53340 100644 --- a/src/mcp/mcp.c +++ b/src/mcp/mcp.c @@ -3969,6 +3969,7 @@ enum { BM25_BIND_EXACT = 8, BM25_BIND_KIND = 9, BM25_BIND_NS = 10, + BM25_BIND_LABEL_WEIGHT = 11, BM25_SQL_AUTO_LEN = -1, /* Inner FTS5 candidate cap. SQLite can early-terminate a plain FTS5 query * (no JOIN/WHERE on outer table) of the form: @@ -3977,6 +3978,11 @@ enum { * and then joining/filtering/re-ranking those, we bound all work to O(N) where * N = BM25_INNER_LIMIT rather than the full match set size. */ BM25_INNER_LIMIT = 2000, + /* Longest label spliced into the MATCH pre-filter; real labels are short + * identifiers, so anything longer simply skips the pre-filter. */ + BM25_LABEL_MAX = 64, + /* Room for "() AND label : \"