mlx-bun library API
    Preparing search index...
    • Fit per-position STS thresholds from observed (conf, accepted) pairs.

      For each position k, we want the smallest τ_k such that pruning on conf_k < τ_k still keeps empirical acceptance precision at or above target among the samples that WOULD be kept (conf ≥ τ_k). Smaller τ_k keeps more of the block (better speedup); we want the smallest one that still meets the target, i.e. we scan candidate thresholds from low to high (in the order of observed conf values) and stop at the first that clears the bar.

      Candidate thresholds are exactly the position's observed conf values (a threshold only ever needs to sit at an observed value — moving it between two observed values changes no sample's keep/drop outcome, so a finer sweep can't do better). Sorted ascending; a candidate τ's precision is P(accepted | conf ≥ τ) over the position's samples, with Laplace (+1 accept, +2 total) smoothing so single-sample / early candidates near the tail can't spike to a false 100%.

      Edge rules (in priority order):

      1. Position 0 → threshold 0. Alg-1 never prunes position 0 anyway (the scheduler in forwardInfer special-cases k > 0), so any fit would be dead code; 0 documents that explicitly and short-circuits the fit.
      2. Fewer than minSamples observations at position k → threshold 0 (insufficient evidence: don't prune on a guess).
      3. No candidate τ clears target (including τ = 1, i.e. "prune always") → threshold 1.0 (the head can't call this position at all; prune it unconditionally rather than risk emitting a token the head has no signal on).
      4. Otherwise → the smallest candidate τ meeting the target.

      Pure and deterministic: same samples array (any order) → same output, since scoring only depends on the multiset of (conf, accepted) pairs per position, and ties in conf sort stably by value (order-independent).

      Parameters

      • samples: ConfSample[]
      • gamma: number
      • target: number = 0.5
      • minSamples: number = 50

      Returns StsCalibration