Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
55901c6
code.calibrate samples its probes from the namespace
KaloyanNaumov Dec 2, 2026
1e33fa6
code.calibrate bounds its probe count and reads one tier's doc comments
KaloyanNaumov Dec 2, 2026
67f7cc5
The probe sampler groups its distractor pool once
KaloyanNaumov Dec 2, 2026
01fa832
Merge upstream main 7278690ba into code-calibrate-namespace-probes
KaloyanNaumov Dec 2, 2026
4b5eafa
The code_calibrate_probes comment drops to two lines
KaloyanNaumov Dec 2, 2026
2224e3e
Merge upstream main into code-calibrate-namespace-probes
KaloyanNaumov Dec 2, 2026
4fd9dd5
Read one chunk per documented function in calibration_units
KaloyanNaumov Dec 2, 2026
d6963d6
Name the doc aggregate apart from its column in calibration_units
KaloyanNaumov Dec 2, 2026
cfc0666
Cover the one-unit-per-function read on real ClickHouse rows
KaloyanNaumov Dec 2, 2026
fddd231
Confirm the generated Go model is current on main
KaloyanNaumov Dec 2, 2026
44d38df
Merge origin/main into the namespace probe calibration line
KaloyanNaumov Dec 3, 2026
5df1a14
code.calibrate keeps a glob that ends a probe query line
KaloyanNaumov Dec 3, 2026
7f0c7e6
code.calibrate output: an older build's reply reads as unknown
KaloyanNaumov Dec 3, 2026
cab53c0
Merge upstream main (cd5041645) into the namespace probe calibration …
KaloyanNaumov Dec 3, 2026
a5ebbc9
code.calibrate: an older build's absent fields stay absent
KaloyanNaumov Dec 3, 2026
40158c0
Format the calibrate previous-build fixture with the pinned Biome
KaloyanNaumov Dec 3, 2026
fba30e8
Merge upstream main (30440ee80) into the namespace probe calibration …
KaloyanNaumov Dec 3, 2026
e474377
Merge upstream main (4947d0294) into the namespace probe calibration …
KaloyanNaumov Dec 4, 2026
f2126ec
code.calibrate round-trip: a present null must not read as a missing key
KaloyanNaumov Dec 4, 2026
4448570
Merge upstream main (a229f49c8) into the namespace probe calibration …
KaloyanNaumov Dec 4, 2026
6b821f1
Merge github/main (5301f2920) into namespace probe calibration line
KaloyanNaumov Dec 4, 2026
fc795eb
Read code-calibration units in batches at the probe ceiling (#2011)
KaloyanNaumov Dec 4, 2026
64a7915
Merge upstream main (8c9e1dd49) into namespace probe calibration line
KaloyanNaumov Dec 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions docs/architecture/llm-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,11 @@ With `LOOM_ADAPTIVE_THRESHOLDS` on (the default), `calibrate_embedder` in
corpora (paraphrase pairs, question-to-fact pairs, distractor pairs) and reads their
cosine distributions (`derive_thresholds`). Memory paraphrases use document/document
vectors; question/fact and distractor pairs use query/document vectors. `code.calibrate`
explicitly uses query/document vectors for its authored query/code positives in both
positive distributions, including the persisted conflict and duplicate gates:
explicitly uses query/document vectors for its query/code positives in both positive
distributions, including the persisted conflict and duplicate gates. Its probes come from
the namespace's documented functions (the doc comment's first paragraph as the query, the
function without it as the positive, a function from another directory as the
distractor), or from a fixed corpus for a namespace with fewer than 20 of them:

| Threshold | Derived as |
| ------------- | ------------------------------------------ |
Expand All @@ -189,6 +192,14 @@ positive distributions, including the persisted conflict and duplicate gates:
| conflict | paraphrase p50 |
| duplicate | paraphrase p75 |

`code.calibrate` then caps abstain at the 10th percentile of the query-to-function
cosines it measured on its sampled probe pairs — up to `LOOM_CODE_CALIBRATE_PROBES`
(200 by default) documented functions, or the fixed corpus for a namespace with fewer
than 20 of them — and keeps the noise floor 0.05 under it. That percentile describes
the 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.

Each search resolves thresholds in three tiers:

1. a per-namespace calibration (`loom.namespace_calibration_result`, written by
Expand Down
2 changes: 1 addition & 1 deletion docs/benchmarks/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ skips paths with a `datasets` segment.
| `bench/fixtures/code_intel_mined_issue_ka.jsonl` | 14 rows | `code_intel_qa.py` | The keyword-agnostic slice (`code_intel_ka_slice.py`) |
| `bench/fixtures/code_intel_history.jsonl` | 105 rows | `code_intel_qa.py` | "What fixed issue N" questions mined from merged PRs |
| `bench/fixtures/code_intel_oss.jsonl` | 304 rows | `code_intel_qa.py` | An MIT-licensed third-party code-search corpus at a pinned revision; model-authored gold |
| `bench/fixtures/code_calibration_probes.jsonl` | 20 query / positive pairs | code calibration (`server/code/app/admin.py`) | Over the ClickHouse repository |
| `bench/fixtures/code_calibration_probes.jsonl` | 20 query / positive pairs | code calibration fallback (`server/code/app/admin.py`) | Over the ClickHouse repository |
| `bench/fixtures/code_plane_ablation/` | 2 tasks, arm A and arm C transcripts | `code_plane_ablation.py selftest`, `acceptance/plugin.py` | Synthetic transcripts that prove the scorer |
| `bench/acceptance/fixtures/shunt_decisions.json` | 12 cases | `acceptance/plugin.py` | Read / Grep decisions the plugin's code shunt must make |
| `bench/code_ask_cache_threshold/pairs.json` | 42 paraphrase, 43 different, 22 different-identifier pairs | `code_ask_cache_threshold/measure.py` | Written from a live `code.ask` cache's questions ([results](./results.md#codeask-answer-cache-threshold)) |
Expand Down
18 changes: 15 additions & 3 deletions docs/operations/code-index-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,21 @@ docker exec loom-workers loom code backfill-prs --namespace code-myrepo --org ac
Then:

- `POST /v1/code.calibrate` (`ADMIN`) derives the code index's abstention thresholds, and
the confident-hit cosine at which `retrieval_confidence` reads 1.0, from
`bench/fixtures/code_calibration_probes.jsonl` (shipped in the image). Run it for
every code namespace, and again after a change of embedding model. A namespace
the confident-hit cosine at which `retrieval_confidence` reads 1.0, from the
namespace's own code. It samples up to `LOOM_CODE_CALIBRATE_PROBES` (200) documented
functions across the namespace's languages and directories. Each probe embeds the first
paragraph of the function's doc comment as the query against the function without that
comment, and against a function from another directory. A namespace with fewer than 20
usable documented functions is calibrated on
`bench/fixtures/code_calibration_probes.jsonl` (shipped in the image) instead;
`probe_source` in a reply from this build says which; a reply from a build before
the field leaves it absent, not `fixture`. The abstain threshold is capped at the
sampled probes' 10th-percentile query-to-function cosine: functions of one repository
share its vocabulary, so an unrelated one scores close to the right one, and the
distractor percentile alone would abstain on many right answers. That percentile is
over the sampled pairs and does not bound abstention for unsampled functions or a
query whose correct hit never enters the candidate set. Run it for every code namespace,
and again after a change of embedding model. A namespace
without its own calibration (`calibration.get` reads `source: cluster`) reads code
on the embedder's boot calibration, which is derived from prose. On an embedding
model that scores a right code hit lower than a right prose answer, answerable
Expand Down
1 change: 1 addition & 0 deletions docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ The code index's network git (clone, fetch, ls-remote, submodule update) through
| `LOOM_CODE_SEARCH_RRF_LEXICAL_WEIGHT_RESPONSIBILITY` | `float` | `1.0` | | Lexical list's RRF weight for a responsibility question (vector = 1.0). 1.0 = equal weights. |
| `LOOM_CODE_SEARCH_ABSTAIN_CARD_BELOW` | `float` | `0.0` | | A prose question whose nearest file card's cosine is below this abstains `off_domain`; independent of the card leg. 0 = off. |
| `LOOM_CODE_SEARCH_ABSTAIN_CONFIDENCE_BELOW` | `float` | `0.35` | | The abstain score below which a code.search result is flagged `low_calibrated_confidence` (still returned). The score is not `retrieval_confidence`: it blends the top cosine, its margin over the second hit, route agreement and the pool size. The deployment sets 0.30. |
| `LOOM_CODE_CALIBRATE_PROBES` | `int` | `200` | | Probes `code.calibrate` samples from a namespace's documented functions, three embeddings each and no LLM call; under 20 usable probes it uses the fixed corpus. |
| `LOOM_CODE_SEARCH_MEDIUM_RISK_FROM` | `float` | `0.35` | | The `retrieval_confidence` from which a code.search result reads `retrieval_risk` "medium"; below it the result reads "high". In the measurement behind the default about half of the prompts sent to another repository's index scored under it. |
| `LOOM_CODE_SEARCH_LOW_RISK_FROM` | `float` | `0.7` | | The `retrieval_confidence` from which a code.search result reads `retrieval_risk` "low": the best cosine is close to that of a confident hit. A prompt about other code usually scores lower, but about one in five sent to another repository's index still read low. With `LOOM_PROMPT_PACK_MIN_CONF` unset the coding-agent plugins send their prompt pointers from it and, for a bug report, below it the first pick of an answer the pick model words `high` or `medium`. |
| `LOOM_CODE_SEARCH_HYDE_KINDS` | `str` | `'responsibility'` | | The question kinds the hypothetical answer votes on. |
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Fields for every `code` op: [operations/code.md](operations/code.md).
| [`code.backport_gaps`](operations/code.md#codebackport_gaps) | The set-wide backport report: which merged fixes labelled for backport does a release branch still owe? | viewer | read | no | |
| [`code.bisect_candidates`](operations/code.md#codebisect_candidates) | Rank PRs that may have introduced a bug; Loom does not test or reproduce it. | viewer | read | no | |
| [`code.blame_range`](operations/code.md#codeblame_range) | Which merged PRs last touched these lines, between release A and B? | viewer | read | no | |
| [`code.calibrate`](operations/code.md#codecalibrate) | Derive this namespace's calibration from the authored probe corpus and persist it: the code-specific abstention thresholds and the confident-hit cosine at the top of the `retrieval_confidence` scale. | admin | write | no | yes |
| [`code.calibrate`](operations/code.md#codecalibrate) | Derive this namespace's calibration and persist it: the code-specific abstention thresholds and the confident-hit cosine at the top of the `retrieval_confidence` scale. | admin | write | no | yes |
| [`code.callees`](operations/code.md#codecallees) | What does this symbol call — forward call edges (depth<=3), tier-marked like code.callers. | viewer | read | no | |
| [`code.callers`](operations/code.md#codecallers) | Find callers before editing shared code. | viewer | read | yes | |
| [`code.context_pack`](operations/code.md#codecontext_pack) | Briefing at the START of a task, instead of exploring file by file. | viewer | read | yes | |
Expand Down
12 changes: 7 additions & 5 deletions docs/reference/operations/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Which merged PRs last touched these lines, between release A and B?

## `code.calibrate`

Derive this namespace's calibration from the authored probe corpus and persist it: the code-specific abstention thresholds and the confident-hit cosine at the top of the `retrieval_confidence` scale.
Derive this namespace's calibration and persist it: the code-specific abstention thresholds and the confident-hit cosine at the top of the `retrieval_confidence` scale.

`POST /v1/code.calibrate` · MCP `loom_code_calibrate` · role `admin` · write · audited · not listed under the MCP `all` toolset

Expand All @@ -254,12 +254,14 @@ Derive this namespace's calibration from the authored probe corpus and persist i

| Output field | Type | Meaning |
| --- | --- | --- |
| `noise_floor` | `float` | Cosine below which a hit is noise: the distractors' 90th percentile plus 0.02. |
| `abstain_threshold` | `float` | Cosine below which the search abstains: `noise_floor` plus 0.05. |
| `noise_floor` | `float` | Cosine below which a hit is noise: the distractors' 90th percentile plus 0.02, or 0.05 under the abstain threshold when that is capped, whichever is lower. |
| `abstain_threshold` | `float` | Cosine below which the search abstains: `noise_floor` plus 0.05, or the probes' 10th-percentile question-to-answer cosine when that is lower. |
| `rerank_skip_above` | `float` | Cosine of a confident hit, the probes' 75th-percentile question-to-answer cosine: where `code.search`'s `retrieval_confidence` reads 1.0. |
| `embedder_model` | `str` | The embedding model the probes ran against; the calibration applies to it. |
| `positives` | `int` | Query/positive pairs read from the probe corpus. |
| `distractors` | `int` | Query/distractor pairs read from the probe corpus. |
| `positives` | `int` | Query/positive pairs the thresholds were derived from. |
| `distractors` | `int` | Query/distractor pairs the thresholds were derived from. |
| `probe_source` | `Literal['namespace', 'fixture'] \| None` | Where the probes came from: `namespace` (its own documented functions) or `fixture` (the fixed corpus); a reply from a build before the field leaves it absent, not `fixture`. |
| `strata` | `int \| None` | Language-and-directory strata the namespace probes were drawn from; 0 for the fixture; a reply from a build before the field leaves it absent, not the fixture. |

## `code.callees`

Expand Down
5 changes: 5 additions & 0 deletions loom.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,11 @@ settings:
# route agreement and the pool size. The deployment sets 0.30. [restart]
# code_search_abstain_confidence_below: 0.35

# Probes `code.calibrate` samples from a namespace's documented functions, three
# embeddings each and no LLM call; under 20 usable probes it uses the fixed corpus.
# [restart]
# code_calibrate_probes: 200

# The `retrieval_confidence` from which a code.search result reads `retrieval_risk`
# "medium"; below it the result reads "high". In the measurement behind the default
# about half of the prompts sent to another repository's index scored under it.
Expand Down
7 changes: 7 additions & 0 deletions schemas/loom-settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,13 @@
"type": "string",
"description": "Comma-separated GitHub logins of autonomous agents that author pull requests or issues in the indexed repositories, beyond the generic bots (dependabot, github-actions, …). They are never suggested as owners, their names are not tracker entities, and bisect ignores the lines they sign."
},
"code_calibrate_probes": {
"default": 200,
"maximum": 1000,
"minimum": 20,
"type": "integer",
"description": "Probes `code.calibrate` samples from a namespace's documented functions, three embeddings each and no LLM call; under 20 usable probes it uses the fixed corpus."
},
"code_calibration_enabled": {
"default": false,
"type": "boolean",
Expand Down
21 changes: 20 additions & 1 deletion scripts/codegen/sdk_rust_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,16 @@ def field(
# JSON value uses Value::Null directly, without an extra Option.
raw = override or self.wire_type(base, model + pascal(wire))
nullable = nullable and raw != "Value"
# A response field marked presence-absent keeps a missing key distinct from an
# explicit null: the outer Option is absence, the inner one is the JSON null.
presence = (
not request and not required and nullable and prop.get("x-loom-presence") == "absent"
)
optional = request and not required
ty = f"Option<{raw}>" if nullable else raw
if optional or (not request and not required and "default" not in prop and not nullable):
if presence:
ty = f"Option<Option<{raw}>>"
elif optional or (not request and not required and "default" not in prop and not nullable):
ty = f"Option<{ty}>"
attrs = [f"rename = {rust_string(wire)}"] if field != wire else []
if optional:
Expand All @@ -425,6 +432,12 @@ def field(
'skip_serializing_if = "Option::is_none"',
f'deserialize_with = "{"present_nullable" if nullable else "present_value"}"',
]
elif presence:
attrs += [
self.default_attr(prop, ty),
'skip_serializing_if = "Option::is_none"',
'deserialize_with = "present_nullable"',
]
elif not required:
attrs += [self.default_attr(prop, ty)]
if required and nullable:
Expand Down Expand Up @@ -881,6 +894,12 @@ def build_contract_tests(selected: tuple[str, ...] | None = None) -> str:
if not request and not schema.get("_rust_projected"):
for key, prop in schema["properties"].items():
if key not in schema.get("required", []) and "default" in prop:
if prop.get("x-loom-presence") == "absent":
lines.append(
f"assert!(encoded.get({rust_string(key)}).is_none(), "
f"{rust_string(op.name + ':' + key + ' absent')});"
)
continue
value = prop["default"]
# JSON Schema may describe a float default with an integer token.
if split_nullable(prop)[0].get("type") == "number" and value is not None:
Expand Down
4 changes: 3 additions & 1 deletion sdk/go/wire/models.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sdk/python/loom/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -6077,6 +6077,8 @@ class CodeCalibrateOutput(TypedDict, total=False):
embedder_model: Required[str]
positives: Required[int]
distractors: Required[int]
probe_source: NotRequired[Optional[Literal["namespace", "fixture"]]]
strata: NotRequired[Optional[int]]


class CodeCallersInput(TypedDict, total=False):
Expand Down
Loading