Repository navigation
code.calibrate samples its probes from the namespace's own code - #2011
KaloyanNaumov wants to merge 48 commits into
Conversation
code.calibrate read a fixed corpus of 20 ClickHouse C++ probes, so every code namespace on one embedder got the same thresholds. It now samples up to code_calibrate_probes (200) documented functions of the namespace, round-robin across language and directory strata: the first paragraph of the doc comment is the query, the function without its doc comment is the positive, and a function from another stratum is the distractor. A namespace with fewer than 20 usable probes falls back to the fixed corpus. The reply names the source and the strata. Distractors from the same repository share its vocabulary: on bge-m3 their 90th percentile is 0.50 to 0.53, so the distractor-only derivation puts abstain at 0.57 to 0.60, above 29 to 42 percent of the namespace's own query/function pairs. code.calibrate therefore caps abstain at the positives' 10th percentile and keeps the noise floor 0.05 under it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
`code_calibrate_probes` is now 20 to 1000. A negative value failed in ClickHouse, a value under 20 silently meant the fixed corpus, and a large one fanned out an embedding request per pair at once. The doc-comment read took `any(doc_comment)` over both index tiers, which write rows under one symbol id. A merge of the SCIP tier could therefore change the drawn probes. It now reads the tree-sitter tier, whose ids the chunks carry. The `noise_floor` and `abstain_threshold` field docs now say what the capped derivation does, and the setting says that three embeddings per probe counts the embedding cache. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
Each probe re-parsed every pool path to pick a distractor from another stratum: size x 5 x size path parses on the event loop, 3.0 s at the default 200 probes and 75 s at the bound of 1,000 on Sonique. The pool's strata are now read once and the other-strata list is built once per stratum. The draws are the same as before, so the probes of a namespace do not change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The only conflict was the generated sdk/go/wire/models.gen.go. It takes main's copy, regenerated with scripts/codegen/sdk_go_gen.py. Every other generator reports its outputs current on the merged tree. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The field comment feeds the generated configuration reference, the settings schema and the example config, regenerated with their generators. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Hand-resolved conflicts: - sdk/go/wire/models.gen.go: header registry-schema hash differed on both sides (generated file); took upstream's side and regenerated with sdk_go_gen, which also refreshed the Go wire models and client. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
An oversized function is stored as several function chunks that share one symbol id. The documented-unit read matched any chunk carrying a documented id, so the tail pieces of such a function became positives for a doc comment they do not answer. Select only chunks whose own symbol (the first of symbol_ids) is a documented one, and keep one per symbol, the piece with the lowest start line, so each documented function yields one positive holding its start line and doc. The test asserts the read's shape and that the unit pairs the first piece with its doc. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
The documented-symbol read aliased any(doc_comment) AS doc_comment and filtered doc_comment != '' in the WHERE. ClickHouse resolves that name to the aggregate and refuses the query (ILLEGAL_AGGREGATION, seen on 26.10.8 and 26.12), so code.calibrate failed on every namespace against a real server; the unit tests answer from a fake and never ran the statement. Alias the aggregate doc, so the WHERE reads the column. A live-ClickHouse test runs calibration_units over real rows: it fails on the old statement with that error and passes now. It covers a documented and an undocumented function, a SCIP-tier row under the same id (which must not change the drawn doc), a tombstoned chunk and the pool read. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
Extend the live calibration_units test with an oversized function stored as three chunks of one symbol and a nested function's chunk whose first symbol is undocumented. The read must give the documented function one unit holding its first piece and its doc, and must not turn the nested chunk into a unit for the outer function's doc. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
zlareb1
left a comment
There was a problem hiding this comment.
The document-to-chunk finding blocks approval. A split function can contribute several positives with the same question and a different fragment as the answer. Distinct documented functions should supply the probes and determine whether there are enough to use namespace calibration. GitHub also reports a merge conflict with main. Please resolve it so CI can test the combined tree.
zlareb1
left a comment
There was a problem hiding this comment.
The calibration query now takes the first chunk per documented function and uses a separate name for the doc aggregate. The 34 focused calibration tests passed. The new ClickHouse test covers the store query in CI.
|
Both points are addressed at cfc0666, pushed after this review (it is on 4b5eafa). |
zlareb1
left a comment
There was a problem hiding this comment.
GitHub reports a conflict with main in sdk/go/wire/models.gen.go. Reconcile the wire schema and regenerate the Go model.
GitHub reported sdk/go/wire/models.gen.go as conflicting with main. Main had not changed that file since this branch's base (git diff 60be594 3d29643 -- sdk/go/wire/models.gen.go is empty), and the merge is clean. `python -m scripts.codegen.sdk_go_gen --check`, with gofmt supplied from the golang:1.26 image, reports sdk/go/wire/models.gen.go and sdk/go/client.gen.go current against the registry model schema SHA 5bc197c6 and leaves git status clean, so nothing in the generated output is hand-written. The other generated artefacts are current on the merged tree too: sdk_py_gen, sdk_ts_gen, sdk_rb_gen, sdk_rust_gen and docs_reference all report current. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
Merged main and checked the generator rather than trusting it: Main had not touched that file since this branch's base, so the merge is clean rather than a resolution. The rest of the generated surface is current on the merged tree too — |
sdk/go/wire/models.gen.go conflicted on its schema digest. The conflict was cleared by taking one side, then scripts.codegen.sdk_go_gen rewrote the file, which now carries main's at_commit fields and memory.for_file printed row alongside this line's changes. Every other generator --check passed with no rewrite. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
Merged main and regenerated rather than resolved: the only conflict was the schema digest line in Every other generator reports current without a rewrite. 145 passed across the SDK and calibration files. |
zlareb1
left a comment
There was a problem hiding this comment.
The open probe-query finding still applies after the Go model conflict was resolved. Preserve the punctuation in a documented query and add a case for a line ending in a path glob.
`probe_query` removed trailing `*` and `/` from every comment line as a set of characters, so a documented description ending in a path glob (`testdata/*`) lost the glob before it was embedded as a query. Only the block-comment closer `*/` is removed now, so the punctuation a question ends in survives. `test_probe_query_keeps_a_glob_that_ends_a_line` covers both: a line ending in a glob keeps its `*`, and a `*/` closer still comes off. Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
@KaloyanNaumov: can this PR also turn on Why on:
Why here and not before this PR lands: the row is keyed by |
zlareb1
left a comment
There was a problem hiding this comment.
The glob fix passes the focused calibration suite (35 tests). The output additions need to tolerate replies from a replica running the previous build.
The branch adds `probe_source` and `strata` to `code.calibrate`'s output. During a code-only rollout the call can land on a replica of the previous build, whose reply carries neither field. Required output fields made that reply fail validation; a default of 0 or "fixture" would misread it as the fixture. Rule 4 says N reads the old and the new wire format, so both fields are now nullable with a None default: unknown because an older replica answered, not empty. This build still writes both fields. The generated Rust contract decodes the old shape and asserts null, the Python model test does the same, and the operations page says an older reply reads as unknown. Assisted-by: Hermes:deepseek-v4.1-flash-1017 Signed-off-by: Kaloyan Naumov <knaumov@gmail.com>
|
The output additions now survive a reply from a replica running the previous build. 7f0c7e6
Rule 4 (N reads the old and the new format; only N+1 writes the new one) and rule 6 (an N−1 replica still answers during a code-only release) are what the shape follows. The operations guide and the reference page are updated in the same commit. Red was the old model reading a reply without the fields: One thing this commit is, and the body should say plainly: a wire break for consumers. Both fields become optional in all five SDKs — |
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
… probe phase The abstain cap now applies inside derive_thresholds, before the trigger gates are clamped to the floor, so rerank_skip_above stays the probes' p75 under the cap. Each probe phase runs in a TaskGroup, so a failed pair cancels the rest, and a pair already measured is not embedded again. The documented read drops test files before its limit, through query_all_sliced. A missing embedder's error names its kind only, block closers match in lower case only, and the worker logs the probe source it used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
zlareb1
left a comment
There was a problem hiding this comment.
The focused calibration suite passed 65 tests. A controlled provider failure reproduced an embedding call that outlives the failed calibration. The inline finding describes the missing cancellation boundary.
| async with in_flight: | ||
| with customer.system(): | ||
| if query: | ||
| va, documents = await asyncio.gather( |
There was a problem hiding this comment.
P2 — If the query embedding raises while the document embedding is still pending, gather propagates the error and leaves the document call running. The outer TaskGroup sees a finished pair, so calibration returns and releases its semaphore while the provider request remains active. A stub that waits for the document call to start before raising reproduces this: calibrate_embedder returns None before the document call reaches its cleanup. Own both calls in a TaskGroup inside the pair and test that a failing query cancels and joins the document call before returning.
…d raw docstrings A cap applied when the distractors' p90 reaches the probes' p75 gave an unrelated function full confidence; such a calibration now keeps its distractor floor and has no confidence scale. Raw and unicode docstring prefixes no longer reach the query. The documented-chunk read is one SELECT, and the live test proves its kind, vector and test-file filters with rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
… query Most documented Go functions open their doc comment with the function's name, which their positive also carries, so the probe asked with the identifier a real question seldom names. The symbols read now returns the name and drops test files with the same pattern as is_test_path; the wire and calibration.get descriptions name the abstain cap, and the probe's concurrency is a named constant. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…d budget text The documented-units read already drops test files, so sample_probes no longer checks them. A distractor keeps its doc comment because search compares a query with the chunk as indexed; the docs and module docstring say so. The code.calibrate budget comment names the work it covers, and the recalibration bullet no longer claims a per-namespace re-probe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
| ) | ||
| vb = documents[0] | ||
| else: | ||
| va, vb = await embedder.embed_many([a, b]) |
There was a problem hiding this comment.
Failed probe leaves embed running
Medium Severity
In _embed_pair, asyncio.gather returns as soon as embed raises and does not cancel the in-flight embed_many. The pair task then exits, so the TaskGroup finishes and releases in_flight while that document embedding is still running. calibrate_embedder returns None and the provider request stays active past the probe.
Reviewed by Cursor Bugbot for commit b53de5d. Configure here.
A chunk over the model's input limit (Gemini's 2048 tokens) was sent whole, the provider refused it, and the phase failed on every rerun of the same draw. Ingest embeds such a chunk by its head; the probe now clips to the same limit. Under 20 documented units the fixed corpus is certain, so the distractor pool is no longer read: the store read is split into calibration_units and calibration_pool. The docs, the calibrate_embedder docstring and the worker's pass comment describe the current behaviour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
…test the late fallback Each picked stratum built its own copy of the pool, up to ~5M references at the 1,000-probe ceiling; the pool is now sorted by stratum and file once and a distractor is drawn from outside the probe's run in place. Tests cover the fixture fallback after sampling (one file, no usable doc comment) and the one-stratum draw from another file. The input-token limit is named max_tokens, apart from the row limits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
zlareb1
left a comment
There was a problem hiding this comment.
The current head still returns from a failed calibration while the paired document embedding is active. The existing inline finding still applies. A controlled provider failure reproduced it on this head.
The 71 focused tests passed. The new inline finding covers a case outside that suite.
| last = next((i for i in range(first, end) if doc[-1] in lines[i]), first) | ||
| if last + 1 < len(lines) and lines[last + 1].strip() in ('"""', "'''", "*/"): | ||
| last += 1 | ||
| lines = lines[:first] + lines[last + 1 :] |
There was a problem hiding this comment.
P2 — Removing the docstring also removes the function body when it shares the same source line. Parsing and chunking def total(): """Return the sum of both page counts."""; return 123 + 456 produces a calibration positive with only the context header. Strip the docstring without dropping the surrounding code and test a one-line function through the chunk path.
The docs and handler docstrings said a namespace falls back under 20 documented functions; the guard counts probes that also have a distractor, and with one stratum the distractor comes from another file. The sorted lists the draw bisects are named for their order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
zlareb1
left a comment
There was a problem hiding this comment.
The two open findings still reproduce on this head. The failed embedding returns before its paired request finishes, and docstring removal can discard the function body. The focused calibration suite passed 71 tests.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Reviewed by Cursor Bugbot for commit 3236b87. Configure here.
| last = next((i for i in range(first, end) if doc[-1] in lines[i]), first) | ||
| if last + 1 < len(lines) and lines[last + 1].strip() in ('"""', "'''", "*/"): | ||
| last += 1 | ||
| lines = lines[:first] + lines[last + 1 :] |
There was a problem hiding this comment.
Docstring strip drops same-line code
Medium Severity
without_doc drops every source line that contains the doc comment, not just the comment text. A one-line function keeps its body on that same line, and chunking also prepends the doc, so the second match deletes the declaration and body. The probe positive is only the context header, so those pairs no longer measure query-to-function similarity.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 3236b87. Configure here.
…s alone A distractor comes from another language or another directory two levels deep, and from another file only when every function shares one of each; the docs said "only one". Each distractor comes with a positive, so the fallback guard counts distractors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
The clip covered only a provider that states its input limit. An OpenAI-compatible endpoint states none, and one that refuses long input (413, or 400 past its context) failed the phase on every rerun of the same draw. The probe now embeds each document through embed_shrinking, the halving ingest stored the chunk's vector with, so a chunk that was indexed can be probed. embed_shrinking and looks_too_long move to server/embedding/documents.py, where the memory plane's calibration can reach them; the clip in the handler is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
a8ef2ba to
64a7915
Compare
…ngest did looks_too_long matched OpenAI's tokens-per-minute 429, whose detail names type=tokens, so embed_shrinking halved the text after the retries ran out and the next call stored or measured a cut text. A retryable status is now never a length refusal, for ingest's per-text fallback, embed recovery and code.calibrate alike. The probe texts also go through ingest's clip_for_embedding first, so a chunk over 20,000 characters is measured by the head ingest embedded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
Signed-off-by: Lareb Zafar <lareb.zafar@clickhouse.com>
zlareb1
left a comment
There was a problem hiding this comment.
Both open findings reproduce on this head. A stub query failure still returns while the paired document request is running, and stripping a same-line docstring still leaves only the chunk header. All 87 focused calibration and embedder tests passed. Request cleanup · Probe body
zlareb1
left a comment
There was a problem hiding this comment.
Both integration failures reproduce on the clean CI base. The curator assertion reverses two proposals created in the same second, and the skill draft assertion omits the binding field. The fixes are on main. Curator PR job · Main job · Fix #2334. Skill draft PR job · Main job · Fix #2331.


TL;DR:
code.calibratenow samples its probes from the namespace's own documented functions instead of a fixed corpus, so a namespace's thresholds come from its own answers. Same-repository distractors score high, so abstain is capped at the probes' 10th-percentile query-to-function cosine; throughcode.calibrateon three repositories it lands at 0.490 to 0.516, against 0.487 from the fixed corpus. A namespace with fewer than 20 usable functions still uses the fixed corpus.Related: #1558
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.calibratederives a code namespace's thresholds from up toLOOM_CODE_CALIBRATE_PROBES(200) of its own documented functions, with the fixed probe corpus as the fallback for a small namespace, and reports which source it used.Why
code.calibratereadbench/fixtures/code_calibration_probes.jsonl, 20 probes over ClickHouse's C++ sources. The namespace argument only named where the row was stored, so every code namespace on one embedder got identical thresholds (#1558).A documented function is a query and an answer the repository already wrote. The first paragraph of its doc comment is the query. The positive is the function's embedded text with every copy of the doc comment removed (a Python chunk can carry the docstring twice). A leading copy of the function's name is dropped from the query: Go opens a doc comment with it (33,927 of 41,555 documented Go functions on a running deployment, against at most 8% in every other language), and a question seldom names the function its answer is. The distractor keeps its own doc comment: it stands for a wrong hit, and every chunk search ranks carries its doc. A positive with its doc left in would score the query against its own text. The distractor is a function from another language-and-directory stratum. Probes are drawn round-robin across strata, in an order seeded by the namespace, so one directory does not dominate and a rerun on an unchanged index reads the same probes. A probe text the provider refuses as too long is halved and sent again, as ingest did before storing the chunk's vector (
embed_shrinking, which moves toserver/embedding/documents.pyso the calibration can use it). Without it a chunk over Gemini's 2048 tokens, or over the context of an OpenAI-compatible server that refuses long input, would fail the phase on every rerun of the same draw. With fewer than 20 documented functions the fixed corpus is certain, and the distractor pool is not read.Measured with bge-m3 (CLS pooling, normalised, as TEI serves it) on three repositories, 200 probes each. Run on the fixed corpus, the same embedder gives abstain 0.4873, against 0.48637 from TEI.
server/(Python)vllm/(Python)Functions from one repository share its vocabulary, so an unrelated function scores 0.50 to 0.53 against a query. With the distractor-only rule, abstain lands above about a third of the namespace's own right answers. That is the over-abstention #1558 reports, coming from the code side this time. The cap keeps abstain at the 10th percentile of the query-to-function cosines measured on the sampled probe pairs (up to
LOOM_CODE_CALIBRATE_PROBES, 200 by default). That percentile describes those sampled pairs, not the namespace: it places no bound on how often search abstains for a function the sample did not draw, or for a query whose correct hit never enters the candidate set. The noise floor stays 0.05 under abstain, andcode.searchreads it only as a stand-in when the vector leg is off. The cap applies insidederive_thresholds, before the query-rewrite, HyDE and rerank-skip gates are clamped to the floor, so the confident-hit cosine stays the probes' 75th percentile under the cap. When the distractors' 90th percentile reaches the probes' 75th, no cosine separates a right function from an unrelated one: the cap is skipped and the calibration keeps no confidence scale, as an uncapped one does.Harder distractors make it worse. A function from the same directory gives distractor p90 0.55 to 0.56 and abstain 0.62 to 0.63, above 57 to 63 percent of the right answers. Distractors therefore come from another stratum.
On the 19 queries from #1558, the top-hit similarity of a correct rank-1 result does not depend on the calibration. So the issue's quoted values give the abstention under each threshold:
The remaining one scores 0.44 and sits under every threshold. Bootstrap spread of the abstain threshold is 0.015 to 0.022 at 20 probes and 0.006 to 0.011 at 100, which is why the fallback starts under 20.
The same comparison through
code.calibrateitself, on stored rows copied from a running deployment (chunks, symbols and bge-m3 vectors; the query side embedded by the same bge-m3 weights), 200 probes per namespace:probe_sourcefixturenamespacenamespacenamespaceThe two Python and TypeScript repositories land together; the C++/SYCL one sits 0.025 lower, about three times the sampling spread at 200 probes. The cap was the binding rule in all three.
Scope and risk
code.calibrateonly: the probe source and the cap. Memory calibration and the cluster probe derive their gates as before (the cap is a flag onlycode.calibratesets); memory calibration shares the probe's changes below. Three reads per run: the namespace's documented function symbols, their live chunks under the served embedding label, and a pool of live function chunks. Each read is capped at five times the probe count and ordered bycityHash64of the id. One run costs three embeddings per probe (four with the embedding cache off, as in thecode_calibrationworker) and no LLM call: a pair passed as both positive corpora is embedded once.calibrate_embeddersends eight pairs at a time, so at most 16 embedding calls are in flight at any probe count, and a failed pair cancels the rest of its phase. At the default 200 probes that is 50 rounds of one query and one document embedding. The three reads, measured withsystem.query_logon the largest code namespace of a running deployment (328,619 live function chunks) at the default: documented symbols 1.12M rows, 218 MiB, 457 ms; their first chunks 1.07M rows, 1.27 GiB, 1,524 ms; the pool 1.07M rows, 1.21 GiB, 1,183 ms; peak memory 288 MiB. A calibration runs once per namespace and embedder.This does not trigger calibration on its own, and it does not change the code-owned fallback thresholds planned in #1558.
Compatibility, rollout and rollback
code.calibratereturns two new fields,probe_source(namespaceorfixture) andstrata.positivesanddistractorsnow count the pairs used from either source.LOOM_CODE_CALIBRATE_PROBES(200). Reruncode.calibrateon each code namespace to replace a fixture-derived row.loom.namespace_calibration_result; they serve until the nextcode.calibrate.Tests
tests/unit/test_embedder_calibration.pychecks that 200 pairs keep at most 16 embedding calls in flight and embed the positives once, that a failed pair stops its phase, and that the cap moves the trigger gates with the floor.tests/unit/test_code_calibration_probes.pycovers query extraction (Python docstrings, C++//and/** @brief */, comments that do not describe the unit) and doc removal, including a docstring carried twice. It also covers stratified sampling, stable draws per namespace, distractors from another stratum (another file when there is one), the store reads (RecordingCH), the namespace and fixture paths of the handler (under 20 documented functions no pool is read; one file, or no usable doc comment, falls back after sampling), probe texts shrunk under a provider that refuses long inputs with or without a stated limit, and the cap. The existing fixture test intest_embedder_calibration.pynow runs through the fallback.tests/integration/test_code_calibration_units_live_ch.pyruns the store reads against a real ClickHouse (a class skeleton, an unembedded stub and a documented test function are left out; each of those filters fails the test when removed): a documented and an undocumented function, a SCIP-tier row under the same id, a tombstoned chunk, a function split into two chunks (one positive, the first piece), and the pool. It caught an aggregate alias the server rejects (ILLEGAL_AGGREGATION) that the recorded-statement tests could not. Ranruff check,ruff format --check, mypy on the touched modules, the mypy and function-length gates, every codegen--check, and the touched tests.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. I checked the measurement and every line of the diff.
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), the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py) and the standalone skill bundles (python3 scripts/codegen/standalone_skills.py).main; no merged migration is edited.hooks/,lib/,bin/,skills/,.mcp.json, the Codexplugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.npm --prefix frontend run build) and its tests pass, iffrontend/changed.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.Note
Medium Risk
Changes how every code namespace's search abstention and
retrieval_confidencescale are computed; operators must re-runcode.calibrateto refresh stored rows, and wrong caps could still over- or under-abstain on repos with weak doc comments.Overview
code.calibratenow builds abstention thresholds from each code namespace's own indexed functions instead of the sharedcode_calibration_probes.jsonlfixture. It reads up toLOOM_CODE_CALIBRATE_PROBES(default 200) documented function chunks from ClickHouse, turns each doc comment's first paragraph into a query, uses the embedded unit text with the doc stripped as the positive, and pairs a distractor from another language/directory stratum (or another file when the repo is homogeneous). Namespaces with fewer than 20 usable probe pairs still use the fixture; the response addsprobe_source(namespace|fixture) andstrata.To avoid over-abstaining when same-repo distractors score almost as high as correct hits, threshold derivation gains
cap_at_answers: for code calibration only, abstain is capped at the probes' 10th-percentile query→function cosine (noise floor 0.05 below), unless distractor p90 reaches positive p75—in which case the cap is skipped.Embedder calibration is tightened for large probe runs: bounded in-flight embedding calls, one embed per pair when positives serve both paraphrase and question-fact roles,
embed_shrinkingon oversize probe texts, andembed_shrinkingis moved fromserver/code/app/index/embed_text.pytoserver/embedding/documents.py(shared by ingest, embed recovery, and calibration). Docs, settings schema, SDK types, and tests cover the new behavior and CH read limits at max probe count.Reviewed by Cursor Bugbot for commit e7ec5e8. Bugbot is set up for automated code reviews on this repo. Configure here.