Back
advanced
Cutting-Edge Topics

Long-Context Models (128K to 1M+ Tokens)

Use long-context models without wasting cost, losing evidence, or confusing the model

25 min read· long-context· context engineering· attention· KV cache

Long-Context Models (128K to 1M+ Tokens)

Modern models can accept very large inputs, sometimes hundreds of thousands or more tokens. That does not mean every application should paste everything into the prompt.

Long context is a capability, not a strategy. You still need context selection, ordering, compression, evaluation, and cost controls.

Why long context is useful

Use caseWhy it helps
codebase reviewinspect many files together
legal or policy reviewcompare long documents
research synthesiskeep multiple sources in view
agent planningpreserve task history
multimodal fileshandle large transcripts or documents

The hidden costs

Long prompts can create:

  • higher input cost
  • slower first-token latency
  • larger KV cache memory
  • harder citation tracking
  • lost-in-the-middle failures
  • privacy exposure from unnecessary context

Long context vs RAG

ApproachBest for
Long contextsmall number of highly relevant long artifacts
RAGlarge changing corpus with search/filter needs
Hybridretrieve first, then use long context for selected documents

Ordering matters

Place context intentionally:

text
system/developer instructions
task
short summary of sources
most important evidence
supporting evidence
output format

Do not bury the key evidence in the middle of unrelated text.

Practical rules

  • Count tokens before sending.
  • Remove irrelevant sections.
  • Summarize repeated history.
  • Keep source IDs with excerpts.
  • Prefer retrieval for large corpora.
  • Cache repeated prefixes where supported.
  • Run evals for long-document edge cases.

Knowledge check

Q1: Why can long context hurt quality? Irrelevant or poorly ordered information can distract the model and hide important evidence.

Q2: When should you prefer RAG over long context? When the knowledge base is large, changing, searchable, or mostly irrelevant to each query.