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

Aperta
#1,558 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@KaloyanNaumov ci sta già lavorando.

Dal 2/12/2026.

  • #2022 di @KaloyanNaumov — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
clickhouse, kubernetes, python

Direzione di ricerca

Start with server/code/app/common.py and trace how resolve_code_thresholds selects calibration, then read server/code/app/admin.py and the calibration probes in bench/fixtures/code_calibration_probes.jsonl. Compare the fallback paths with the reported code.search abstentions and check the index status and repository reporting paths. Done means an uncalibrated code namespace uses an appropriate code calibration and exposes its calibration status, with tests covering the fallback and reporting behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug help wanted up-for-grabs

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.
Lingua principale
Python
Stelle
263
Fork
47
Merge medio
14h 21m
PR unite (30g)
873

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ClickHouse/loom

Tutte le issue di ClickHouse/loom

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.