Skip to content

The lexical leg of code search cuts its pool on each row's vote times the path penalty the ranking applies - #1673

Merged
zlareb1 merged 8 commits into
mainfrom
fix/code-search-test-mention-keeps-priors
Nov 28, 2026
Merged

zlareb1 merged 8 commits into
mainfrom
fix/code-search-test-mention-keeps-priors

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Related: #1664
Related: #1671

Changelog category (leave one):

  • Improvement

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

code.search keeps source rows among its lexical candidates that test and doc rows used to displace: for a query that does not ask for tests or docs, the lexical leg keeps the 200 rows whose reciprocal-rank vote times the ranking's path penalty is largest, each row votes with its rank in the whole leg, and rows with one lexical score rank source first. retrieval_confidence and abstain are still computed from the leg's first 200 rows; the lexical statement reads more for these queries.

Why

The path penalties acted after the pool was cut. The lexical leg returned its first 200 rows by rank. Fusion gives a row 1 / (60 + rank), and the ranking multiplies that by 0.35 on a test, example or benchmark path and by code_search_prose_penalty on a prose file. So the leg kept test rows worth 0.35 / 260 and dropped source rows worth up to 1 / 261.

Measured on 29 public issues whose fixes change source files only (the measurement is described under Tests):

  • Test and doc rows held 83% of the leg's 200 rows on the issue text and 80% on the first line alone.
  • The changed file was among the 200 rows for 20 of 29 issues, and a changed definition for 14.

What the change does:

  • The leg keeps the 200 rows with the largest factor / (60 + rank), the row's own term in the fused score. factor is the pair the ranking applies to the query: 0.35 and code_search_prose_penalty, each 1 when the query's words turn that penalty off or the fusion signals are off.
  • A row votes with its rank in the whole leg. A source row admitted from rank 340 votes 1 / 400, not with its place among the rows that survived. A row in the pool scores what it would score if the leg returned every row.
  • Rows with one score rank by their factor, the largest first, in the scan and in the rank. The score is a sum of idfs over the query words a chunk holds, so the rows of a one-word or two-word query tie by the thousand, and ClickHouse returns equal rows in no fixed order. Ranked by the score alone, the wrapped statement numbered them in the reverse of the order the plain statement returns them in: on an index that holds the source tree before tests/, test rows took the first ranks, the pool and the rows calibration reads. queryset matches 1,930 chunks of a 70,000-chunk namespace with one score (338 source, 340 prose, 1,252 test): main returns 200 source rows, the head before this key returned 200 test rows, and this head returns 200 source rows.
  • The scan reads a bounded depth. No row past rank 260 * hi / lo - 60 can be in the pool, where lo and hi are the smallest and largest factor a path can get: 2,912 rows for both default penalties, 980 for the prose penalty alone, 683 for the test penalty alone, never more than 10,000.
  • Calibration does not read the cut. The statement also returns the leg's own first 200 rows. Leg agreement, the top similarity and abstention are computed on those, as on main. A penalty reaches them only as the order of rows with one score.
  • One definition of the path classes (server/code/domain/index/path_class.py, patterns that Python's re and ClickHouse's match both read) and one decision of the pair (pool_penalties, called once in _gather_legs, kept on the search state for the leg and the ranking).

Design calls:

  • The cut is on the vote, not on the lexical score. An earlier head of this branch cut on lex_score times the factor. The factor is calibrated for the reciprocal-rank score, and applied to a sum of idfs it removed almost every test and prose row from the leg (83% of the pool to 32%). A set that can contradict it showed the cost: 35 questions whose answer is a test-tree, example or prose file and that carry no test or doc word (under Tests). The asked-for file was in the top 10 for 20 on main and for 1 with that cut. With this head it is 20.
  • Equal rows rank by the factor, not by where the table holds them. Main returns equal rows in the order of the table's key, which starts with the path, so which of them it keeps follows from the repository's directory names. The wrapped statement returns them in another order, and a rank that follows either order lets a tie of test rows fill the pool. The factor is the one order between a source row and a demoted row that the ranking already states.
  • The rank is not recomputed among the survivors. Doing so would lift every source row by the test rows removed above it, which changes the score of rows main already ranks and is supported only by a set whose targets are all source files.
  • No rule on query length. A test word anywhere in the query turns off the test-path penalty, as on main. A head before that read such a word as a mention when the query was longer than 32 lexemes; that rule is removed, because the 29 issues cannot contradict it and 23 prompts that ask for tests or docs did.

What the change does not do:

  • It moves few answers. The rows it admits vote less than 1 / 260, so they reach the page only with a second vote or a prior. On the 29 issues against main, the changed file reaches the top 3 of the hybrid search and of the hook's request for one more issue (16 to 17, 15 to 16), both in the named half, and the top 5 of the lexical-only search for one more (17 to 18). The hybrid top 10 does not move (18). The lexical-only searches lose one definition at rank 10 (13 to 12 on the issue, 15 to 14 on the first line).
  • A long report that mentions a test. 13 of the 29 issues carry a test word. Only prose rows leave their pool. Against main, one of the 13 loses the changed file from the lexical-only page (under Tests).
  • The order of rows with one score and one factor. It is the order ClickHouse returns them in, and the wrapped statement returns them in another order than the plain one. Which source rows of a large tie are among the first 200 therefore differs from main, and with them the retrieval_confidence of a short query (under Tests). The statement has no key that fixes that order.
  • The vector leg's 200 rows are cut on distance alone, and the concept leg calls the lexical statement without the factors.

Scope and risk

  • Touches: the lexical leg's statement (server/code/store/index/search.py: the same statement read deeper, inside two window levels), domain/index/pool_cut.py (the constant and the depth), domain/index/path_class.py, a helper in store/index/sql.py, and in server/code/app/search/: priors.py (pool_penalties; _apply_fusion_signals takes the pair), gather.py, lexical.py (returns the pool and the leg's first rows), fusion.py (the lexical vote reads the row's rank), pipeline.py and calibrate.py (calibration fuses and reads the leg's first rows), rank.py, state.py, track.py (a verdict for a row cut on its path penalty), definitions.py (the definition leg reads the shared path class). The descriptions of LOOM_CODE_FUSION_SIGNALS and LOOM_CODE_SEARCH_PROSE_PENALTY say that they also decide the lexical candidates.
  • Leaves alone: the intent rule and its readers, the vector statement, the index, the extractor stamp, the scorer, the symbol route, the calibration arithmetic, and the lexical statement when both factors are 1 (byte for byte, asserted).
  • The lexical statement costs more. It fetches the body columns of every row it reads at depth, 980 to 2,912 rows for the default penalties, not 200, and sorts on the path factor after the score. From system.query_log, main to this head, on namespaces of 65,000 to 77,000 chunks and one of 1,769:
    • The statement alone with the same terms, run in one process and interleaved (the first lines of the 29 issues and 29 one-word queries, three times each, 174 pairs): duration p50 92 ms to 124 ms, p95 355 ms to 414 ms, sum 22.3 s to 27.8 s (1.25 times); read_rows p50 71,633 to 118,075; read_bytes p50 21.4 MiB to 40.5 MiB, p95 31.3 MiB to 51.5 MiB; memory_usage p50 15.3 MiB to 17.1 MiB, p95 46.2 MiB to 47.1 MiB. Ranked by the score alone the wrapped statement took 112 ms at p50 and 26.5 s in sum: the second sort key adds 5%.
    • Through the server, 174 pairs of requests (the 29 issues, issue text and first line, three rounds, the two servers interleaved, the machine loaded by other work): the statement's duration p50 290 ms to 395 ms, p95 1,272 ms to 1,476 ms, sum 74.3 s to 93.8 s (1.26 times); read_rows p50 80,780 to 128,839; read_bytes p50 28.8 MiB to 46.5 MiB, p95 31.5 MiB to 51.4 MiB; memory_usage p50 56.8 MiB to 58.2 MiB, p95 92.4 MiB to 92.8 MiB; rows returned 200 to 270 at p50. The leg's wall time p50 308 ms to 406 ms; the request p50 1,071 ms to 1,160 ms.
    • A smaller code_search_prose_penalty reads deeper, up to 10,000 rows (ClickHouse's limit for fetching bodies lazily).
    • Not measured on a namespace larger than 77,000 chunks. The upper bound is the cost of fetching every candidate's body.
  • A file that is not source moves down a little when it is the answer. On 16 questions answered by a module of the library's test package or by a prose page, the asked-for file moves on 4 of 32 requests against main: down one place on 3, and into the top 10 on 1 (under Tests). Source rows the leg now returns pass it. On the head before the tie order, 35 such controls moved on 11 of 105 requests against a build without the cut, each time down, by one to four places.
  • File coherence counts the new rows. A file with more rows in the pool gets a larger lift for its best chunk. On the head before the tie order, all five worse cells on the 29 issues were one rank, from this.
  • lexical_rank on a unit can exceed 200: it is the row's rank in the whole leg.
  • Rows with one score and one factor come back in another order than on main for a query the cut applies to (see above). It moves the answers of short queries, whose rows tie in large groups, and through them retrieval_confidence: on 18 queries of one to six words in hybrid mode, confidence differs from main on 17, by 0.001 to 0.200; two rise past 0.4, and one at 0.350 starts abstaining at 0.346. On the 58 issue-text and first-line requests it differs on 3, by 0.001 to 0.003, and none changes whether it abstains.
  • Not measured: a provider embedding model (the hybrid rows use a deterministic n-gram stand-in; calibration reads the same rows as on main with any model), a language other than Python, a repository whose tests are not under a test or tests directory.

Compatibility, rollout and rollback

  • Wire: no op or field changes. A unit's lexical_rank can exceed 200. track_path has one more verdict text, beyond pool: lexical <score> over floor <floor>, cut on its path penalty.
  • Operator steps: none. No setting, migration or re-index.
  • Rollback: a revert restores the old statement and leaves nothing behind.

Tests

Measurement. 29 public issues of two open-source Python web frameworks, each with the commit that fixed it. 14 were named before any measurement (the named half) and 15 were drawn with a fixed seed. Each base commit is indexed whole into its own namespace (64,674 to 76,607 chunks, and one of 1,769), tests and docs included. A request is POST /v1/code.search with top_k: 10, fresh: true and legs as named. "File" is the rank of the first changed file among distinct files; "def" is the rank of the first unit that covers a changed line. The harness and its index are not in the repository. Five runs of the head before the tie order returned identical answers (319 of 319 requests, scores and confidence included), and three rounds of 58 requests on this head did (58 of 58).

The vector leg ran on a deterministic n-gram stand-in, not a provider model, so the hybrid rows are the lexical leg plus that stand-in. The lexical-only rows do not depend on it.

This head against main. One harness run each on main 1fd16706d8, which has the definition leg, and on this head, the two servers up together. A cell with one number is the same on both.

Request (n=29) file@1 file@3 file@5 file@10 def@1 def@3 def@5 def@10
Issue, hybrid 9 16 to 17 18 18 4 11 11 11
Issue, lexical only 9 15 17 to 18 21 5 10 10 13 to 12
Issue as one line, first 2,000 characters, top 3 (the prompt hook's request, before its confidence gate) 9 15 to 16 n/a n/a 5 11 n/a n/a
Issue, hybrid, tests and docs excluded by glob 10 21 22 25 6 11 12 14
First line only, hybrid 13 21 to 22 25 26 to 27 4 10 11 12
First line only, lexical 11 to 12 20 to 19 23 to 22 26 to 27 8 12 to 11 12 to 11 15 to 14
code.context_pack, first 500 characters 8 to 9 15 to 16 17 17 7 to 8 10 to 11 11 11
code.context_pack, first line 12 19 to 20 21 23 5 9 10 10
Issue, vector only 6 8 8 9 2 3 3 3
  • Of 261 issue-and-request cells, 21 move: 15 better and 6 worse.
  • Four of the worse cells are one or two ranks. One changed definition leaves a page (first line, lexical: file 3 to 4). One changed file leaves a page (issue, lexical only): its function moves from the 9th unit to the 11th behind two test rows that gain two lexical ranks each. That issue carries a test word, so its test rows are not demoted and now rank before the prose rows they tie with.
  • The named half gains in nine count cells and loses in four, all four on the first line with the lexical leg alone. The seeded half gains in four and loses in three.
  • The vector-only answers are identical (29 of 29).
  • Against the head that ranked by the score alone, run on the same base, 4 cells move: 3 better, and the lost file above.

Short queries, this head against main. 18 queries of one to six words on one 70,000-chunk namespace (queryset, middleware, queryset filter, model field, how does the paginator count pages and 13 like them), top 10. A test row is a row under a test, example or benchmark directory.

18 queries, 180 rows Main Ranked by the score alone This head
Lexical only: test rows in the top 10 2 97 2
Lexical only: queries whose top 10 is test rows only 0 6 0
Hybrid: test rows in the top 10 6 44 6
Hybrid: queries that abstain 0 2 1
  • Hybrid confidence on this head differs from main on 17 of the 18, by 0.001 to 0.200: the rows of one score and one factor come in another order, so another 200 of a tie are read.
  • Two rise past 0.4 (0.384 to 0.584, 0.356 to 0.403). The one that starts abstaining stood at 0.350 on main and is at 0.346.

Controls whose answer is not a source file, this head against main. 16 questions on the same namespace, each with its file fixed from the repository listing before any request and none with a test or doc word: 8 answered by a module of the library's test package, 8 by a how-to or topic page. Columns are main and this head.

Request Target at rank 1 Target in top 3 Target in top 10 Abstains Pass the 0.4 gate
Search, hybrid 0 / 0 1 / 1 7 / 7 4 / 4 9 / 10
Search, lexical only 1 / 0 2 / 2 7 / 8 0 / 0 16 / 16
  • The target moves on 4 of the 32 requests: down one place on 3 (5 to 6, 7 to 8, 1 to 2) and into the page at rank 10 on 1.
  • Confidence differs on 3 of the 16 hybrid requests (0.363 to 0.424, 0.321 to 0.297, 0.466 to 0.501); none changes whether it abstains.

The head before the merge of main and before the tie order (fb57e46b8f), against the main of that time, which had no definition leg. Everything from here to "Unit tests" was measured on that head, and its control sets were not sent again. The cut on votes it measures is this head's; the tie order it reports beside the cut is the one the second sort key replaces.

Three builds: main, the control (that head with both factors forced to 1 in the statement, so the pool is the leg's first 200 rows in the wrapped statement's tie order), and that head. A cell with one number is the same on all three; otherwise it reads main / control / head, and the cut's own effect is control to head.

Request (n=29) file@1 file@3 file@5 file@10 def@1 def@3 def@5 def@10
Issue, hybrid 9 11 / 11 / 12 13 13 4 6 8 8
Issue, lexical only 9 9 12 / 12 / 13 15 / 15 / 16 5 5 6 9
Issue as one line, first 2,000 characters, top 3 (the prompt hook's request, before its confidence gate) 9 10 / 10 / 11 n/a n/a 5 7 n/a n/a
Issue, hybrid, tests and docs excluded by glob 10 16 17 21 6 8 9 11
First line only, hybrid 13 / 12 / 13 19 23 25 4 9 10 11
First line only, lexical 11 / 11 / 12 18 / 17 / 17 21 / 21 / 20 24 / 24 / 25 8 11 / 10 / 10 11 / 10 / 10 14 / 13 / 13
code.context_pack, first 500 characters 4 9 12 12 / 13 / 13 4 6 6 6
code.context_pack, first line 11 17 20 / 22 / 22 22 / 23 / 23 6 9 10 10
Issue, vector only 6 8 8 9 2 3 3 3
  • Of 261 issue-and-request cells, the tie order alone moves 9 (6 better, 3 worse) and the cut moves 16 more (11 better, 5 worse, every worse one by one rank).
  • Both code.context_pack gains and the three first-line lexical definition losses are the tie order, not the cut.
  • The gain is in the 16 issues without a test word: lexical file@10 10 to 11, hybrid and hook file@3 7 to 8. The 13 with a test word keep every count of the issue-text rows; one of them moves one rank (issue D below).
  • Tests and docs in the hybrid top 10: 16% to 14% for the 16 issues, 71% to 72% for the 13.
  • The vector-only answers are identical (58 of 58).

Each half of the set:

Request Named half (14): file@1 file@3 file@10 def@3 def@10 Seeded half (15): file@1 file@3 file@10 def@3 def@10
Issue, hybrid 3 4 / 4 / 5 6 2 3 6 7 7 4 5
Issue, lexical only 3 3 4 / 4 / 5 2 2 6 6 11 3 7
Issue as one line, top 3 4 4 / 4 / 5 n/a 3 n/a 5 6 n/a 4 n/a
Issue, hybrid, tests and docs excluded by glob 5 8 8 4 4 5 8 13 4 7
First line only, hybrid 7 / 6 / 7 9 13 3 3 6 10 12 6 8
First line only, lexical 5 / 5 / 6 8 / 7 / 7 9 / 9 / 10 4 / 3 / 3 5 / 4 / 4 6 10 15 7 9
code.context_pack, first 500 characters 2 4 6 2 2 2 5 6 / 7 / 7 4 4
code.context_pack, first line 5 6 10 / 11 / 11 2 2 6 11 12 7 8
  • The named half gains one issue in six cells: hybrid and hook file@3, lexical file@10, first-line lexical file@1 and file@10, and first-line hybrid file@1, which the tie order had taken.
  • The seeded half gains nothing in these columns. Outside them the cut moves it at file@5 only: lexical 8 to 9, first-line lexical 12 to 11.

The lexical leg's own 200 rows (the leg run in process with and without the factors):

Query Rows the ranking demotes Changed file among the 200 Named / seeded Changed definition among the 200 Named / seeded
Issue text 83% to 59% 20 to 25 8 to 10 / 12 to 15 14 to 18 7 to 8 / 7 to 10
First line 80% to 45% 26 to 28 11 to 13 / 15 to 15 19 to 24 8 to 12 / 11 to 12

By the factors in force on the issue text:

Words in the issue Issues Rows the ranking demotes Changed file among the 200 Changed definition
No test or doc word (both penalties) 16 85% to 49% 11 to 14 7 to 11
A test word (prose penalty only) 10 81% to 68% 6 to 8 6 to 6
A test word and a doc word (no penalty) 3 83% to 83% 3 to 3 1 to 1

The deepest row of a pool is at rank 209 to 810 over these 55 statements. The statement returns 271 rows at the median (313 at most): the pool and the rows of the leg's first 200 that are not in it.

Calibration. The hook's request on the 29 issues, as the plugin ships it (an answer is delivered when the search does not abstain and retrieval_confidence is at least 0.4). The control and this head are the same in every cell.

Set Abstains Confidence under 0.4, not abstaining Delivered With a changed file in its three With a changed definition Median confidence Legs agree
All 29 2 to 2 9 to 9 18 to 18 8 to 8 7 to 7 0.421 to 0.421 11 to 11
Named 14 1 to 1 6 to 6 7 to 7 3 to 3 3 to 3 0.400 to 0.400 4 to 4
Seeded 15 1 to 1 3 to 3 11 to 11 5 to 5 4 to 4 0.433 to 0.433 7 to 7
  • Over all 261 requests of a harness run that carry a calibration: confidence, abstention and leg agreement differ between the control and this head on 0. Between main and the control (the tie order) confidence differs on 5, by 0.001 to 0.040; one request stops abstaining; leg agreement differs on 0; none crosses 0.4.
  • One of the 5 is a hook request (0.325 to 0.337, abstains on both).

Controls that can contradict the cut: the answer is not a source file. 21 questions written for this change, each with the files that answer it fixed from the repository listing before any search was sent, and none with a test or doc word: 6 about code under a test package of the library (the test client, the settings override, the live server), 2 about support files of the test tree, 6 answered by a how-to or reference page, 4 by an example application, 2 by a deployment or pattern page, 1 by the test configuration. 14 are sent to a namespace of each half and 7 to the small namespace, which is in the named half: 35 requests, 21 and 14. Columns are main, the earlier head that cut on score times factor, the control, and this head. "Target" is the rank of the first asked-for file among distinct files.

Request Set Target at rank 1 Target in top 3 Target in top 10 Abstains Pass the 0.4 gate Legs agree
Search, hybrid All 35 2 / 0 / 3 / 2 7 / 0 / 7 / 7 20 / 1 / 21 / 20 10 / 15 / 10 / 10 20 / 16 / 20 / 20 27 / 17 / 27 / 27
Search, hybrid Named 21 1 / 0 / 2 / 1 4 / 0 / 4 / 4 10 / 1 / 11 / 11 5 / 8 / 5 / 5 12 / 11 / 12 / 12 16 / 12 / 16 / 16
Search, hybrid Seeded 14 1 / 0 / 1 / 1 3 / 0 / 3 / 3 10 / 0 / 10 / 9 5 / 7 / 5 / 5 8 / 5 / 8 / 8 11 / 5 / 11 / 11
Search, lexical only All 35 0 / 0 / 0 / 0 8 / 0 / 10 / 9 22 / 0 / 22 / 22 0 35 n/a
Search, lexical only Named 21 0 / 0 / 0 / 0 4 / 0 / 5 / 5 11 / 0 / 11 / 11 0 21 n/a
Search, lexical only Seeded 14 0 / 0 / 0 / 0 4 / 0 / 5 / 4 11 / 0 / 11 / 11 0 14 n/a
Hook shape, top 3 All 35 2 / 0 / 3 / 2 7 / 0 / 7 / 7 n/a 10 / 15 / 10 / 10 20 / 16 / 20 / 20 27 / 17 / 27 / 27
Hook shape, top 3 Named 21 1 / 0 / 2 / 1 4 / 0 / 4 / 4 n/a 5 / 8 / 5 / 5 12 / 11 / 12 / 12 16 / 12 / 16 / 16
Hook shape, top 3 Seeded 14 1 / 0 / 1 / 1 3 / 0 / 3 / 3 n/a 5 / 7 / 5 / 5 8 / 5 / 8 / 8 11 / 5 / 11 / 11
  • By class, hybrid top 10 on main and this head: code under a test package 8 and 8 of 12, prose 7 and 8 of 14, examples 2 and 2 of 4, test support 3 and 2 of 5.
  • Control to head, the target moves on 11 of 105 requests, always down: one place on 6, two on 3, four on 1, and one from rank 10 off the page.
  • Confidence, abstention and the gate are the same on the control and this head for all 105.

Controls that can contradict a length rule. 23 prompts, each with the files it asks for fixed before any run: 14 ask for tests (30 to 40 lexemes), 6 ask for docs, 3 list ten identifiers. Each was sent as a search (top_k: 10) and in the hook's shape (top_k: 3). Columns are main and this head.

Prompts Request Target at rank 1 Target in top 3 Target in top 10 Test rows (docs rows for the doc prompts), mean Abstains Pass the 0.4 gate Pass it with the target in top 3 Legs agree
Ask for tests (14) search 7 / 8 11 / 12 13 / 13 6.2 / 6.1 of 10 0 / 0 12 / 12 9 / 10 9 / 9
Ask for tests (14) hook shape 7 / 8 11 / 11 n/a 2.0 / 2.0 of 3 0 / 0 12 / 12 9 / 9 9 / 9
Ask for docs (6) search 5 / 5 5 / 5 5 / 5 9.7 / 9.7 of 10 0 / 0 6 / 6 5 / 5 6 / 6
Ask for docs (6) hook shape 5 / 5 5 / 5 n/a 2.8 / 2.8 of 3 0 / 0 6 / 6 5 / 5 6 / 6
List identifiers (3) search 3 / 3 3 / 3 3 / 3 n/a 0 / 0 2 / 2 2 / 2 1 / 1
  • Confidence is the same on main, the control and this head for all 46 requests. The doc prompts return identical answers (12 of 12).
  • The hook delivers the asked-for test file for 9 of the 14 prompts on main and on this head.

Other controls, 46 requests on main, the control and this head:

Control Requests Control to head Main to control (the tie order)
Symbol-shaped identifier 5 Identical Identical
Short question that asks for tests 7 10 of 10 shared on all 4 to 10 of 10 shared; confidence moves on 4, by -0.061 to +0.047
A test name the index does not hold 1 Identical (abstains) Identical
Short question that asks for docs 2 9 and 10 of 10 shared 8 and 6 of 10 shared; one starts abstaining (0.376 to 0.329)
Short query naming a test file 1 10 of 10 shared 9 of 10
Search scoped to tests (path_prefix, path_globs) 2 Identical Identical
Vector only 2 Identical Identical
Short question about the implementation 6 10, 10, 10, 10, 9 and 9 of 10 shared 6 to 10 of 10 shared; confidence moves on 2 and one stops abstaining (0.401 to 0.436)
Long prompts that ask for tests or docs, lists of identifiers, the hook shape 13 10 of 10 shared on 11; 9 of 10 and 2 of 3 on the others 10 of 10 on all
Small namespace, rare words, one plain word, two identifiers 7 10 of 10 shared on 5; 8 and 9 on the others 7 to 10 of 10 shared; confidence moves on 1
  • Confidence, abstention and the 0.4 gate are the same on the control and this head for all 46.
  • Against main, confidence differs on 8, two requests change whether they abstain (one each way) and two cross 0.4 (both upward). All of it is the tie order.

Issues that got worse, control to head. Ranks are file/def, - for not in the top 10.

Issue Request Control Head Cause
A First line, lexical 8/8 9/9 A function of another file, at lexical rank 120, gets a larger coherence lift: its file has more rows in the pool.
B First line, lexical 2/8 2/9 One more source file passes on coherence.
C Issue, lexical 7/- 8/- A backend module at lexical rank 126 moves from 8th to 5th on coherence.
C First line, lexical 5/- 6/- The changed file's own coherence share shrinks: the lift is a share of the largest file sum in the pool, which grew.
D Issue, lexical 6/8 7/9 A test row passes the changed function by 0.00004 of score: both coherence shares moved. The issue carries a test word, so only prose rows left its pool.

Control to head, no issue loses a changed file or a changed definition from a page. The tie order alone takes one definition off one (first line, lexical: 3/3 to 4/-).

Latency and cost.

  • Requests with a lexical leg, two harness runs of each build interleaved (406 requests each): median 300 ms to 307 ms, p95 457 ms to 474 ms. The leg's own time (retrieval_work.lexical_leg_ms): median 160 ms to 174 ms, p95 277 ms to 300 ms.
  • The plain and the wrapped statement with the same terms, 59 pairs from system.query_log of those runs: duration p50 118 ms to 174 ms, p95 190 ms to 238 ms; read_rows p50 72,907 to 122,918; read_bytes p50 25.6 MiB to 42.6 MiB, p95 31.4 MiB to 51.5 MiB; memory_usage p50 42.6 MiB to 56.6 MiB, p95 63.2 MiB to 81.2 MiB; result 696 KiB to 858 KiB.
  • One statement alone, three runs each: plain 51 ms and 29.1 MiB; wrapped at depth 200, 47 ms and 29.1 MiB; at depth 980, 56 ms and 40.1 MiB; at depth 2,912, 63 ms and 49.8 MiB; at depth 2,912 without the body columns, 40 ms and 24.1 MiB. The cost is the bodies of the rows read at depth, not the ranking.
  • The wrapped statement equals a cut computed in Python from its own full ranking for 54 of 55 statements; the other differs in one row whose vote ties with the 200th.
  • All 12 shapes of the statement (three scopes, with and without a path prefix, both token gates) run on a 70,000-chunk namespace.

Unit tests.

  • tests/unit/test_code_lexical_pool_cut.py: the pair of a query, the ranking multiplying by the pair it is handed, the path classes, the factor's SQL, the depth for seven factor pairs, a property test that no row past the depth is in the pool (20 seeds, mixed classes, a factor over 1), a first-ranked test row staying while the last test rows leave, a row voting with its rank in the whole leg, the leg returning the pool and its own first rows, calibration reading the leg's own order while the ranking reads the pool, and what search hands the leg.
  • test_code_lexical_statement.py holds the plain and the wrapped statement byte for byte. test_code_lexical_token_gate_sql.py runs the cut on clickhouse-local, including a test row that matches every term and outlasts 130 source rows that match two, which a cut on score times factor drops, and two 600-row ties stored with the source rows between benchmark rows and test rows: the source rows take the first ranks and the pool.
  • test_code_search_provenance.py: the track_path verdict for a row cut on its path penalty.
  • Each of ten mutations fails a test: a vote by position, calibration fusing the pool, leg agreement read from the pool, a cut on score times factor, a depth equal to the pool, a leg handed factors of 1, a ranking that ignores the pair, a statement without the leg's first rows, a leg that returns every row as the pool, and a pair that ignores the fusion-signal switch. A rank by the score alone fails one of the two tie tests.

Run here, on this head:

  • Under pytest, the eight unit test files of the search pipeline and the definition leg (174 tests), and the statement, pool cut, fusion signal, package contract and public copy files with the analyzer's shape-list test (132 tests): all pass.
  • test_code_lexical_token_gate_sql.py cannot create its table on the local clickhouse-local, which lacks the table's vector codec, on main as here. Its 14 bodies pass against the same table without the codec.
  • ruff format --check, ruff check, mypy on the three changed modules, the function-length gate, the settings, docs, SDK and plugin generators with --check, and prettier on the changed Markdown and YAML.
  • The analyzer shape list, regenerated on fake providers: the 12 shapes of the wrapped statement are replaced by 12, and the merge of main adds main's own.

On the head before the merge, the test bodies of 50 unit test files were called directly without a pytest session: every body that passes on main passed there.

Left to CI: the full unit suite, the analyzer corpus against a migrated ClickHouse and the integration suite.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. The agent ran the harness on main, the control build and this head, read the per-issue rank changes behind every worse cell, wrote the control questions and fixed their targets before sending them, and ran the gates listed.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • Local format, lint, type checks and focused tests pass. The full make test-unit and applicable integration results are reported by CI; a full local run is not required before pushing.
  • Generated files are regenerated in this PR, not by hand: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code


Note

Medium Risk
Changes core lexical retrieval SQL and fusion semantics for implementation queries; trades higher ClickHouse read depth (hundreds–thousands of rows) for better source recall, with calibration deliberately unchanged.

Overview
code.search no longer takes the lexical leg’s top 200 rows by BM25 alone when test-path and prose penalties apply. The lexical ClickHouse query scans to a bounded depth and keeps the 200 chunks with the largest path_factor / (60 + lex_rank), while each survivor still fuses using its global leg rank (lex_rank). Calibration, abstention, and leg agreement keep using the leg’s uncut first 200 rows (lexical_head), not the penalty-trimmed pool.

Path classification moves into path_class.py with patterns shared by Python ranking and SQL (path_penalty_sql). pool_penalties decides the (noise, prose) pair once per query; the lexical leg and post-RRF fusion both use it. Settings/docs now state that LOOM_CODE_FUSION_SIGNALS and LOOM_CODE_SEARCH_PROSE_PENALTY govern lexical candidate selection as well as fused-score multipliers. track_path can report rows dropped for path penalty despite a strong lexical score.

Reviewed by Cursor Bugbot for commit f8408b7. Bugbot is set up for automated code reviews on this repo. Configure here.

…, and cuts the lexical pool on them

One test word anywhere in a query turned off the test-path penalty, the
fan-in prior, the kind prior and file saturation, and one doc word turned
off the prose penalty. In a pasted issue or prompt the word says where the
fault showed: the top ten went to tests and docs although the code to change
was source. A query asks for tests or docs when it carries the word and fits
the lexical leg's 32-lexeme term list; a longer one keeps the priors.

The penalties multiplied the fused score, after the lexical leg had taken
its 200 rows by raw score, so test and doc rows held the pool and the source
rows the ranking prefers were never candidates. The leg cuts its pool on the
score times the same path factors and returns the rows in score order.

The path classes move to server/code/domain/index/path_class.py as patterns
Python and ClickHouse both read, so the ranking and the statement agree on
which file is a test or a doc.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
loom-docs Ready Ready Preview Nov 28, 2026 1:58am UTC
loom-telemetry Ready Ready Preview Nov 28, 2026 1:58am UTC

Request Review

…he lexical pool cut remains

The rule that read a test or doc word as a mention past 32 lexemes is removed.
Its support was a set of issues whose targets are source by construction, and
it took the asked-for test file out of the top three for long prompts that ask
for tests. The intent rule is main's again; `window.py` is unchanged from main.

What stays: the lexical leg cuts its pool on the two path penalties the ranking
applies to the query, and the path classes have one definition for Python and
SQL. One helper (`_path_factors`) turns the query's words into both factors
for the leg and for the ranking.

Calibration reads the legs after the cut, so leg agreement and the fused head
count the rows the pool holds. The comments and the architecture page that
said calibration was unaffected now say that.

The unit test file is renamed for what it covers and its fixtures name no
other project.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread server/code/app/search/priors.py Resolved
@zlareb1 zlareb1 changed the title Code search keeps its source priors when a long query mentions a test, and cuts the lexical pool on them The lexical leg of code search cuts its pool on the path penalties the ranking applies Nov 27, 2026
zlareb1 and others added 3 commits November 28, 2026 05:55
…bration reads the leg's own order

The pool was cut on lex_score times the path factor. The ranking multiplies
the fused reciprocal-rank score by that factor, not the lexical score, so the
cut took almost every test, example and prose row out of the leg: a question
whose answer is such a file lost it (35 written controls with no test or doc
word: target in the top 10 for 20 on main and 1 with that cut).

The leg now keeps the 200 rows with the largest factor / (60 + rank), the
row's own term in the fused score, and each row votes with its rank in the
whole leg. A row in the pool scores what it would score had the leg returned
every row. The scan reads the depth past which no row can be in the pool.

The statement also returns the leg's own first 200 rows. Calibration fuses
and reads those, so leg agreement, the top similarity and abstention do not
depend on the cut.

The path factor pair is decided once, in `_gather_legs`, and kept on the
search state for the leg and the ranking.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…tors

`cut_depth` took the smallest factor and assumed none over 1. It now takes
the two factors and bounds the depth by the largest over the smallest, so a
factor set above 1 cannot leave a pool row past the scan.

Only the lexical leg carries a rank on its rows, so the helper that reads it
is `_lexical_ranks` and the vector leg votes by position as before. A leg
that returned nothing is fused once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The search test had a pool row in the vector leg's rows, so the legs agreed
whether calibration read the leg's own rows or the pool. The vector rows are
now the prose row the cut left out and a row the lexical leg never saw: leg
agreement and the top similarity hold only on the leg's own order.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
@zlareb1 zlareb1 changed the title The lexical leg of code search cuts its pool on the path penalties the ranking applies The lexical leg of code search cuts its pool on each row's vote times the path penalty the ranking applies Nov 28, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit fb57e46. Configure here.

Comment thread server/code/store/index/search.py Resolved
zlareb1 and others added 3 commits November 28, 2026 06:45
…ath class

Merge of origin/main. Two conflicts:

- `server/code/app/search/priors.py`: main added `_noise_path` over the two
  regexes this branch moved to `domain/index/path_class.py`. The branch's side
  is kept, and the definition leg calls `path_class.is_noise_path`, the same
  two patterns, so one definition decides which path the ranking demotes, the
  lexical leg cuts on and the definition leg passes over.
- `tests/analyzer/shapes.txt`: both sides added a line at one place. The file
  equals a regeneration from the builders.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…ut moves confidence

Calibration reads the lexical leg's own first rows, not the pool the leg cuts
on the path penalties, so `retrieval_confidence` and `abstain` do not depend
on the cut. The descriptions of `code_fusion_signals` and
`code_search_prose_penalty` still said they did. The sentence is removed from
both, and the settings reference, schema and example are regenerated.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The cut ranked the rows it read by `lex_score` alone. The score is a sum of
idfs over the query words a chunk holds, so the rows of a one-word or two-word
query tie by the thousand, and ClickHouse returns equal rows in no fixed
order: the wrapped statement numbered them in the reverse of the order the
plain statement returns them in. On a table that holds the source tree before
`tests/`, the test rows took the first ranks, and with them the pool and the
rows calibration reads.

Measured on a 70,000-chunk namespace against main: the query `queryset`
matches 1,930 chunks with one score (338 source, 340 prose, 1,252 test). Main
returns 200 source rows and the cut returned 200 test rows. Of 18 short
queries, the lexical-only top 10 was all test rows for six that are all
source on main, and `queryset filter` went from confidence 0.618 to 0.348 and
abstained.

The scan and the rank now order by the score, then by the factor of the
row's path, the largest first. Rows the ranking demotes less rank first among
equal scores whatever order the table holds them in, and the scan's depth
keeps them. The plain statement is unchanged. The 18 queries return source
rows as on main.

Two tests on clickhouse-local hold a 600-row tie with the source rows stored
between benchmark rows and test rows; one of them fails on the statement
before this change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant