Library
AI Engineering

Building AI systems

AI Engineering

Chip Huyen · O'Reilly Media · 2024

The argument

AI engineering is the work of building applications on top of foundation models that you did not train yourself. The author argues that the model-as-a-service approach turned AI from a specialist field into a development tool anyone can use, and that this changes where the hard problems are. More usage means more chances for expensive failures, so evaluation becomes the central discipline. The book then gives a ladder to climb: start with the simplest technique that works, and move to heavier ones only when evaluation shows you need them.

How the book is built

  1. 01

    Framing the field

    Chapter 1

    Traces the path from language models to large language models to foundation models, and defines AI engineering as the practice that grew out of it. It surveys use cases (coding, image and video production, writing, education, conversational bots, information aggregation, data organization, workflow automation) and then covers planning an application: evaluating the use case, setting expectations, milestone planning and maintenance. It closes with the AI engineering stack, split into three layers, and compares AI engineering with ML engineering and with full-stack engineering.

  2. 02

    What a foundation model is made of

    Chapter 2

    Walks through the ingredients that decide how a model behaves: training data (including multilingual and domain-specific models), architecture and size, and post-training through supervised finetuning and preference finetuning. It then covers sampling, which is how a model turns probabilities into text, including sampling strategies, test-time compute and structured outputs. The chapter ends on the probabilistic nature of these systems, which explains why the same prompt can give different answers.

  3. 03

    Evaluation methodology

    Chapter 3

    Starts with why open-ended output is hard to evaluate, then builds the toolbox. Language modeling metrics come first: entropy, cross entropy, bits-per-character and bits-per-byte, and perplexity. Exact evaluation follows: functional correctness, similarity against reference data, and embeddings. The longest part is AI as a judge, covering why to use it, how to use it, its limitations and which models can act as judges. The chapter ends with comparative evaluation, where models are ranked by head-to-head preference.

  4. 04

    Evaluating whole systems

    Chapter 4

    Moves from evaluating a model to evaluating a system. It defines evaluation criteria (domain-specific capability, generation capability, instruction-following, cost and latency), then a model selection workflow that includes the build versus buy decision and how to read public benchmarks. It finishes with a three-step evaluation pipeline: evaluate all components of the system, write an evaluation guideline, and define evaluation methods and data.

  5. 05

    Prompt engineering

    Chapter 5

    Covers in-context learning (zero-shot and few-shot), system prompts versus user prompts, and context length and efficiency. The best-practice section is concrete: write clear instructions, give enough context, break complex tasks into subtasks, give the model time to think, and iterate. It adds prompt engineering tools and how to organize and version prompts. The last third is defensive: proprietary prompts and reverse prompt engineering, jailbreaking, prompt injection, information extraction, and defenses against prompt attacks.

  6. 06

    RAG and agents

    Chapter 6

    Retrieval-augmented generation is covered through its architecture, retrieval algorithms, retrieval optimization and RAG beyond text. Agents are covered through an overview, tools, planning, failure modes and evaluation, and memory. The two share one idea: the model gets information or capabilities from outside its weights.

  7. 07

    Finetuning

    Chapter 7

    Starts with when to finetune and when not to, and how finetuning compares with RAG. The technical core is memory bottlenecks: backpropagation, trainable parameters, memory math, numerical representations and quantization. It then covers techniques (parameter-efficient finetuning, model merging, multi-task finetuning) and practical tactics.

  8. 08

    Dataset engineering

    Chapter 8

    Treats data as an engineering product. Data curation is organized around quality, coverage and quantity. Then come data acquisition and annotation, augmentation and synthesis (traditional and AI-powered), and model distillation. The chapter ends with data processing: inspecting, deduplicating, cleaning and filtering, and formatting data.

  9. 09

    Inference optimization

    Chapter 9

    Explains why serving a foundation model is costly and how to reduce cost and latency. It defines the inference performance metrics and the role of AI accelerators, then separates two levels of optimization: the model itself, and the inference service around it.

  10. 10

    Putting it together

    Chapter 10 and Epilogue

    Presents an architecture built up in five steps: enhance context, put in guardrails, add a model router and gateway, reduce latency with caches, and add agent patterns. It then covers monitoring and observability, pipeline orchestration, and user feedback, including how to extract feedback from conversations, how to design for it, and where it falls short.

Concepts worth keeping

Model-as-a-service

You call a hosted or open model instead of training one. The skills that matter shift from model training toward evaluation, prompting, context construction and system design.

Perplexity

A measure of how surprised a language model is by text. It is the exponential of cross entropy, so lower is better. It is useful for comparing language models during training, and weak as a measure of whether an application answer is correct.

AI as a judge

Using a model to score another model's output against a rubric. It scales where human review does not, but the judge is itself a probabilistic model. For an engineer that means calibrating its scores against a sample of human labels before trusting it.

Retrieval-augmented generation

Fetch relevant documents at query time and place them in the prompt, so the model answers from supplied evidence. It adds knowledge without changing weights, and its quality depends on retrieval as much as on the model.

Finetuning memory math

Training needs memory for weights, gradients and optimizer state, not only the weights. Numerical precision and quantization change that budget, which is why parameter-efficient techniques that train few parameters are attractive.

The five-step architecture

Context enhancement, guardrails, a router and gateway, caching, and agent patterns. The order matters: each step is added when the previous one stops being enough.

What the author concludes

The publisher overview states the argument directly: the more AI is used, the more catastrophic failures become possible, so evaluation matters more. The book's practical conclusion is a progression. Choose a model with an evaluation pipeline, adapt it with prompting first, add retrieval or agents when the task needs outside knowledge or actions, finetune when the cheaper methods plateau, and design the architecture and the user feedback loop so the system improves after launch.

Limits to keep in mind

  • It was published in December 2024. The principles are stable, but specific models, benchmarks and tools in this field change within months, so use it for the structure and check current tooling separately.
  • It is a map of decisions, not a code tutorial. The publisher lists it as intermediate to advanced, and it assumes you can already build software.
  • Agents and test-time compute are moving areas. Treat the agent chapter as a framework for thinking about failure modes, not a final recipe.

What I take into AI engineering work

  • Write the evaluation pipeline before building features. Decide what good output means, how you will measure it, and on what data.
  • Climb the ladder in order: prompting, then retrieval, then finetuning. Each step costs more and needs a reason that evaluation can show.
  • Budget cost and latency as requirements from day one, not as an afterthought.
  • Treat prompt injection as a normal threat model for any application that reads outside text.
  • Log user feedback from the start. It is both a product signal and future training data.

Sources

My note

The framing that stands out is that AI engineering starts from a model you did not train, so evaluation of open-ended output becomes the main engineering problem. Prompting, retrieval and finetuning are treated as different levers with different costs, not as steps on one ladder. Agents add tools and planning, and the book is clear that they also add new ways to fail.

Next bookSpeech and Language Processing