Skip to content

A code namespace that was never calibrated abstains on most correct hits, because it inherits the memory calibration #1558

Done

Description

@KaloyanNaumov

TL;DR: code.search abstains on most correct hits (8 of 13 correct top results in our test) because an uncalibrated code namespace inherits thresholds derived from short English memory statements. This asks for automatic calibration, a code-specific default, and a visible warning when calibration is missing.

Company

Lumnus

Component

Code index

Describe the situation

code.search abstains on most hits that are correct. A code namespace that was never calibrated serves the cluster's embedder calibration, which is derived from short English memory statements, and the abstain threshold it yields sits above most real query-to-code cosines.

The thresholds come from server/code/app/common.py:147-162 (resolve_code_thresholds), which calls resolve_calibration(org, ns): a per-namespace row in loom.namespace_calibration_result if there is one, else the cluster row, else the scalar settings. The result reaches server/code/app/search/calibrate.py (abstain_threshold passed to calibrate_retrieval and finalize_abstain). The cluster row comes from calibrate_embedder at boot (server/memory/app/embedder_calibration.py:260-261): noise_floor = distractor_p90 + 0.02, abstain_threshold = noise_floor + 0.05. Its probe corpus is 20 DISTRACTOR_PAIRS of short unrelated statements ("Bowie is a dog." against "Where does the user work?"), plus paraphrase and question-to-fact pairs, all memory-style English. No code text is in it. For bge-m3 this gives distractor_p90 0.592, noise_floor 0.612 and abstain_threshold 0.662.

The per-namespace calibration for code exists only as the admin operation code.calibrate (server/code/app/admin.py:44-95, probes in bench/fixtures/code_calibration_probes.jsonl), and its docstring says the namespace "must not inherit prose-derived gates". Nothing runs it: neither ingest nor the first embed calls it, and code.index_status and code.repos do not mention that a namespace has no calibration row. It is documented (docs/guides/repository-questions.md, docs/operations/code-index-operations.md, docs/architecture/llm-architecture.md) as a step an administrator runs after indexing, so a deployment that indexes without that step silently serves the memory gates. calibration.get for the namespace returns source: cluster, which is the only place the fallback shows.

What code.calibrate measures today is the embedder on code in general, not the namespace. handle_code_calibrate reads a fixed corpus, bench/fixtures/code_calibration_probes.jsonl: 20 query/positive/distractor triples drawn from ClickHouse's own C++ sources. The namespace argument only names where the result is stored. Running it on two of our namespaces (a kernels repository and a Python service) gave the same row for both, abstain 0.48637 and noise floor 0.43637, against the cluster's 0.662 / 0.612. That fixes the prose-versus-code gap for every code namespace at once, but two repositories in different languages and domains get identical gates by construction.

Measured on 19 queries whose target file we knew, across three namespaces (vLLM main, a vLLM fork branch, vllm-xpu-kernels), embedder bge-m3 via TEI (dense, 1024 dimensions), top_k 5, one call each, none of the namespaces calibrated:

  1. The target was in the top 5 for 17 of 19 and rank 1 for 13.
  2. 12 of 19 abstained, all below_threshold.
  3. 8 of the 13 correct rank-1 hits abstained (62%). Their quoted similarities were 0.44, 0.58, 0.60, 0.62, 0.62, 0.64, 0.64 and 0.65: none reached 0.662.
  4. Easy queries worded close to identifiers abstained too, for example "RMS norm kernel" (0.58, target csrc/layernorm.cpp at rank 1) and "rotary position embedding base class" (0.64, RotaryEmbedding at rank 1).
  5. retrieval_confidence does not separate the groups: 0.496-0.644 for correct rank-1 hits, 0.481-0.629 for the others.

An agent that honours abstain discards hits that are right and falls back to grep.

Does it reproduce on the latest release or main?

Yes

How to reproduce

  1. Index a code namespace and embed it, with a real embedder (bge-m3 here) and without running code.calibrate.
  2. calibration.get for the namespace shows source: cluster and an abstain_threshold around 0.66.
  3. Run code.search with a handful of queries whose target file you know (an identifier-close one such as "RMS norm kernel" and a paraphrase). A large share of the correct top-1 results come back with abstain: true, abstain_code: below_threshold and a quoted similarity under the threshold.
  4. Run code.calibrate for the namespace and repeat: this shows how much of the abstention is the inherited gate. Then run it for a second namespace in another language: both rows come out identical (0.48637 / 0.43637 here), because the probes come from the fixed fixture.

Expected performance

A code namespace does not abstain on its correct hits because it inherited gates derived from another kind of text. Some options, in order of how much they change:

  1. Calibrate a code namespace automatically, on its first completed embed and again when its embedder changes, with the existing code.calibrate probe set.

  2. Until a namespace has its own row, fall back to a code-specific default instead of the memory calibration, so that a code search never reads the cluster row.

  3. Make the missing calibration visible: code.index_status and code.repos report calibration: cluster (or a warning) when a code namespace has no per-namespace row, and code.search could say so in calibration_explanation when it abstains on the cluster gate.

  4. Say in the operations docs that an uncalibrated code namespace serves the memory calibration and abstains on correct hits, next to the existing code.calibrate step, and add the step to the new-repository checklist.

  5. Optionally, let code.calibrate sample its probes from the namespace itself: for example, query/positive pairs from a namespace's own documented functions (docstring or comment as the query, the unit as the positive), with distractors drawn from other units of the same namespace. A per-namespace row would then reflect that repository's language and vocabulary, and the fixed fixture would become the fallback.

Option 3 is the smallest change and is useful whichever of 1, 2 and 5 is chosen. Options 1 and 2 can be met with the fixed fixture as it is; 5 is the question of whether per-namespace calibration should be per-namespace in what it measures.

Environment

Loom 1.3.0 (Helm chart 0.3.0), ClickHouse 26.10 self-managed, Kubernetes. Embedder bge-m3 through TEI (dense, 1024 dimensions); no LLM routed. The code paths cited above are unchanged at upstream `8ce2640dd`.

How this was found

Found and reproduced on our deployment with AI assistance.

Redaction

  • I removed tokens, keys, passwords and personal or customer data from everything above.

Activity

  1. added
    bug
    help wanted
    up-for-grabs
    on Nov 26, 2026
  2. mikemikimike commented on Nov 26, 2026

    @mikemikimike

    I plan to make code search use a namespace code calibration when available and code-owned fallback thresholds otherwise, so prose-derived cluster calibration cannot silently gate code results. I will also report when the fallback is active in code.index_status and code.repos. The regression coverage will verify the selected thresholds for a calibrated namespace, a missing row, and an unavailable calibration read.

  3. KaloyanNaumov commented on Dec 1, 2026

    @KaloyanNaumov
    ContributorAuthor

    Thanks, that plan covers the part that is still open.

    Since it was posted, #1627 added the index-status warning for a namespace without its own calibration, and #1688 put code.search's confidence on the calibrated scale. Abstention still reads the inherited thresholds, so an uncalibrated code namespace can still abstain on correct hits. Code-owned fallback thresholds, reported in code.index_status and code.repos, close that.

    We now run code.calibrate on every code namespace when it is added, so our deployment no longer shows the inheritance. A new namespace still serves searches between its first index and its calibration, though. When there is a branch, I can run it against a fresh namespace before and after calibration and report which thresholds it selects in each state.

  4. KaloyanNaumov commented on Dec 2, 2026

    @KaloyanNaumov
    ContributorAuthor

    @mikemikimike product decision needed here, beyond your plan. The code-owned fallback thresholds, reported in code.index_status and code.repos, cover the inheritance. Two questions remain:

    1. Should a code namespace calibrate itself on its first completed embed, and again when its embedder changes? code.calibrate needs only the embedder, no LLM, so the embed worker could run it. A setting for it would follow recalibration_enabled, which already re-runs the embedder probe.
    2. Should code.calibrate sample its probes from the namespace itself, with a documented unit's docstring as the query, the unit as the positive and other units as distractors? Today it reads a fixed fixture, so every code namespace on one embedder gets the same row.

    If the answer to 2 is no, 1 adds little over the fallback: both give the thresholds of the same fixture.

  5. KaloyanNaumov commented on Dec 2, 2026

    @KaloyanNaumov
    ContributorAuthor

    cc @zlareb1, the product call on the two questions above is yours.

  6. KaloyanNaumov commented on Dec 2, 2026

    @KaloyanNaumov
    ContributorAuthor

    @mikemikimike, two PRs close this from the calibration side. #2011 makes code.calibrate sample its probes from the namespace's own documented functions, so a code namespace gets its own thresholds (question 2). #2022 runs code.calibrate on a namespace's first completed embed and again when its embedder changes, behind a setting next to recalibration_enabled, off by default (question 1).

    With both on, a code namespace runs uncalibrated only between its first index and its first completed embed. Your code-owned fallback thresholds would be a good safety net for that window, and they are welcome as your own PR if you want them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wantedup-for-grabs

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions