mlx-bun library API
    Preparing search index...

    Full-attention storage with independently advancing row positions. Speculative rollback changes coverage, without moving the retained KV. Subsequent appends overwrite each row's rejected suffix in place when MLX can donate the buffer. Queue membership is outside this layout.

    Reads: append through updateAndFetch, then the stock fused SDPA, a window through windowRead (its source storage's). While every row is unpadded and at one position, decode passes no mask and a window the fused causal mask; otherwise both pass the per-row mask (causal, past each row's left padding) for their query count, built once per forward through masks.

    Implements

    Index
    • Parameters

      • masks: AttentionMasks = ...

        The per-forward masks of the model this layout serves.

      • windowRead: DenseRead = sdpaRead

        The window read of the storage it was made from (KVCache.windowRead).

      Returns BatchedKVCache

    keys: MlxArray | null = null
    leftPad: number[] = []
    masks: AttentionMasks = ...

    The per-forward masks of the model this layout serves.

    rowOffsets: number[] = []
    values: MlxArray | null = null
    windowRead: DenseRead = sdpaRead

    The window read of the storage it was made from (KVCache.windowRead).

    • get aligned(): boolean

      Every row unpadded and at one position: a windowless read needs no per-row mask. Layouts that keep their positions in this one read it.

      Returns boolean

    • Window: L new positions per row, causal within the window, for prefill chunks, prefill tails and speculative verify windows. Query i of a row sees the row's earlier valid positions and window positions 0..i, limited to the cache's sliding window. Left padding and prepared prefill padding are never visible. Outputs at padded query positions are unspecified and the caller ignores them. To append context without attending, make this call and dispose the read unused.

      Parameters

      Returns AttentionRead

    • Stable storage identity for compatibility guards and persistence. REQUIRED: every capability predicate (isPlainKvCache, isRotating*, packages/inference/src/state/persistence.ts codecs) is a string compare on this value, so a missing override used to fail OPEN into wrong routing (PRs #42/#43: BatchedRotatingCache shipped without one and batched joins dropped running rows). Wrappers report their own kind plus the inner kind.

      Returns string

    • Speculative verify-round support for NON-trimmable recurrent caches (SSMCache — gated-DeltaNet conv + recurrent state). A cache exposing these is spec-eligible without isTrimmable(): the serve loop arms a round before the verify forward (the layer snapshots pre-round state — free, MLX arrays are immutable — and records its position-local kernel inputs), then resolves it: commit on full accept, or rollback(keep) which restores the snapshot and bit-exactly REPLAYS the first keep window tokens through the recurrence (identical arithmetic prefix ⇒ identical state). Trimmable caches leave these unset and keep trim().

      Returns void

    • Drop the last n tokens (future writes overwrite them). bypass (default false → unchanged behavior) skips the isTrimmable guard for the speculative-decode rollback case (trim the last n ≤ γ tips right after a

      1 concat write); rotating caches then physically shrink the buffer tail.

      Parameters

      • count: number

      Returns void