12Asymmetric binary quantization: a per-dimension threshold recovers the bits a real embedding’s own anisotropy collapses
Verbs:storage_precision = "binary"’s own coarse-code fit — a per-dimension threshold τ learned from the corpus (sign(v − τ), median default), replacing the old fixed-0sign(v) — applied automatically, with no new config knob, through the same jammi.connect(..., config=...) / search() surface binary-precision.qmd measures · Background: anisotropy in real transformer embeddings — a large shared “common-mean” direction nearly every representation projects onto (Ethayarajh 2019) — composed with HNSW as the navigable proximity graph the binary sidecar is built over (Malkov and Yashunin 2020) and the recall-vs-memory trade quantization buys (Johnson, Douze, and Jégou 2021) · Checked: measurement (the anisotropy diagnosis itself — ‖μ‖/E‖v‖ and the collapsed-dimension count — plain-vs-asymmetric no-rescore recall@1/(10?) against the engine’s exact search, and the rescore companion’s identity to the normalized input; every number measured live).
binary-precision.qmd measured storage_precision = "binary"’s retrieve→rescore trade — one packed sign bit per dimension, Hamming-ranked, a mandatory exact rescore recovering most of the recall the coarse code gives up. What that chapter’s own numpy oracle did NOT question is the packing rule itself: sign(v), a threshold fixed at exactly 0, for every dimension, on every corpus. That rule is silently wrong for a real transformer embedding. Real embeddings are anisotropic — nearly every row shares a large common direction (measured below: at full scale, on ModernBERT-base, a corpus mean vector whose own norm is almost as large as a typical row’s) — so a fixed threshold at 0 does not split a dimension’s values into two roughly-balanced halves; on a dimension the shared mean dominates, sign(v) returns the SAME bit for nearly every row, and a bit that never disagrees across the corpus carries zero Hamming-distance information. The engine’s binary sidecar therefore fits a per-dimension τ from the corpus itself — sign(v − τ), τ a per-dimension median by default — so each dimension’s own bit boundary tracks where that dimension’s values actually split, not an assumption the corpus is centered at the origin. This chapter measures the diagnosis that motivates the fix, the fix’s own effect on collapsed dimensions and no-rescore recall, and confirms the fix is exactly as narrow as its own design claims: storage-side only, touching nothing but the coarse Hamming code — the exact-f32 rescore companion, and therefore the final answer once rescore runs, is unaffected.
12.1 The corpus and the oracle
The same corpus the two preceding chapters measure — the papers embedded once, held-out queries, the engine’s exact search as ground truth. At full scale these are ModernBERT-base embeddings; at small, the random-weight fixture encoder’s — which, measured below, is anisotropic too: mean-pooled transformer states share a common direction whether or not the weights were trained.
2026-10-03T07:44:19.126102Z WARN jammi_kernels::admission: fused-kernel domain check failed; falling back to the eager composition op="attention_block_fused" predicate="head_dim_is_attention_block_fixed_head_dim"
corpus 360 papers × 32 dims, 40 held-out queries
12.2 The diagnosis — how anisotropic is the corpus?
‖μ‖ / E‖v‖: the corpus mean vector’s norm over the average row norm. Near 0, the rows share no direction; near 1, nearly every row projects heavily onto the same one (Ethayarajh 2019). A collapsed dimension puts more than 99% (or fewer than 1%) of rows on the same side of a threshold: its bit is nearly constant across the corpus, so it can never tell two rows’ Hamming codes apart.
mu = vectors.mean(axis=0)anisotropy =float(np.linalg.norm(mu) / np.linalg.norm(vectors, axis=1).mean())def collapsed(threshold) ->int: above = (vectors > threshold).mean(axis=0)returnint(np.sum((above <0.01) | (above >0.99)))THRESHOLDS = {"zero": np.zeros(corpus.dims), "median": np.median(vectors, axis=0), "mean": mu}dead = {name: collapsed(t) for name, t in THRESHOLDS.items()}print(f"‖μ‖ / E‖v‖ = {anisotropy:.4f}")for name, n in dead.items():print(f"collapsed dims (of {corpus.dims}) at a {name} threshold: {n}")
‖μ‖ / E‖v‖ = 0.9978
collapsed dims (of 32) at a zero threshold: 30
collapsed dims (of 32) at a median threshold: 0
collapsed dims (of 32) at a mean threshold: 0
claim("the corpus is anisotropic: its mean direction carries most of a row's norm", anisotropy >0.5, f"‖μ‖ / E‖v‖ = {anisotropy:.4f}")claim("a fixed-0 threshold collapses dimensions", dead["zero"] >0,f"{dead['zero']} of {corpus.dims}")claim("a median threshold, splitting every dimension in half, collapses none", dead["median"] ==0)
✓ the corpus is anisotropic: its mean direction carries most of a row's norm (‖μ‖ / E‖v‖ = 0.9978)
✓ a fixed-0 threshold collapses dimensions (30 of 32)
✓ a median threshold, splitting every dimension in half, collapses none
On a real, anisotropic embedding a large share of dimensions is dead under a fixed-0 rule — every one contributes the same bit to every row. Centering each dimension at its own corpus median eliminates that collapse: not by adding information, but by putting each dimension’s bit boundary where its values actually split.
12.3 The fix, isolated — sign(v) against sign(v − τ), in numpy
Before touching the engine: rank the whole corpus by raw Hamming distance at each threshold, with no candidate restriction and no rescore — the packing rule’s own effect on recall.
def hamming_recall(threshold) ->tuple[float, float]: bits = vectors > threshold at_1, at_k =0, 0.0for q, truth inzip(queries, corpus.exact): ranked = np.argsort(((q > threshold) != bits).sum(axis=1), kind="stable") ids = [corpus.corpus_ids[j] for j in ranked[:K]] at_1 += ids[0] == truth[0] at_k +=len(set(ids) &set(truth)) / Kreturn at_1 /len(queries), at_k /len(queries)no_rescore = {name: hamming_recall(t) for name, t in THRESHOLDS.items()}print(f"{'threshold':>10}{'recall@1':>11}{'recall@10':>11}")for name, (r1, r10) in no_rescore.items():print(f"{name:>10}{r1:>11.4f}{r10:>11.4f}")
threshold recall@1 recall@10
zero 0.0000 0.0375
median 0.1000 0.3375
mean 0.1250 0.3025
for name in ("median", "mean"): claim(f"a {name} threshold recovers no-rescore recall the fixed-0 code loses", no_rescore[name][1] > no_rescore["zero"][1],f"recall@{K}{no_rescore[name][1]:.4f} against {no_rescore['zero'][1]:.4f}")
✓ a median threshold recovers no-rescore recall the fixed-0 code loses (recall@10 0.3375 against 0.0375)
✓ a mean threshold recovers no-rescore recall the fixed-0 code loses (recall@10 0.3025 against 0.0375)
Both corpus-fit thresholds clear the fixed-0 rule: the diagnosis is not a curiosity, it costs no-rescore recall, and centering recovers information the fixed rule threw away. Median is the engine’s default because it splits every dimension exactly in half — the most information a bit can carry. Neither closes the gap to the exact answer: a 1-bit-per-dimension code is lossy, and that gap is what rescore closes.
12.4 The engine’s own code — reachable, with no separate knob
The corpus-fit median threshold is the only way binary packs: no [embedding.ann] key selects the fixed-0 rule or another reduction. The proof is the config surface itself — every config struct denies unknown fields, so a key it does not declare is refused when the session opens, never parsed and ignored:
refused: Configuration error: embedding.ann.binary_threshold_kind: unknown field `binary_threshold_kind`, expected one of `connectivity`, `build_expansion`, `search_expansion`, `storage_precision`, `oversample`
claim("the config surface refuses a key that would select another threshold", refused isnotNoneand"binary_threshold_kind"in refused)
✓ the config surface refuses a key that would select another threshold
12.5 Through the engine — the no-rescore proxy and the rescored default
oversample=1 hands the rescore only k coarse candidates, so it is the engine’s own near-no-rescore reading; the table’s default (32) is the search a caller gets.
claim("rescoring a wider candidate set never loses recall", rescored[1] >= proxy[1],f"recall@{K}{rescored[1]:.4f} against {proxy[1]:.4f} at oversample 1")claim("rescored at the default, binary comes within two points of the exact ceiling", rescored[1] >= exact_ceiling[1] -0.02,f"recall@{K}{rescored[1]:.4f} against {exact_ceiling[1]:.4f}")
✓ rescoring a wider candidate set never loses recall (recall@10 1.0000 against 0.3425 at oversample 1)
✓ rescored at the default, binary comes within two points of the exact ceiling (recall@10 1.0000 against 1.0000)
12.6 Cosine-invariance — the rescore companion never sees τ
τ touches only the coarse Hamming code the graph is built from. The .rawf32 companion the rescore reads holds the table’s vectors as ingested — L2-normalized, as every embedding table stores them before any precision-specific packing runs. Read back off the segments, in order, it equals the normalized input:
companion 360 × 32; max |companion − normalize(input)| = 5.96e-08
claim("the rescore companion is the normalized input, untouched by the threshold", companion.shape == vectors.shape and max_diff <1e-5, f"max difference {max_diff:.2e}")
✓ the rescore companion is the normalized input, untouched by the threshold (max difference 5.96e-08)
Whatever the coarse threshold gets wrong about which candidates to propose, the rescore’s answer is computed from exact data every time.
12.7 Honest framing — a floor raised, not a solved 1-bit code
The corpus-fit threshold is a real improvement at the level it works on — the coarse, no-rescore ranking — and it comes entirely from reviving the dimensions the anisotropy killed, never from holding more information than one bit per dimension can. It does not make binary a substitute for f32; the mandatory rescore is still what closes the gap to the exact answer.
12.8 Bridge note
The right threshold is a property of the corpus, not an assumption about it. A fixed sign(v) at 0 silently assumes an embedding space is centered at the origin along every dimension — real transformer embeddings are anisotropic instead (Ethayarajh 2019), and that assumption costs real Hamming-distance information on the dimensions where it is most wrong. Fitting a per-dimension threshold from the corpus itself (sign(v − τ), median by default, no separate config knob — confirmed here by an unsupported key being refused loud at load, never parsed and silently ignored) eliminates the collapsed dimensions and measurably improves no-rescore recall, both in an isolated numpy fold and through the real engine’s own search(). It stays exactly as narrow as its design claims: the exact-f32 rescore companion is confirmed to hold the same L2-normalized vectors every precision’s ingestion path normalizes, untouched by τ, so the fix only ever changes WHICH coarse candidates retrieve→rescore considers, never how the final answer is scored — cosine-invariant, storage-side, benefiting every binary index built on top of HNSW’s navigable proximity graph (Malkov and Yashunin 2020) with no trainer, wire, or API change. And it is honestly partial: binary is still a 1-bit-per-dimension code, no-rescore recall stays well under the exact baseline even after the fix, and the mandatory rescore stage binary-precision.qmd measured is still what does most of the work of recovering the true answer (Johnson, Douze, and Jégou 2021) — the threshold fix raises the floor the coarse code hands to rescore; it does not replace rescore.
Ethayarajh, Kawin. 2019. “How Contextual Are Contextualized Word Representations? Comparing the Geometry of BERT, ELMo, and GPT-2 Embeddings.” In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (EMNLP-IJCNLP).
Johnson, Jeff, Matthijs Douze, and Hervé Jégou. 2021. “Billion-Scale Similarity Search with GPUs.”IEEE Transactions on Big Data 7 (3): 535–47.
Malkov, Yu A., and Dmitry A. Yashunin. 2020. “Efficient and Robust Approximate Nearest Neighbor Search Using Hierarchical Navigable Small World Graphs.”IEEE Transactions on Pattern Analysis and Machine Intelligence 42 (4): 824–36.