Basics · 8K ALiBi Cross-Encoder Mechanics & Token-Length Scaling

Inside 8K ALiBi Cross-Attention vs Bi-Encoder Cosine

Unlike bi-encoders that compress a passage into one vector before seeing the query, a cross-encoder feeds <s> query </s></s> passage </s> through 6 joint self-attention layers. Test how symmetric ALiBi avoids the 512-token cliff and benchmark real CPU WASM scaling from 128 to 4,096 tokens.

1. Load Jina Reranker v1 Turbo EN (38.30 MB q8 WASM)

2. Live Token-Length Context Sweep (128 → 2,048+ tokens)

Upstream tokenizer_config.json defaults model_max_length to 512, even though JinaBERT's ALiBi slopes train up to 8,192 tokens. Our worker sets model_max_length = 8192 and sweeps real CPU WASM forward passes below.

Latency scaling across context lengths

Measured WASM telemetry

Live cross-encoder scaling benchmark across sequence lengths
Target Exact tok Latency Tok/s Logit NaN
Click "Run live 128 → 2,048 token sweep" above to benchmark on this device.

3. ALiBi Full Context vs 512-Token Cutoff & Score Calibration

Score calibration curve (logit → σ(z))

Cross-attention vs Bi-encoder dot product

Bi-encoder (u · v): Encodes query and document independently into fixed vectors, so fine-grained token interactions (like matching an appendix step at token #1,020 to an exact query constraint) collapse into a single cosine number.

Cross-encoder (Q × K across 6 ALiBi layers): Attends directly between every query token and every document token with linear distance bias −m · |i − j|, preserving sharp relevance discrimination past 512 tokens.

Show the code

Show the code: variable max_length tokenization & cross-encoder forward pass
Show the code: numerically stable logistic sigmoid calibration