Book a 30-min callBook a call

Long context vs RAG: when to put everything in the prompt and when to retrieve

When to put whole documents in a long prompt and when to retrieve: what the research shows, cost and latency, hybrids, and how to test it on your own data.

A stack of pages flowing straight into a model box on one side, and on the other a grid of small squares narrowed by a funnel to three that reach the same model.
Written by
BYD Tech
Published
Topic
Deep dives
Reading time
13 min read

Questions people ask

Does a long context window make RAG obsolete?

No. It removes the need for retrieval when the material is small and stable enough to fit, and it lets retrieval return larger pieces. Large or fast-changing corpora, per-user access control, citations and high request volume still favor retrieving what each question needs.

How big can a knowledge base be before I need retrieval?

Anthropic's contextual retrieval write-up puts the line at about 200,000 tokens, roughly 500 pages, for its models. In practice the line is where accuracy on your own test set starts to fall or where latency and per-request cost become too high, which may be well below the window size.

Is the lost-in-the-middle effect still a problem with newer models?

Models have changed since Liu and colleagues ran their tests in 2023, but RULER (2024) and NoLiMa (2025) still report accuracy falling with length on harder tasks. Put the most relevant material first or last, put the question at the end, and test with the answer at different depths.

Are needle-in-a-haystack scores a good way to compare models?

Only as a minimum bar. Most models score near perfectly on the basic test, which checks retrieval of one literal fact. Tests with paraphrased questions, several needles, multi-hop tracing and aggregation, such as RULER and NoLiMa, separate models much more, and a test on your own documents tells you most.

Building something like this?