Needle-in-a-haystack test
Definition
A long-context test that hides one fact in a large block of unrelated text and checks whether the model can find and repeat it.
In more detail
Popularised in 2023 as a quick way to probe advertised context windows, the test varies the haystack length and the needle's position and plots where retrieval fails. Most current models pass the simple version almost perfectly.
That is why a pass says little about real work. Finding one exact sentence is much easier than combining several facts, reasoning over them or ignoring similar distractors. Harder variants add multiple needles and distractors, and you learn more by testing your own long documents and questions.
Related terms
Benchmark
A public, standard test set used to compare models on a capability such as coding, maths or knowledge, under the same conditions.
Context window
The maximum number of tokens a model can consider in one request, covering both the input you send and the output it writes.
Lost in the middle
The finding that language models use information at the start and end of a long context better than information buried in the middle.
Read more about Needle-in-a-haystack test
- Context rot
The gradual decline in a model's accuracy and instruction-following as its context fills up with long, stale or irrelevant content.
- LLM evaluation
Measuring AI system quality with datasets, code checks and model-graded tests.
- RAG vs long context vs fine-tuning: how to choose
What each approach changes, what it costs, where it fails, and a practical order to try them in before you commit to one.