Large language models don't recall facts from a long context uniformly. Empirical studies (Liu et al., "Lost in the Middle", 2023) show retrieval accuracy is highest when the relevant fact sits near the start (primacy) or end (recency) of the context window, and dips in the middle. This simulator models that curve directly, drawn as two layered panels: a chunk row (top) and the recall-probability curve versus depth (bottom). Drag horizontally on the chunk row to move the needle.
d = needle depth, 0..1 (0 = start, 1 = end)
S(d) = 0.5·[e^(-d/τ) + e^(-(1-d)/τ)] / 0.5·[1 + e^(-1/τ)]
τ = 0.12 + 0.35·Q Q = model quality, 0..1
floor= clamp(0.08 + 0.55·Q − 0.35·L, 0.03, 0.95)
L = (contextLen − 8) / (96 − 8)
R(d) = floor + (1 − floor)·S(d) ← probability the needle is recalled
Fixed vs. the 3D sibling: the source engine used τ = 0.12 + 0.35·(1 − Q), which makes τ shrink as quality rises — that sharpens the dip precisely when the model is supposed to be better at long context (numerically verified: at 96 chunks, going from Q=0 to Q=100 drove the middle-of-context recall from ≈0.63 down to ≈0.30, the opposite of the "stronger model flattens the dip" claim in its own theory text). This engine uses τ = 0.12 + 0.35·Q instead, so higher quality widens τ and genuinely flattens the curve, matching the documented intent and the real mitigation seen in better long-context models.
- Context length — number of chunks in the window. Longer windows lower the floor (harder overall retrieval), matching the observed trend that longer contexts amplify the middle dip.
- Needle depth — where the target fact sits, 0% = very first chunk, 100% = very last chunk. Drag on the chunk row to set it directly.
- Model quality — a stronger long-context model raises the floor and widens τ, flattening the dip — the mitigation seen in newer LLMs (better positional encodings, hierarchical attention, retrieval-augmentation).
- Run Trial — draws one Bernoulli sample with probability R(d): success (green flash) or miss (red flash), accumulated per depth bucket in the bottom panel.
- Auto-Sweep — repeatedly runs trials while sweeping the needle across every depth, building the empirical curve (blue dots, bottom panel) live against the theoretical curve (blue line).
Real-world relevance: this is exactly why RAG pipelines re-rank and place the most important chunks near the edges of the prompt, and why chunk ordering — not just chunk relevance — matters for long-context accuracy.