Skip to content
Engineering Bible
AI Engineering

AI Engineering on LLMs

An LLM predicts the next token

  • It reads text and predicts the most likely next piece, over and over.
  • Those pieces are tokens: a word or part of one. 1,000 words is ~1,300 tokens.
  • Price, speed and limits are all counted in tokens.

Transformers read everything at once

  • Nearly every modern LLM is a transformer, an architecture from Google in 2017.
  • Attention lets each token look at every other token to work out meaning.
  • In “the bank of the river”, attention ties “bank” to “river”, not money.
  • Comparing every pair means the work grows with the square of the input.

Sampling picks the next token

  • The model scores every next token. Temperature sets how bold the pick is.
  • Low temperature for facts, code and data. Higher for ideas and writing.
  • The same prompt can give different answers. Plan for that.

Example: likely next tokens after “The sky is”

blue
62%
clear
15%
dark
9%
cloudy
6%
falling
1%
Low temperature almost always picks “blue”. Higher temperature sometimes picks the others.

The context window is its working memory

  • It's how many tokens the model sees at once: the prompt plus the answer.
  • It remembers nothing between calls. Each request resends what matters.
  • Long context costs more, runs slower, and details in the middle get missed.

The KV cache makes answers stream

  • Each new token needs attention data from every token before it.
  • The KV cache keeps that data, so it isn't recomputed for every token.
  • That's why the first token is slowest, and the rest stream out quickly.
  • The cache grows with context, so long chats eat GPU memory.

It makes things up, so ground it

  • An LLM writes likely text, not checked facts. That's hallucination.
  • Put the facts in the prompt, ask for structured output, allow “I don't know”.
AI Engineering in five pages1 / 5