# Needle in a Haystack Test

> A test that hides one fact in a long text and asks the model to find it.

**Field:** Artificial Intelligence  
**Category:** Evaluation & Benchmarks  
**Also known as:** Needle in a Haystack, NIAH, Needle-in-a-Haystack Benchmark

## Think of it like

It is like hiding one odd sentence in a long book. Then you ask if the reader spotted it.

## Definition

A needle in a haystack test checks if a model can find one fact hidden in a very long text. A short line, the needle, is placed somewhere in a long pile of other text. The model is then asked a question that only that line answers. The test is run many times, moving the needle from start to end and making the text longer. The results form a grid that shows where the model misses. Passing it shows the model can find a fact, not that it understands the whole text.

## Example

Lucy hides the line 'The secret code is 7429' in a 300-page report. The model finds it near the start but misses it in the middle.

## Why it matters

Models now take very long inputs. This test checks if they can really use every part of them.

## Common mistake

Thinking a perfect score means the model reasons well over long texts. Finding one line is far easier than linking many.

## Three principles

- **Hide one fact.** Then ask about it.
- **Move it around.** Start, middle and end.
- **Grow the pile.** Try longer and longer texts.

## Related terms

- [Context Window](https://learn.benibix.com/term/ai/context-window)
- [Lost in the Middle](https://learn.benibix.com/term/ai/lost-in-the-middle)
- [AI Benchmark](https://learn.benibix.com/term/ai/ai-benchmark)
- [Large Language Model (LLM)](https://learn.benibix.com/term/ai/large-language-model)

![A grid of results. Across the bottom, text length grows from short to long. Up the side, the needle moves from the start of the text to the end. Most cells are ticks, and a few in the middle of the longest texts are crosses.](https://learn.benibix.com/diagrams/ai5-needle-haystack.svg)

---

Source: https://learn.benibix.com/term/ai/needle-in-a-haystack
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
