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
- 1Read a chapterTop to bottom. The diagrams move when you click them.
- 2Build the small thingEvery chapter ends with something to make on your own machine.
- 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
- Python and ML fundamentalsThe language of the AI ecosystem and the maths behind models.read →
- Foundation modelsWhat a language model is and how it produces text.read →
11 sections
- 2.1What a language model is
- 2.2Tokens
- 2.3Embeddings: meaning as geometry
- 2.4The transformer
- 2.5How a model is made
- 2.6Open-weight and proprietary models
- 2.7The limits, and why they exist
- 2.8Choosing a model is an engineering decision
- 2.9The maths underneath
- 2.10Build it: one app, three providers
- 2.11Where people go wrong
- Compute and inferenceThe hardware and the process that run a model.read →
11 sections
- 3.1A model is a very large pile of numbers
- 3.2CPU, GPU and TPU
- 3.3Training and inference
- 3.4Prefill and decode: why the first token is slow
- 3.5The KV cache
- 3.6Making inference cheaper
- 3.7The context window, priced
- 3.8Serving a model
- 3.9The maths underneath
- 3.10Build it: a model on your own machine
- 3.11Where people go wrong
- Prompt engineering and LLM APIsControlling a model through instructions, context, examples and output schemas.read →
13 sections
- 4.1Anatomy of a model API call
- 4.2Four different jobs
- 4.3Layers of instruction
- 4.4Writing an instruction that holds
- 4.5Techniques
- 4.6Prompts are code
- 4.7Output your code can trust
- 4.8Managing the context window
- 4.9Sampling settings
- 4.10Calling an API reliably
- 4.11The maths underneath
- 4.12Build it: a support triage assistant
- 4.13Where people go wrong
- Data engineering and retrievalConnecting a model to private, live knowledge it was never trained on.read →
13 sections
- 5.1Why retrieval, and not training
- 5.2The shape of a retrieval system
- 5.3Ingestion: getting clean text out of real documents
- 5.4Chunking: deciding what a searchable unit is
- 5.5Embeddings: the meaning of a chunk as a vector
- 5.6Search: finding the nearest chunks
- 5.7Generating an answer with citations
- 5.8Private and live data
- 5.9Architectures, from simple to elaborate
- 5.10Evaluating retrieval
- 5.11The maths underneath
- 5.12Build it: Project 1, a knowledge assistant
- 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
- MemoryKeeping what matters about a user and a conversation across sessions.read →
- Agents and tools(being written)Systems that plan, call tools, observe the result and loop until the goal is done.what it will cover
- Guardrails and AI security(being written)Protecting an AI app from hostile input, leaks, unsafe output and runaway agents.what it will cover
- Model routing and caching(being written)Sending each request to the right model, and not paying twice for the same answer.what it will cover
- Multimodal AI(being written)Apps that read and produce images, audio and video, not only text.what it will cover
- Fine-tuning and model adaptation(being written)Changing a model's weights to fit a task, a format or a domain.what it will cover
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
- Evals and testing(being written)Measuring quality when the same input can give different outputs.what it will cover
- Observability and tracing(being written)Seeing inside an AI request in production: prompts, retrieval, model calls, tools, cost.what it will cover
- Deployment and LLMOps(being written)Taking an AI app from a laptop to thousands of users, and keeping it running.what it will cover
- AI architecture and system design(being written)Designing AI systems that scale, recover from failure and stay affordable.what it will cover
- Application layer(being written)The product people actually touch, tying every layer together.what it will cover
- Governance, privacy and compliance(being written)Making AI systems responsible, transparent and lawful.what it will cover
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.
Intelligence and knowledge
prompting, retrieval, memory, fine-tuning
1 / 10 · Application layer
The question arrives
An authenticated request reaches the API, is checked against the user's usage limit, and opens a stream so the answer can arrive as it is written.
Work each one by hand with tiny numbers first, then in NumPy, then check it against a library. Each note says which chapters lean on it.
maths note 1
Notation, functions, exponentials and logs
Every later formula is written in this notation, and logs are why a model can multiply a thousand tiny probabilities without them rounding to zero.
used in: chapter 1
maths note 2
Vectors, norms, dot product, similarity
Embeddings are vectors, and semantic search is ranking them by this number.
used in: chapter 5, chapter 10
maths note 3
Matrices and linear layers
A transformer is mostly matrix multiplication, and brute-force vector search is one matrix times one vector.
maths note 4
Retrieval maths: TF-IDF, BM25, ranking metrics
Hybrid search, reranking and retrieval evaluation are these formulas and nothing more.
used in: chapter 5
maths note 5
Probability foundations
This is how a language model defines the probability of a text, and why a ten-step agent at 95% per step finishes only 60% of the time.
maths note 6
Softmax and sampling
Temperature, top-k and top-p, every generation setting an API takes, are this one function.
maths note 7
Calculus: derivatives, chain rule, gradients
Training is following the gradient of the loss downhill, and backpropagation is the chain rule run backwards.
used in: chapter 11
maths note 8
Optimization, loss and low-rank matrices
The optimizer, the learning rate and why LoRA trains 0.39% of the weights and still fits on a small GPU.
used in: chapter 11
maths note 9
Statistics for evals
80% on a hundred questions is somewhere between 72% and 88%. Without this, noise ships as an improvement.
used in: chapter 8, chapter 12
maths note 10
Production numbers: percentiles, throughput, cost
Dashboards, budgets, routing and caching decisions are all these numbers.
used in: chapter 9, chapter 13, chapter 15
maths note 11
Information theory: entropy, cross-entropy, perplexity
What loss means when you fine-tune, what perplexity measures, and why a tuned model is held close to its base.
used in: chapter 11, chapter 12
maths note 12
Transformer maths, end to end
Read the attention formula, size a GPU for a model and explain why long contexts cost so much.
used in: chapter 2, chapter 3, chapter 14
0 / 28 can explain
AI fundamentals
Building on model APIs
Retrieval and data
Agents and memory
Production engineering
Whatever you meet in these chapters, a new database, a model, a framework, ask it these. Draw a card.
1 of 8: What problem does it solve?
- Training a language model from scratch
- Weeks of GPU programming
- Multi-agent systems before a single agent works
- Five orchestration frameworks at once
- Fine-tuning before prompting and retrieval
- Complex Kubernetes before a simple deploy
Do not drop backend strengths to become an AI engineer; combine them. Node.js, TypeScript, SQL, Postgres, Redis, APIs and system design are the foundation. Python, models, retrieval, agents and production engineering go on top.