Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 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
0535cde
Merge main (15d0fe18ee) into the namespace probe calibration line
zlareb1 Dec 5, 2026
ace2294
Merge main (15d0fe18ee) into the namespace probe calibration line
zlareb1 Dec 5, 2026
a605eaa
Bound code.calibrate's embedding calls and drop the presence extension
zlareb1 Dec 5, 2026
854b0bc
Merge origin/main into pr/code-calibrate-namespace-probes
zlareb1 Dec 5, 2026
79ae18a
Derive code.calibrate's gates from the capped floor and stop a failed…
zlareb1 Dec 5, 2026
adba450
Merge origin/main into pr/code-calibrate-namespace-probes
zlareb1 Dec 5, 2026
b2ef5d1
Count the uncached embedding in the code_calibrate_probes description
zlareb1 Dec 5, 2026
c17cb21
Skip code.calibrate's cap when distractors pass most answers, and rea…
zlareb1 Dec 5, 2026
5324626
Merge origin/main into pr/code-calibrate-namespace-probes
zlareb1 Dec 5, 2026
bd0f9a3
Drop the name a Go doc comment opens with from code.calibrate's probe…
zlareb1 Dec 5, 2026
3279a65
Merge origin/main into pr/code-calibrate-namespace-probes
zlareb1 Dec 5, 2026
1f7d03f
code.calibrate: drop the dead test-file skip and correct the probe an…
zlareb1 Dec 5, 2026
b53de5d
Merge origin/main into pr/code-calibrate-namespace-probes
zlareb1 Dec 5, 2026
b7540d4
code.calibrate: clip each probe text to the embedder's input limit
zlareb1 Dec 5, 2026
875acef
Merge origin/main into pr/code-calibrate-namespace-probes
zlareb1 Dec 5, 2026
a957555
code.calibrate: draw distractors without per-stratum pool copies and …
zlareb1 Dec 5, 2026
200e91a
Merge origin/main into pr/code-calibrate-namespace-probes
zlareb1 Dec 5, 2026
b170cf4
code.calibrate: state the fallback as probes with a distractor
zlareb1 Dec 5, 2026
3236b87
Merge origin/main into pr/code-calibrate-namespace-probes
zlareb1 Dec 5, 2026
d76a394
code.calibrate: name the distractor's stratum and guard on distractor…
zlareb1 Dec 5, 2026
3290fb7
Merge origin/main into pr/code-calibrate-namespace-probes
zlareb1 Dec 5, 2026
a77fabe
code.calibrate: shrink a probe text the provider refuses, as ingest did
zlareb1 Dec 5, 2026
a8ef2ba
Merge origin/main into pr/code-calibrate-namespace-probes
zlareb1 Dec 5, 2026
cd61fb2
embedding: never shrink a text on a retryable error; clip probes as i…
zlareb1 Dec 5, 2026
e7ec5e8
Merge origin/main into pr/code-calibrate-namespace-probes
zlareb1 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
24 changes: 19 additions & 5 deletions docs/architecture/llm-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,13 @@ 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 in another language or another
directory two levels deep as the distractor, or another file when every function shares
one language and directory), or from a fixed corpus for a namespace that yields fewer
than 20 such probes:

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

`code.calibrate` caps abstain at the 10th percentile of the query-to-function cosines
it measured on its probe pairs (up to `LOOM_CODE_CALIBRATE_PROBES`, 200 by default, or
the fixed corpus) and keeps the noise floor 0.05 under it; the trigger gates are then
clamped to that floor. When the distractors' 90th percentile reaches the pairs' 75th,
no cosine separates a right function from an unrelated one, so the cap is skipped and
the calibration has no confidence scale. The 10th-percentile cap describes the probe
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 All @@ -213,9 +227,9 @@ Each search resolves thresholds in three tiers:
- With adaptivity off and a real embedder other than `text-embedding-3-small` (the model
the scalar gates were tuned for), boot logs a warning. You own re-benching.
- The `recalibration` worker (weekly, `LOOM_RECALIBRATION_ENABLED`, on the leader)
re-runs the probe, publishes the result as the cluster calibration,
warns on a drift of 0.05 or more, and re-probes namespace corpora with at least 5
similar and 3 distractor pairs.
re-runs the probe, publishes the result as the cluster calibration and warns on a
drift of 0.05 or more. Per-namespace calibrations come only from `code.calibrate`,
which the `code_calibration` worker also runs (`LOOM_CODE_CALIBRATION_ENABLED`).

**Why.** Deriving thresholds from the model's own distribution makes an embedder swap a
configuration change. The cost: thresholds are statistical. A namespace corpus whose
Expand Down
2 changes: 1 addition & 1 deletion docs/benchmarks/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,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
32 changes: 23 additions & 9 deletions docs/operations/code-index-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,29 @@ 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
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
searches then read `medium` or `high`, and with `LOOM_PROMPT_PACK_MIN_CONF` unset the
coding-agent plugins send one search pointer there, the first pick, only for a bug
report whose answer the pick model words `high` or `medium`
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 in another language or another directory two levels
deep (another file when every function shares one language and directory). A
namespace that yields fewer than 20 probes with both a usable query and a distractor
is calibrated on `bench/fixtures/code_calibration_probes.jsonl` (shipped in the image)
instead; `probe_source` in the reply says which. The abstain threshold is capped at the
probes' 10th-percentile query-to-function cosine: functions of one repository share
its vocabulary, so an unrelated one, read as indexed with its doc comment, scores
close to the right one read without it, and the distractor percentile alone would
abstain on many right answers. The cap is skipped when the distractors' 90th
percentile reaches the probes' 75th. The 10th-percentile cap is over the probe 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 searches then read `medium` or
`high`, and with `LOOM_PROMPT_PACK_MIN_CONF` unset the coding-agent plugins send one
search pointer there, the first pick, only for a bug report whose answer the pick
model words `high` or `medium`
([the pick](../features/integrations/claude-code.md#model-picked-pointers-for-a-bug-report)).
- `loom code describe --top-pct 20` (optional, LLM cost) writes one-line descriptions for
the most central chunks. `--limit N` starts at most N description calls. `--max-usd D`
Expand Down
1 change: 1 addition & 0 deletions docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,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 (four uncached) 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
6 changes: 3 additions & 3 deletions docs/reference/operations/calibration.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ Resolve the active calibration for (org, namespace): per-namespace, then cluster
| --- | --- | --- |
| `source` | `str` | "namespace" / "cluster" / "scalar" |
| `embedder_model` | `str` | The embedder the thresholds were derived for; with `scalar`, the configured model. |
| `noise_floor` | `float` | Cosine below which a search hit is dropped as noise (distractor P90 + 0.02 when probed). |
| `noise_floor` | `float` | Cosine below which a search hit is dropped as noise (distractor P90 + 0.02 when probed; for a code namespace, 0.05 under an abstain threshold capped at question-to-fact P10). |
| `rerank_skip_above` | `float` | Top-hit cosine at or above which the LLM rerank is skipped (question-to-fact P75, never below `hyde_fallback_threshold`). |
| `hyde_fallback_threshold` | `float` | The question-to-fact P25 gate, never below `query_rewrite_threshold`; `loom_search` reads it as its precision floor. |
| `query_rewrite_threshold` | `float` | The question-to-fact P10 gate, held at least 0.01 above `noise_floor`. |
| `abstain_threshold` | `float` | Top-hit cosine below which a search abstains (`noise_floor` + 0.05 when probed). |
| `abstain_threshold` | `float` | Top-hit cosine below which a search abstains (`noise_floor` + 0.05 when probed; for a code namespace, at most question-to-fact P10 unless distractor P90 reaches its P75). |
| `conflict_threshold` | `float` | Cosine at or above which a write against an active peer is flagged `conflicted` (paraphrase P50 when probed). |
| `duplicate_threshold` | `float` | Cosine at or above which a write with a canonical-form mismatch is marked `duplicate` (paraphrase P75 when probed). |
| `similar_p10` | `float` | Probe percentiles; default 0.0 when source is 'scalar' (no probe ran). |
| `similar_p25` | `float` | 25th percentile cosine of the paraphrase pairs. |
| `similar_p50` | `float` | Median cosine of the paraphrase pairs. |
| `similar_p75` | `float` | 75th percentile cosine of the paraphrase pairs. |
| `distractor_p50` | `float` | Median cosine of the unrelated (distractor) pairs. |
| `distractor_p90` | `float` | 90th percentile cosine of the distractor pairs, the anchor of `noise_floor`. |
| `distractor_p90` | `float` | 90th percentile cosine of the distractor pairs, the anchor of `noise_floor` unless a code namespace's abstain cap moved it. |
| `similar_pairs_n` | `int` | Paraphrase pairs the probe embedded; 0 when `source` is `scalar`. |
| `distractor_pairs_n` | `int` | Distractor pairs the probe embedded; 0 when `source` is `scalar`. |

Expand Down
14 changes: 8 additions & 6 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. |
| `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. |
| `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. |
| `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, unless the distractors' 90th percentile reaches the probes' 75th. |
| `rerank_skip_above` | `float` | Cosine of a confident hit, the probes' 75th-percentile question-to-answer cosine and at least 0.01 over `noise_floor`: 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). |
| `strata` | `int \| None` | Language-and-directory strata the namespace probes were drawn from; 0 for 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 @@ -2233,6 +2233,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 (four uncached) 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 (four uncached) and no LLM call; under 20 usable probes it uses the fixed corpus."
},
"code_calibration_enabled": {
"default": false,
"type": "boolean",
Expand Down
2 changes: 2 additions & 0 deletions 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 @@ -6511,6 +6511,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
Loading