Models and labs

What is a one-million-token context window good for?

· By Robert Scales · 4 min read

Short answer

A one-million-token context window lets a model read roughly 700,000 words, an hour of video or a large codebase in a single request, so you can ask questions across a whole body of material at once. It shines for one-off deep reading of a big, self-contained set of documents, but it is slower and costlier per question than retrieval for large libraries you query again and again.

A model's context window is how much text it can hold in view at once: your instructions, any documents you paste in, the conversation so far and its own reply. It's measured in tokens, the small pieces of text (or of images, audio and code) that a model actually processes. Last week Google announced Gemini 1.5 Pro, with a standard window of 128,000 tokens. Some developers and business customers can now try a window of up to one million tokens in a private preview. For comparison, Anthropic's Claude 2.1 holds 200,000 tokens, about 500 pages.

What fits in a million tokens

Google gives these rough equivalents for one million tokens:

MaterialAbout one million tokens holds
TextOver 700,000 words
AudioAbout 11 hours
VideoAbout 1 hour
CodeOver 30,000 lines

Google's demonstrations show what that size makes possible: asking questions about the 402-page transcripts of the Apollo 11 mission, picking out plot points and small details in a 44-minute silent Buster Keaton film, and reasoning over more than 100,000 lines of code. In research, Google tested windows as large as ten million tokens.

The practical gain is that you no longer have to cut your material into pieces and decide in advance which pieces matter. Good uses include:

  • Contracts and reports: compare every clause across a stack of agreements, or find where two policy documents contradict each other.
  • Codebases: ask how a feature works when the answer spans dozens of files.
  • Recordings: search hours of meetings or lectures for the moment a topic came up.
  • Learning from a manual: Google reports that, given a grammar book for Kalamang, which fewer than 200 people speak, the model learned to translate English into it about as well as a person studying the same book.

A worked "needle in a haystack" test

The standard way to check whether a model really uses its whole window is the needle-in-a-haystack test: hide one out-of-place sentence somewhere in a very long document and ask the model to find it. Google reports that Gemini 1.5 Pro located the planted text in 99% of trials, even with a million tokens around it.

You can run a small version yourself with any long-context model you have access to:

  1. Take a long public-domain text, such as a novel from Project Gutenberg.
  2. Insert one sentence that doesn't belong, about two-thirds of the way through: "The secret ingredient in Grandma Lucie's soup is smoked paprika."
  3. Paste the whole text with this question:
Prompt
Below is a long document. Answer the question using only the document. If you find the answer, quote the sentence it comes from.

<document>
[paste the full text here]
</document>

Question: What is the secret ingredient in Grandma Lucie's soup?
  1. Repeat with the sentence near the start, the middle and the end, and note where, if anywhere, it fails.

How you ask matters. When an independent tester ran this kind of test on Claude 2.1, the model often replied that the document didn't say, because the hidden sentence looked out of place. Anthropic found that starting Claude's answer with "Here is the most relevant sentence in the context:" raised its score on that test from 27% to 98%. Asking for a quote, as in the prompt above, nudges models in the same direction.

Try it: Run the test at two lengths, a 20-page excerpt and the full book, and time how long each answer takes. The difference in waiting time is the trade-off this article is about.

Does a long context replace retrieval?

Not for most ongoing work, though it changes when you need it. Retrieval-augmented generation, or RAG, is the approach described in a 2020 paper by Lewis and colleagues: instead of giving the model everything, a search step pulls the few passages most relevant to each question from a large collection and passes only those to the model. The paper's authors pointed out that models store facts in their parameters but struggle to access them precisely, to show where an answer came from, or to update what they know. Retrieval addresses all three.

A long window shifts the balance in a few ways. For a single, self-contained set of documents that you'll question deeply once, such as one due-diligence file or one codebase, loading everything avoids the risk that the search step misses the passage you needed. Setup is simpler too: no index to build.

But cost and speed favour retrieval for repeated use. Models process every token you send, every time you ask. Sending a million tokens to answer each question means reading a library to look up one fact. Google itself tells early testers to expect longer waits with the one-million-token window, says it is still working to cut latency and computing needs, and plans pricing tiers that rise from the 128,000-token standard. Retrieval also scales past any window: a company wiki or years of email can be far larger than a million tokens, and it changes daily.

The likely pattern is a mix. Use retrieval to narrow a huge or changing collection down to the relevant documents, then use a long context to read those documents whole rather than in fragments. And whichever you use, ask for quotes so you can check the answer against the source.

Sources

  1. Introducing Gemini 1.5, Google's next-generation AI model — Google (Sundar Pichai and Demis Hassabis), February 15, 2024
  2. Long context prompting for Claude 2.1 — Anthropic, December 6, 2023
  3. Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks — arXiv (Patrick Lewis and 11 co-authors), May 22, 2020

Get the free Guide to Artificial Intelligence

Sign up for the weekly newsletter and receive the free guide: what changed in AI this week, one lesson, one prompt to try. Unsubscribe in one click.

How we handle your address

Back to top

Display

Your choices are saved in this browser only. No data is sent.

Text size
100%
Colours
Reading
More settings
Accessibility statement