AI stack engineering

AI, from the ground up.

Software with a model inside it: how it works, how to build it, and how to run it safely. Seventeen chapters in three parts, read in order, at your own pace.

Written for people who can already write some code. Words you may not know are underlined where they first appear: tap one for a plain meaning.

where you are

You have not started yet. Chapter 1 is the place to begin.

chapters finished
0 / 17
things you can explain
0 / 28

Kept in this browser only.

how it works

  1. 1Read a chapterTop to bottom. The diagrams move when you click them.
  2. 2Build the small thingEvery chapter ends with something to make on your own machine.
  3. 3Tick what you can explainIf you could explain it to a friend without notes, tick it.

contents

seventeen chapters, in three parts.

Read them in order. Each one builds on the one before.

part I

Foundation and retrieval

  1. Python and ML fundamentalsThe language of the AI ecosystem and the maths behind models.
    8 sections
    1. 1.1Why Python, when you already have TypeScript
    2. 1.2The Python you actually need
    3. 1.3The data tools
    4. 1.4What machine learning actually is
    5. 1.5Neural networks in one page
    6. 1.6The maths for this chapter
    7. 1.7Build it: a classifier in a notebook
    8. 1.8Where people go wrong
  2. Foundation modelsWhat a language model is and how it produces text.
    11 sections
    1. 2.1What a language model is
    2. 2.2Tokens
    3. 2.3Embeddings: meaning as geometry
    4. 2.4The transformer
    5. 2.5How a model is made
    6. 2.6Open-weight and proprietary models
    7. 2.7The limits, and why they exist
    8. 2.8Choosing a model is an engineering decision
    9. 2.9The maths underneath
    10. 2.10Build it: one app, three providers
    11. 2.11Where people go wrong
  3. Compute and inferenceThe hardware and the process that run a model.
    11 sections
    1. 3.1A model is a very large pile of numbers
    2. 3.2CPU, GPU and TPU
    3. 3.3Training and inference
    4. 3.4Prefill and decode: why the first token is slow
    5. 3.5The KV cache
    6. 3.6Making inference cheaper
    7. 3.7The context window, priced
    8. 3.8Serving a model
    9. 3.9The maths underneath
    10. 3.10Build it: a model on your own machine
    11. 3.11Where people go wrong
  4. Prompt engineering and LLM APIsControlling a model through instructions, context, examples and output schemas.
    13 sections
    1. 4.1Anatomy of a model API call
    2. 4.2Four different jobs
    3. 4.3Layers of instruction
    4. 4.4Writing an instruction that holds
    5. 4.5Techniques
    6. 4.6Prompts are code
    7. 4.7Output your code can trust
    8. 4.8Managing the context window
    9. 4.9Sampling settings
    10. 4.10Calling an API reliably
    11. 4.11The maths underneath
    12. 4.12Build it: a support triage assistant
    13. 4.13Where people go wrong
  5. Data engineering and retrievalConnecting a model to private, live knowledge it was never trained on.
    13 sections
    1. 5.1Why retrieval, and not training
    2. 5.2The shape of a retrieval system
    3. 5.3Ingestion: getting clean text out of real documents
    4. 5.4Chunking: deciding what a searchable unit is
    5. 5.5Embeddings: the meaning of a chunk as a vector
    6. 5.6Search: finding the nearest chunks
    7. 5.7Generating an answer with citations
    8. 5.8Private and live data
    9. 5.9Architectures, from simple to elaborate
    10. 5.10Evaluating retrieval
    11. 5.11The maths underneath
    12. 5.12Build it: Project 1, a knowledge assistant
    13. 5.13Where people go wrong

at the end of this part you can build

Knowledge assistant

Upload documents, parse, chunk, embed into pgvector, answer with citations and per-document permissions.

part II

Advanced AI applications

  1. MemoryKeeping what matters about a user and a conversation across sessions.
    10 sections
    1. 6.1Why a model forgets
    2. 6.2Memory is not retrieval
    3. 6.3Kinds of memory
    4. 6.4The memory lifecycle
    5. 6.5Choosing what goes in the prompt
    6. 6.6Keeping memories apart, private and correct
    7. 6.7Tools for memory
    8. 6.8Build it: an assistant that remembers you
    9. 6.9The maths underneath
    10. 6.10Where people go wrong
  2. Agents and tools(being written)Systems that plan, call tools, observe the result and loop until the goal is done.
  3. Guardrails and AI security(being written)Protecting an AI app from hostile input, leaks, unsafe output and runaway agents.
  4. Model routing and caching(being written)Sending each request to the right model, and not paying twice for the same answer.
  5. Multimodal AI(being written)Apps that read and produce images, audio and video, not only text.
  6. Fine-tuning and model adaptation(being written)Changing a model's weights to fit a task, a format or a domain.

at the end of this part you can build

Research and workflow agent

Project 1 plus an orchestration graph, tools, web search, MCP, memory and human approval.

part III

Production AI engineering

  1. Evals and testing(being written)Measuring quality when the same input can give different outputs.
  2. Observability and tracing(being written)Seeing inside an AI request in production: prompts, retrieval, model calls, tools, cost.
  3. Deployment and LLMOps(being written)Taking an AI app from a laptop to thousands of users, and keeping it running.
  4. AI architecture and system design(being written)Designing AI systems that scale, recover from failure and stay affordable.
  5. Application layer(being written)The product people actually touch, tying every layer together.
  6. Governance, privacy and compliance(being written)Making AI systems responsible, transparent and lawful.

at the end of this part you can build

Production AI product

Project 2 plus a web front end, an API, Redis, routing, guardrails, evals, tracing, containers and CI/CD.

keep these handy

the whole picture, on one shelf.

Come back to these while you read.

An AI application is built in layers. Each chapter teaches one of them; the engineering on the right runs through all of them.