Rebuild detection¶
Rebuilding an embedding corpus can change its floating-point values even when its text and encoder are unchanged. SEMQ turns each embedding into symbols, reports changed row IDs, and compares the differences with a floor: the largest variations observed in unchanged rebuilds. Passing the gate means the candidate stayed within that measured envelope; it does not establish semantic equivalence.
Setup: 5,183 SciFact documents · e5-small-v2 · quant with four bins.
Each section is a separate experiment with its own calibration. The hardware and frozen results are listed with that experiment.
- No false alarms on real rebuilds: none with 20 rebuilds in the floor, over 2,000 resamples of 28 rebuilds, where a hash of the floats,
np.allcloseand a fixed tolerance rejected all of them. - Real changes caught: 4 of 4 pipeline changes, and one swapped word in one document 96.8% of the time.
- A compact, portable state. A float check calibrated on the same rebuilds catches content changes as well, catches small numeric faults better and can list rows too; SEMQ compares a compact state that every platform reads the same way and reports a structured diff.
How the gate decides¶
Here a row is one document's embedding. The reference is the state you trust; a candidate is a new rebuild. A row's hamming is how many of its symbols differ from the reference, and the p99 is taken over the changed rows only, not over the whole corpus.
Compare each with the same reference. Keep the largest observed value of each statistic as the floor.
Compare it with that reference, then check each value against its floor limit.
- Changed rows
243 ≤ 280Within - p99 symbols changed
2 ≤ 2Within - Most symbols changed in one row
267 > 3Exceeds
within accepts the first two values; per-row also checks the last and flags 2 rows.Measure a floor for a specific reference and expected rebuild settings. Recalibrate when the reference or noise regime changes. Each candidate is compared with that reference: within checks the changed-row ratio and p99 Hamming; --per-row also checks the largest row change. The example shows the numeric checks; a changed encoder manifest also fails the gate.
Real pipeline changes¶
A floor measured from 3 unchanged rebuilds, then seven candidates: two more unchanged rebuilds and five changes to the pipeline. Each bar is the share of rows whose symbols changed, not how serious the change is. Moving the normalization after the model shifts no coordinate by more than 3e-8, so it counts as no change: four real changes remain.
Hardware: CPU: AMD EPYC 7R32 (x86_64) · GPU: NVIDIA A10G.
The floor allowed 2 of 5,183 rows to change, by at most 1 symbol each.
The same runs, judged by other checks. A false alarm flags a rebuild with unchanged text and encoder; a miss lets a tested pipeline change pass. False alarms count only the 2 rebuilds held out from the 3 used to measure the floor.
| Check | False alarms on held-out rebuilds | Tested changes missed |
|---|---|---|
| Hash of the FP32 bytes | 2 of 2 | 0 of 4 |
np.allclose, default tolerances |
2 of 2 | 0 of 4 |
| Any row with cosine below 0.9999 | 0 of 2 | 1 of 4 (the precision) |
| Largest absolute difference, calibrated on the nulls | 0 of 2 | 0 of 4 |
| SEMQ diff against its floor | 0 of 2 | 0 of 4 |
In these runs, every held-out rebuild changed the FP32 bytes. The fixed cosine threshold also lets the switch to half precision pass. A threshold on the largest difference works when it is calibrated on your own rebuilds, which is what the floor does.
Source: rebuild.json, produced by python -m benchmarks.rebuild.
False alarms and detection power¶
Hardware: CPU: AMD EPYC 7R32 (x86_64) · GPU: NVIDIA A10G.
28 rebuilds of the same corpus that change only the device, the batch size and the input order. Every rebuild's floats differed from the reference, but there were only 5 SEMQ states: 9 matched the reference and the other 19 changed 1 to 2 rows (hamming at most 1).
Each of 2,000 draws holds out one rebuild, measures a floor from N of the others, and judges the held-out rebuild, then the same rebuild with one fault. Calibrated float checks take their threshold from the same N rebuilds. Intervals are 95% Clopper–Pearson.
False alarms. With 20 rebuilds in the floor, the floor, both calibrated float checks and one bfloat16 spacing plus 1e-5 (a fixed tolerance built for this comparison; 1e-5 is PyTorch's default atol) raised none in 2,000 draws (95% interval 0%–0.18%). A hash of the floats, np.allclose and a fixed tolerance of one bfloat16 spacing rejected every rebuild. With only 3 rebuilds in the floor, the floor raised 8.7% and the calibrated float checks 5.6% to 9.8%: a floor from a few rebuilds can underestimate the variation in unchanged candidates. The draws resample the same 28 rebuilds, so the intervals describe this pool, not every future rebuild.
False alarms by check
| Check | False alarms | 95% interval |
|---|---|---|
SEMQ floor, within |
0% | 0%–0.18% |
| SEMQ floor, per-row | 0% | 0%–0.18% |
| Largest absolute difference, calibrated | 0% | 0%–0.18% |
| Lowest row cosine, calibrated | 0% | 0%–0.18% |
| SimHash, 3 bits per dimension, calibrated | 0% | 0%–0.18% |
| Hash of the FP32 bytes | 100% | 99.8%–100% |
np.allclose, default tolerances |
100% | 99.8%–100% |
| Fixed tolerance of one bfloat16 spacing | 100% | 99.8%–100% |
| One bfloat16 spacing plus 1e-5 | 0% | 0%–0.18% |
Detection. Each fault is injected into a held-out rebuild. On the tested content edits, SEMQ and the calibrated float checks had similar detection rates: one replaced document 100% for every check, one swapped word 96.8% for the floor and 97.8% for the cosine check. Some cuts remove only text beyond the model's 512-token window, leaving the model input unchanged.
Numeric changes. A perturbation can change floats without crossing a quantization boundary. SEMQ's symbols change only when a coordinate crosses that boundary; the calibrated float checks detect smaller movements in these runs. One bfloat16 spacing plus 1e-5 is the uncalibrated counterpart of the largest-difference check, which takes its tolerance from the rebuilds instead. Of these 6 changes it detected only “Noise on every coordinate, 100× rebuild noise” (100% of draws), and the other 5 in no draw: its absolute tolerance sits above the rebuild noise, which keeps it free of false alarms, and above the smaller changes too. SimHash with 3 bits per dimension, the budget of this floor, is calibrated on the same rebuilds and raises an alarm when either its changed-row count or its largest row Hamming distance exceeds every null; the float checks use one statistic each. It raised 0% false alarms, as did the floor. Against the per-row floor it detected faults more often on “Noise on every coordinate, 1× rebuild noise” (41.4% vs 5.3%) and “Scale 1% of coordinates by 1 + 1e-4” (100% vs 67.5%); less often on “Swap 1 word in one document” (96.1% vs 96.8%, within each other's 95% interval); the other 11 tied. Each row below names the injected change. Angular change is the median 1 − cosine between modified rows and those same rows before the injection. The scaled dimensions are the same in every document.
SEMQ withinlargest difference, calibratedlowest cosine, calibrated
Detection rates by fault
| Fault | Angular change (1 − cosine) | Floor, within |
Floor, per-row | Largest difference, calibrated | Cosine, calibrated | One bfloat16 spacing plus 1e-5 | SimHash, calibrated |
|---|---|---|---|---|---|---|---|
| Replace 1 document | 1.9e-01 | 100% | 100% | 100% | 100% | 100% | 100% |
| Replace 2 documents | 1.9e-01 | 100% | 100% | 100% | 100% | 100% | 100% |
| Replace 10 documents | 1.9e-01 | 100% | 100% | 100% | 100% | 100% | 100% |
| Cut the last 2% of words in one document | 1.4e-03 | 87.8% | 87.8% | 87.8% | 87.8% | 87.8% | 87.8% |
| Cut the last 10% of words in one document | 2.9e-03 | 96.0% | 96.0% | 96.0% | 96.0% | 96.0% | 96.0% |
| Cut the last 50% of words in one document | 1.5e-02 | 100% | 100% | 100% | 100% | 100% | 100% |
| Swap 1 word in one document | 7.6e-04 | 96.8% | 96.8% | 97.8% | 97.8% | 97.8% | 96.1% |
| Swap 3 words in one document | 3.3e-03 | 100% | 100% | 100% | 100% | 100% | 100% |
| Noise on every coordinate, 1× rebuild noise | 1.9e-13 | 5.3% | 5.3% | 31.7% | 52.6% | 0% | 41.4% |
| Noise on every coordinate, 10× rebuild noise | 1.9e-11 | 100% | 100% | 100% | 100% | 0% | 100% |
| Noise on every coordinate, 100× rebuild noise | 1.9e-09 | 100% | 100% | 100% | 100% | 100% | 100% |
| Scale 1% of coordinates by 1 + 1e-4 | 4.1e-11 | 67.5% | 67.5% | 100% | 100% | 0% | 100% |
| Scale 1% of coordinates by 1 + 1e-3 | 4.1e-09 | 100% | 100% | 100% | 100% | 0% | 100% |
| Scale 10% of coordinates by 1 + 1e-4 | 4.4e-10 | 100% | 100% | 100% | 100% | 0% | 100% |
Precision of the check. SimHash here is computed in FP32 on the CPU with NumPy. Each bit is the sign of a sum of 384 products, and the order of that sum depends on the library and the device, and can depend on the batch size. Over 1,150,307 vectors, the 150,307 vectors of these rebuilds and 1,000,000 seeded unit vectors, computing the same FP32 projection another way changed the bits of 1 to 55 rows per million, with no change to the floats; batches of 64 and 4,096 on the GPU changed the same number of rows. TF32 on the NVIDIA A10G changed 102,052 per million. With a floor from 20 rebuilds hashed with NumPy, an unchanged rebuild was rejected in 0% of 2,000 draws when hashed with NumPy too, 0% when hashed another way in FP32, and 100% when hashed in TF32. On these 5,183-row rebuilds a few dozen rows per million is a fraction of a row. With the projection held at FP32, SimHash raised as many false alarms as the floor. TF32 is a change of precision, off by default for PyTorch matrix products. SEMQ quantizes each coordinate on its own, with rules fixed by the specification: the conformance vectors check the same bytes in every binding and on every platform CI tests. The specification fixes only that step: an embedding model run in TF32 changes the floats that both checks receive.
SimHash computed another way than NumPy on the CPU
| SimHash computed as | Rows whose bits differ, per million | False alarms | 95% interval |
|---|---|---|---|
| FP32 on the CPU, NumPy, as the floor | 0 | 0% | 0%–0.18% |
| FP32 on the CPU, PyTorch | 1 | 0% | 0%–0.18% |
| FP32 on the GPU, batches of 64 | 55 | 0% | 0%–0.18% |
| FP32 on the GPU, batches of 4,096 | 55 | 0% | 0%–0.18% |
| TF32 on the GPU, batches of 4,096 | 102,052 | 100% | 99.8%–100% |
When the rebuild noise varies (synthetic)¶
The rebuilds above changed at most 2 rows each. To test rebuilds that change hundreds of rows every time, this pool adds noise: each of 40 nulls is a GPU rebuild plus Gaussian noise (σ = 4.5e-6 per coordinate), renormalized, and changes 223 to 286 rows. It is a controlled test of varying noise, not a model of a specific GPU kernel.
Why within can miss a localized change. The p99 summarizes changed rows and can omit the largest individual changes. In this candidate, the changed-row count and p99 both stay within the floor, so within passes. Per-row also checks each row against max_hamming and flags the replaced documents.
1–2 symbols changed per row
260 and 267 symbols changed
What per-row adds¶
Per-row caught localized changes the p99 hid, at the cost of more false alarms in this synthetic test. Compare both outcomes before choosing a gate; these are observed rates, not guarantees.
| Scenario | within |
With per-row |
|---|---|---|
| Replace 1 documentDetected · higher is better | 5.5%4.5%–6.5% | 100%99.8%–100% |
| Replace 2 documentsDetected · higher is better | 8.5%7.3%–9.8% | 100%99.8%–100% |
| Unchanged rebuildFalse alarm · lower is better | 5.5%4.5%–6.5% | 8.1%6.9%–9.3% |
Detection of replaced documents
| Fault | SEMQ floor, within |
SEMQ floor, per-row | Largest absolute difference, calibrated | Lowest row cosine, calibrated |
|---|---|---|---|---|
| Replace 1 document | 5.5% | 100% | 100% | 100% |
| Replace 2 documents | 8.5% | 100% | 100% | 100% |
How calibration affects false alarms
False-alarm bounds. The floor keeps, for each statistic, the largest value over N calibration rebuilds. When those rebuilds and the candidate are produced the same way (exchangeable), an unchanged candidate exceeds that largest value with probability at most 1/(N+1). A gate checking s statistics therefore rejects it at most s/(N+1) of the time. within checks two statistics; per-row adds a third. These are upper bounds, not predicted rates. The observed rates below are lower; dependence between statistics and tied Hamming values can make the bounds conservative.
withinper-rowbound s/(N+1)
More calibration rebuilds reduced false alarms in this synthetic pool. Solid lines show observed rates, whiskers show 95% resampling intervals, and dashed lines show the theoretical upper bounds. Lower is better.
| Calibration rebuilds | within |
95% interval | Upper bound | Per-row | 95% interval | Upper bound |
|---|---|---|---|---|---|---|
| 3 | 27.1% | 25.2%–29.1% | 50.0% | 29.5% | 27.6%–31.6% | 75.0% |
| 5 | 18.4% | 16.7%–20.1% | 33.3% | 20.9% | 19.2%–22.8% | 50.0% |
| 10 | 10.1% | 8.8%–11.5% | 18.2% | 12.7% | 11.2%–14.2% | 27.3% |
| 20 | 5.5% | 4.5%–6.5% | 9.5% | 8.1% | 6.9%–9.3% | 14.3% |
| 39 | 2.5% | 1.9%–3.3% | 5.0% | 5.1% | 4.2%–6.2% | 7.5% |
Source: floor-power.json, produced by python -m benchmarks.floor_power.
Which rows changed?¶
Hardware: CPU: AMD EPYC 7R32 (x86_64) · GPU: NVIDIA A10G.
Edit 1% of the corpus (52 documents cut to their first half and embedded again). Distribution drift, the check embedding monitors use, sees nothing; diff returns the 52 ids that changed and no others. The two answer different questions: whether the distribution moved, and which documents changed.
| Documents edited | Centroid distance | Domain classifier AUC | SEMQ diff |
|---|---|---|---|
| 0.1% (5 rows) | 5.1e-09 · no drift | 0.40 · no drift | 5 of 5 identified |
| 1% (52 rows) | 4.0e-07 · no drift | 0.41 · no drift | 52 of 52 identified |
| 5% (259 rows) | 9.8e-06 · no drift | 0.43 · no drift | 258 of 259 identified |
| 10% (518 rows) | 3.9e-05 · no drift | 0.46 · no drift | 516 of 518 identified |
| 50% (2,592 rows) | 9.6e-04 · no drift | 0.71 · drift | 2,586 of 2,592 identified |
Drift checks follow Evidently's defaults (centroid distance with threshold 0.2, a domain classifier with ROC AUC threshold 0.55), re-implemented in numpy. With these thresholds, the domain classifier flagged drift only in the tested 50% scenario; the centroid check flagged none. From 5% up a few edited documents encode to the same quantized row as before, so diff misses them; no unedited row was reported in these runs.
Source: granularity.json, produced by python -m benchmarks.granularity.
What these runs do and do not show
- One corpus and one model. The floor describes these rebuilds, not another pipeline's.
- The rebuilds vary the device, the batch size and the input order, and changed at most 2 rows each.
- The varying-noise pool is synthetic.
- The previous model revision also changes the manifest, which alone fails the gate. With the manifest unchanged, it still changes 100% of rows.
- The draws resample one fixed pool. The intervals describe that pool.