LLMs & Generative AI

Tokenization & Context Windows

LLMs operate on tokens, not raw characters or words directly. The context window is the maximum token budget the model can condition on during one request.
  • A token is a model-facing chunk of text
  • Context is working memory, not permanent memory
  • Long context has real costs
  • Ordering and formatting matter
  • Different languages and code tokenize differently
Context budget
Everything useful must fit inside the current request's context.
What spends tokens
Context ingredientWhy include itRisk if overused
InstructionsDefine behavior and constraintsLong policies become hard to follow
ExamplesTeach output patternToo many examples crowd evidence
Retrieved chunksGround answers in factsNoise causes wrong grounding
Chat historyPreserve stateOld state conflicts with current task
Tool outputsFresh external dataLarge raw outputs hide key facts
Sources
  • Hugging Face LLM CourseTokenizers library; LLM basics
  • Machine Learning Crash CourseIntro to Large Language Models
  • OpenAI API DocumentationText generation and context management