Repository navigation
Conversation
The lexical leg of code.search scores a chunk by the idf of the query lexemes it holds, over at most 32 lexemes. A query past the token threshold kept its identifiers in reading order and then its rarest words. Rarest selects what the code to change is least likely to hold: hash pieces and route words of a link, names the corpus does not contain, and prose that is rare in code because it is not code vocabulary. Each such lexeme only adds other chunks to the pool. A long query now keeps its opening (its first lexemes, half the list) and the whole forms of its identifiers, rarest first when they exceed the list. URLs, bare numbers and hash-like words are removed before the tokenizer splits them, and the prose after the opening is not kept. A query under the threshold is unchanged. Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…it repeats The opening of a long query is not always its subject: after a greeting or a template the first 16 lexemes held none of it, and prose after them was never eligible. The lexical list is now the identifiers and, for half the list, the words: those the query says more than once first, then the others in reading order. An English function word, and a word more than an eighth of the chunks hold, is not kept, so they no longer reach the text-index gate. A hash is stripped only at seven or more hex characters with digits among letters, so a short code (F401, e164) is a term and a number ranks last. A query of only addresses and hashes keeps them as its terms. The concept leg passes its terms as chosen terms, so a long list is cut to its rarest, not to its first. Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…s and is never left without words The terms a caller adds to a long question ranked above its words and its identifiers, so six proposed names took every slot the question's own identifiers had. They now rank after the identifiers' whole forms, the rarest first. A word that more than one chunk in eight holds was removed from the list. In a namespace of a few chunks that removed every word, and the lexical leg returned nothing. Such a word now ranks after the other words and fills a slot they leave free, as a number and an unknown lexeme do. Only the question is stripped of links and hashes, so a caller's term of that shape stays a term. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
A lexeme of a caller's term that the question also says left the question's words and ranked with the pieces of the proposed names, the rarest first, so a subject word that many chunks hold was cut once the list was full. The words are now chosen from the question alone, with its own counts, and a caller's terms only add to the list: their identifiers beside the question's, the lexemes only they hold after them. The function words are the closed classes of English, listed by class, with the halves the tokenizer leaves of contractions. A hash is hex in which letters and digits meet at two or more places, so a word and a number such as ed25519 stays a term. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
A function word was never a word to keep, so a question about `only()` or one that says a call returns `None` lost that word, and a question of function words alone was asked with nothing. A function word now counts where the question writes it as code: called, read off an object, alone in backticks, or capitalised inside a sentence. One it never writes that way fills a slot when no other word is left. Past the list's size the question's identifiers go before the words it says once, and a caller's terms take the slots the question leaves, so its known terms are the same with and without them. A UUID is removed whole like a hash, and a hex word in which letters and digits alternate (a group of an id, a colour) is a word, not an identifier that is always kept. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…h as repeated words Each frame of a traceback repeats the directories of its path, so `usr`, `lib`, `python`, `site`, `packages` and the package directories counted as words the query repeats and took 7 of its 16 word slots. On a seven-frame traceback the lexical-only request lost the file the trace ends in, which the old selection returned first. A path's directories say where a file is, so `term_counts` does not count them: a lexeme only they hold is said once, and the file's own name is counted as written. A run of names joined by `/` or `\` is a path when it starts at a root or ends in a file name with an extension, so `request/response`, `and/or` and `1/8` are counted as words. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ 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 53cfaab. Configure here.
…entence as a path The last name of a path took the full stop that ends its sentence, so a relative path there (`in db/models/query.py.`) showed no extension and was read as words set side by side: its directories counted as repeated and could take word slots. The extension is now looked for before the name's trailing full stops. `request/response.` and `and/or.` are still counted as words. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
|
Closing without merging. Measured with a real embedding model on 29 public issues, this change is within one instance of zero in every hybrid cell (gold file in the top 10: 25 before, 25 with this change alone), and combined with the two search changes already on main it moves a pasted traceback's own file from rank 1 to rank 3 on the default hybrid request. The gains reported in this PR were measured with a placeholder embedder, where the lexical list carried the whole ranking. The follow-up is the weight of the lexical list in fusion for long queries, which the same measurement shows matters more. |

Changelog category (leave one):
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.searchon a long query, such as a pasted issue or a whole prompt, now searches its lexical leg with the query's identifiers and the words it repeats, whatever the query opens with. It no longer keeps the rarest words of the body, the pieces of links, hashes and UUIDs, or the English function words of its prose.Why
The lexical leg scores a chunk by the idf of the query lexemes it holds, over at most 32 lexemes. A query past
code_search_query_max_tokens(48) kept its identifiers in reading order and then its rarest words. On 29 public issues (24 of them past the threshold) that choice is the wrong way round:The word rows count every word outside the 77 function words of the earlier revisions, on the 24 issues past the threshold. A word in more than one chunk in eight is in the gold chunk because it is in most chunks; it is ranked last for what it costs at the gate (under Tests), not for being off subject.
The same words by where they stand:
culprit,duck, a reporter's name).eed,fdanddaeread as rare words.also,only,all,doesn) occur 101 times in these issues as a word rare enough to keep. The gold chunk holds them 20% of the time, the rate of a word said once (21%), and 8 of the 14 that held a slot on the third revision held it because the issue repeats them.only(),.all(),returns Noneandthe WHERE blockname code. On the long issues 10 function words that at most one chunk in eight holds are written that way, and the gold chunk holds 9 of them; it holds 40% of the 391 written only as prose (43% of 205 on the named half, 35% of 186 on the seeded half). Nine of the ten are on the named half and one on the seeded half, so this rule rests on how code is written and on the unit tests, not on these counts.The rule now, for a query past the threshold:
F401,e164), a word and a number (ed25519) and a word around one digit (face2face) are terms.7c05,ff00aa: a group of an id, a colour) is a word, not an identifier. A word and a number (F401,c8) is an identifier, as before./usr/lib/python3.11/site-packages/django/forms/formsets.py,D:\app\models\query.py,db/models/query.py:12) are not counted as said, so the frames of a traceback do not make them words the query repeats; a lexeme only they hold is a word said once, and the file's own name is counted as written. Names joined by/or\are a path when they start at a root or end in a file name with an extension:request/response,and/orand1/8are counted as words. A full stop after the last name ends the sentence and is not part of the name, soin db/models/query.py.is a path.only(), read off an object (qs.only), alone in backticks, or capitalised inside a sentence (returns None,the WHERE block). Its uses in prose and inside an identifier (order_by) are not counted. The list is the closed classes by class (determiners, pronouns, auxiliaries and modals, prepositions, conjunctions, question and place words, negation and the focus particles) and the halves the tokenizer leaves of contractions (doesn,ve,ll): 200 lexemes, written from the grammar before any run.extra_terms: a caller's terms are not words of the query, so they are neither stripped nor filtered nor counted as said. They take the slots the query leaves, the whole forms of their identifiers before the lexemes only they hold, the rarest first. The query's words are chosen from the query alone, so the terms of the query that the index contains are the same with and without them. The concept leg passes its term list this way, so a long list is cut to its rarest tokens, as before this change.Designs measured and dropped:
query,set,sql, a proposedPaginator) left the query's words and ranked with the pieces of the names, rarest first, and the counts of what the query says included the names. With the six related names 7 of the 24 long issues lost a word of their own list (5 of 11 named in advance, 2 of 13 seeded), and for 6 of them the gold chunk holds a lost word; with the unrelated names 13 losterror, a piece of one name. None loses a word now (table under Tests).ed25519from a question about a key type. On these issues, in any of the four forms under Tests, the two rules remove the same words.only(), or one that says a call returnsNone, lost that word however often it said it, and a long query of function words alone was asked with no term, so its lexical leg returned nothing. Against the third revision's 77 words it moved 0 cells up and 4 down on the seeded half as written. A function word now counts where it is written as code and fills a slot otherwise (table under Tests).usr,lib,python,site,packagesand two package directories took 7 of the 16 word slots and the lexical-only request lost the file the trace ends in from the top 10 (control under Tests).7c05ande89bof a UUID split at their letter-digit edges like an identifier and were always kept. On these issues, as written, after a greeting, after a form and as one line, removing UUIDs and reading such a group as a word changes no list; one control under Tests has three UUIDs.Scope and risk
server/code/domain/index/query_trim.py(the plan and the selection), the one call in the lexical leg and the one in the concept leg.select_rarestis replaced byselect_terms.aggregate over window functionstwice losesover, and with it one request (issue G under Tests). A capitalised function word after a heading that lost its line break, or in a title in title case, reads as code and takes a word slot: one issue's one-line request gainswhenafter itsDescriptionheading, and no cell moves. Repetition marks a format as well as a subject: each frame of a Python traceback repeatsFileandline, and they take two word slots. On a seven-frame traceback written for it the lexical-only request returns the file the trace ends in second, behind the function of the trace's fourth frame, where the old selection returns it first; the hybrid request returns it first on both builds (control under Tests). A route written like a path (/admin/login/) is read as one, so its words are not counted as repeated. A query that fills the list alone is asked without a caller's terms. A hash spelled as one run of letters and one of digits reads as a name and stays a term: about one seven-character hash in eight, one twelve-character hash in a hundred; a short id of that shape (ff0000,a456) is kept as an identifier, as a code (F401) is. Eight of the 29 issues are worse on one or two requests each (listed under Tests), 6 of the 11 cells on the request that excludes tests. On the seeded half two top-10 file counts are one below the old selection: the lexical-only request (9 against 11) and the request that excludes tests (12 against 13).Compatibility, rollout and rollback
retrieval_work.query_trimmed_tokens_usedand thequery_trimmed(...)part ofscore_explanationcan now report fewer than 32.code_search_query_max_tokenschanged, and its three generated files with it.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 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.searchwith the issue text,top_k: 10,fresh: trueandlegsas 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. Cells are issues hit, before to after. The harness and its index are not in the repository; three runs of each build return identical answers.The vector leg ran on a deterministic n-gram stand-in, not a provider model, so the hybrid rows are the lexical leg plus vector noise. The lexical-only rows do not depend on it.
The issues as written (each opens with its title):
code.context_pack, first 500 charactersThe last three rows return identical answers before and after, as do the five issues under the threshold.
One greeting sentence of 19 lexemes before each issue:
code.context_pack, first 500 charactersAn issue form before each issue (three headings outside the fixed heading list, a checkbox line and an environment line):
code.context_pack, first 500 charactersUnder the form the stand-in vector leg finds the gold file for 2 of 29, and the top ranks of the hybrid rows follow it.
Each half of the set, before to after:
The opening rule this pull request first carried, as before / opening rule / now:
code.context_packfile@10The opening rule finds three more files in the top 10 on the issues as written, which all open with their title, and falls below the old selection when they do not.
The tables above are from this revision, run
lq-terms-n-53cfaabbof the harness on the pushed commit, with a greeting run and a form run of the same commit. Against the fifth revision (runlq-terms-m-6898d4a0), which counted the directories of a path as words, the lists of 2 of the 24 long issues as written differ and 3 of 232 cells move, two down and one up. On the seeded half the lexical-only request loses the file of issue F (rank 4 to absent: its list dropshome,dev, a user name andsqlforfetch,compiler,resultsandvalue, and its top 10 holds tests and the files of the trace's outer frames), and the same issue's definition moves from rank 3 to 1 with tests excluded. On the named halfcode.context_packloses the file of theonly()issue (rank 4 to absent, as before the change: two directory words of the reporter's own paths leave its list for__init__, the name of a file in its trace, andfetch). After a greeting the two cells of issue F move the same way, and after a form none. The leg-level tables below (the leg's own pool, a caller's terms) and the function-word table are from the fifth revision's lists.The fifth revision against the fourth: the fourth revision's tables came from a run made before its commit; a run of that commit (
lq-head-8f86ba24) returns the same answers, 0 of 232 issue-and-request cells different. Against it the fifth revision's lists of the 24 long issues as written differ on 3, each by one function word the issue writes as code (WHERE,only(),None), and 4 of 232 cells move, all up: one on the named half (code.context_packfor theonly()issue, file rank 6 to 4) and three on the seeded half (the definition of theNoneissue: rank 9 to 5 on the lexical request, absent to 7 on the hybrid one, 10 to 5 with tests excluded). After a greeting 2 cells move, one up and one down, both on the named half, and after a form none (against the fourth revision's greeting and form runs, which were made before its commit and not repeated).How a function word is treated, against the third revision (77 words, never a word to keep), as cells better / worse on the five issue requests:
The seeded cell that is worse as written is issue G below, which says
overtwice in prose. The named one is theonly()issue oncode.context_pack(file rank 3 to 4; 6 on the fourth revision). In the leg's own pool the class and no list at all differ by at most two issues per half at the top 10 and the top 50, for files and for definitions, in each form: as file top 10 / top 50 with the class against without, 4 / 7 against 4 / 6 (named) and 8 / 11 against 7 / 11 (seeded) as written, 5 / 7 against 4 / 7 and 8 / 13 against 6 / 12 after a greeting, 3 / 7 against 4 / 7 and 8 / 11 against 7 / 11 after a form. What the class changes most is the gate: its median share is 42%, 36% and 35% with the class and 43%, 43% and 40% without.Issues that got worse on the issues as written, as file/def ranks with
-for not in the top 10 (11 of 145 issue-and-request cells are worse and 38 better: 4 and 12 of 70 on the named half, 7 and 26 of 75 on the seeded half):annotations,subquery,columnsare said once; the words the issue repeats come from a pasted test. Hybrid and lexical are unchanged.localandtakeare said once; the repeated words are from pasted model code. With tests excluded, 7/- to -/-.timedeltaandconvertersare said once, in traceback lines, and the top 10 holds the files of the trace's outer frames. With tests excluded, 1/7 to 1/1.aggregatesandcontainare said once, andover, which the issue says twice in prose (aggregate over window functions), is a function word it never writes as code. With tests excluded, 9/- to -/-.In the lexical leg's own 200-row pool (the leg's statement replayed with each list, issues past the threshold), as before / opening rule / now:
Six terms added by the caller to each issue (
extra_terms, whatexpandandcode.askpass), in the leg's own 200-row pool, as before / fourth revision / now. The first list is six names from the query and admin layers, which most of the issues are about; the second is six names from the request, template, mail and static-file layers. Both were written before the first run and are the same for every issue. "Loses an identifier" counts issues whose list holds fewer of the query's own indexed identifiers than fit in 16 slots (identifiers the index lacks are not counted, which an earlier table did). "Loses a term" counts issues whose list lacks an indexed term that the same build's list without the caller's terms holds. "A name not asked" counts issues whose list holds fewer of the proposed names than the index contains.Cost over the 29 issues as written, two passes on each build in one session, in milliseconds (pass 1, pass 2), measured on the second revision. The fourth revision's lists for these requests differ from its lists by one or two words on 11 of the 24 long issues, and this revision's from the fourth's by one word on 3; neither was timed:
The unchanged rows show the run-to-run spread. In
system.query_logthe lexical statement (232 per pass) reads the same rows (median 79,968 before, 79,813 after) in less time (median 136 ms to 118 ms, p95 288 ms to 226 ms) with less memory (median 54 MB to 42 MB). The list's median length falls from 32 to 24.5 lexemes.Share of a namespace's chunks that pass the text-index gate (
hasAnyTokenson the list), as before / opening rule / now:In a replay of the rule on the issues as written, the median with a common word ranked like any other word is 62%, and without the function-word list 43%. The largest namespace here holds 76,607 chunks, and on it the statement reads every row whatever the gate admits; a larger namespace was not measured.
The neighbours of the two shares, in the leg's own pool, as file in the top 10 / top 50 and definition in the top 10 / top 50. Neither value was chosen from this table:
Controls, the same request to both builds on one index:
many to many, andmanyis not asked for.deadbeef07: both builds answer. The list isdeadbeef, 15 numbers and 16 of those words, which now read as names the index does not contain; the old selection asked with 32 link and hash fragments.only(), written as code and again as prose, under one sentence of prose: written as code its list holdsonlyin the place of its sixteenth word; in prose its list is the fourth revision's. Neither build returns the method's file in the top 10 in either form: the sentence takes ten of the sixteen word slots, the known cost above.None:noneis in the list in the place of a word said once. Neither build returns the method's file in the top 10.changelist_view, the function of the trace's fourth frame; the fifth revision did not return it in the top 10. In the leg's own pool the file is at rank 4 with the old list, 20 with the fifth revision's and 2 with the new one: the directories of the paths held 7 of the 16 word slots, and the list now holdskwargs,options,view,valid,formsets,errorsandfullin their place, besideFileandline. The lexical-only request is therefore one rank worse than before the change on this control, and that difference is known.7c05and a colourff00aa: the fourth revision's list held 13 pieces of the ids among its 28 terms; the list is now 16 words of the prose. A unit of one of the three files that hold the answer is at rank 2 on the hybrid and the lexical-only request, and none is in the top 10 before the change.Other checks:
ruff format --check,ruff check, the function-length gate, the mypy gate, the secret gate and every generator's--checkpass. The mypy gate's only errors here are five inserver/llm/vertex_auth.pyfrom a library this machine lacks; CI has it.is_hash,is_id_piece,strip_non_terms,term_counts,select_terms, the plan, and the service seam: a greeting or a form before a prose question keeps the subject words in the scan; a question of only links and hashes still has terms; a short code is a term, and so is a word and a number such ased25519; a UUID leaves no term and a group of an id is not an identifier; a long concept term list is cut to its rarest tokens; a long question with six proposed names keeps its own identifiers and the proposed names in the scan, throughcode_search.search; a long question whose proposed names repeat three of its words, with more lexemes than slots, is asked with its own list whole and in order beside the names, throughcode_search.search; the question's known terms are the same with and without a caller's terms at five list sizes, and a question that fills the list alone keeps its identifiers; a function word counts where it is called, read off an object, alone in backticks or capitalised inside a sentence, and not in prose, at a sentence's start or inside an identifier; a long question whose subject isonly()orNoneis asked with that word, and the same question in prose is not; a function word of each class and the half of a contraction waits for every other word; a question of function words alone still has a list; past the list's size a word said once goes after the identifiers and a repeated one before them; a seven-frame traceback keeps the names its frames call, the subject its sentence states and the names of its files, and gives no word slot to the directories of its paths; the directories of a path are not counted when it starts at a root, follows a drive or is relative with an extension, also at the end of a sentence, a directory word the prose also says is counted where the prose says it, andrequest/response, a fraction and a date are counted as words; a namespace of five chunks and a question whose every word is common still give a list that holds the subject words; a caller's term shaped like a hash stays a term and changes neither the question's identifiers nor its counts. Eleven of the changed tests fail on the fourth revision's source (checked by calling the test file against it), and the traceback test and the path test fail on the fifth revision's. Eleven linear-time cases cover the module's reads of request text, three of them for paths. I ran the test bodies by direct call; the suite itself runs in CI.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 measured the before and after tables above on its own index, read the per-issue rank changes, and ran the gates listed.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make test-unitand applicable integration results are reported by CI; a full local run is not required before pushing.docs/reference/configuration.mdand thedocs/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/describe the system as it now is, and this description names any operator steps and wire changes.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code
Note
Medium Risk
Changes lexical token selection for over-threshold queries—a core retrieval path—with nuanced heuristics (function words, paths, hashes), though short queries and wire/API stay unchanged and rollback is a revert.
Overview
Long
code.searchqueries (abovecode_search_query_max_tokens) no longer gate the lexical leg on the rarest tokens in reading order. The trim plan inquery_trim.pynow strips URLs, UUIDs, and commit hashes before tokenizing, scores how often each lexeme appears (with English function words counting only when written as code, and traceback path directories excluded), andselect_termsfills at most 32 slots with identifier whole forms plus about half the list for repeated subject words first.Call sites (
lexical.py, concept expansion incards.py) switch fromselect_raresttoselect_termsand pass richerTrimPlanfields (said,own,named) for callerextra_terms. Docs, schema, and settings text forcode_search_query_max_tokensdescribe the new behavior;query_trimmed_tokens_usedmay report fewer than 32. Unit tests are expanded heavily around the new rules and the search seam.Reviewed by Cursor Bugbot for commit 6f9ae68. Bugbot is set up for automated code reviews on this repo. Configure here.