top of page

Welcome to the VBNN Digital Library

Unlock a Vast Knowledge Ecosystem

Featuring over 30,000 books, academic papers, illustrations, and expert insights—continuously updated to support your research and professional growth.

​

Welcome to our library!

Here, you will find an exclusive collection created 100% by our own faculty, meaning you will not find these resources anywhere else. Over the last 20 years, our team has written much more than what is currently online, and we are actively working to upload our complete back catalog. We update our platform regularly, so be sure to check back from time to time. If you ever need help finding a specific resource, you can always contact us!

​

Maximize Your Access

Log in to instantly view and download tailored resources directly aligned with your specific program and curriculum.

Ready to begin? Sign in above to explore your personalized dashboard.

​

Please note: Login is only possible using your institutional email address; otherwise, the system will not recognize your account.

​

VBNN Library AI

Introducing our fully integrated Library AI. Designed to support your research, you may submit inquiries in any language and receive precise, evidence-based responses drawn exclusively from our published scholarly articles and textbooks.

Search...

Latest Publications:

Search this site

Results found for empty search

  • Agentic Workflows (Building Autonomous AI Systems with LangChain and AutoGPT)

    Download the Book (PDF): Introduction On 30 March 2023, a game developer named Toran Bruce Richards published a small Python program to GitHub under the name Auto-GPT. It did something that, at the time, felt slightly illicit. Instead of asking GPT-4 a question and reading the answer, it gave the model a name, a role and a handful of goals, then fed the model's own output back to it as the next input. The model was told it could issue commands: search Google, browse a website, read and write files, run Python, even spawn other copies of itself. Each turn it produced a block of structured text containing its "thoughts", its "reasoning", its "plan", a line of "criticism" aimed at itself, and the command it wanted to run. The program executed the command, appended the result to the conversation, and went round again. Within weeks it was the most talked-about repository on GitHub. People set it to work on market research, on building websites, on running small businesses. One well-publicised fork, ChaosGPT, was given the goal of destroying humanity, and mostly tweeted about it. What actually happened when people ran Auto-GPT was more instructive than the headlines. It got stuck. It searched for the same thing five times in a row. It wrote a file, forgot it had written it, and wrote it again. It decided the best next step was to research how to do the task rather than doing it. It ran up bills, because every turn sent the whole growing conversation back to GPT-4, which at the time cost three cents per thousand input tokens. Every so often it did something genuinely impressive, and that was enough to keep people coming back. But very few of the businesses it was asked to start ever opened. Three and a half years later, the same basic shape (a language model, a set of tools, and a loop that feeds results back to the model) sits underneath coding assistants that resolve real issues in real repositories, customer service systems that issue refunds, research tools that read hundreds of pages before writing a report, and back-office automations that reconcile invoices against purchase orders. LangChain and LangGraph, the most widely used open-source frameworks for building such systems, reached their 1.0 releases in October 2025 and list Uber, LinkedIn, Klarna and JP Morgan among their users. AutoGPT itself has turned into a platform with a visual builder in which agents are assembled from typed blocks. The Model Context Protocol, which standardises how models discover and call tools, was handed to a Linux Foundation body in December 2025 with more than ten thousand public servers already in existence. The loop did not get dramatically more clever between 2023 and 2026. Models improved, a great deal, and that matters. But the more important change was in what surrounds the model. The systems that work now bound what the model may do, record what it has done, check what it claims, stop it when it wanders, recover when the network fails halfway through a payment, and ask a person before doing anything irreversible. The systems that failed in 2023 did none of that. They treated autonomy as a property you grant to a model by removing constraints. The systems that succeed treat it as something you build, deliberately and in layers, around a component you know to be unreliable. The argument of this book That observation is the controlling idea of everything that follows: an agent's reliability lives in the loop you build around the model, not in the model itself, so autonomy should be engineered and earned step by step rather than granted. Each chapter takes one part of that loop and shows how to build it well. This is not a pessimistic position. Models will keep improving, and a better model makes every part of the loop easier. But even an excellent model is a probabilistic component. If a step succeeds 95 percent of the time, twenty such steps in a row succeed about 36 percent of the time. That arithmetic does not care how impressive any single step looks in a demo. It is why a research group at METR, measuring how long a task (in human working time) an agent can complete half the time, found in 2025 that models of that era succeeded almost always on tasks a human finishes in under four minutes and less than one time in ten on tasks that take a human more than four hours. The length of task agents can handle has been growing fast, doubling roughly every seven months by METR's estimate, and that is precisely why the engineering around the loop matters more each year rather than less. Longer tasks mean more steps, more state, more chances to fail, and more damage when failure goes unnoticed. The practical upshot is that the decisions which determine whether an agent works are mostly ordinary software engineering decisions applied to an unusual component. What exactly does a tool accept and return? What happens when it times out? Where is the state stored, and can the run resume after a crash without charging the customer twice? Which actions require a human signature? How is the agent stopped when it begins to repeat itself? How will you know, before your users tell you, that last week's prompt change halved the success rate on refund requests? None of these questions is answered by a better prompt. Who this is for and what it covers This book is written for practitioners: software engineers, technical leads, data scientists and technically minded product people who have used language models through a chat interface or a single API call and now want to build systems that take multiple steps on their own. It assumes you can read Python and know roughly what an HTTP request is. It does not assume you have built an agent before. The two names in the subtitle are there for a reason. LangChain, with its companion runtime LangGraph, is the most widely adopted toolkit for building agentic systems in code, and its evolution from a library of composable "chains" in 2022 to a graph-based runtime with persistence and human approval in 2025 is a compressed history of what the field learned. AutoGPT is the project that made the idea of an autonomous agent famous, and its evolution from an open-ended loop to a platform of constrained, inspectable blocks tells the same story from the other direction. Studying both together shows that the practitioners who started from opposite ends of the design space converged on the same conclusions. The book uses both as worked material, but it is not a manual for either. APIs change; the reasons behind them change much more slowly. Where code appears, it is short and illustrative, and the prose carries the argument. The chapters run in the order you would build a system. Chapter 1 defines an agent precisely, separating it from the many things that are called agents, and traces how the loop came to be. Chapter 2 argues that most multi-step AI systems should begin as fixed chains of calls, and shows how to compose them. Chapter 3 treats tools as contracts between a model and the world, and explains how to design them so a model can use them correctly. Chapter 4 takes the most common and most dangerous tool, access to the web, and covers search, fetching, scraping, and the legal and adversarial terrain around them. Chapter 5 deals with state and memory: what the model sees on each turn, what is stored outside it, and why a larger context window does not remove the problem. Chapter 6 puts these pieces together in LangChain and LangGraph, including durable execution and human interruption. Chapter 7 studies AutoGPT, from its original loop to its current platform, as a case study in the costs and lessons of maximal autonomy. Chapter 8 is the core of the engineering argument: how to design loops that tolerate failure through budgets, retries, idempotency, checkpoints, verification and escalation. Chapter 9 covers the two disciplines without which no agent should reach production, security against prompt injection and systematic evaluation. A note on terms and time Vocabulary in this field is unsettled, and marketing has made it worse. "Agent" is applied to everything from a chatbot with a search box to a system that runs unattended for days. This book uses the term narrowly, and Chapter 1 explains the definition. "Workflow" is used in the sense that has become common among practitioners: a system in which the sequence of steps is fixed by code, even if each step involves a model. "Agentic workflow", the phrase in the title, covers the whole range between the two, and much of the craft lies in choosing where on that range a given problem belongs. The book describes the field as it stands in late 2026. Specific version numbers, model names and benchmark scores will date quickly, and the text uses them sparingly, mainly where a specific number makes an argument concrete. The incidents and research it cites are real and are listed in the notes. Where the evidence is thin or disputed, the text says so. The design principles are the part meant to last. They are drawn from things that went wrong, often expensively, and from the patterns that the people who build these systems for a living have settled on after trying the alternatives. One more expectation is worth setting. Building a good agent is less glamorous than the demos suggest. Most of the work is in defining interfaces, handling errors, writing evaluation cases and reading traces of runs that went wrong. That work is what turns an impressive prototype into a system you can leave running. If this book does its job, you will come away less excited about autonomy as a spectacle and more capable of delivering it as a product. CHAPTER 1 From Prompt to Loop A single call to a language model is a function. Text goes in, text comes out, and whatever the model "decided" exists only in the words it returned. You can chain such calls together, inspect each output, and decide in your own code what to do next. Nothing about this is autonomous. The interesting shift happens at a specific and identifiable moment: when the output of the model is allowed to determine what the program does next, and the result of that action is fed back to the model so it can decide again. At that point the program contains a loop whose control flow is chosen, turn by turn, by a probabilistic component. That is what this book means by an agent. The definition is deliberately narrow. It excludes a great deal of what is sold as agentic: a chatbot that answers questions from a knowledge base, a classifier that routes emails, a pipeline that summarises documents and writes the summaries to a database. Those systems may use models well and may be extremely valuable. But their sequence of steps is fixed by the programmer. The model fills in content; it does not choose the path. The distinction matters because the engineering problems are different. A fixed pipeline fails in predictable places and can be tested step by step. A loop whose path is chosen at runtime can fail anywhere, in combinations nobody wrote down, and its cost and duration are not known in advance. Anthropic's engineering team drew the same line in a widely read December 2024 essay, "Building Effective Agents", by Erik Schluntz and Barry Zhang. They called the first kind of system a workflow, in which models and tools are orchestrated through predefined code paths, and the second an agent, in which the model dynamically directs its own process and tool use. Their central advice was that most problems are better served by workflows, and that complexity should be added only when simpler designs demonstrably fall short. The rest of this book agrees, and tries to make that advice operational. But to know when you need an agent, you first have to see exactly what one is made of. The anatomy of the loop Strip away the frameworks and every agent has the same five parts. The first is the model, which reads a context and produces either a final answer or a request to take an action. Modern models do this through a feature that providers call function calling or tool use: the developer describes available tools with names, descriptions and parameter schemas, and the model can respond with a structured request such as "call search_orders with customer_id set to 4471" instead of, or alongside, ordinary text. The second is the tool set, the code that actually does things. A tool might query a database, call a third-party API, fetch a web page, run a shell command, or send an email. Tools are where the agent touches the world, and therefore where it does damage when it goes wrong. The third is the state: everything the agent knows about the task so far. In the simplest agents this is just the list of messages, the user's request, the model's replies, the tool calls and their results, which grows with every turn. In more serious systems it includes structured fields such as a plan, a list of completed subtasks, files written, budget spent and approvals pending. The fourth is the controller, the plain code that runs the loop. It sends the state to the model, inspects the response, executes any requested tool calls, appends the results to the state, checks whether to stop, and repeats. The controller is the part most demos treat as trivial and most production systems spend most of their effort on. The fifth is the stop condition. The obvious one is that the model returns an answer without requesting a tool. The necessary ones are everything else: a maximum number of turns, a maximum spend, a deadline, a detected repetition, an error that cannot be retried, a request for human approval. In code, a minimal controller fits in about a dozen lines of Python. It initialises a list of messages with the system prompt and the user's request. It then enters a for loop bounded by a constant, MAX_TURNS. On each pass it sends the messages and the tool schemas to the model and appends the reply to the list. If the reply contains no tool calls, the loop returns the reply's text as the answer. Otherwise, for each requested call, it runs the named tool with the supplied arguments through a function called run_tool, and appends the result as a tool message tagged with the call's identifier. If the loop runs out of turns without an answer, the controller raises a BudgetExceeded error carrying the message history, so the caller can see how far the run got. Everything else in this book is elaboration of that loop: what goes into run_tool, what messages becomes when it no longer fits, what happens when run_tool throws halfway through, what MAX_TURNS should be and what should happen when it is reached, and which calls should never be executed without a person looking first. The loop is easy to write and hard to make trustworthy. That gap is the subject. It is worth noticing what the model does not do in this picture. It does not execute anything. It cannot open a socket or write a file. Every effect in the world happens because the controller chose to carry out a request the model made. This is the most important architectural fact about agents, and it is easy to lose sight of when frameworks hide the controller. It means every safety property you want, every limit, permission, confirmation and audit record, can be enforced in ordinary code at the point where requests become actions. The model proposes; the controller disposes. Systems that forget this, and let model output flow straight into a shell or a database without a deterministic checkpoint, are the ones that make the news. How the loop was discovered The pieces of this design came together over about eighteen months, and the order in which they arrived explains a good deal about why the tooling looks the way it does. The first piece was the observation that language models reason better when they write out intermediate steps. Jason Wei and colleagues at Google showed in early 2022 that prompting a large model with worked examples containing explicit reasoning, a technique they called chain-of-thought prompting, sharply improved its performance on arithmetic and multi-step reasoning tasks. A model that writes down its reasoning is, in a sense, using its own output as working memory. The second piece was the idea of routing parts of a problem to external systems. In May 2022, researchers at AI21 Labs led by Ehud Karpas described an architecture they called MRKL (pronounced "miracle"), for Modular Reasoning, Knowledge and Language, in which a language model acts as a router that sends sub-problems to specialised modules such as a calculator, a database or a weather API, and composes the results. MRKL was a design for a system rather than a technique for prompting, but it named the essential division of labour: the model decides, the tools compute. The third piece, and the one that defined the modern loop, was ReAct. Shunyu Yao and colleagues at Princeton and Google published "ReAct: Synergizing Reasoning and Acting in Language Models" in October 2022. ReAct interleaved the two earlier ideas. The model was prompted to alternate between a Thought (free-text reasoning about what to do), an Action (a call to a tool such as a Wikipedia search), and an Observation (the tool's result, inserted by the controller), repeating until it produced an answer. On interactive decision-making benchmarks, ALFWorld, a text-based household environment, and WebShop, a simulated online store, ReAct prompting with only one or two examples outperformed imitation and reinforcement learning methods by absolute success-rate margins of 34 and 10 percentage points respectively. Just as importantly, its traces were readable. A person could look at the Thought lines and see why the agent did what it did, and where it went wrong. ReAct was a prompting technique, and early implementations had to parse the model's free text to find the Action line and its arguments. That parsing was fragile. A model might write "Action: Search[Paris population]" one time and "I will now search for the population of Paris" the next, and the controller had to cope. Meta's Toolformer paper, published by Timo Schick and colleagues in February 2023, approached the problem from training rather than prompting: it showed that a model could teach itself, from a small number of demonstrations, when to insert API calls into its own text and how to use the results. The industry answer arrived on 13 June 2023, when OpenAI added function calling to its chat API. Developers could now describe functions with JSON Schema, and the model, fine-tuned for the purpose, would return a structured call instead of prose that had to be parsed. Anthropic, Google and others followed with equivalent features. The fragile part of ReAct became a native capability of the model interface, and agents became markedly easier to build. In between, in the spring of 2023, came the public experiment. GPT-4 was released on 14 March. Within three weeks, Auto-GPT had appeared, and alongside it Yohei Nakajima's BabyAGI, a much shorter script that maintained a task list, executed the top task, and asked the model to generate new tasks from the result. Both projects bolted a ReAct-style loop to the most capable model then available and pointed it at open-ended goals. Their popularity was enormous and their practical results were thin, for reasons Chapter 7 examines in detail. But they established the public image of an agent, a system you give a goal and leave alone, and that image has shaped expectations, often unhelpfully, ever since. LangChain sits across this whole period. Harrison Chase released it as an open-source Python library in October 2022, initially as a set of abstractions for composing prompts, models and parsers into "chains", plus an implementation of ReAct-style agents. As the field moved, LangChain moved with it, accumulating integrations with hundreds of model providers, vector stores and tools. In January 2024 the team released LangGraph, a separate library for building agents as explicit graphs of steps with shared state, after concluding that the original agent abstractions hid too much of the loop for developers to control it. In October 2025 both reached 1.0, with LangChain's agent constructor rebuilt on the LangGraph runtime. That trajectory, from hiding the loop to exposing it, is one of the clearest signals in the field about where reliability comes from, and Chapter 6 follows it in detail. Degrees of autonomy Once the loop is visible, it becomes clear that "agent or not" is too coarse a question. Systems differ along several independent dimensions, and the useful design question is how much freedom to grant on each. One dimension is control of the path. At one extreme the code fixes every step. Next comes routing, where the model chooses among a few fixed branches. Then come bounded loops, where the model chooses which tool to call next but within a small, task-specific set and a fixed turn limit. At the far end the model can create its own subtasks, spawn sub-agents and decide when it is finished. Each step along this dimension makes the system more flexible and harder to test. A second dimension is reach of the tools. An agent that can only read from a product catalogue is a different object from one that can issue refunds, which is different again from one with an unrestricted shell. The same loop, the same model and the same prompt can be harmless or dangerous depending entirely on what the tools allow. A third is duration and supervision. Some agents run for a few seconds inside a user's request, with the user watching the result. Others run for hours in the background and report back. The longer an agent runs unwatched, the more the controller has to do on the user's behalf: limit spending, detect drift, save progress, and decide when to stop and ask. A fourth is reversibility of effects. Reading a web page can be repeated freely. Writing a draft file can be undone. Sending an email to a customer, executing a trade, or dropping a database table cannot. The reversibility of the most dangerous action an agent can take should govern how much of the rest of the design is devoted to preventing that action from happening by mistake. Thinking in these dimensions dissolves a lot of confused debate about whether some system "really" is an agent. It also suggests the basic discipline of the field: grant freedom along each dimension only where the task requires it, and only as far as your ability to observe and correct the system extends. A coding assistant that proposes changes in a sandbox and asks before pushing them is highly autonomous on the path dimension, modest on reach, short on duration, and fully reversible. That combination is why coding assistants became the first broadly successful agents. They sit in the region where a mistake costs a few minutes of a developer's attention rather than a customer's money. What the model contributes and what it cannot It is tempting, when an agent fails, to reach first for a better prompt or a bigger model. Sometimes that is right. A model that cannot follow a multi-step instruction, or that misreads tool schemas, will not be rescued by any amount of surrounding code. But it helps to be precise about what the model contributes to the loop, because that sets the boundary of what the loop must provide. The model contributes judgement in context. It reads an unstructured request, a page of search results, an error message or a half-finished plan, and decides what is relevant and what to do next. It can translate between the messy language of people and the strict language of APIs. It can recognise that a tool result does not answer the question and try something else. No earlier technology did these things at all, and they are the reason agents exist. The model does not contribute guarantees. It will sometimes call a tool with plausible but wrong arguments. It will sometimes report success when the tool returned an error, especially if the error message was ambiguous. It will sometimes repeat an action it has already taken, particularly when its context has grown long and the earlier action is buried. It will follow instructions it finds inside the data it reads, which, as Chapter 9 shows, is the root of the most serious security problem in the field. And its behaviour on a given input varies from run to run. A benchmark called τ-bench, published by Yao and colleagues at Sierra in June 2024, made that last point vivid. It simulated customer service conversations in retail and airline domains, where an agent had to follow written policies while using tools to look up and change bookings. The best model at the time succeeded on fewer than half the tasks, and when the same task was run eight times, the fraction of tasks solved on all eight attempts fell below a quarter in the retail domain. An agent that succeeds on a task most of the time is not the same as an agent that can be trusted with that task. Those properties define the job of everything outside the model. The tools must make wrong arguments hard to express and easy to detect. The state must keep the relevant history visible and the irrelevant history out of the way. The controller must notice repetition, bound cost, retry transient failures, refuse forbidden actions, and verify claims of success against the world rather than against the model's word. The surrounding process must measure success across many runs, not one. None of that is a criticism of the model. It is the normal relationship between a system and an unreliable component, the same relationship a database has with a disk that occasionally fails, or a web service has with a network that occasionally drops packets. Engineering has well-developed techniques for building reliable systems out of unreliable parts. The craft of agentic systems is mostly the work of applying those techniques to a new kind of unreliability. The next chapter starts where that craft should start: with the observation that many multi-step problems do not need the model to choose the path at all, and are better solved by composing calls in fixed sequences that you can test, measure and trust. CHAPTER 2 Chains Before Agents The first useful thing to know about building agents is when not to. A surprising share of the multi-step problems that teams bring to agent frameworks have a shape that is known in advance: extract these fields, look up these records, compare the two, draft a response, check the draft against a policy. When the shape is known, letting a model choose the path at runtime buys flexibility the task does not need and pays for it in cost, latency, variance and debuggability. Writing the path down in code, and using the model only to do the parts that require judgement, produces a system that is cheaper, faster, easier to test and easier to fix. This is not a temporary concession to weak models. It follows from the arithmetic of chained probabilities and the economics of testing, and it holds even when the model is excellent. It is also the natural starting point for building an agent, because the components of a well-built chain, structured outputs, validation between steps, explicit error handling, and logs of every intermediate result, are exactly the components a reliable agent needs. A team that has built good chains already has most of the machinery for a good loop. The arithmetic of composition Suppose each step in a multi-step process succeeds with probability p, independently. The whole process succeeds with probability p raised to the number of steps. At p = 0.95, five steps succeed 77 percent of the time; ten steps, 60 percent; twenty steps, 36 percent. At p = 0.99, fifty steps still succeed only about 61 percent of the time. Real steps are not independent, and errors at one step sometimes get caught and corrected at the next, so the numbers are a simplification. But the direction is right, and practitioners see it constantly: systems that look excellent on each component fall apart end to end. Fixed chains attack this arithmetic in three ways that a free-running agent cannot easily match. First, they reduce the number of model decisions. In a chain, the model never decides which step comes next, because the code already knows. Every decision you take away from the model is a decision that cannot go wrong. Second, they allow a gate after each step. Because the output of step three is expected to have a particular shape, the code can check it before step four begins: does the extracted invoice total parse as a number, does it match the sum of the line items, is the supplier one we have on file? A failed check can trigger a retry of that step alone, a fallback, or a halt with a precise error, instead of letting a bad value propagate through ten more steps and surface as a confident but wrong final answer. Gates turn the multiplication of probabilities into something closer to a sequence of independent, repairable stages. Third, chains make each step separately testable. You can assemble fifty examples of step three's input and expected output, measure its accuracy, change its prompt, and measure again, without running the whole system. An agent's behaviour emerges from the interaction of all its decisions, so it can only be tested as a whole, and whole-system tests are slower, noisier and more expensive. There is a further practical benefit. A chain's cost and latency are predictable. If it makes four model calls of known size, you know roughly what each run will cost and how long it will take, and you can provision for it. An agent that might take three turns or thirty cannot be costed in advance, which matters a great deal when it runs a million times a month. Five patterns that cover most of the ground Schluntz and Zhang's essay named five recurring workflow patterns, and they are a good map of the territory. Each is simple, and most real systems combine several. Prompt chaining is a fixed sequence of calls, each consuming the previous one's output, with optional gates between them. Generating marketing copy and then translating it is a chain; so is extracting the claims from a contract, checking each against a policy, and drafting a summary of exceptions. Chaining trades a little latency for much higher accuracy, because each call has a narrow task it can do well. Routing classifies an input and sends it down one of several specialised paths. A support system might route refund requests, technical questions and account changes to different prompts, tools and even models, using a small, fast model for the classification itself and a larger one only where needed. Routing is the first point at which a model influences control flow, but in a tightly bounded way: it picks one of a handful of labels, and the code takes it from there. Because the output is a label, the router can be evaluated like any classifier, with precision and recall on a labelled test set. Parallelisation runs several calls at once and combines the results. It comes in two forms. Sectioning splits a task into independent parts, such as reviewing each clause of a contract separately, or running a content check alongside the main response generation, and merges them. Voting runs the same task several times and aggregates, which exploits the model's variability rather than suffering from it. Xuezhi Wang and colleagues at Google showed in 2022 that sampling several chain-of-thought answers and taking the majority, a method they called self-consistency, substantially improved accuracy on reasoning benchmarks over a single sample. Voting is also a cheap way to estimate confidence: if five samples agree, the answer is more likely right than if they split three to two. Orchestrator-workers has a central model break a task into subtasks at runtime and dispatch them to worker calls, then synthesise the results. It looks like parallelisation, but the subtasks are not known in advance; the orchestrator decides them from the input. A coding assistant that must change an unknown number of files to implement a feature is the canonical example. This pattern sits on the boundary between workflow and agent, because the model now shapes the structure of the work, though usually in one planning step rather than continuously. Evaluator-optimiser pairs a generator with a critic in a loop: one call produces a draft, another evaluates it against explicit criteria and returns feedback, and the generator revises until the critic is satisfied or a limit is reached. It works when the criteria can be stated clearly and when feedback actually helps, as in literary translation or code that must pass tests. It is the first pattern with a genuine loop, and it already needs a stop condition and a turn limit. Table 1 sets these patterns beside the fully autonomous agent loop, along the dimensions that matter most for engineering. Table 1. Workflow patterns compared with an autonomous agent loop. Pattern Who chooses the path Number of model calls Best suited to Main risk Prompt chaining Code Fixed Decomposable tasks with known steps Error propagation without gates Routing Model picks a label, code acts Fixed per route Distinct input categories Misclassification Parallelisation Code Fixed, concurrent Independent subtasks, voting Inconsistent merged results Orchestrator-workers Model plans once, code dispatches Varies with plan Subtasks unknown in advance Poor decomposition Evaluator-optimiser Code loop, model judges Bounded by iterations Clear criteria, useful feedback Critic and generator agree on wrong answer Autonomous agent Model, every turn Unbounded without limits Open-ended tasks, unpredictable steps Drift, loops, cost, unsafe actions The table makes a point that the prose should state plainly. Moving down it, flexibility rises and so does every kind of risk. The decision to move a system down a row should be driven by evidence that the row above cannot do the job, not by the appeal of the row below. Making chains robust in practice The quality of a chain depends less on the cleverness of its prompts than on the discipline of its seams. Three practices do most of the work. The first is structured output at every boundary. If step two produces free text that step three must parse, you have rebuilt the fragility that function calling was invented to remove. Every major provider now supports constraining output to a JSON Schema, and frameworks wrap this in convenient forms. In LangChain, a model's with_structured_output method takes a Pydantic class and returns validated instances of it; LangChain 1.0's agent constructor accepts a response_format that does the same for an agent's final answer. A schema forces the model to commit to fields, gives the code something it can validate mechanically, and documents the interface between steps in a form other engineers can read. A typical extraction step makes the idea concrete. The developer defines a Pydantic class called InvoiceFields with five fields: the supplier name and invoice number as strings, the total as a number constrained to be zero or greater, the currency as a string that must match the pattern of a three-letter code, and a list of line-item totals. Passing that class to with_structured_output produces an extractor whose output is guaranteed to be an InvoiceFields instance or an error. The very next line of code then checks that the line-item totals sum to the stated total, within a cent, and raises a validation failure if they do not. The validation after the call is the point. The schema guarantees that total is a non-negative number; it cannot guarantee that it is the right number. A domain check, here that line items sum to the total, catches a class of extraction error that no schema can. Every gate should combine both kinds of check: shape, which the schema handles, and sense, which only your knowledge of the domain can supply. The second practice is narrow steps with explicit inputs. A step that receives only what it needs is easier to prompt, cheaper to run and less likely to be distracted. Passing an entire email thread to a step whose job is to extract a tracking number invites the model to mention something else it noticed. Narrow steps also make failures interpretable: when a step that only extracts dates gets a date wrong, there are only a few possible causes. The third practice is deterministic code wherever determinism is possible. If a step can be done with a regular expression, a SQL query, a lookup table or arithmetic, it should be. Models are excellent at reading messy input and poor at being consistent; code is the reverse. Good chains alternate between the two, using the model to turn unstructured input into structured data and code to do everything that can be done on structured data. A remarkable number of agent failures in the wild come from asking a model to do arithmetic, compare dates or count items that a few lines of Python would have handled perfectly. LangChain's original contribution was a vocabulary for composing such steps. Its LangChain Expression Language, introduced in 2023, let developers pipe prompts, models, parsers and arbitrary functions together with a | operator into "runnables" that supported batching, streaming, retries and fallbacks uniformly. A runnable could be given .with_retry() to retry transient failures or .with_fallbacks([other_model]) to try a second provider if the first failed. Those primitives are still available and still useful for linear pipelines. The broader lesson they encoded is that composition, retry and fallback are properties of the pipeline, not of the prompt, and belong in code that every step shares. A worked example: expense review Consider a concrete case that teams often propose as an agent: reviewing employee expense claims. Each claim arrives as a form with attached receipts, and a reviewer must check that the receipts match the claimed amounts, that each expense is permitted under the company's travel policy, that limits for meals and hotels are respected, and that nothing has been claimed twice. An "expense agent" with tools to read receipts, search the policy and look up past claims is easy to imagine and easy to demo. Written as a chain, the same system has six steps. The first is a model call with structured output that extracts, from each receipt image or PDF, the merchant, date, currency, amount and category, with a confidence field. The second is code: it converts currencies at the rate for the receipt date, sums the receipts, and compares them with the claimed total. The third is code again: it looks up past claims by the same employee for the same merchant and date to catch duplicates. The fourth is a routing call that classifies each line into one of the policy's categories. The fifth is code that applies the numerical limits for each category and city, which come from a table, not from a prompt. The sixth is a model call that reads the remaining flagged items together with the relevant policy paragraphs, retrieved by category rather than by semantic search, and drafts a short explanation for the reviewer. Only two of the six steps use a model in a way that requires judgement, and each has a narrow job and a structured output. Every arithmetic comparison, lookup and limit check is code, and so is exactly right every time. Each step logs its input and output, so when a reviewer disagrees with a flag, the trace shows at once whether the extraction misread a receipt, the classifier chose the wrong category, or the policy table is out of date. Low-confidence extractions are routed to a person rather than passed on. The system's cost per claim is fixed and small, and each step can be evaluated on its own labelled examples. Where does an agent belong in this design? Possibly nowhere. Possibly in one place: claims with unusual circumstances, a cancelled flight, a conference fee paid in a foreign currency through a colleague's card, may need the system to gather information it did not expect to need. A bounded agentic step, triggered only for claims the chain cannot resolve, with read-only access to booking records and the policy and a turn limit, can investigate and write up its findings for the reviewer. The chain handles the ninety-odd percent of routine claims cheaply and predictably; the agent handles the exceptions, where its flexibility is worth its cost; and a person still makes the decision on anything the system cannot clear. When to cross the line If chains are so much easier to trust, why build agents at all? Because some tasks genuinely do not have a shape known in advance. A research question may need two searches or twenty, depending on what the first one returns. A bug may be fixed by changing one line or require reading six files to understand. A customer's problem may turn out, three messages in, to be a different problem from the one they described. For these tasks, the cost of encoding every possible path in code exceeds the cost of letting a model choose, and the value of the task justifies the variance. A useful test has three questions. Can you write down the steps in advance for most inputs? If yes, write a chain, and handle the rare exceptions with a fallback to a person. Does the number or kind of steps depend on information discovered during the task? If yes, some runtime decision-making is needed, and the question becomes how little. And can success be checked at the end, by running tests, comparing a database state to a goal, or having a person review a draft? If not, think hard before building an agent at all, because you will have no way to know when it is wrong. When the answer does point to an agent, the chain still has a role. Many of the most effective production systems are hybrids: a fixed workflow with a bounded agentic step inside it. A support pipeline might classify the request, retrieve the customer's records and relevant policies deterministically, hand a bounded agent a small set of tools and a turn limit to resolve the issue, and then pass the agent's proposed action through a deterministic policy check and, for refunds above a threshold, a human approval queue. The agent does what only an agent can do, adapting to the specifics of the conversation, while everything around it stays fixed, cheap and testable. There is empirical support for this restraint. Sayash Kapoor, Arvind Narayanan and colleagues at Princeton, in a July 2024 paper titled "AI Agents That Matter", reviewed agent benchmarks and found that elaborate agent architectures often failed to beat simple baselines once cost was taken into account, such as retrying a plain model call several times or escalating to a stronger model only on failure. They argued that agent evaluations should report cost alongside accuracy, because an agent that is two points more accurate at ten times the cost is rarely the better system. Their critique was aimed at research benchmarks, but it applies with more force in production, where every unnecessary turn is paid for on every request. The practical rule that falls out of all this is simple to state and hard to follow when a demo of a free-running agent is on the table: start with the most constrained design that could possibly work, measure it, and relax constraints one at a time only where measurement shows a constraint is the thing holding the system back. Each relaxation should come with the machinery to observe and limit the new freedom it grants. The rest of this book supplies that machinery, beginning with the part of the loop through which every agent acts on the world: its tools. CHAPTER 3 Tools as Contracts An agent is only as capable as its tools and only as safe as their limits. A model that can reason brilliantly about a refund but has no way to look up the order is useless; a model with an unrestricted database connection is a hazard no matter how carefully it reasons. Between those extremes lies the main design surface of any agentic system: the set of functions the model is allowed to request, what each one accepts, what each one returns, and what each one is allowed to change. The right way to think about a tool is as a contract between two parties who cannot see each other. On one side is a model that knows only what the tool's name, description and parameter schema tell it, and what the tool returned on previous calls. On the other side is code that will do exactly what it is asked and nothing more. Every misunderstanding between them, a parameter interpreted differently, an error that reads like success, a return value too large to fit, turns into an agent failure. Good tool design is the craft of writing contracts that a model can honour and that code can enforce. Anthropic's engineers have argued that this deserves as much effort as designing a human interface. In "Building Effective Agents" they called it the agent-computer interface, and gave an example from their own work on SWE-bench, a benchmark in which an agent must resolve real GitHub issues in Python repositories. Their agent kept making mistakes with relative file paths after it had changed directory. Rather than adjusting the prompt, they changed the tool so that it required absolute paths. The model used that version without error. The lesson generalises: when an agent misuses a tool repeatedly, the first suspect is the tool, not the model. How tool calling actually works It helps to be precise about the mechanics, because several common mistakes follow from misunderstanding them. When you call a model with tools, the provider's API receives, alongside the conversation, a list of tool definitions. Each has a name, a natural-language description, and a JSON Schema describing its parameters. The provider renders these into the model's context in a format the model was trained on. The model then generates a response which may contain one or more tool-call blocks, each with a generated identifier, the tool name and a JSON object of arguments. Nothing has been executed at this point. Your code reads the tool calls, runs the corresponding functions, and sends their results back as tool-result messages tagged with the same identifiers, after which the model continues. Three consequences follow. First, tool definitions are part of the prompt. They consume context on every call, and the model reads them with the same attention, and the same failures of attention, as anything else in its context. A long, vague description is a long, vague prompt. Second, the arguments the model produces are generated text that happens to be shaped like JSON. Providers now offer strict modes that guarantee the arguments conform to the schema, and these are worth using, but conformance to a schema is not correctness. A well-formed customer_id can still be the wrong customer. Third, the tool result is just another message. The model has no special channel telling it whether a call succeeded; it infers that from whatever text you return. If your tool returns None on failure, or a stack trace the model cannot interpret, the model will guess, and it will sometimes guess wrong in the direction of reporting success. Modern models can also request several tool calls in one turn, for instance three searches at once. This is valuable for latency, and most frameworks execute parallel calls concurrently. It also means your controller must handle partial failure: two of three calls succeed and one times out. Each result goes back with its identifier, and the failed one should come back as an explicit error rather than being silently dropped, or the model will assume it has information it does not. In LangChain, the simplest way to define a tool is to decorate a typed Python function with @tool. The function's name becomes the tool name, its docstring becomes the description, and its type annotations become the parameter schema. Consider a tool called get_order that takes a single string argument, order_id. Its docstring says three things: that it looks up one order by its ID, which has the format 'ORD-' followed by eight digits; that it returns the order's status, items, total and shipping address; and that it should be used before answering any question about a specific order. In its body, if the database lookup finds nothing, the function does not raise an exception. It returns a small dictionary with an error field whose text reads, in effect, "No order found with ID ORD-12345678. Check the format or ask the customer to confirm it." Otherwise it returns a summary of the order. Every line of that docstring is doing work. It tells the model the identifier format, what the tool returns, and when to use it. The not-found path returns a message that tells the model what to do next, instead of raising an exception that would either crash the loop or arrive as an unreadable traceback. Designing the contract Several design decisions recur in every tool set, and the choices that work are now fairly well understood. Granularity. The most tempting tool is the most general one: give the agent execute_sql or run_shell and let it figure out the rest. General tools are powerful and occasionally necessary, especially in coding agents where the space of useful actions really is open-ended. But they push all the work of correctness and safety onto the model, and they make every policy the model must follow a matter of prompting rather than enforcement. For most business tasks, narrower tools work better. A refund_order(order_id, amount, reason) tool can check in code that the amount does not exceed the order total, that the order is within the refund window, and that the reason is one of the permitted values. An agent with execute_sql can be asked to do all that, and will usually comply, until the day it does not. The opposite mistake is wrapping every endpoint of an existing API as a separate tool. APIs designed for programmers are often too fine-grained for models: to schedule a meeting, a model might need to list users, fetch each calendar, compute overlaps and then create an event, each a separate call with its own chance of error. Anthropic's September 2025 guidance on writing tools for agents recommends consolidating such sequences into tools that match the task an agent is actually trying to do, a single schedule_event that finds availability and books it, so the model makes one decision instead of five. The right granularity is the one at which each tool corresponds to a meaningful step in the task, with the mechanical sub-steps handled in code. Names and descriptions. Names should be unambiguous and, when an agent has many tools, grouped by consistent prefixes so related tools sit together, crm_search_contacts and crm_update_contact rather than search and update. Descriptions should say what the tool does, when to use it, when not to, what each parameter means, and what comes back. Parameter names should carry meaning: user_id rather than user, start_date_iso rather than date. Where a parameter has a fixed set of valid values, express it as an enum in the schema so the model cannot invent a new one. Small edits to descriptions often produce large changes in behaviour, and they should be treated as code: versioned, reviewed and evaluated. Return values. A tool's output becomes part of the model's context, so it should contain what the model needs to decide its next step and nothing more. Raw API responses are usually wrong on both counts: full of internal identifiers, metadata and nested structures the model does not need, and missing the human-readable fields that would help it. Return names rather than opaque IDs where possible, keep the IDs the model will need for follow-up calls, and cap the size. When results are large, paginate or truncate with an explicit note saying more exists and how to get it. Claude Code, Anthropic's coding agent, limits tool responses to 25,000 tokens by default for exactly this reason: a single unbounded result can push everything else out of the model's attention. Errors as information. Tool errors should be returned to the model, not thrown past it, and they should be written for the model to act on. "Invalid date" is less useful than "start_date must be in YYYY-MM-DD format; you sent '03/10/2026'". "Rate limited" is less useful than "This service allows 10 requests per minute; wait before retrying or narrow the query". There is an important distinction here, though, which Chapter 8 develops. Errors the model can fix, such as malformed arguments or a record not found, should go back to the model. Errors it cannot fix, a network timeout, a provider outage or an expired credential, should be handled by the controller with retries or escalation, and the model should be told about them only if they persist. Sending every transient network blip to the model wastes turns and invites it to improvise. Side-effect classes. Every tool should be classified, in code, by what it can change. A practical scheme has three classes: read-only tools, which can be called freely and retried safely; reversible writes, such as creating a draft or adding a label, which can be undone; and irreversible or external actions, such as sending messages, moving money or deleting data, which need idempotency protection and usually human approval. The classification should drive controller behaviour automatically. Read-only tools can run in parallel and be retried; irreversible tools run one at a time, carry idempotency keys, and pass through an approval gate when the stakes warrant. Making the class an explicit attribute of the tool, rather than something a reviewer has to infer from its name, is the cheapest safety measure in agent engineering. How many tools. Every tool definition consumes context and competes for the model's attention. Agents given dozens of overlapping tools choose among them less reliably than agents given a handful of distinct ones. When a system genuinely needs many tools, two techniques help: route first, so a classifier narrows the toolset to the ones relevant to this request, or let the model search a tool catalogue and load definitions on demand. LangChain 1.0 ships middleware for both approaches, an LLM-based tool selector that picks the relevant subset before the main call, and support for providers' server-side tool search. Neither is a substitute for a well-curated toolset. Testing tools the way the model will use them Tools are usually tested as functions: given these arguments, does the code return the right result? That test is necessary and nowhere near sufficient, because the failures that matter most happen at the interface, where the model chooses which tool to call and what to pass. A tool can be perfectly correct and still be misused every third time because its description is ambiguous or its parameters invite the wrong values. The effective test puts a model in front of the tool. Assemble a set of realistic requests, give an agent the tool set, run each request several times, and read the transcripts. The patterns that emerge are specific and fixable: the model passes a customer's name where an ID was expected, so the parameter needs a clearer name and an example; it calls the search tool when it should call the lookup tool, so the descriptions need to say when each applies; it ignores the pagination note and concludes there were only ten results, so the note needs to be more prominent or the default page larger. Anthropic's tool-writing guidance recommends exactly this loop of evaluating, reading transcripts and revising descriptions, and goes further, suggesting that a model can be asked to analyse the transcripts and propose improvements to the tool definitions itself, with the changes then checked against held-out cases. Two techniques make this cheaper. The first is emulation: during early development, a model can stand in for a tool's implementation, generating plausible responses from the tool's description, so that the agent's use of the tool can be studied before the real integration exists. LangChain includes an emulator middleware for this purpose. Emulated results are no substitute for the real thing, but they surface interface problems early, when they are cheapest to fix. The second is recording: capture real tool responses during development runs and replay them in tests, so that the model's behaviour can be evaluated repeatably without calling live services. Tool definitions should also be versioned alongside the prompts that use them. A change to a description is a change to the agent's behaviour, often a larger one than a change to the system prompt, and it should go through the same evaluation before release. Teams that keep tool descriptions in code, reviewed like any other change and run against an evaluation suite in continuous integration, avoid a common failure: an engineer improves one tool's description for one case and silently degrades three others. The Model Context Protocol Until late 2024, every framework and every application defined tools in its own way. A tool written for LangChain had to be rewritten for another framework, and an integration with a company's internal systems had to be rebuilt for every agent that needed it. In November 2024, Anthropic published the Model Context Protocol, an open specification for exposing tools and data to models through a standard client-server interface. MCP is deliberately modest. An MCP server is a program that exposes three kinds of thing: tools, functions the model can call; resources, data the application can read into context; and prompts, reusable templates. Clients, which are the agent applications, connect to servers, discover what they offer, and relay the model's tool calls to them, using JSON-RPC messages over either standard input and output for local servers or HTTP for remote ones. The protocol says nothing about how an agent should reason or loop. It standardises only the boundary between agents and the systems they use. That modesty is why it spread. OpenAI, Google and Microsoft adopted it in their own products during 2025, and by the time Anthropic transferred MCP to the newly formed Agentic AI Foundation under the Linux Foundation in December 2025, alongside OpenAI's AGENTS.md convention and Block's goose agent, the company reported more than ten thousand active public MCP servers and over ninety-seven million monthly downloads of the Python and TypeScript SDKs. LangChain provides adapters that load an MCP server's tools as ordinary LangChain tools, and AutoGPT's platform can use MCP servers as blocks. For practitioners, this means that a well-built MCP server for an internal system is reusable across every agent framework a company adopts. Table 2 compares the main ways a tool reaches a model in current practice. Table 2. Four ways of giving a model a tool. Mechanism Where the tool is defined Discovery Portability Typical use Provider function calling JSON Schema in each API request Sent with every call Tied to your code Direct API integrations, small systems LangChain tool Decorated Python or TypeScript function Passed to the agent constructor Any model LangChain supports Framework-based agents MCP server Separate process or remote service Client lists tools at connection Any MCP-compatible client Shared integrations across apps and teams AutoGPT Platform block Typed block in the platform's library Visual palette in the builder Within the AutoGPT platform Low-code agent assembly The convenience of MCP brings a risk that deserves emphasis. Connecting an agent to a third-party MCP server means letting someone else's code define tools your model will read and call. Tool descriptions are prompt text, and a malicious or compromised server can put instructions in them. In April 2025, the security firm Invariant Labs demonstrated what it called tool poisoning: an MCP tool whose description contained hidden instructions that caused an agent to read sensitive local files and pass their contents to the attacker through an innocent-looking parameter. Because the description is shown to the model but rarely to the user, the attack is invisible in normal use. The defences are the ones you would apply to any third-party dependency: use servers from sources you trust, pin versions so a description cannot change silently, review tool definitions when they change, and run untrusted servers with the least privilege possible. Chapter 9 returns to this in the broader context of prompt injection. Tools as the enforcement point The deepest reason to treat tools as contracts is that they are where policy becomes enforceable. A prompt can ask a model not to refund more than the order total. A tool can make it impossible. A prompt can ask the model not to email customers outside business hours, or not to modify records belonging to another tenant, or not to touch production during a code freeze. A tool can check the clock, the tenant ID or the freeze flag and refuse, with an error message explaining why. The pattern is to move every rule that can be stated precisely out of the prompt and into the tool, leaving the prompt to carry only the judgement that cannot be codified. Policies in prompts are suggestions to a probabilistic reader. Policies in tools are guarantees. Each one you move removes a class of failure from the system entirely, and it does so without depending on any property of the model. This applies with special force to the tools through which agents read the outside world, because there the inputs are not just unpredictable but potentially hostile. The next chapter takes up that case: giving an agent access to the web. Hashtags: #AgenticWorkflows #AutonomousAISystems #AIAgents #AgenticAI #LangChain #LangGraph #AutoGPT #ArtificialIntelligence #LargeLanguageModels #LLMAgents #AIOrchestration #WorkflowAutomation #IntelligentAutomation #ToolCalling #FunctionCalling #ModelContextProtocol #MCP #ReActAgents #PromptChaining #MultiAgentSystems #AgentArchitecture #AgentMemory #StateManagement #HumanInTheLoop #DurableExecution #PromptInjectionDefense #AgentReliability #AIEvaluation #AIEngineering #ProductionAI

  • Trademark Law and Brand Protection (Dilution, Parody, and Domain Disputes)

    Download the Book (PDF): Introduction In 2014 a company that makes rubber dog toys shaped like liquor bottles put a new product on the market. It was a squeaky vinyl bottle in the unmistakable shape of a Jack Daniel's whiskey bottle, with the familiar black label and filigreed lettering. But the label read "Bad Spaniels," the bottle promised "The Old No. 2 on Your Tennessee Carpet," and the fine print noted that the contents were "43% POO BY VOL." and "100% SMELLY." Jack Daniel's was not amused. What followed was more than a decade of litigation that went to the Supreme Court of the United States, came back down, produced a finding that the toy tarnished one of the most famous brands in the world, and then, in August 2026, ended with a federal appeals court directing judgment for the dog toy company. A dispute over a chew toy is an unlikely place to find the whole of modern trademark law, but it is all there. There is the question of whether consumers would think the whiskey maker had made or approved the toy, which is the question of likelihood of confusion. There is the separate question of whether, even without any confusion, the toy harmed the famous brand by associating it with dog waste, which is the question of dilution. There is the question of whether a joke at a brand's expense deserves special constitutional solicitude, which is the question of parody and the First Amendment. And hovering behind it is the question every brand owner eventually faces: how much enforcement is wise, and when does defending a mark begin to cost more than it protects? This book is about those questions. It is written for lawyers who advise companies on their brands, for in-house counsel and brand managers who make enforcement decisions, and for anyone who wants a clear account of how American law protects commercial identity. It concentrates on the four areas where the most consequential and most contested disputes now arise: the likelihood-of-confusion standard that sits at the center of infringement law; the slow erosion of a mark into a generic word, which lawyers call genericide; the special protection that famous marks receive against dilution; and the fights over internet domain names, which have their own statute, their own global arbitration system, and their own peculiar economics. Running through all of them is the tension between protecting a brand and allowing others to talk about it, criticize it, and make fun of it. The argument of this book A single idea connects these subjects, and it is worth stating plainly at the outset because it shapes the advice in every chapter. A trademark is not a piece of property in the way a house or a patent is. It is a relationship between a sign and the public's understanding of that sign. The law protects a mark because, and only to the extent that, the public uses it to identify where goods or services come from. Every major doctrine in this book is a way of asking whether that relationship is being damaged, and by whom. Likelihood of confusion asks whether a defendant's use would lead the public to misunderstand the source of goods. Genericide asks whether the public has stopped using the mark to identify a source at all, and started using it as the ordinary name for a kind of thing. Dilution asks whether the public's association between a famous mark and a single source is being weakened or soured. Cybersquatting law asks whether someone has registered an internet address in order to exploit the public's association between a name and a business. And the parody and First Amendment cases ask when a defendant's use of a mark is really a comment on the brand rather than an attempt to borrow its source-identifying power. It follows that the best brand protection is not the most aggressive. The lawyer who understands that a mark's legal value lives in public perception will spend more energy managing that perception, gathering evidence of it, and choosing fights that strengthen it, and less energy sending demand letters to comedians. Overreaching enforcement often damages the very thing it aims to protect: it produces unfavorable precedent, fee awards, public ridicule, and in some cases a court opinion declaring that the mark means less than its owner claimed. The Bad Spaniels litigation, which began as a straightforward attempt to stop a crude joke, ended with an appellate court holding that the whiskey maker had failed to prove any harm to its reputation at all. That is the book's argument: trademark rights are measured by meaning, the doctrines are tools for detecting injury to meaning, and practical brand protection is the discipline of building, documenting, and defending meaning while leaving room for the speech the law is designed to tolerate. What the chapters cover Chapter 1 lays the foundation. It explains what makes a sign capable of functioning as a trademark, the spectrum of distinctiveness from fanciful coinages to generic words, the role of registration, and the limits that keep trademark law from becoming a tool for monopolizing useful product features. Chapter 2 takes up the likelihood-of-confusion standard, the test that decides most infringement cases. It explains the multi-factor tests the federal circuits use, the kinds of confusion courts recognize, the role of consumer surveys, and a question now before the Supreme Court about whether the strength of a mark is for a judge or a jury to decide. Chapter 3 turns to genericide: how Aspirin, Thermos, and Escalator lost their status as brands, why Google did not, and what the Supreme Court's 2020 decision about Booking.com means for owners of descriptive and hybrid names. It ends with the practical discipline of usage management that keeps a successful brand from becoming a victim of its own success. Chapter 4 addresses dilution, the doctrine that protects famous marks against uses that cause no confusion but still threaten the mark's distinctiveness or reputation. It traces the idea from a 1927 law review article to the Trademark Dilution Revision Act of 2006 and explains why dilution claims succeed far less often than brand owners expect. Chapter 5 examines parody and the First Amendment: the Rogers v. Grimaldi test for expressive works, the Supreme Court's decision in Jack Daniel's Properties, Inc. v. VIP Products LLC, the aftermath in the lower courts, and the constitutional decisions that have reshaped what the government may refuse to register. Chapters 6 and 7 cover domain disputes. The first explains litigation under the Anticybersquatting Consumer Protection Act, including its bad-faith factors, its statutory damages, and its in rem jurisdiction over domain names themselves. The second explains the Uniform Domain-Name Dispute-Resolution Policy, the fast, cheap, and global arbitration system through which most domain disputes are actually resolved, along with the rights protection mechanisms attached to the newer generic top-level domains. Chapter 8 draws the threads together into an enforcement strategy. It covers remedies, including the Supreme Court's recent decisions on profits and extraterritorial reach, and it addresses the judgment calls that separate effective brand protection from what critics call trademark bullying. The conclusion considers what follows from all of this for a practitioner advising a brand today, and what remains unsettled. A word on scope The book is principally about United States federal law: the Lanham Act of 1946, as amended, and the cases interpreting it. State law matters at the edges, particularly for dilution and unfair competition, and it is noted where it does. Because brands travel and domain names are global, there are comparative notes on European Union law where the contrast illuminates the American approach. The law described is current as of late 2026. Trademark law has moved quickly in recent years, with four Supreme Court decisions touching the field since 2023 and a fifth case granted for decision, and a reader relying on any specific rule should confirm that it has not changed. This book is for education and orientation, not legal advice on any particular matter. One last observation before the substance. Trademark law is often taught as a dry set of registration rules and factor lists. In practice it is one of the most human areas of law. It turns on what ordinary people see, assume, and remember when they walk down a supermarket aisle or type a name into a browser. The judges who decide these cases are asking what the public thinks, and the lawyers who win them are the ones who can show it. That is the practical lesson under every chapter that follows. Chapter 1: What a Trademark Protects Every trademark dispute, however exotic its facts, eventually comes back to a simple question: what does this sign mean to the people who encounter it? Before a court can decide whether a competitor's name is confusingly similar, whether a famous brand has been diluted, or whether a domain name was registered in bad faith, it has to know what rights the plaintiff actually holds. Those rights are not defined by the owner's investment, its ambitions, or the size of its legal department. They are defined by the public's understanding. This chapter sets out the foundations: what a trademark is, how the law sorts signs by their capacity to identify a source, how registration works and what it adds, and the limits that stop trademark law from being used to monopolize things that should be free for everyone. Source identification as the core function A trademark is any word, name, symbol, or device, or any combination of them, that a person uses to identify and distinguish its goods from those of others and to indicate their source, even if that source is unknown. That definition, found in section 45 of the Lanham Act, 15 U.S.C. § 1127, contains the whole logic of the field. The sign matters only because it tells the public something about origin. A consumer who picks up a box of cereal marked with a familiar name does not need to know the corporate structure of the company behind it. What the consumer knows is that goods bearing this name come from a single, consistent source, and that the experience of the last box is a fair guide to the next. The law protects that function for two reasons that point in the same direction. The first is consumer protection. A shopper who relies on a mark should not be deceived into buying something from a different source. The second is producer protection. A business that invests in consistent quality and builds a reputation should be able to capture the benefit of that reputation rather than having it taken by imitators. Courts and scholars often describe this in economic terms: trademarks lower consumers' search costs, because a trusted mark lets a shopper skip the work of investigating every product afresh, and they give producers an incentive to maintain quality, because the reputation attached to the mark is an asset worth protecting. Service marks do the same work for services, collective marks for the goods or services of members of an organization, and certification marks for goods that meet a standard set by the certifier, such as a regional origin or a safety standard. The principles in this book apply to all of them, and for convenience the book uses "trademark" and "mark" to cover the family. The range of things that can serve as a mark is broad. Words and logos are the familiar cases, but the Supreme Court held in Qualitex Co. v. Jacobson Products Co. (1995) that a color alone can function as a mark if it has acquired secondary meaning, in that case the particular green-gold of dry-cleaning press pads. Product packaging, restaurant décor, the shape of a product, a sound, and even a scent have all been recognized as capable of identifying source. What unites them is the functional test: does the relevant public see the sign as saying "this comes from a particular source," or merely as decoration, description, or a useful feature? The breadth of subject matter is matched by a fundamental limit on scope. Trademark rights protect against uses that interfere with the source-identifying function. They do not give the owner control over every appearance of a word in the English language. The owner of APPLE for computers cannot stop a grocer from selling apples, and the owner of a mark cannot generally stop a competitor from using the mark to refer truthfully to the owner's product in comparative advertising. Much of the law explored in later chapters, from nominative fair use to parody, is the working out of that limit. The spectrum of distinctiveness Not every sign is equally capable of identifying a source. Some are coined words that mean nothing except the brand. Others are ordinary words that tell consumers something about the product and only gradually come to be associated with one producer. The courts sort word marks along a spectrum first articulated in its modern form by Judge Henry Friendly in Abercrombie & Fitch Co. v. Hunting World, Inc. (2d Cir. 1976), a case about the word "safari" for clothing. The categories remain the starting point for every analysis of a mark's validity and strength, and they differ in how protection is acquired and how strong it is, as Table 1 sets out. Table 1. The spectrum of distinctiveness for word marks. Category Relationship to product Illustrations Protection Fanciful Invented word with no prior meaning KODAK, EXXON, XEROX Inherently distinctive; strongest Arbitrary Real word unrelated to the product APPLE for computers, CAMEL for cigarettes Inherently distinctive; strong Suggestive Hints at a quality; requires imagination COPPERTONE for sunscreen, GREYHOUND for buses Inherently distinctive Descriptive Directly describes a quality or feature SHARP for televisions, a surname, a place name Only with secondary meaning Generic The common name of the product itself "aspirin," "escalator," "cellophane" Never protectable Fanciful and arbitrary marks are the easiest to protect. A coined word such as KODAK has no meaning except as a brand, so any use of it by another seller for related goods is almost certain to suggest a connection. An arbitrary mark takes a real word and applies it to something unrelated; the word "apple" tells you nothing about a computer, so when it appears on one, consumers understand it as a brand. Suggestive marks require a step of imagination to connect the mark to the product. COPPERTONE suggests the result of using a suntan product without describing the product itself. Suggestive marks are treated as inherently distinctive, which means they are protected from first use without proof that the public has come to associate them with a source. Descriptive marks directly describe a characteristic, quality, function, ingredient, or purpose of the goods. They are not protected on first use, because a competitor may need the word to describe its own product, and because consumers will at first read the word as information rather than as a brand. A descriptive term becomes protectable only when it acquires what the law calls secondary meaning or acquired distinctiveness: proof that the primary significance of the term in the minds of the relevant public is to identify a producer rather than the product. Surnames and geographic terms are treated similarly. McDONALD'S and FORD began as surnames and became marks through use. Generic terms, at the bottom of the spectrum, are never protectable. They are the ordinary names of the goods, and granting one seller exclusive rights in them would prevent competitors from telling consumers what they sell. The line between descriptive and generic, and the process by which a successful mark can slide from the protected categories into the generic one, is the subject of Chapter 3. The boundaries between these categories are contested in practice, and much turns on where a mark lands. The line between suggestive and descriptive is especially fought over, because it determines whether the owner must prove secondary meaning. Courts use several tests: whether the term requires imagination to connect to the product, whether competitors need the term to describe their own goods, and whether others in the industry actually use it descriptively. None is decisive, and reasonable judges disagree. What a practitioner should take from this is that the choice of mark at the outset has lasting consequences. A client who insists on a name that describes the product is choosing a mark that will be harder to register, harder to enforce, and weaker against similar names for as long as it is used. The advice to choose a distinctive name is the cheapest brand protection there is. Trade dress and its special rules The distinctiveness spectrum was designed for words. The Supreme Court has adapted it, not always smoothly, to trade dress: the overall look of a product or its packaging. In Two Pesos, Inc. v. Taco Cabana, Inc. (1992), the Court held that the festive décor of a Mexican restaurant chain could be inherently distinctive and protected without proof of secondary meaning. Eight years later, in Wal-Mart Stores, Inc. v. Samara Brothers, Inc. (2000), it drew a sharp line. Product design, the Court held, can never be inherently distinctive. Consumers are aware that even the most unusual product shapes are usually chosen to make the product more useful or appealing, not to identify its maker, so a design is protected only on proof of secondary meaning. Packaging, by contrast, can be inherently distinctive, and where the category is doubtful, courts are to err toward classifying the dress as product design and requiring secondary meaning. The distinction matters enormously to clients in fashion, furniture, consumer electronics, and any industry where the look of the product is part of its appeal. A company that launches a distinctive product shape cannot rely on trade dress law to stop immediate copying. It needs design patent protection, copyright where available, or time and investment to build secondary meaning. Trade dress is further limited by the functionality doctrine. A feature that is essential to the use or purpose of a product, or that affects its cost or quality, cannot be protected as a trademark, however strongly consumers associate it with one source. In TrafFix Devices, Inc. v. Marketing Displays, Inc. (2001), the Supreme Court held that a dual-spring design for keeping road signs upright in the wind was functional; the fact that the design had been claimed in an expired utility patent was strong evidence of functionality. The rule prevents trademark law, whose protection can last forever, from being used to extend the limited monopoly that patent law grants. Aesthetic functionality, a related doctrine, denies protection to features whose appeal is itself the reason consumers buy, such as a color that matches other products, although the courts have applied it cautiously. The Second Circuit's decision in Christian Louboutin S.A. v. Yves Saint Laurent America Holding, Inc. (2012) illustrates the balance. The court held that Louboutin's red lacquered outsole had acquired secondary meaning and was protectable, but only where the red sole contrasted with the rest of the shoe; it did not extend to an all-red shoe. Registration, use, and priority In the United States, trademark rights arise from use, not from registration. A business that adopts a distinctive mark and uses it in commerce acquires common-law rights in the geographic area where it trades and where its reputation extends. Federal registration on the Principal Register adds valuable benefits on top of those rights, but it does not create them from nothing. The benefits of registration are substantial. A registration provides nationwide constructive notice of the owner's claim and nationwide constructive use as of the application date, which freezes the rights of later users outside the owner's actual trading area. It creates a presumption that the mark is valid and that the registrant owns it and has the exclusive right to use it for the listed goods. It allows the owner to record the registration with U.S. Customs and Border Protection to stop infringing imports. It unlocks enhanced remedies against counterfeiters. And after five years of continuous use following registration, the owner can file a declaration making the registration incontestable. In Park 'N Fly, Inc. v. Dollar Park & Fly, Inc. (1985), the Supreme Court held that an incontestable registration cannot be challenged on the ground that the mark is merely descriptive. Incontestability does not, however, protect a mark against a claim that it is or has become generic, or that it is functional, or that it has been abandoned. Registration is obtained by application to the United States Patent and Trademark Office. An applicant can file on the basis of actual use or on the basis of a bona fide intent to use the mark, in which case registration issues only after use begins. The examining attorney reviews the application for compliance with the statute's bars, the most important of which prevents registration of a mark that so resembles a registered mark as to be likely to cause confusion, and another that bars registration of merely descriptive terms without proof of acquired distinctiveness. After examination the mark is published for opposition, and third parties may challenge it before the Trademark Trial and Appeal Board. The Supreme Court held in B&B Hardware, Inc. v. Hargis Industries, Inc. (2015) that the Board's likelihood-of-confusion decisions can have preclusive effect in later infringement litigation when the usages adjudicated are materially the same, which means opposition proceedings are no longer a low-stakes skirmish. The Trademark Modernization Act of 2020 added two procedures, expungement and reexamination, that let third parties challenge registrations for marks that were never used, or not used as of the relevant date, for some or all of the listed goods. These tools matter to practitioners because the register had become cluttered with overbroad and fraudulent filings, and a cluttered register makes clearance harder and more expensive for everyone. Registration also has constitutional limits of recent vintage. The Lanham Act once barred registration of disparaging marks and of immoral or scandalous marks. The Supreme Court struck down the first in Matal v. Tam (2017) and the second in Iancu v. Brunetti (2019), holding that both discriminated on the basis of viewpoint. In Vidal v. Elster (2024), however, the Court upheld the bar on registering a mark that consists of or comprises the name of a living individual without that person's consent, rejecting a challenge from an applicant who sought to register "Trump too small" for T-shirts. The Court reasoned that the names clause was viewpoint-neutral and fit within a long tradition of restricting trademarks that contain another person's name. Chapter 5 returns to what these decisions imply for the relationship between trademark law and free speech. Why the foundations matter to enforcement The foundations covered in this chapter might seem remote from the disputes in the rest of the book, but they shape every one of them. A mark's position on the distinctiveness spectrum is a major factor in the likelihood-of-confusion analysis, and it will be an important question in the Supreme Court's review of whether mark strength is for a judge or a jury, discussed in the next chapter. The line between descriptive and generic determines whether a mark can be lost altogether. The requirement that a mark be distinctive or famous is the first element of every cybersquatting claim. And the principle that trademark law protects source identification, not words as such, is the root from which the defenses for parody, commentary, and comparative advertising grow. The practical counsel is straightforward. At the outset, choose marks that sit high on the spectrum and clear them properly. Register them early and in every class where the business operates or plans to operate. Keep evidence of use, advertising, sales, and consumer recognition, because the day will come when the owner has to prove what the mark means to the public, and that proof is far easier to assemble from contemporaneous records than to reconstruct under the pressure of litigation. The strongest trademark portfolios are built by companies that treat the meaning of their marks as an asset to be documented, not merely asserted. Chapter 2: The Likelihood of Confusion The heart of trademark infringement is a prediction. The Lanham Act makes a defendant liable for using a mark in a way that "is likely to cause confusion, or to cause mistake, or to deceive." Section 32, 15 U.S.C. § 1114, applies that standard to registered marks, and section 43(a), 15 U.S.C. § 1125(a), extends it to unregistered marks, trade dress, and false suggestions of affiliation, sponsorship, or approval. The plaintiff does not have to show that anyone was actually confused, though evidence that someone was is powerful. It has to show that an appreciable number of ordinarily prudent purchasers are likely to be confused about the source of the goods or about the defendant's connection with the plaintiff. Because the standard is a prediction about the minds of consumers, it cannot be applied by a formula. Courts instead use lists of factors that bear on the probability of confusion, weigh them in light of the facts, and reach an overall judgment. This chapter explains those factor tests, the several forms of confusion that courts recognize, the evidence that actually decides cases, and a pending Supreme Court case that may reshape how the most important factor is decided. The multi-factor tests Every federal circuit has its own list of likelihood-of-confusion factors. The lists were developed independently, mostly in the 1960s and 1970s, and they vary in length and wording. They overlap far more than they differ, and a practitioner who understands one can work with any of them. The four most cited are compared in Table 2. Table 2. Leading likelihood-of-confusion tests. Test Court and year Number of factors Distinctive features Polaroid Corp. v. Polarad Electronics Corp. 2d Cir. 1961 8 "Bridging the gap"; quality of defendant's goods AMF Inc. v. Sleekcraft Boats 9th Cir. 1979 8 Marketing channels; likelihood of expansion Interpace Corp. v. Lapp, Inc. 3d Cir. 1983 10 Designed for non-competing goods In re E. I. du Pont de Nemours & Co. C.C.P.A. 1973 13 Used by the USPTO and the Trademark Trial and Appeal Board The factors common to nearly every list are these: the strength of the plaintiff's mark; the similarity of the marks; the relatedness or proximity of the goods; the channels of trade and marketing; the degree of care purchasers exercise; the defendant's intent in adopting its mark; and evidence of actual confusion. Some tests add the likelihood that the plaintiff will expand into the defendant's market, which the Second Circuit calls "bridging the gap," and some add the quality of the defendant's goods, on the theory that a senior user's reputation is at particular risk if it is associated with shoddy products. Courts repeatedly say that the factors are not a mathematical scorecard. The weight of each depends on the case, and a single factor can dominate. In practice, a few factors carry most of the load. Similarity of the marks is usually the first and most important. Courts compare the marks in their entireties as consumers encounter them, considering sight, sound, and meaning, rather than dissecting them letter by letter. A mark that shares a dominant element with another may be confusingly similar even if the full marks differ; conversely, a shared descriptive or common element may count for little. Context matters too. The same words presented in a distinctive house style, alongside a well-known house mark, may be less likely to confuse than the words standing alone. Relatedness of the goods asks whether consumers would expect the goods to come from the same source. The goods need not compete. A consumer might reasonably expect a clothing brand to license sunglasses or a soft-drink company to sponsor a sports event. The question is whether the public would plausibly assume a connection, and it is increasingly answered with evidence of how brands in the relevant industry actually expand and license. Strength of the mark has two dimensions. Conceptual strength is the mark's place on the distinctiveness spectrum described in Chapter 1. Commercial or marketplace strength is the degree of public recognition the mark has actually achieved. A strong mark receives a broader scope of protection, because consumers who know it well are more likely to assume that a similar mark on related goods comes from the same source. A weak mark, especially one surrounded by similar third-party marks, receives a narrow scope; consumers accustomed to seeing many similar names learn to distinguish them by small differences. Intent can be decisive when the evidence shows deliberate copying. Courts reason that a defendant who set out to trade on another's goodwill probably succeeded, and in some circuits an intent to confuse raises a presumption of likely confusion. But knowledge of a plaintiff's mark is not the same as intent to confuse, and a defendant that adopts a mark intending to parody, comment on, or compare itself to the plaintiff has an intent that points away from confusion, not toward it. Actual confusion is the best evidence that confusion is likely, and its absence after a long period of side-by-side use can be persuasive evidence that it is not. Anecdotal evidence, such as misdirected emails, customer complaints, or misplaced orders, is admissible but is often discounted if it is sparse or reflects inattention rather than genuine confusion about source. The kinds of confusion The classic infringement case involves point-of-sale confusion about source: a shopper buys the defendant's product believing it to be the plaintiff's. The Lanham Act's amendments in 1962 and 1988 broadened the statute's language, and the courts have recognized several other forms of actionable confusion. Sponsorship or affiliation confusion occurs when consumers know the defendant made the product but believe the plaintiff sponsored, licensed, or approved it. This is the form most at issue in merchandising, parody, and co-branding cases, and it is where the law is most contested. A consumer who sees a university's colors on a T-shirt may or may not assume the university licensed it, and the answer depends heavily on evidence of what consumers actually believe about licensing practices. Initial interest confusion occurs when a defendant uses a plaintiff's mark to capture a consumer's initial attention, even though the consumer realizes the true source before buying. The Ninth Circuit gave the doctrine its most famous formulation in Brookfield Communications, Inc. v. West Coast Entertainment Corp. (1999), which likened the use of a competitor's mark in website metadata to posting a misleading billboard on a highway that diverts drivers to a different store. The doctrine has since been significantly narrowed. In Network Automation, Inc. v. Advanced Systems Concepts, Inc. (2011), the Ninth Circuit held that the purchase of a competitor's mark as a search-advertising keyword was not infringing where the resulting advertisements were clearly labeled and consumers were sophisticated, and in Multi Time Machine, Inc. v. Amazon.com, Inc. (2015) it held that a search-results page listing clearly labeled competing products did not create a likelihood of confusion as a matter of law. The trend across the circuits is to ask whether the consumer is genuinely confused at any point, rather than merely distracted or offered an alternative. Post-sale confusion occurs when the purchaser is not confused but observers who see the product later are. The doctrine is most often applied to luxury goods and distinctive designs, where the harm is that knock-offs seen in public erode the prestige and exclusivity of the original. The Sixth Circuit applied it in Ferrari S.p.A. Esercizio Fabbriche Automobili e Corse v. Roberts (1991) to fiberglass kits that turned ordinary cars into replicas of Ferrari designs. Reverse confusion inverts the usual story. A large junior user saturates the market with a mark, and consumers come to believe that the smaller senior user's goods come from the larger company. The senior user loses control of its identity and may even be thought an infringer of the very mark it adopted first. The Tenth Circuit's decision in Big O Tire Dealers, Inc. v. Goodyear Tire & Rubber Co. (1977), in which Goodyear's national "Bigfoot" campaign swamped a small tire dealer's prior use of the same name, remains a leading illustration, and the Third Circuit set out an adapted factor analysis for reverse-confusion claims in A&H Sportswear, Inc. v. Victoria's Secret Stores, Inc. (2000). Reverse confusion matters to large brand owners as much as to small ones, because it is the claim a large company faces when it launches a new brand without proper clearance. Evidence: what actually wins cases Although the factors are framed as legal considerations, confusion is a question about consumer perception, and cases are won and lost on evidence of that perception. Three kinds of evidence dominate. Surveys. A well-designed consumer survey is often the most persuasive evidence of likely confusion or its absence. Two formats dominate. The Eveready format, named after the Seventh Circuit's decision in Union Carbide Corp. v. Ever-Ready Inc. (1976), shows respondents the defendant's product and asks open-ended questions about who makes it and whether it is connected with any other company. It is widely regarded as the gold standard where the plaintiff's mark is strong and well known, because respondents' spontaneous identification of the plaintiff is strong evidence that the defendant's product calls it to mind. The Squirt format, from the Eighth Circuit's decision in SquirtCo v. Seven-Up Co. (1980), presents the two marks together or in close sequence and asks whether they come from the same or related sources. It is often used where the plaintiff's mark is weaker or the goods are sold side by side, and it is criticized for suggesting a connection that respondents would not otherwise draw. Surveys need a proper control, a stimulus identical to the test stimulus except for the allegedly infringing feature, so that background noise can be subtracted from the result. They need the right universe of respondents, meaning prospective purchasers of the defendant's goods in most forward-confusion cases. Courts frequently reduce the weight given to a survey because of flaws in the universe, the stimulus, the control, or the questions, and a survey that is excluded or discounted can be worse than none, since it invites the inference that the party could not produce better evidence. Marketplace evidence. Evidence of how the goods are actually sold, advertised, and encountered is increasingly central. Screenshots of online listings, photographs of retail shelves, evidence of third-party use of similar marks, and records of the plaintiff's licensing practices all bear on how consumers perceive the marks in real conditions. Third-party registrations and uses are particularly important in establishing that a mark is weak. A defendant who can show dozens of similar marks on related goods can often persuade a court that consumers are used to distinguishing among them. Documents and testimony about intent. Internal documents showing how the defendant chose its mark, what it knew about the plaintiff, and whether it considered and rejected alternatives because of the risk of conflict often carry more weight with a fact-finder than any expert. A clean clearance record is a defendant's best protection; an email proposing to "get as close as we can" to a competitor's name is a plaintiff's best exhibit. Who decides mark strength: a question before the Supreme Court The likelihood-of-confusion analysis is generally treated as a question of fact, reviewed on appeal for clear error, although some circuits treat the ultimate conclusion as a mixed question or as a matter of law when the underlying facts are undisputed. The practical significance is that a fact question must ordinarily go to the jury in a case where a jury has been demanded, while a question of law can be resolved by the judge on summary judgment. That distinction is at the center of RiseandShine Corp. v. PepsiCo, Inc., No. 24-1016, which the Supreme Court agreed to hear in the summer of 2026. RiseandShine sells canned cold-brew coffee under the RISE mark. PepsiCo launched an energy drink under the name MTN DEW RISE ENERGY. The district court granted RiseandShine a preliminary injunction in 2021, finding that its mark was conceptually strong. In 2022 the Second Circuit reversed, holding that the RISE mark was conceptually weak for a caffeinated morning beverage because of the word's obvious associations with waking up and energy. The district court then granted summary judgment to PepsiCo, and the Second Circuit affirmed in an unpublished order in December 2024. The question presented is whether the strength of a mark is a question of fact in the likelihood-of-confusion analysis. The petitioner argues that the Second Circuit stands alone in treating conceptual strength as a question of law that a court may decide for itself, and that the other circuits treat distinctiveness as a factual question about consumer perception. The case is scheduled for decision in the October 2026 Term. The stakes are practical. If conceptual strength is a question of law, defendants will more often be able to end cases at summary judgment by persuading a judge that the plaintiff's mark is merely suggestive or descriptive and therefore entitled to narrow protection. If it is a question of fact, plaintiffs with arguably weak marks will more often get to a jury, and the settlement value of their claims will rise. The case also has a conceptual dimension that connects to the argument of this book. If mark strength is a measure of what the public perceives, it is difficult to see why a judge's view of the dictionary should settle it, and a ruling that treats it as factual would push litigants further toward evidence of actual public understanding. Whatever the Court decides, a practitioner advising a client with a mark near the descriptive end of the spectrum should build the record of marketplace strength, through sales figures, advertising, unsolicited media coverage, and surveys, because it is that record, rather than argument about the word itself, that will carry the day. Defenses built into the confusion analysis Two defenses sit so close to the confusion inquiry that they belong in this chapter. The first is classic or descriptive fair use, codified in section 33(b)(4), 15 U.S.C. § 1115(b)(4), which permits the use of a term "otherwise than as a mark" to describe the defendant's own goods fairly and in good faith. In KP Permanent Make-Up, Inc. v. Lasting Impression I, Inc. (2004), the Supreme Court held that a defendant asserting this defense does not bear the burden of disproving confusion, and that some degree of confusion is compatible with fair use. A sunscreen maker may say its product protects "all day" even if another company owns ALL DAY as a mark, so long as it uses the words descriptively and in good faith. The second is nominative fair use, which permits a defendant to use the plaintiff's mark to refer to the plaintiff's own goods, as in "repairs for Volkswagen vehicles" or "compatible with iPhone." The Ninth Circuit framed the doctrine in New Kids on the Block v. News America Publishing, Inc. (1992): the product must not be readily identifiable without the mark, only so much of the mark may be used as is reasonably necessary, and the user must do nothing to suggest sponsorship or endorsement. The circuits disagree about whether nominative fair use is an affirmative defense or a modification of the confusion test, but they agree on its substance. It is the doctrine that allows resellers, repair shops, comparative advertisers, and journalists to name the brands they deal with, and it becomes important again in the domain-name chapters, because a domain name that uses a brand to identify a genuine reseller or fan site may be legitimate under the same reasoning. Both defenses rest on the same foundation as everything else in this chapter. The law protects the mark's function of identifying source. When a defendant uses the words for some other purpose, to describe its own goods or to refer to the plaintiff's, and does so honestly, there is no injury to that function, and so there is no infringement. Chapter 3: Genericide and the Defense of a Successful Name The most dangerous threat to a famous brand is often not a counterfeiter or a competitor. It is the brand's own success. A product that creates a new category, or dominates it so thoroughly that its name becomes shorthand for the category, runs the risk that the public will stop hearing the name as a brand and start hearing it as the ordinary word for the thing. When that happens, the law takes the mark away. Aspirin, cellophane, escalator, thermos, yo-yo, trampoline, and zipper were all once brands. Each became the common name of a product, and each passed into the public domain for anyone to use. This process, which lawyers call genericide, is the purest illustration of the principle that trademark rights live in public perception. The owner may have spent fortunes promoting the mark, may hold an incontestable registration, and may have policed infringers diligently. None of that matters if the relevant public now uses the word to mean the product rather than the producer. This chapter explains how the law decides whether a mark has become generic, traces the leading cases from Aspirin to Booking.com, and sets out the practical discipline that successful brands use to avoid the fate. Why the law takes generic words away The rule that generic terms cannot be trademarks is not a punishment for success. It follows from the purpose of trademark law. A trademark is protected because it tells consumers who made a product. A generic term tells consumers what the product is. If one seller could monopolize the common name of a product, its competitors would be unable to tell customers what they were selling, and consumers would be forced to learn awkward circumlocutions. A rival maker of acetylsalicylic acid tablets that could not call them aspirin, in a market where everyone asked for aspirin, would be at a disadvantage having nothing to do with the quality of its product. For that reason, genericness is a complete defense to infringement and a ground for cancelling a registration at any time, even after it has become incontestable. Section 14(3) of the Lanham Act, 15 U.S.C. § 1064(3), provides that a petition to cancel may be filed at any time if the registered mark becomes the generic name for the goods or services for which it is registered. The primary significance test The central question is how the relevant public understands the term. The standard formulation comes from Learned Hand's opinion in Bayer Co. v. United Drug Co. (S.D.N.Y. 1921): the question is what buyers understand by the word for whose use the parties are contending. Bayer had introduced acetylsalicylic acid in the United States under the name Aspirin, and for years the drug was protected by patent, so the name was the only word most people knew for it. When the patent expired and competitors entered, the public, especially ordinary retail buyers, knew the product only as aspirin. Hand held that as to those consumers the word had become generic, while noting that among manufacturers, physicians, and pharmacists, who knew the chemical name, it might still function as a brand. The split result illustrates that genericness is assessed by reference to the relevant public, which is the purchasing public for the goods in question. The Supreme Court endorsed the approach in Kellogg Co. v. National Biscuit Co. (1938), holding that "shredded wheat" had become the generic name of a cereal product formerly protected by patent, and that to establish a trademark the plaintiff had to show that the primary significance of the term in the minds of the consuming public was not the product but the producer. That phrase, primary significance, became the governing test. Congress wrote the test into the statute after a Ninth Circuit decision seemed to depart from it. In Anti-Monopoly, Inc. v. General Mills Fun Group, Inc. (1982), the court held MONOPOLY generic for a board game, relying on a survey that asked whether respondents bought the game because they wanted a Parker Brothers product or because they wanted to play Monopoly. Most said the latter, and the court treated that as proof that the word identified the game rather than the producer. Critics pointed out that the survey confused the question of what a consumer wants with the question of what the word means; most people who ask for a brand-name product want it because of what it is. The Trademark Clarification Act of 1984 amended section 14(3) to provide that the primary significance of the registered mark to the relevant public, rather than purchaser motivation, is the test, and that a mark does not become generic merely because it is also used as the name of a unique product. Cases that went each way The history of genericide is a series of lessons about how brands are lost and how they are saved. DuPont Cellophane Co. v. Waxed Products Co. (2d Cir. 1936) held that "cellophane" had become generic. DuPont had used the word as the only name for its transparent wrapping film, advertised it heavily as a product, and never offered consumers an alternative generic name. The public had no other word for the material, so the brand became the name. King-Seeley Thermos Co. v. Aladdin Industries, Inc. (2d Cir. 1963) held that "thermos" had become generic for vacuum-insulated bottles among the general public. The company had at one time actively encouraged the generic use of the word, and by the time it began to police usage, the public had adopted it. Survey evidence showed that a large majority of respondents knew the product only as a thermos. The court allowed competitors to use "thermos" in lower case but required them to avoid the capitalized form and the words "original" and "genuine," a compromise that shows how courts sometimes try to preserve some residual source significance. The Otis Elevator Company lost ESCALATOR in a 1950 decision of the Commissioner of Patents, Haughton Elevator Co. v. Seeberger, in large part because Otis itself had used the word generically in its own patents and advertisements, describing its product as "an escalator" rather than as an ESCALATOR brand moving stairway. The Seventh Circuit reached a similar result for YO-YO in Donald F. Duncan, Inc. v. Royal Tops Manufacturing Co. (1965), noting that Duncan's own advertising had used the word as the name of the toy. Against these losses stand notable survivals. DuPont, having learned from cellophane, took a different approach when it introduced TEFLON. It paired the mark with the generic term "PTFE" or "nonstick coating" and policed usage aggressively. When a competitor challenged the mark in E. I. DuPont de Nemours & Co. v. Yoshida International, Inc. (E.D.N.Y. 1975), DuPont's survey asked respondents to classify a list of terms as brand names or common names, after first explaining the difference with examples. A clear majority identified TEFLON as a brand. The format, now called the Teflon survey, became the standard method for testing genericness where a mark is well known. The most prominent modern challenge was to GOOGLE. In Elliott v. Google, Inc. (9th Cir. 2017), the plaintiffs, who had registered hundreds of domain names combining "google" with other words, argued that the mark had become generic because people use "google" as a verb meaning to search the internet. The Ninth Circuit rejected the argument. Verb use, the court held, does not by itself establish genericness, because a person can use a brand name as a verb while still understanding that it identifies a particular search engine. The question is not whether the word is used as a verb but whether the primary significance of the word to the public is as the name of a type of search engine rather than as the name of a particular one. The plaintiffs had no evidence of that, and Google's survey evidence showed that most people understood GOOGLE as a brand. The decision is important for companies whose names have become verbs. It confirms that everyday phrases such as "google it," "photoshop the picture," or "xerox the memo" are not in themselves fatal, provided the public still recognizes the underlying mark as a brand. It is not a license to ignore the problem, however. Verb use is a leading indicator that a brand is drifting toward the category name, and the companies whose marks have survived that drift have typically worked hard to arrest it. Booking.com and the generic-plus-domain problem The Supreme Court's most recent pronouncement on genericness came in United States Patent and Trademark Office v. Booking.com B.V. (2020). The USPTO had refused to register BOOKING.COM for online hotel reservation services, reasoning that "booking" was generic for those services and that adding the top-level domain ".com" to a generic term produced a term that was also generic. The Office relied on the Supreme Court's nineteenth-century decision in Goodyear's India Rubber Glove Manufacturing Co. v. Goodyear Rubber Co. (1888), which held that adding "Company" to a generic term did not make it a trademark. The Court, in an opinion by Justice Ginsburg, rejected the USPTO's per se rule. Whether a term is generic, the Court held, depends on its meaning to consumers. A compound term of the form "generic.com" is generic only if consumers perceive it as the name of a class of services, and here the lower courts had found, on the basis of survey and other evidence, that consumers perceived BOOKING.COM as a brand. Because only one entity can hold a particular domain name at a time, a "generic.com" term may convey to consumers an association with a particular website. Justice Breyer dissented, warning that the decision would allow owners of such marks to harass competitors using similar descriptive names. The majority addressed that concern by stressing that the scope of protection for such a mark would be narrow. Because BOOKING.COM is weak, close variations such as "ebooking.com" or "hotel-booking.com" would be less likely to cause confusion, and classic fair use would permit competitors to describe their services using the word "booking." The decision, in other words, makes registration of these marks possible but leaves them thin. For practitioners the lessons are twofold. First, the genericness inquiry is empirical. The Court emphasized consumer perception and accepted survey evidence, while cautioning in a footnote that surveys must be evaluated carefully and are not the only relevant evidence; dictionary definitions, usage by competitors and the media, and the applicant's own usage all matter. Second, a descriptive or quasi-generic brand is a fragile asset. A client building a business on a name like BOOKING.COM should invest early in secondary meaning and in evidence of it, and should expect to enforce the mark only against close copies. The Federal Circuit added a related point in Bullshine Distillery LLC v. Sazerac Brands, LLC (2025). A competitor sought to cancel the FIREBALL registration for cinnamon whisky, arguing that "fireball" had long been the generic name for a spicy cocktail and so could never function as a brand. The court rejected a rule of "once generic, always generic" and held that the relevant question for a registration's validity is how the public understood the term at the time of registration, not how the word was used in some earlier era. Genericness, on this view, is a matter of what a word means now to the relevant public, and meaning can change in either direction. A term that was once generic can become a brand, just as a brand can become generic. Comparative note: the European approach European Union law reaches a similar result by a somewhat different route. Under the EU Trade Mark Regulation, a registered mark may be revoked if, in consequence of the acts or inactivity of the proprietor, it has become the common name in the trade for a product or service in respect of which it is registered. The emphasis on the owner's conduct means that an owner who has taken reasonable steps to prevent generic use is better placed than under a pure consumer-perception test. The Court of Justice of the European Union held in Backaldrin Österreich The Kornspitz Company GmbH v. Pfahnl Backmittel GmbH (2014) that the relevant class for assessing whether KORNSPITZ had become a common name included end consumers, not only the bakers who bought the baking mix, and that a proprietor's failure to encourage sellers to indicate that the name was a trademark could amount to inactivity. The ruling reinforces a point that applies equally in the United States: a brand owner's obligations extend to the way intermediaries present the mark to the ultimate consumer. The discipline of usage management Genericide is not an event but a process, and it can be managed. The companies that have kept famous marks through decades of market dominance have done so by consistent, sometimes tedious, discipline. The core practices are well established. 1. Pair the mark with a generic name. A brand should always appear with a noun that names the product: VASELINE petroleum jelly, BAND-AID brand adhesive bandages, VELCRO brand fasteners, KLEENEX tissues. Giving the public a generic alternative is the single most important defense, because genericide happens most readily when consumers have no other word for the thing. Johnson & Johnson changed its long-running advertising jingle to say "I am stuck on Band-Aid brand" precisely to reinforce the distinction, and Velcro Companies released a humorous video in 2017 urging customers to say "hook and loop" instead of using the brand as a noun. 1. Use the mark as an adjective, never as a noun or verb. Internally and externally, the mark should modify the generic term. "Make a XEROX copy" is better than "make a xerox." Xerox has for many years run print advertisements reminding writers and editors that its name is a brand and should not be used as a verb. 1. Distinguish the mark typographically. Capital letters, a distinctive typeface, and the registration symbol all signal to readers that the word is a brand. 1. Police third-party usage without overreaching. Owners should monitor media, dictionaries, competitors, and online marketplaces and correct generic use, usually with polite letters rather than litigation. Dictionary publishers often respond to evidence that a term is a trademark by adding a notation, which can later be useful evidence. The aim is not to stop every casual use in conversation, which is impossible and would make the owner look foolish, but to prevent the adoption of the mark as the category name by the trade, the press, and competitors. 1. Control the owner's own usage. Aspirin, escalator, and yo-yo were lost partly through their owners' own generic use. Marketing teams, product managers, and even patent drafters must be trained to use the mark properly, because an owner's own documents are among the first exhibits a challenger will seek. 1. Gather evidence before it is needed. A brand owner with a dominant product should periodically commission genericness surveys, document its enforcement efforts, and archive examples of proper usage in the media. When a challenge comes, as it did for Google, the owner that can produce years of evidence will be in a far stronger position than one scrambling to commission a survey after the complaint is filed. The practical tension is between marketing, which wants the brand to become synonymous with the category, and law, which punishes it for doing so. The resolution is not for lawyers to stop marketers from building a dominant brand, but to ensure that the dominance is expressed as "the leading brand of X" rather than "the name for X." The public can be taught to ask for a KLEENEX tissue; it cannot easily be taught to stop asking for a kleenex once the habit is formed. Genericide is one of the few areas of trademark law where preventive discipline is far cheaper than any cure, and where a brand's owner has almost complete control over the outcome if it acts early enough. Hashtags: #TrademarkLawAndBrandProtection #TrademarkLaw #BrandProtection #IntellectualProperty #TrademarkRights #TrademarkInfringement #TrademarkDilution #TrademarkParody #DomainDisputes #Cybersquatting #TrademarkRegistration #LanhamAct #LikelihoodOfConfusion #ConsumerConfusion #TrademarkDistinctiveness #Genericide #FamousTrademarks #DilutionByBlurring #DilutionByTarnishment #TrademarkFairUse #FirstAmendment #BrandIdentity #TradeDress #TrademarkEnforcement #TrademarkLitigation #DomainNameProtection #ACPA #UDRP #TrademarkDisputes #BrandEnforcement

  • Smart Textiles (Conductive Yarns and Washable Electronics)

    Download the Book (PDF): Introduction In April 2023 a small number of denim jackets stopped being smart. They were the Levi's Commuter Trucker jackets built with Google's Jacquard technology, first sold in 2017, which let a cyclist brush or tap a woven patch on the cuff to skip a song or take a call. The fabric still worked. The conductive threads in the cuff still carried current. What ended was the companion app: Google announced that support would stop on 24 April 2023, and with it the jackets lost the only thing that made them more than jackets. A backpack made with Saint Laurent, another with Samsonite and a football insole made with Adidas went the same way. It is a strange way for a piece of clothing to fail, and it is a useful place to begin, because it shows how many separate things have to keep working for a garment to stay smart. The yarn has to conduct. The joint between yarn and electronics has to hold. The battery, radio and processor have to survive sweat, friction and being thrown in a washing machine, or else be removed every time. And above all of that sits a layer of software and business decisions that the fabric cannot control. A jacket is expected to last for years. A circuit board, a connector and an app are each on their own clock. This booklet is about the engineering that lives between those clocks. Its subject is the class of garments that sense, carry or process electrical signals: shirts that record the heart's electrical activity, compression sleeves that measure the bending of a joint, socks that track pressure under the foot, base layers that estimate breathing from the stretch of the ribcage. The field calls them smart textiles or e-textiles, and it has been promising them to the public for more than two decades. Some have reached the market and stayed there, mainly in elite sport, military research, space medicine and clinical monitoring. Many more have arrived with publicity and left quietly. The argument The argument of this booklet is simple to state and hard to act on. A smart garment succeeds or fails not on how well it conducts on the first day, but on whether its conductors, its joints and its data survive the body and the wash for the life of the garment. Conductivity is the easy part. There are dozens of ways to make a thread carry current, and laboratories publish new ones every month. The difficult part is keeping that current path intact while the fabric stretches by a third, rubs against itself thousands of times an hour, soaks in salty sweat, and then spends an hour being tumbled in hot alkaline water with a load of towels. Nearly every important design decision in the field follows from that one fact. It explains why the most interesting conductor of the past fifteen years, the silver nanowire, is valued less for its raw conductivity than for the way a network of wires can be embedded in rubber and pulled without breaking. It explains why so much of the effort in a real product goes into the few centimetres where soft fabric meets a hard electronics module, because that is where nearly everything breaks. It explains why athletes, who sweat more, move harder and wash their kit more often than anyone else, are both the most valuable early users and the most punishing test. And it explains why the washing machine deserves a chapter of its own. Why athletes The booklet leans on elite sport for its examples, for three reasons. First, sport is where smart garments have found paying customers who use them repeatedly. Professional football, rugby, basketball and endurance programmes already collect heart rate, movement and training load every day, and many have tried shirts with built-in electrodes. Second, athletes are an extreme case. A shirt that works for a sprinter in a summer training camp will usually work for an office worker. The reverse is rarely true. Third, sport forces honest questions about what a measurement is for. A coach does not want a stream of numbers; a coach wants to know whether a player should train hard today, and a medical officer wants to know whether a runner is heading towards heat illness. Measurements that do not change such decisions are a cost, not a benefit, however elegant the fabric. The same discipline applies beyond sport. A shirt that records the heart rhythm of a patient at home faces the same sweat, the same stretching and the same laundry. The clinical stakes are higher and the regulatory path longer, but the physics is identical. What the booklet covers, and what it leaves out The chapters move from the material outward. The first explains why fabric and circuitry are natural enemies, mechanically and chemically, and why the body is a harsh environment for electronics. The second surveys the conductive yarns available today, from silver-plated nylon to stainless steel staple fibre, and explains how the structure of a yarn changes its electrical behaviour. The third is devoted to silver nanowires: how they are made, why a random network of them conducts, and how embedding them in elastomers lets a conductor stretch. The fourth deals with construction: weaving, knitting, embroidery, printing and lamination, and the interconnects that join soft circuits to hard electronics. The middle of the booklet turns to the body. The fifth chapter explains how textiles sense the heart, breathing, movement and temperature, and what physical effects corrupt those signals. The sixth follows the data into elite sport, looking at validation studies, the estimation of quantities such as core body temperature, and the rules professional leagues have written about who may use athlete data and for what. The last two chapters face the laundry. The seventh treats washing as an engineering load case, describing what actually breaks in a machine and why. The eighth covers testing, the international standards that now exist for e-textile washing durability, and the design choices that follow from taking durability seriously from the first sketch. Some things are deliberately left out. Energy harvesting from body heat or motion, light-emitting fabrics, textile antennas and fashion-led interactive garments are real fields with their own literature, but they would dilute the central argument. So would a catalogue of every start-up that has made a smart shirt. Companies come and go quickly in this field, and naming them invites the same fate as the Jacquard jacket: the text ages faster than the ideas. Products appear here when they teach something. A note on evidence The field moves fast and its marketing moves faster. Claims of "washable" or "medical-grade" are often made without saying washable how many times, under what conditions, or to what failure criterion. Wherever a number appears in what follows, it comes from a published study, a standard or a manufacturer's own technical statement, and the source is named. Where good numbers do not exist, the text says so. That honesty matters, because one of the things this booklet argues is that the field's progress depends on reporting durability as rigorously as it reports conductivity. A reader who finishes should be able to look at any smart garment, whether a product on a shelf or a prototype in a lab, and ask the questions that decide whether it will still work after the fiftieth wash: where the current flows, where the stiffness changes, what happens when it gets wet, and who decides when it stops being smart. Chapter 1: Why Fabric and Circuits Disagree Put a printed circuit board and a T-shirt side by side and they look like opposites, which is because they are. A circuit board is designed to hold things still. Its copper traces are a few tens of micrometres thick, bonded to a glass-fibre laminate that barely flexes, and the components soldered to it are rigid blocks whose leads would crack if the board bent repeatedly. A T-shirt is designed to move. Its knitted loops slide over one another so that the fabric can stretch, shear and drape around a curved, changing body. Every useful property of clothing, from comfort to fit to the way a sleeve follows an elbow, comes from the freedom of fibres to shift relative to each other. Every useful property of a circuit comes from components that never shift at all. Smart textiles exist in the space between those two philosophies, and the first job of anyone working in the field is to understand exactly how wide that space is. The gap is partly mechanical and partly chemical, and both halves decide where things break. How fabric moves A fabric is not a sheet of material in the way a plastic film is. It is a structure made of fibres twisted into yarns and yarns interlaced or interlooped into cloth. Its mechanical behaviour comes far more from that structure than from the stiffness of the fibres themselves. A polyester fibre is fairly stiff along its length. A polyester knit is soft and stretchy, because when you pull it, the loops first straighten and slide, the yarns rotate at their crossing points, and only at large extensions do the fibres themselves begin to carry significant load. Woven fabrics, in which two sets of yarns cross at right angles, are stiff along the yarn directions and much softer on the diagonal, where the crossing yarns can scissor. That is why a woven shirt drapes but does not stretch much unless elastane is added. Knitted fabrics, built from interlocking loops, can extend easily in both directions. A compression garment of the kind athletes wear typically combines nylon or polyester with a substantial fraction of elastane so that it can be pulled on and then holds the body firmly while moving with it. The strains involved are large by electronic standards. Skin over the knee or elbow lengthens substantially when the joint bends, and the fabric over it must follow or the garment pulls and slips. A compression shirt worn by a rower or a basketball player is stretched across the back and shoulders every time the arms reach forward. Tens of percent of strain, applied thousands of times in a session, are normal working conditions for clothing. A copper trace on a circuit board, by contrast, will crack after a fraction of a percent of strain if it is cycled repeatedly. Bulk metals simply do not tolerate that kind of deformation for long. There is a second, subtler kind of motion. Fabric bends around very small radii. A collar folds sharply, a cuff is crumpled into a ball in a gym bag, a garment is wrung and tumbled in a washing machine. Bending a conductor puts its outer surface in tension and its inner surface in compression, and the strain at the surface depends on how thick the conductor is relative to the bend radius. A thin conductor survives tight folds that would crack a thick one. This is one reason the field has gravitated towards very fine filaments, thin coatings and nanoscale conductors: thinness buys bendability. Finally, fabric rubs. Yarns abrade against each other at every crossing point, the garment rubs against skin, against other clothing, against a backpack strap or a seat. In a washing machine, every surface is scraped against every other surface for an hour. Abrasion removes coatings, frays fibres and slowly wears through anything sitting on the surface. A conductive layer that is perfectly stable on a laboratory bench can vanish under abrasion that a normal shirt barely notices. How circuits fail Electronic engineers already know a great deal about mechanical failure. The relevant knowledge comes mostly from the reliability of solder joints, connectors and flexible circuits, and three lessons from that body of work carry over directly. The first lesson is fatigue. A metal that is bent once a little way will spring back. A metal bent repeatedly, even within its elastic range, accumulates microscopic damage and eventually cracks. The number of cycles it survives falls steeply as the strain amplitude rises. Wires in headphone cables break near the plug for exactly this reason: that is where they flex most, most often. In a garment, the equivalent flex points are everywhere. The second lesson is that failures concentrate where stiffness changes. When a soft material is joined to a hard one and the assembly is bent or stretched, the soft part deforms and the hard part does not. The strain does not fade gradually across the joint; it piles up at the boundary. A cable that enters a plug without a strain-relief boot fails at the plug. A flexible circuit fails at the edge of a stiffener. The general rule, which reviewers of e-textile washing tests have restated in their own vocabulary, is that weak points are contacts between different materials and components, especially where there is a high stiffness gradient, and transition areas within the same material. The third lesson is that moisture and ions are lethal. Electronics are designed to operate dry. Water alone is a modest threat, but water carrying dissolved salt becomes an electrolyte. It lets current leak between conductors that should be isolated, and it drives corrosion. When two conductors at different voltages sit close together in a damp, salty film, metal ions can dissolve from one and migrate towards the other, growing thin filaments that eventually short the circuit. This electrochemical migration is a well-known failure mechanism in ordinary electronics exposed to humidity. In a garment soaked with sweat, the conditions are far more aggressive. It helps to put rough numbers on the bending problem, because they explain why the field is obsessed with thinness. When a straight conductor of thickness t is bent around a radius R, its outer surface is stretched and its inner surface compressed. The surface strain is approximately t divided by twice R. The relation is simple geometry, and it is the same relation that tells a plumber how tightly a copper pipe can be bent. Consider a fold in a garment with an inner radius of one millimetre, which is gentle by the standards of a crumpled sleeve or a collar folded in a kit bag. A copper wire one tenth of a millimetre thick, roughly the thickness of a human hair, would see a surface strain of about five percent at that fold. Copper begins to yield permanently at strains of a fraction of a percent, so every such fold deforms the wire plastically, and repeated folding will break it after relatively few cycles. Reduce the wire to twenty micrometres and the surface strain falls to about one percent. That is still beyond the elastic range, but low enough that fatigue life increases dramatically. Reduce it further, to the scale of a metal coating a micrometre or so thick on a polymer filament, and the coating itself experiences whatever strain the filament underneath experiences; its thinness no longer protects it, and its survival depends on how well it is bonded and how much the filament stretches. These numbers lead to three conclusions that recur through the rest of this booklet. Thin conductors survive bending far better than thick ones. Bundles of many thin conductors combine low resistance with bendability, which is why multifilament and litz constructions dominate. And coatings are only as durable as the substrate they sit on and the bond that holds them, which is why so much textile failure is really interface failure. An obvious objection is that the electronics industry already makes flexible circuits. Phones, cameras and laptops contain thin polyimide films printed with copper traces that fold around hinges and through tight spaces. Why not simply sew those into clothing? The answer is that flexible is not the same as stretchable. A polyimide flexible circuit bends easily but does not lengthen. It behaves like a sheet of paper: you can roll it into a tube, but you cannot wrap it smoothly around a sphere, because that would require the sheet to stretch. The human body is full of surfaces that change shape in two directions at once, such as the shoulder, the hip and the knee. A flexible circuit placed there either restricts movement, rides up and wrinkles, or tears. Flexible circuits still have a place in smart garments. They are excellent as small rigid-ish islands carrying components, placed where the body is relatively flat and still, and connected to each other by genuinely stretchable conductors. This island-and-bridge architecture, borrowed from research on stretchable electronics, is one of the most practical ways to combine conventional components with fabric. But it relocates rather than removes the central problem: every island has an edge, and every edge is a stiffness step. The body as an operating environment It is worth being concrete about what the skin does to a garment, because most electronic design guidelines assume nothing like it. Sweat is mostly water, but it carries sodium chloride along with smaller amounts of potassium, lactate, urea and other compounds. Its exact composition varies between people and changes with acclimatisation, diet and exercise intensity. For the purposes of a conductor, the key facts are that it is wet, salty and slightly acidic to neutral, and that it is delivered continuously to the inner surface of the garment during exercise. An athlete training hard in heat can lose a litre or more of sweat an hour, and much of it passes through or dries in the base layer. Salt crystals left behind as sweat evaporates are abrasive and hygroscopic: they draw moisture back from the air. Skin also sheds oils and dead cells, and supports a community of bacteria that thrive in warm, damp fabric. Hygiene, rather than aesthetics, is the reason athletic and medical garments must be laundered after almost every use. A garment that cannot be washed cannot be worn against the skin for long. Temperature is less extreme. Skin sits a few degrees above or below 33 degrees Celsius in most conditions, which is gentle for electronics. The danger from heat comes later, in the washing machine and the tumble dryer, where temperatures can be considerably higher and are combined with mechanical action and chemistry. And the body moves in ways that matter for sensing as well as durability. A sensor that relies on contact with the skin, such as an electrode measuring the heart's electrical activity, depends on the garment staying put. When it slides, the signal is corrupted. When it lifts, the signal disappears. The very looseness that makes clothing comfortable is the enemy of a stable measurement. Much of the chapter on sensing is about managing that conflict. The final element of the operating environment arrives once a week, or once a day for an athlete. A domestic wash cycle combines four factors that German chemist Herbert Sinner, working for the detergent company Henkel, described in 1959 as the four contributors to cleaning: chemistry, temperature, mechanical action and time. Detergents are alkaline and contain surfactants that strip oils and penetrate fine gaps; many contain enzymes and oxidising bleaches. Water temperatures range from cold to 60 degrees Celsius or more for hygienic washing. The drum lifts and drops the load, the garments rub and fold, and the spin cycle presses everything against the drum wall at high acceleration. A full cycle lasts an hour or more, and drying in a tumble dryer then adds heat and further tumbling. From a textile engineer's point of view, this is a deliberate, controlled assault on the surface of fabric, designed to remove anything loosely attached. From an electronics engineer's point of view, it is an immersion test combined with a fatigue test combined with a chemical attack, repeated for the life of the product. It would be hard to design a more effective way to find the weak points in a smart garment. That is why washability, more than any other single property, separates working products from demonstrations. Where the electronics go Given this environment, designers have a limited number of strategies, and every commercial smart garment adopts one of them or a blend. The most common is the removable module. The sensing elements, such as electrodes, conductive traces and stretch sensors, are built into the fabric and made as robust as possible. The rigid electronics, meaning battery, processor, memory and radio, live in a small sealed pod that clips or snaps onto the garment and is taken off before washing. The Polar Team Pro Shirt, announced at the Consumer Electronics Show in January 2017, followed this model, with heart rate electrodes embedded in the fabric and a sensor pod with satellite positioning and motion sensors at the back of the collar. Ralph Lauren's PoloTech shirt, made with the Canadian company OMsignal and launched in August 2015, used silver fibres in the fabric with a detachable black box containing the electronics. Google's Jacquard tag, the small module that sat in the cuff of the Levi's jacket, came off for washing too. The removable module dodges the hardest problem, which is waterproofing a battery and circuit board well enough to survive repeated washes. But it does not remove the hard–soft boundary. It moves it to the connector, the snap or clip where the pod meets the fabric. That connector must make reliable electrical contact through sweat and movement, must survive being washed without the pod attached, and must keep doing so for hundreds of attach and detach cycles. A large share of real-world failures happen there. The second strategy is full integration. The electronics are sealed in the garment and the whole thing goes into the wash. This is attractive for users, who often forget to remove modules, and essential for applications where the garment must be worn continuously. It is also much harder. It demands encapsulation that keeps water out of every component for hundreds of hours of washing, flexible interconnects that survive constant bending, and some way to charge a battery without exposed contacts. Wireless charging and very thin, flexible batteries help, but the encapsulation problem remains. The third strategy avoids local electronics altogether, or nearly so. A passive sensing garment carries only conductors and sensing structures, and is read by a separate device, which may be a wristwatch, a pod or a reader worn nearby. Many research garments take this approach because it makes washing simpler. Its cost is the need to route signals over long textile paths, which pick up noise and add resistance, and to make contact with the external device somewhere. None of these strategies escapes the core problem of joining a conductor that moves with the fabric to one that does not. They only choose where that join sits and how it is protected. Put together, these considerations define the problem the rest of this booklet addresses. A useful smart garment needs current paths that conduct well enough for the signal they carry, that stretch and bend with the fabric for thousands of cycles without cracking, that resist abrasion and corrosion in sweat, and that come out of hundreds of wash cycles with their resistance close to where it started. It needs joints between those soft paths and hard electronics that spread strain rather than concentrating it and that keep water away from metal. It needs sensing structures that stay in good contact with a moving body. And it needs all of this at a cost and comfort level that make someone want to wear it. The obvious first question is what to make the conductors from. The answer depends on which of those demands matters most, and on an honest reckoning of the trade-offs between conductivity, flexibility, durability, comfort and cost. That is the subject of the next chapter. Chapter 2: The Conductive Yarn Palette Ask a textile engineer how to make a conductive thread and you will get a list rather than an answer. Metal can be drawn into fine wire and twisted with ordinary fibres. Polymer filaments can be plated with silver or copper. Short stainless steel fibres can be blended into a spun yarn like wool into cotton. Carbon can be made into fibre directly. Conductive polymers can be coated onto fabric or spun into filaments. Nanomaterials, from carbon nanotubes to the silver nanowires of the next chapter, can be dipped, printed or sprayed. Each route gives a different balance of conductivity, flexibility, comfort, durability and cost, and each fails in its own way. Choosing among them is not a matter of picking the most conductive option. It starts with a question that is easy to skip: what does this particular current path have to do? What the conductor is for Electrical paths in a garment do one of three jobs, and the requirements differ by orders of magnitude. Signal paths carry information from a sensor to an amplifier. The textile electrodes that pick up the heart's electrical activity, for example, deliver signals of around a millivolt, and the amplifier they feed is designed to draw almost no current. In that situation the resistance of the path between electrode and amplifier hardly matters if it is stable. Tens or even hundreds of ohms are acceptable, because almost no current flows and so almost no voltage is lost along the way. What matters is that the resistance does not change abruptly when the wearer moves, because a sudden change can appear as a spike in the signal, and that the path is shielded or routed so that it does not pick up interference. Power paths carry current to run electronics, light sources or heaters. Here resistance matters directly. A path with resistance R carrying current I dissipates power equal to I squared times R, which is lost as heat and drops the voltage available at the far end. For a heated garment, which is deliberately resistive, the designer chooses a resistance to give the desired warmth at the battery voltage. For a path that must supply a processor or a radio, the designer wants as little resistance as possible. Data paths carry digital communication between components, for example between sensors distributed around a garment and a central module. These need modest resistance, but also consistent electrical behaviour along their length so that fast signals are not distorted. Long textile paths with variable spacing between conductors are not good at this, which is why many designs avoid running high-speed data through fabric at all. Sensing structures form a fourth category. Some conductive yarns are chosen precisely because their resistance changes with strain or pressure. These are the materials of stretch and pressure sensors, and for them a stable resistance would be a defect. The challenge is to make the change repeatable, so that the same stretch gives the same reading every time. Once the job is clear, the choice of material narrows considerably. Metals: wire, plating and steel The most conductive option is metal wire. Copper and silver are the best common conductors, with bulk resistivities of about 1.7 and 1.6 hundred-millionths of an ohm-metre respectively. A fine copper wire can carry real power with negligible losses. But solid metal wire behaves badly in fabric. It is stiff compared with fibres, it work-hardens and fatigues when bent repeatedly, and once it kinks it stays kinked. A single thick wire sewn into a shirt feels like what it is. Two ideas make wire more textile-friendly. The first is to make it very thin. The strain at the surface of a bent wire is proportional to its thickness divided by the bend radius, so halving the thickness halves the strain. Wires a few tens of micrometres across can be bent into tight folds without exceeding their fatigue limits. The second idea is to use many thin wires instead of one thick one, each individually insulated with an enamel coating and twisted together. This construction, called litz wire, has long been used in high-frequency electronics, and textile versions combine enamelled copper or silver-coated copper filaments with polyester or other carrier fibres. The enamel insulation is important in garments, because conductors that touch when the fabric folds would otherwise short-circuit. Wire can also be made stretchable by geometry rather than material. When a fine wire is wrapped helically around an elastic core, such as an elastane filament, stretching the yarn mostly unwinds the helix rather than lengthening the wire. The wire bends but barely stretches. The same principle appears at every scale in stretchable electronics, from wavy metal films to serpentine traces printed on rubber: let the conductor change shape so that it does not have to change length. Its cost is that the yarn can only stretch as far as the helix allows before the wire goes taut, and that repeated straightening and recoiling still fatigues the metal over time. Copper's main weakness in a garment is corrosion. It oxidises in air and is attacked by sweat, turning green and losing conductivity. Insulation helps, but any breach in the enamel, such as at a joint or after abrasion, becomes a corrosion point. Silver is more resistant in many respects, though it reacts with sulphur compounds and tarnishes. Gold and platinum do not corrode, but are used only in tiny quantities, for example as plating on contact points. The second major family takes an ordinary polymer filament, usually polyamide (nylon), and coats it with a thin layer of metal, most often silver. The result looks and handles almost like a normal synthetic yarn and can be knitted, woven, sewn and embroidered on standard machinery. Silver-plated polyamide yarns, sold under trade names such as Shieldex, have become one of the workhorse materials of e-textile research and products, and the silver fibres in many smart shirts and textile electrodes are of this type. The silver layer is thin, far thinner than the filament it coats, so the yarn's conductivity is much lower than that of solid silver wire of the same diameter. It is still good enough for signal paths and electrodes, and for short power paths. Because the conductor is spread over many fine filaments, each with its own coating, the yarn is soft and flexible, and a break in one filament does not interrupt the path. The weakness is that the conductor sits on the surface. Abrasion wears the silver off. Repeated flexing can crack the coating where the filament bends most. Washing combines both, and reviews of e-textile washing studies consistently report gradual loss of metal from metallised textiles, with the greatest loss in the first few cycles. Silver also tarnishes when exposed to sulphur compounds in the air or in some detergents, forming silver sulphide, which conducts far worse than silver. There is an environmental dimension too: silver released from textiles during washing enters wastewater, a question explored in the chapter on laundering. Silver has one property that makes it especially attractive for skin contact. A silver electrode in contact with chloride-containing sweat slowly forms a thin layer of silver chloride, and the silver–silver chloride interface is the same electrochemical system used in the gel electrodes of hospital electrocardiographs. It gives a stable electrical interface between the ionic currents of the body and the electronic currents of the circuit. This is part of the reason silver-based fabrics dominate textile electrodes. A third approach uses stainless steel. Steel can be drawn into extremely fine fibres, a few micrometres in diameter, either as continuous filaments or cut into short staple lengths. The Belgian company Bekaert, under the Bekinox name, is one long-established producer. Staple steel fibres can be blended with polyester, cotton or other fibres and spun into yarn on conventional spinning equipment, so that the conductor is distributed through the yarn rather than coated on its surface. Stainless steel is much less conductive than silver or copper, with a bulk resistivity roughly forty times higher. But it does not corrode in sweat, it does not lose a coating because there is no coating, and it survives abrasion and washing far better than plated yarns. Its main drawbacks are that it is harder on knitting needles and sewing machines, it can feel slightly coarse in high concentrations, and it cannot easily be soldered. In spun yarns, current flows from fibre to fibre through contact points rather than along continuous filaments, so the yarn's resistance depends on how tightly the fibres are pressed together and can drift as the yarn relaxes or is compressed. For many signal paths and heating applications, steel's robustness outweighs its modest conductivity. Carbon, polymers and coatings Carbon fibre, made by heating polymer precursors until only a graphitic carbon structure remains, conducts electricity but with resistivity hundreds to thousands of times higher than metals. It is too brittle in bending to be comfortable in most garments, but carbon-loaded polymer fibres and carbon-coated fabrics are widely used for heating elements, antistatic textiles and some electrodes, where a moderate, stable resistance is exactly what is wanted. The study of textile electrodes discussed in the chapter on sensing found that pure carbon coatings showed significant impedance degradation over a month, while coatings that combined carbon nanotubes with ionic liquids were much more stable, which is a reminder that the same element can behave very differently depending on formulation. Intrinsically conductive polymers offer a different route. The most widely used in e-textiles is PEDOT:PSS, a blend of a conductive polythiophene with a polymeric acid that makes it dispersible in water. It can be dyed, printed or coated onto fabrics almost like an ordinary finish. Its conductivity varies enormously with processing, from barely conductive to high enough for many signal applications after suitable treatment. PEDOT:PSS is soft and flexible, and because it conducts both electrons and ions, it forms a low-impedance interface with skin. Its weaknesses are sensitivity to water, since the PSS component swells and can wash out, and a tendency for conductivity to drift with humidity. Beyond these established families lies a long tail of newer materials: carbon nanotubes and graphene inks, two-dimensional metal carbides known as MXenes, liquid metal alloys of gallium and indium that remain fluid at room temperature and can be sealed in elastic tubes or fibres, and the silver nanowires that are the subject of the next chapter. Each has impressive laboratory results. Few have yet demonstrated the combination of durability, safety, cost and manufacturability needed for mass-market garments. Table 1 sets out the main families, comparing the conductivity of their underlying materials with their principal strengths and failure modes. The resistivity figures are standard bulk values for the conductor itself; a finished yarn conducts less well because only part of its cross-section is conductive and because current must cross contacts between fibres. Table 1. Main families of conductive yarn and their trade-offs. Family Conductor bulk resistivity (ohm-metre) Main strength Main failure mode Fine or litz metal wire Copper about 1.7 × 10⁻⁸ Highest conductivity, carries power Fatigue cracking, corrosion where insulation breaks Silver-plated polyamide Silver about 1.6 × 10⁻⁸ (thin layer) Textile handling, skin-friendly electrodes Coating loss by abrasion and washing, tarnish Stainless steel staple or filament About 7 × 10⁻⁷ Corrosion and wash resistance Lower conductivity, fibre-contact drift, hard to solder Carbon fibre or carbon coating About 10⁻⁵ for carbon fibre Stable moderate resistance for heating Brittleness, high resistance PEDOT:PSS coating Varies widely with treatment Soft, low skin impedance Water sensitivity, drift Sources: resistivities are standard handbook values for bulk materials; failure modes summarise the reviews of Rotzler and Schneider-Ramelow (2021) and the electrode study of Alizadeh-Meghrazi and colleagues (2021). Why the structure of the yarn matters A conductive yarn is not a wire, and treating it as one leads to surprises. Three structural effects matter most. The first is contact resistance. In any yarn made of many filaments or short fibres, current does not flow along a single continuous path. It flows along a filament until that filament ends or loses contact, then crosses to a neighbour through a point contact. Each of these crossings adds resistance, and the total depends on how many contacts there are and how firmly the fibres press on each other. Twisting a yarn tighter presses the fibres together and generally lowers resistance. Stretching it can either tighten contacts, lowering resistance, or pull fibres apart, raising it, depending on the yarn's construction. This is why the same yarn can behave as a near-constant conductor in one fabric and as a strain sensor in another. It is also why comparing yarns on paper is treacherous. Manufacturers quote resistance per metre, but the figure depends on the tension applied during measurement, the distance between contacts and how the contacts grip the yarn, and a value measured on a straight, taut length says little about the same yarn relaxed inside a knit. Standardised measurement methods for conductive yarns, discussed in Chapter 8, exist partly to bring order to this, and a careful designer measures candidate yarns in the actual fabric structure before choosing. The second is the fabric structure around the yarn. When a conductive yarn is knitted, the loops of the knit touch each other at many points. Current can short-cut through these contacts instead of following the full length of yarn. When the fabric is stretched, the contact pattern changes and the resistance changes with it. Knitted conductive fabrics therefore tend to be strain sensitive, which is useful for a stretch sensor and a nuisance for a signal path. Woven structures, in which the conductive yarn runs straight, are usually more stable. Embroidered paths, stitched onto the surface of a base fabric, can be laid in carefully controlled patterns, including zigzags that stretch without straining the yarn. The third is insulation. Clothing folds, and when it folds, conductive paths that were centimetres apart can touch. A garment with uninsulated traces carrying different signals, or a power line next to a ground line, is a short circuit waiting to happen, especially when wet. Insulation can come from coating individual yarns, from laminating a thin polymer film over printed or stitched traces, or from building the conductor into the inner layer of a multilayer fabric. Every insulation choice adds stiffness and every one becomes, in the washing machine, another layer that can crack or peel. A designer choosing conductive yarns works through a short sequence of questions. What current does the path carry, and how much resistance can it tolerate? How much will the fabric stretch and bend at this location, and how often? Will the conductor touch skin, and if so, does it need to make good electrical contact or should it be isolated? How will the garment be made, and can the yarn run on the machines that will make it? And how many wash cycles must it survive, at what temperature, with what detergent, before its resistance drifts beyond what the electronics can tolerate? That last question is the one most often left until too late. A yarn that looks ideal on a reel can lose most of its conductivity after a few dozen washes, and a yarn that seems unpromising because of its modest conductivity may still be working after hundreds. The practical answer in many products is a mix: silver-based yarns where skin contact is needed, steel or insulated metal where robustness matters, and careful design to keep the most delicate conductors away from the places where the fabric works hardest. The material that has done most to change those trade-offs in the last fifteen years is not a yarn at all but a nanoscale filler that can be built into almost any textile or elastomer. Silver nanowires deserve close attention, not because they solve every problem but because they show clearly how geometry, rather than raw material, decides whether a conductor can stretch. Chapter 3: Silver Nanowires and the Art of the Stretchable Network A silver nanowire is a rod of crystalline silver a few tens of nanometres across and tens of micrometres long. The wires used in a widely cited study of conductive threads from the University of Waterloo, for example, were about 35 nanometres in diameter and 15 micrometres long, which means each one was roughly four hundred times longer than it was wide. Scattered on a surface, they look under an electron microscope like a heap of uncooked spaghetti. Individually, each is an excellent conductor, because it is essentially a single crystal of the most conductive metal there is. Collectively, they form something more interesting: a network that can conduct across a surface while remaining mostly empty space, and that can change shape without breaking. That combination is why silver nanowires became one of the most studied materials in flexible and stretchable electronics. They were first pursued as a replacement for indium tin oxide, the brittle transparent conductor used in touchscreens and displays. A sparse network of wires lets light through the gaps while carrying current along the wires, and unlike a ceramic film it does not crack when bent. The same properties make them attractive for textiles, with transparency replaced by a more important virtue: the network can follow a fibre, a knit loop or a stretched elastomer without losing its connectedness. Making and connecting the wires Most silver nanowires are made by a solution method known as the polyol process, developed into a reliable route for wires largely by the group of Younan Xia in the early 2000s. A silver salt, usually silver nitrate, is dissolved in ethylene glycol and heated. The glycol acts as both solvent and reducing agent, converting silver ions into metallic silver. A polymer, polyvinylpyrrolidone, commonly abbreviated PVP, is added to the mixture. PVP binds more strongly to the side faces of the growing silver crystals than to their ends, so new silver atoms preferentially attach at the ends and the crystals grow into long wires rather than spheres or cubes. Small amounts of chloride or other ions are added to control the early stages of crystal formation. Two features of this process matter downstream. First, it produces wires coated with a thin layer of PVP. That coating keeps the wires dispersed in liquid, which is useful for coating and printing, but it is an insulator. Where two wires cross, the PVP layer sits between them and adds resistance. Second, the process can be tuned to give longer or thinner wires, and the dimensions of the wires strongly affect how well the network conducts, how transparent it is, how it responds to strain and how quickly it degrades. Once made, nanowires are typically supplied as a dispersion in water or alcohol and applied like an ink. They can be dip-coated onto threads, sprayed or printed onto fabrics, filtered into films, or mixed into a liquid polymer that is then cured. A single nanowire is too short to carry current across a garment. Current travels through the network by passing from wire to wire at the points where they cross. Whether a continuous path exists from one side of a coated area to the other depends on how many wires there are per unit area. At low densities the wires form isolated clusters and the coating does not conduct at all. As the density rises, clusters grow and merge, and at a certain critical density a cluster suddenly spans the whole area. This threshold is called the percolation threshold, borrowing a term from the physics of fluids flowing through porous rock, and the behaviour around it is one of the classic problems of statistical physics. Above the threshold, conductivity rises steeply as more wires are added, because more parallel paths become available. Longer wires percolate at lower densities, simply because each wire reaches farther and touches more neighbours. This is why manufacturers push for high aspect ratios: the longer the wires relative to their width, the less silver is needed to make a conductive network. In a well-made network, the resistance of the wires themselves is a small part of the total. Most of the resistance sits at the junctions, where current must cross from one wire to another through a small contact area and, initially, through the PVP coating. A great deal of research effort has gone into lowering junction resistance. Heating the network moderately softens and partially removes the PVP and lets the silver at crossing points fuse slightly; the Waterloo threads were annealed at 150 degrees Celsius for this reason. Pressing the network mechanically, exposing it to intense light pulses that heat the junctions selectively, or treating it chemically can achieve similar welding at lower bulk temperatures, which matters when the substrate is a polymer fabric that would melt under heat. The Waterloo study, published by Yahya Atwa, Nupur Maheshwari and Irene Goldthorpe in 2015, shows what this approach can do on ordinary threads. By dip-coating cotton, polyester and nylon threads in a nanowire dispersion, with simple surface pre-treatments for the synthetic fibres, they achieved resistances as low as 0.8 ohms per centimetre, adjustable by changing the concentration of the dispersion and the number of dips. A nylon thread immersed repeatedly in a stirred detergent solution at 25 degrees Celsius showed no change in resistance over five washings. That is an encouraging laboratory result, and also a modest one by the standards of real laundry, which is far longer, hotter and more mechanically violent. The gap between such bench tests and genuine washing is a theme of the later chapters. Why a network can stretch Here is the central idea of the chapter. A bulk metal film cracks when stretched by more than a few percent, because the metal itself must lengthen and it cannot do so elastically. A nanowire network does not have to lengthen any individual wire to accommodate stretching. When the surface under it extends, wires can slide past one another, rotate towards the direction of stretch, and lose some contacts while making others. The network reorganises rather than breaking. Its resistance rises, because some junctions separate and paths become longer and fewer, but as long as enough paths remain, it keeps conducting. On its own, a loose network would be fragile. The wires would shift permanently, and repeated stretching would progressively disconnect it. The decisive step is to embed the network in an elastomer, a rubbery polymer that stores the deformation elastically and pushes the wires back towards their original positions when released. A well-known demonstration came from the group of Yong Zhu at North Carolina State University, published by Feng Xu and Yong Zhu in Advanced Materials in 2012. They deposited silver nanowires on a silicon substrate, poured liquid polydimethylsiloxane, the silicone rubber known as PDMS, over them and cured it. When the cured rubber was peeled away, the nanowires came with it, embedded just beneath the surface. The resulting conductors could be stretched to 50 percent strain while remaining conductive, and they were robust under repeated mechanical loading. The researchers also exploited a geometric trick. When the conductor was stretched and released for the first time, the surface buckled into a wavy pattern. Later stretching first flattened these waves before straining the network itself, giving a range of extension over which conductivity stayed relatively stable. The embedding also prevented the delamination that plagues coatings simply laid on top of rubber. This is the same principle as wrapping a wire around an elastic core, applied at the nanoscale. The conductor survives large deformation because geometry, not material, absorbs most of the strain. There is a flip side. If stretching a nanowire network raises its resistance, then measuring its resistance tells you how much it has been stretched. The property that a designer of interconnects wants to minimise is exactly what a designer of strain sensors wants to maximise. Morteza Amjadi and colleagues at the Korea Advanced Institute of Science and Technology made this explicit in a study published in ACS Nano in 2014. They sandwiched a silver nanowire network between layers of PDMS and showed that the resulting sensor could be stretched up to 70 percent while its resistance rose in a controlled way. The sensitivity of a strain sensor is usually expressed as a gauge factor, the fractional change in resistance divided by the strain. Theirs could be tuned between about 2 and 14 by adjusting the construction. To show the idea in use, they built a glove with five sensors, one over each finger, that tracked finger bending well enough to control a hand in a virtual environment. For a garment, the dual nature of the network is both an opportunity and a hazard. A compression sleeve with a nanowire sensor over the elbow can measure joint angle. But a nanowire interconnect running across the same elbow, carrying a signal from a chest electrode to a sleeve-mounted module, will change its resistance every time the arm bends. Whether that matters depends on the circuit, as the previous chapter explained. For a high-impedance signal path, small resistance changes are tolerable. For a strain sensor read by measuring resistance, any extra variable resistance in the leads is an error. Good designs keep sensing and interconnecting functions separate, making sensors deliberately strain sensitive and interconnects deliberately insensitive, through choice of geometry, wire density and encapsulation. Building nanowires into fabric There are three broad ways to put silver nanowires into a garment, and they reflect different views about which component should provide the stretch. The first is to coat the textile directly. Threads or finished fabrics are dipped in or sprayed with a nanowire dispersion, so that the wires wrap around individual fibres. The fabric's own structure supplies stretch: as a knit is pulled, the fibres slide and the loops reshape, and the network on each fibre bends but does not need to extend much. This approach is simple and keeps the textile breathable and soft. Its weakness is exposure. The wires sit on the outside of fibres, where they meet abrasion, sweat and detergent directly. The second is to coat the textile and then overcoat it with a thin elastomer or polyurethane layer that locks the wires in place and shields them. This sacrifices some breathability and softness in the coated area, but it greatly improves resistance to abrasion and washing. The overcoat must be thin and flexible enough not to turn the fabric into a stiff patch, because a stiff patch creates exactly the stiffness gradient that concentrates strain at its edges. The third is to build the conductor separately, as a nanowire network embedded in a thin stretchable film, typically thermoplastic polyurethane, and then laminate that film onto the fabric with heat and pressure. This is closer to how printed stretchable electronics are made and allows precise patterning of traces and electrodes. The film carries the conductor and provides the elastic restoring force; the fabric carries the load and gives comfort. The challenge is the bond between film and fabric, which must survive washing without peeling. Table 2 summarises the main techniques that researchers and manufacturers use to keep a nanowire network conductive under repeated strain, with their benefits and costs. Table 2. Techniques for keeping a silver nanowire network conductive under strain. Technique How it works Benefit Cost Embedding below an elastomer surface Wires locked in rubber that restores their positions Large reversible stretch, no delamination Less breathable, adds stiffness Pre-strain and buckling Surface waves flatten before network strains Stable resistance over a working range Range limited to the buckle amplitude Junction welding Heat, light, pressure or chemistry fuses crossings Lower and more stable resistance Process heat can damage textile substrates Higher aspect ratio wires Longer wires keep more contacts while sliding Conducts at lower density and higher strain Longer wires are harder to make and disperse Protective overcoat Polymer layer shields wires from abrasion and chemistry Better wash and sweat survival Thicker, stiffer, can crack or peel Sources: Xu and Zhu (2012); Amjadi and colleagues (2014); Atwa, Maheshwari and Goldthorpe (2015); Guan and colleagues (2022). How nanowire networks degrade Nanowires are not invulnerable, and their weaknesses follow from their size. A wire 35 nanometres across has an enormous surface area relative to its volume. Any process that attacks the surface, removing even a few nanometres of silver, threatens to sever the wire completely. A bulk silver conductor would shrug off the same attack. A 2022 review in Critical Reviews in Solid State and Materials Sciences by Guan and colleagues surveyed the main degradation routes for nanowire networks, drawing largely on their use in transparent electrodes. Four matter for garments. Heat is the first. Thin metal wires become unstable at temperatures far below the melting point of bulk silver. Above a critical temperature, surface atoms become mobile enough that a wire breaks up into a chain of droplets, a phenomenon called Rayleigh instability after the same physics that breaks a thin stream of water into drops. Garments are rarely hot enough for this, but processing steps such as heat lamination and the hotter settings of a tumble dryer or iron deserve attention. Current is the second. High current densities can cause electromigration, in which flowing electrons push silver atoms along the wire, thinning it at weak points until it breaks. Junctions, where current concentrates, are especially vulnerable. This rarely limits signal paths but matters for any nanowire trace that carries power or heats. Light is the third. Ultraviolet light in particular can accelerate the breakdown of networks, partly by driving chemical reactions at the wire surface. Outdoor athletes wear their garments in strong sunlight, so this is not a laboratory curiosity. Chemistry is the fourth and, for textiles, the most important. Silver reacts with sulphur compounds to form silver sulphide, the familiar black tarnish, which conducts poorly. It reacts with chloride, which sweat supplies in abundance. It can be oxidised by bleaching agents in detergents. On a bulk silver surface these reactions form a thin surface layer. On a nanowire they can consume a significant fraction of the conductor, and at junctions they can open the contacts on which the network depends. The mitigation strategies discussed in that review and elsewhere converge on a common answer: protect the wires. Coatings of other metals, oxides, polymers or graphene can shield the silver surface. Embedding the network in an elastomer keeps reactive species away. Welding the junctions makes them less vulnerable to being opened. In practice, the more completely a nanowire network is sealed, the longer it lasts, and the less silver it releases into skin contact and wastewater. Silver nanowires have earned their prominence. They demonstrate that conductivity close to that of metal can coexist with large, repeated stretching, if the conductor is a network embedded in an elastic matrix rather than a continuous film. They can be applied to existing textiles with processes not far removed from dyeing and finishing. They can serve as both interconnect and sensor, depending on how the network is built. And they have helped make wavy, buckled, helical and network geometries the common language of stretchable electronics. What they do not do is remove the need for protection. A bare nanowire network on a fabric surface is more vulnerable to sweat, bleach and abrasion than a silver-plated yarn, not less, because its conductor is so thin. Every practical nanowire textile is therefore a composite: wires plus an elastomer or overcoat plus a textile. And composites fail at their boundaries. The interface between coated and uncoated fabric, between laminated film and base cloth, between soft network and hard connector, is where the next chapter goes. Hashtags: #SmartTextiles #ConductiveYarns #WashableElectronics #ElectronicTextiles #ETextiles #WearableTechnology #WearableElectronics #SmartClothing #IntelligentFabrics #TextileEngineering #ConductiveFibers #SilverNanowires #StretchableElectronics #FlexibleElectronics #FunctionalTextiles #SmartGarments #TextileSensors #FabricSensors #BiomedicalWearables #SportsTechnology #AthleteMonitoring #PhysiologicalMonitoring #TextileElectrodes #PrintedElectronics #ConductivePolymers #PEDOTPSS #Nanotechnology #WashabilityTesting #ElectronicDurability #WearableInnovation

  • Healthy Boundaries with Parents (Emotional Independence and Communication for Young Adults)

    Download the Book (PDF): Introduction Somewhere in the first year after leaving home, most young adults have a version of the same small, disorienting moment. The phone lights up with a parent's name for the fourth time that day. Or a text arrives asking why a grade dropped, and you realize your mother has been checking the portal. Or you come home for winter break, having spent four months deciding for yourself when to eat, sleep, study and see friends, and within an hour someone asks where you are going and when you will be back. None of these moments is a crisis. Each is a small collision between two versions of the family: the one that existed when you were a child living under your parents' roof, and the one that has not been built yet. This book is about building the second one. It is written for college students and young adults roughly between eighteen and the late twenties who are working out how to be close to their parents without being run by them, and how to be independent without cutting themselves off. It is also written, in part, for the parents, advisers, resident assistants and counselors who stand beside those young adults and want to help without taking over. The central argument is simple to state and harder to live: emotional independence is not distance. It is the capacity to remain yourself while staying in relationship with the people who raised you. A young adult who never calls home is not necessarily independent, and one who calls every day is not necessarily dependent. What matters is whether you can think your own thoughts, make your own decisions, tolerate your parents' disagreement, and still stay connected to them. Why this transition is harder now than it looks Families have always had to renegotiate the relationship when children grow up. What has changed is the shape of the path. The psychologist Jeffrey Jensen Arnett argued in 2000 that the years from the late teens through the twenties had become a distinct developmental period in industrialized societies, which he called emerging adulthood. Marriage, parenthood and stable careers now arrive later than they did for earlier generations, and the years in between are marked by exploration, instability and the peculiar sense of being neither an adolescent nor fully an adult. That in-between status is not only a feeling. It is written into money, housing and paperwork. A 2023 Pew Research Center survey of more than 3,000 parents of young adults found that 59 percent had helped their 18- to 34-year-old children financially in the past year, while only 45 percent of young adults in a companion survey said they were completely financially independent. Among 18- to 24-year-olds, 57 percent were living in a parent's home. The same research found something that should reassure anyone who worries that closeness is a problem in itself: most parents and young adults described their relationship positively, and large majorities of parents said they text their young adult children at least a few times a week. Constant contact is now the ordinary condition of family life, not a sign that something has gone wrong. That is the setting in which boundaries have to be worked out. A student may be legally an adult, with the right under federal law to control access to her own education records, while her parents pay her tuition, carry her on their health insurance until she turns 26, and appear as her emergency contact. She may be making her own decisions about coursework and relationships while her parents can see her location on their phones. The formal markers of adulthood and the practical realities of dependence rarely line up neatly, and much of the friction between young adults and their parents comes from the gap between them. What this book means by a boundary The word "boundary" has become popular enough to be misused. In casual speech it sometimes means a demand: "My boundary is that you stop criticizing my girlfriend." Understood that way, a boundary becomes a way of controlling another person's behavior, and it tends to fail, because no one can make another adult stop having opinions. In this book, a boundary is a decision about what you will do. It describes where you end and another person begins: what information you share, what decisions you make yourself, how you respond when someone pushes, and what you will and will not take part in. "I'm not going to discuss my relationship over dinner; if it comes up, I'll change the subject or step away" is a boundary. It does not require your father to agree. It requires you to act on it calmly and consistently. Good boundaries are usually quieter than people expect. They are less about dramatic announcements than about hundreds of small moments in which you choose not to over-explain, not to lie, not to explode and not to cave. A boundary is also not the same as a wall. Walls keep people out entirely. Boundaries create a shape for the relationship, and the shape can include a great deal of closeness. Many young adults who set boundaries well end up closer to their parents, because they no longer have to hide, placate or brace for conflict every time they talk. A few commitments This book tries not to pathologize parents. The research on overparenting, which later chapters examine in detail, finds real associations between highly controlling parenting and poorer outcomes for young adults, but the effects are modest, the studies are mostly correlational, and much of what gets called helicopter parenting grows out of love, fear and a changing economy rather than any wish to dominate. Most parents who hover are anxious, not malicious. Understanding that does not oblige you to accept every intrusion, but it changes how you respond, and it makes you far more likely to be heard. It also tries not to treat one culture's model of adulthood as universal. In many families, especially those with roots in collectivist cultures and many families of first-generation college students, obligation to parents and siblings is not a failure of independence but a core value, one that research links to positive well-being. Healthy boundaries in those families look different from boundaries in a family that expects children to leave at eighteen and call on Sundays. Both can be healthy. And it recognizes that not every student is dealing with parents who are too close. Some are dealing with parents who are distant, unreliable, hurtful or absent. Some have cut contact, and some have had contact cut with them. Those students need the same core skills, but they also need practical information about money, paperwork and support that a book aimed only at over-involved families would leave out. How the book is organized The first two chapters lay out the developmental ground: what emerging adulthood asks of families, and the idea of differentiation of self, which offers the most useful single framework for thinking about emotional independence. Chapter 3 examines over-involved parenting, what the research actually shows and why it happens. Chapter 4 turns to the practical question of information: what parents can and cannot see under FERPA and health privacy law, and how location sharing, passwords and portals complicate things. Chapter 5 takes up money, which is often where the most important boundaries are negotiated and where the leverage is least equal. Chapter 6 considers culture, family obligation and the particular position of first-generation students. Chapter 7 is the most hands-on: it provides preparation methods and scripts for difficult conversations, along with ways to handle the reactions that usually follow. Chapter 8 addresses distant and estranged families. Chapter 9 explains when and how to use counseling, and when a family situation calls for more urgent help. A brief note before starting: this book offers general information and practical guidance, not individual psychological, medical, legal or financial advice. Laws and institutional policies differ and change, and a counselor, financial aid officer or other professional who knows your situation can tell you things a book cannot. If you are ever in danger, or thinking about harming yourself, contact emergency services or, in the United States, call or text 988 to reach the 988 Suicide & Crisis Lifeline. That resource and others appear again in the final chapter. The scenarios in these pages are illustrative composites, not real individuals. They are drawn to be recognizable, because the problems they describe are common. If you see yourself in one of them, that is the point: you are not the first person to find this transition difficult, and the difficulty is not a sign that your family is broken. It is a sign that your family is changing. Chapter 1: The Renegotiation Consider a first-year student who moves three hundred miles from home in August. She has been, by every account, a responsible teenager: good grades, a part-time job, a driver's license, a history of making sensible choices. Within six weeks she finds herself in an argument with her father about whether she should drop a chemistry class. He thinks dropping it is a mistake that will close off a pre-medical path. She is not sure she wants that path. The argument is not really about chemistry. It is about who gets to decide, and neither of them has a clear answer, because the rules that governed decisions in their family were written for a child living at home and have not been rewritten for a young adult living somewhere else. Every family eventually has to renegotiate the relationship between parents and children. What is unusual about the present moment is how long the renegotiation takes, how many practical ties remain in place while it happens, and how little guidance families get. This chapter lays out the developmental ground: what the period between adolescence and settled adulthood looks like, what it asks of young adults and parents, and why the renegotiation so often feels like conflict even in loving families. The in-between years In 2000, the developmental psychologist Jeffrey Jensen Arnett published an article in American Psychologist proposing that the years from roughly eighteen to twenty-five had become a distinct stage of life in industrialized societies. He called it emerging adulthood. The argument rested on a demographic shift that had been building for decades: the median ages of marriage and first childbirth had risen sharply, a much larger share of young people were entering higher education, and the path into stable work had become longer and less predictable. Young people were no longer moving directly from adolescence into the roles that had traditionally defined adulthood. Instead they spent years in a period of exploration. Arnett later described five features that characterize this period. It is the age of identity explorations, when young people try out possibilities in love, work and worldview. It is the age of instability, with frequent changes of residence, relationships and jobs. It is the most self-focused age of life, not in the sense of selfishness but because obligations to others are at a low point and young people are working out what they themselves want. It is the age of feeling in-between: asked whether they have reached adulthood, many young people in this period answer "in some ways yes, in some ways no." And it is the age of possibilities, when optimism about the future tends to run high and when people have an unusual chance to change direction. Arnett's framework has critics. Some researchers have argued that it describes a relatively privileged slice of young people, those with the resources to explore rather than those who must work full-time at eighteen or care for relatives. That criticism is fair, and Chapter 6 returns to it. But the framework captures something real about how the transition feels to many students. The same young person may be managing her own schedule, bank account and romantic life while her parents hold the purse strings, carry the insurance card and expect a weekly report. She is an adult in some rooms and a child in others. One of the more illuminating findings in Arnett's research concerns how young people themselves define adulthood. Across many studies, they tend not to name the traditional markers such as marriage, finishing school or buying a home. The criteria they rate most highly are individualistic and psychological: accepting responsibility for yourself, making independent decisions, and becoming financially independent. Adulthood, in their view, is something you become on the inside before it is confirmed by the outside world. That definition places the relationship with parents at the center of the transition, because parents are the people from whom young adults are learning to take responsibility, make decisions and support themselves. From hierarchy toward mutuality It helps to name what is actually changing. In childhood, the parent-child relationship is necessarily hierarchical. Parents make decisions on children's behalf, set rules, enforce consequences, and hold information that children do not. This hierarchy is not a flaw; it is how children are kept safe and taught to function. Adolescence loosens it. Teenagers push for more say, parents grant autonomy in stages, and the negotiation over curfews and phone use is part of how both sides practice the change. Emerging adulthood asks the family to move further, toward something closer to a relationship between adults. That does not mean parents and grown children become equals in every respect. Parents often continue to hold more resources, more experience and, in many cultures, a position of respect that does not disappear. But the basic currency of the relationship changes. Decisions that were once the parent's to make become the young adult's. Rules give way to requests. Information that was once owed becomes information that is offered. Advice replaces instruction. This shift is not a single event. It happens domain by domain, and often unevenly. A family may reach an easy understanding that a daughter's choice of friends is her own business while still treating her choice of major as a joint decision. A son may be fully trusted with money but still reminded to wear a coat. Most of the friction in these years comes from mismatches about which domains have shifted and which have not. The student who dropped chemistry assumed that course choices had become hers. Her father assumed that decisions with large financial and career consequences were still shared. Neither was being unreasonable; they simply had different maps. Part of the work of this period, then, is making the maps explicit. Many families never discuss which decisions belong to whom. They find out only when they collide. One of the most useful things a young adult can do, usually during a calm moment rather than a heated one, is to ask directly: "Which decisions do you see as mine now, and which do you still want a say in?" The answer is often revealing for both sides, and it turns an unspoken struggle into a conversation. Young adults often experience their parents' resistance to the renegotiation as a refusal to accept that they have grown up. Sometimes it is. More often it reflects the fact that parents are going through their own transition, with its own losses and anxieties, and have had even less preparation for it. For many parents, the child's departure removes a role that has organized daily life for eighteen years. The daily logistics of parenting, which could be exhausting, also provided purpose, structure and a steady flow of information about the child's well-being. When a child leaves, much of that information stops arriving. A parent who once knew what their child ate for dinner, who their friends were and how they were sleeping now knows only what the child chooses to report. For an anxious parent, that silence can fill with worst-case scenarios. Parents also carry knowledge that young adults sometimes discount: they have seen how small decisions can have large consequences. The father who argued about chemistry may have watched his own plans narrow because of a choice he made at nineteen. His intensity may reflect his own history more than his daughter's situation. That does not make him right, but it makes his behavior intelligible. There is also an economic backdrop. The stakes of the transition to adulthood feel higher than they did a generation ago. College is expensive, many students borrow heavily, and early career paths are less certain. Parents who have invested significant money, and who see their child's future as fragile, are understandably reluctant to step back from decisions that could affect whether that investment pays off. Technology has made stepping back harder still. It is easy to check a location, read a grade portal or send a text, and each of those actions feels small. Together they can add up to a level of monitoring no earlier generation of parents could have managed. Finally, parents are often navigating their own life transitions at the same moment. A parent in her late forties or fifties may be caring for aging parents of her own, facing changes at work, managing health problems, or discovering what her marriage looks like without children in the house. The empty nest is not uniformly sad; many parents report relief and new freedom. But it is a transition, and people in transition tend to cling to what is familiar. A mother who calls her son every evening may be responding partly to her own loneliness, and the most helpful response may be less a boundary against her than a quiet recognition that she, too, is working out who she is now. Recognizing these pressures helps young adults respond to their parents with more generosity and less defensiveness. It does not mean accepting every intrusion. A parent's anxiety is real, but it is the parent's to manage, and a young adult who organizes her whole life around keeping her parents calm has not become independent. She has simply moved the parental hierarchy inside her own head. It would be unfair to put the whole burden of the renegotiation on parents. Young adults contribute to the confusion too, often without noticing. The most common contribution is inconsistency. A student who wants her parents to stay out of her decisions about classes may also call them in a panic when a registration deadline looms and ask them to sort it out. A son who resents his mother's questions about his social life may also depend on her to schedule his doctor's appointments and remind him about his car insurance. From the parent's side, these signals are mixed. The young adult seems to want autonomy in some moments and rescue in others, and the parent has no way of knowing which is which until the moment arrives. This inconsistency is not hypocrisy. It is what learning looks like. Young adults are acquiring new capacities at different rates, and it is natural to reach for familiar support when the stakes feel high. But it is worth being honest about. If you want your parents to step back in a particular domain, the most persuasive argument is not a speech about your rights. It is a track record of handling that domain yourself, including handling it when it goes badly. Parents tend to extend trust in the places where they see competence. A second common contribution is secrecy used as a substitute for boundaries. Many young adults, rather than telling their parents that some areas of life are now private, simply stop reporting and hope no one notices. This works until it does not. When the concealed information surfaces, as it often does, the parent experiences it as deception rather than privacy, and the result is more monitoring, not less. There is a real difference between saying "I'm not going to share the details of my relationship, but I'm doing fine" and pretending the relationship does not exist. The first is a boundary. The second is a secret, and secrets tend to invite suspicion. A third contribution is reactivity. Young adults, like everyone, sometimes respond to their parents with more heat than the situation calls for. A question about grades becomes a fight about control. A suggestion becomes an insult. Much of this reactivity comes from the fact that parents know exactly where their children are most sensitive, and young adults are still learning to respond to those sensitivities without being governed by them. The next chapter takes up this problem in depth, because the ability to stay calm in the presence of a parent's anxiety is, in many ways, the core skill of emotional independence. Contact is not the problem It is tempting to measure independence by frequency of contact, as if the student who calls home once a month were more grown up than the one who talks to her mother every day. The research does not support that shortcut. In the late 2000s, the psychologist Barbara Hofer and her colleagues studied communication between college students and their parents at Middlebury College and the University of Michigan. They found that students were in contact with their parents an average of 13.4 times a week, across phone calls, texts, email and other channels, with parents and students each initiating roughly half. More interesting than the frequency was what it predicted. Students in the most frequent contact tended to be less autonomous, and students whose parents continued to monitor them closely were the least satisfied with the relationship, describing it as controlling. But students who regulated their own academic lives, whatever their level of contact, were happier in college, happier with their parents and had higher grades. It is worth pausing on the direction of that association. A study like Hofer's cannot say whether frequent contact made students less autonomous or whether less autonomous students sought out more contact. Both are plausible, and both probably happen. A student who is struggling may call home more, and a parent who is called often may find it harder to step back. What the finding does show is that frequency by itself is a poor guide. Two students with identical phone records can have entirely different relationships with their parents. The implication is that what matters is not how often a young adult talks to her parents but what the contact is doing. A daily call in which a student shares news, asks for an opinion she then weighs for herself, and hangs up feeling supported is very different from a daily call in which a parent checks whether assignments were completed and approves plans for the evening. The first is closeness. The second is supervision conducted by phone. The Pew research cited in the introduction points in the same direction. Most young adults in its 2023 survey said their parents were about as involved in their day-to-day lives as they wanted them to be, and large majorities described the relationship in positive terms. Frequent contact is simply the ordinary texture of family life for this generation. Healthy boundaries do not require reducing it. They require making sure that the contact serves the relationship as it is now, rather than preserving the relationship as it was. What success looks like If independence is not measured by distance, how would a family know the renegotiation was going well? A few signs are worth watching for. Decisions are made by the person who will live with their consequences, with others offering input rather than approval. A young adult can tell her parents about a choice they will dislike without lying, apologizing excessively or picking a fight. Parents can express worry or disagreement without trying to override the decision, and the young adult can hear that disagreement without abandoning her position or feeling that the relationship is at stake. Help, including financial help, is offered and received with clear understandings about what it does and does not buy. Both sides can say no to requests from the other without the refusal becoming a crisis. And the relationship has room for the parents to be people rather than only parents, and for the young adult to be a person rather than only a child. None of these conditions arrives all at once, and few families achieve all of them. The renegotiation is uneven, with setbacks and relapses. A family can move forward for months and then fall back into old patterns during a holiday visit, a health scare or a financial crunch. That is normal. The goal is not a perfect adult relationship by graduation but a direction of travel, with each side learning to trust the other a little more. The chapters that follow give that direction of travel more structure. The next one introduces an idea from family systems theory that explains why some young adults can hold their ground with their parents calmly while others either fold or explode, and why the answer is not to care less about your family but to be more fully yourself within it. Chapter 2: Connected Without Being Fused Picture two sophomores who have both decided to switch their majors from engineering to history, and who both know their parents will be unhappy. The first student avoids telling her parents for most of a semester. When she finally does, over the phone, her mother's voice tightens and her father asks what she plans to do for a living. Within five minutes the student is shouting that they have never supported anything she wanted, then crying, then promising to think it over. She hangs up, spends the evening looking at engineering requirements again, and does not sleep. The second student tells his parents at the start of the semester. His father is also displeased and asks the same question about making a living. The student says that he has thought about it, that he understands the worry, and that he is going to try history for at least a year and see how it goes. His father argues for a while. The son listens, answers some of the questions, declines to argue about others, and says he has to go to class. The next week he calls as usual and talks about something else. The two students care equally about their parents. They face the same disapproval. What differs is how much of their parents' anxiety they absorb, and whether they can hold a position without either abandoning it or going to war over it. That capacity has a name in family systems theory: differentiation of self. It is the single most useful idea in this book, and this chapter explains what it is, why it matters and how it can be developed. Bowen's idea Differentiation of self is the central concept in the family systems theory developed by the psychiatrist Murray Bowen from the 1950s onward. Bowen observed that families function as emotional units: anxiety in one member spreads to others, and families develop patterns for managing that anxiety that shape how each member thinks and behaves. Within any family, individuals vary in how well they can maintain a sense of self while remaining emotionally connected to the others. Bowen described differentiation on two levels. Internally, it is the ability to distinguish between thinking and feeling, so that a person can experience strong emotion without being driven entirely by it. Interpersonally, it is the ability to remain yourself in close relationships: to hold your own beliefs and make your own choices while staying in contact with people who think and choose differently. A well-differentiated person can be deeply attached to her family and still disagree with them calmly. A poorly differentiated person tends toward one of two patterns. Either she fuses with the family, taking on its anxieties and expectations as her own and struggling to know what she herself wants, or she cuts herself off, managing the intensity of family relationships by distance, silence or rupture. The crucial insight is that fusion and cutoff are two versions of the same problem. The young adult who does everything her parents ask and the young adult who refuses to speak to them are both being governed by the family's emotional field. One is obeying it; the other is fleeing it. Neither has found a way to be both connected and separate. Bowen argued that cutoff, although it can feel like independence, often leaves the underlying patterns intact. People who cut off from their families frequently reproduce the same dynamics in their new relationships, because they never learned to stay in contact with intense feelings without being overwhelmed by them. This does not mean that cutting contact is always wrong. Chapter 8 addresses situations in which distance is necessary for safety or well-being, and Bowen's framework should not be used to shame people who have made that choice. But for most young adults dealing with ordinarily difficult families, the framework offers a clear goal: not to get away from your parents, and not to do what they want, but to become someone who can be fully yourself in their presence. Bowen's theory was developed clinically, through observation of families in treatment, and for a long time it was criticized for lacking empirical grounding. In 1998, the psychologists Elizabeth Skowron and Myrna Friedlander published a measure called the Differentiation of Self Inventory, which broke the concept into four related dimensions. The instrument is widely used in research and is worth knowing about because its four dimensions give a practical vocabulary for self-observation. The first dimension is emotional reactivity: the tendency to respond to others with automatic emotional intensity, to be flooded by feelings or thrown by other people's moods. The second is what Bowen called the "I-position": the ability to state clearly what you think and believe, and to hold that position under pressure. The third is emotional cutoff: the tendency to manage anxiety in relationships by withdrawing, avoiding intimacy or distancing. The fourth is fusion with others: over-involvement in other people's emotional lives, difficulty separating your own views from those of important people, and a need for their approval to feel settled. Research using this and related measures has generally found that higher differentiation is associated with lower anxiety, fewer psychological symptoms and better relationship functioning, although as with much correlational research, the direction of influence is not always clear. For practical purposes, the four dimensions work as a self-check. After a difficult conversation with a parent, a young adult can ask: Did I react more strongly than the situation called for? Did I say what I actually think? Did I want to disappear? Did I lose track of my own view because I needed them to approve of it? Autonomy is not the same as independence A second body of research sharpens the picture in a way that matters especially for families from cultures that value interdependence. Self-determination theory, developed by the psychologists Edward Deci and Richard Ryan, proposes that people have basic psychological needs for autonomy, competence and relatedness, and that well-being depends on those needs being met. In this theory, autonomy does not mean independence from others. It means acting from motives you endorse, experiencing your choices as your own rather than as imposed from outside. A person can be autonomous while depending heavily on others, as long as the dependence is one she chooses and values. Conversely, a person can be highly independent, living alone and asking for nothing, while acting out of pressure, fear or defiance rather than genuine choice. In 2007, the researcher Bart Soenens and colleagues tested this distinction in the context of parenting. They separated two things parents might do: promote independence, by encouraging children to decide and act on their own, and promote volitional functioning, by encouraging children to act on their own values and interests, whatever those turned out to be. The second form of autonomy support, they found, was the one more consistently related to adolescents' well-being. What seemed to matter was not whether young people were making decisions alone but whether the decisions felt like their own. This distinction is liberating for young adults who feel torn between their families and an idea of independence they have absorbed from the surrounding culture. A student who chooses to live at home, call her mother every day and consult her parents on major decisions is not necessarily less autonomous than one who moves across the country and consults no one. What matters is whether she is doing those things because she values them or because she cannot imagine doing otherwise. Differentiation, understood this way, is not about how much you depend on your family. It is about whether you can think clearly about that dependence and choose it. Reactivity and the I-position Most young adults do not need a theory to recognize reactivity. They know the tightening in the chest when a parent's name appears on the phone at an unusual hour, the flash of irritation when a question lands on a sore spot, and the way certain phrases from a parent can make them feel twelve years old. Reactivity is fast. It happens before thought, and it is often out of proportion to the triggering event because it is responding not to this particular question but to hundreds of similar questions over many years. Understanding reactivity does not make it disappear, but it does create a small space between the trigger and the response, and that space is where differentiation happens. Several practices widen it. The first is noticing the physical signs. Reactivity usually shows up in the body before it shows up in words: a racing heart, a hot face, clenched hands. Learning to catch those signals gives you a moment to slow down. Some people find it useful simply to name the reaction silently, "I'm getting defensive," which tends to reduce its grip. The second is buying time. A young adult is almost never obliged to respond to a parent immediately. "Let me think about that and get back to you" is a legitimate response to almost any question. So is ending a call that is going badly: "I don't want to keep talking about this right now. Can we pick it up tomorrow?" Taking time is not avoidance if you actually return to the conversation. It is simply a refusal to make important statements while flooded. The third is getting curious. Reactivity narrows attention to threat. Curiosity widens it. Asking a parent a genuine question, such as "What worries you most about this?", often lowers the temperature on both sides, because it shifts the conversation from a contest to an exchange of information. It also gives you better information about what is actually driving the parent's behavior, which is often different from what it appears to be. The fourth is practicing outside the moment. Many young adults find it helpful to rehearse difficult conversations in advance, with a friend, in writing or in their heads, precisely so that when the familiar trigger arrives they have a response ready that is not simply the old reaction. Chapter 7 offers specific methods for doing this. If managing reactivity is the defensive half of differentiation, the positive side is the ability to say clearly what you think, want and intend to do. Bowen called this taking an "I-position," and it differs in important ways from both compliance and attack. An I-position is a statement about yourself, not about the other person. "I've decided to switch to history" is an I-position. "You never let me choose anything" is an accusation. "Maybe I should think about it more" said in order to end the discomfort is a retreat. The I-position is calm, specific and not dependent on the other person's agreement. It does not demand that parents approve; it simply informs them of where you stand. A good I-position usually includes some acknowledgment of the other person's view. "I know you're worried about job prospects, and I've thought about that. I've decided to try history for a year." The acknowledgment is not a concession. It signals that you have heard the concern and are not dismissing it, which makes the statement easier to receive. It also demonstrates the very maturity the parent may be doubting. Taking an I-position also means being prepared for the reaction. Bowen observed that when one member of a family changes position, the rest of the family typically responds with pressure to change back. He called these "change back" reactions, and they are entirely predictable: arguments, guilt, anger, withdrawal of warmth, appeals to other family members. They are not evidence that the new position is wrong. They are evidence that the family system is adjusting. A young adult who expects the pushback and does not interpret it as catastrophe is much more likely to hold steady long enough for the family to adapt. The psychologist Harriet Lerner, whose book The Dance of Anger translated many of Bowen's ideas for general readers, made the same point: when you change your part in a familiar pattern, others will almost always push you to resume it, and the task is to stay the course without counterattacking. Triangles and the long work Bowen's theory contains one more idea that young adults find immediately recognizable: triangles. When tension between two people rises, Bowen observed, they tend to pull in a third person to relieve it. A mother who is frustrated with her son may complain to his sister rather than speaking to him. A student who is angry with her father may vent to her mother, who then carries the message. Parents in conflict with each other may each confide in a child. Triangles are not always harmful, and venting to a trusted sibling can be a healthy way to process frustration. But they tend to keep the real conflict from being addressed, and they place the third person in a difficult position. Young adults often find themselves in triangles that were set up long before they left home: acting as the go-between for divorced parents, serving as a parent's confidant about marital problems, or being the "easy" child against whom a sibling is compared. Stepping out of a triangle does not require a confrontation. It usually means gently redirecting communication to where it belongs. "It sounds like you're upset with Dad about this. Have you told him?" Or: "I'd rather not carry messages between you and Mom. If there's something you want her to know, it would be better coming from you." These statements are small, but they can change the shape of a family's communication over time, and they relieve the young adult of a role that often generates quiet resentment. Bowen believed that differentiation levels are largely shaped in childhood and change slowly. Later clinicians have been more optimistic, and the experience of many people who work at it suggests that meaningful change is possible, especially in early adulthood, when the family's patterns are being renegotiated anyway. Leaving home offers a natural opportunity: a young adult sees her family from a new distance, encounters other families with different patterns, and has room to try new responses. The work is rarely dramatic. It consists mostly of repeated small moments: noticing a reaction and not acting on it, stating a view and not retracting it, staying on the phone through a difficult conversation rather than hanging up or collapsing. Each such moment builds a little more capacity for the next. Over time, many young adults find that conversations that once felt impossible become merely uncomfortable, and then routine. Consider how this plays out for the second student in the opening example, the one who switched to history. His father's first reaction was argument. Over the next month there were further attempts: forwarded articles about unemployment among humanities graduates, a pointed comment from an uncle at a birthday dinner, a stretch of cooler phone calls. The student did not treat any of these as an emergency. He read the articles and said he found one of them useful. He told his uncle he appreciated the concern. He kept calling. By the end of the semester his father was asking which history courses he liked best. Nothing dramatic happened; the family simply adjusted to a new fact, because the student had stayed both steady and present long enough for the adjustment to occur. Had he either caved in the first week or stopped calling home, the family would have learned something very different. It is also worth saying what differentiation is not. It is not coldness, detachment or a refusal to be affected by family members. A well-differentiated person can feel her mother's disappointment keenly and still hold her position. She can be moved by her father's worry and still decide that the decision is hers. The goal is not to stop caring but to care without losing yourself. The next chapter turns to a pattern that tests differentiation more than almost any other: the highly involved parent. Understanding what drives that involvement, and what the research does and does not say about its effects, is the first step toward responding to it without either surrender or war. Chapter 3: Understanding the Over-Involved Parent A junior receives an email from her academic adviser asking her to schedule a meeting. Before she has opened it, her father has texted to ask whether she has seen it, because the university's parent portal sent him a notice too. By the end of the day he has suggested three times for the meeting, drafted some questions she might ask, and wondered aloud whether he should call the adviser himself. She is annoyed, then guilty about being annoyed, because he is plainly trying to help and because on at least two past occasions his help got her out of real trouble. This is what most people mean by helicopter parenting: a parent who remains closely involved in the details of a young adult's life, especially in areas where the young adult could manage alone. The term is often used as an insult, and popular writing about it tends toward caricature, with parents calling professors to dispute grades or attending job interviews. The reality is more ordinary and more sympathetic. This chapter looks at what over-involvement is, what the research does and does not show about its effects, why parents do it, and how young adults can respond in ways that protect their autonomy without wounding the relationship. Naming the pattern The image of a parent hovering like a helicopter predates the modern debate. It appears in the psychologist Haim Ginott's 1969 book Between Parent and Teenager, in which a teenager complains that his mother hovers over him like a helicopter. The phrase spread through parenting literature in the following decades and became a staple of commentary about college students in the 2000s, when cell phones made constant contact cheap and easy and when administrators began reporting more parents intervening directly with universities. For a long time the concept was loose, used to describe everything from mild anxiety to outright control. In 2012, the developmental psychologists Laura Padilla-Walker and Larry Nelson tried to pin it down. Surveying 438 undergraduates from four American universities, along with their parents, they developed a measure of helicopter parenting and tested whether it was distinct from other forms of parental control that researchers had long studied. Behavioral control refers to monitoring and rule-setting; psychological control refers to manipulating a child's emotions, for example through guilt or withdrawal of love. Helicopter parenting, they found, was statistically distinct from both. It captured something specific: a parent's tendency to intervene in and solve problems for a young adult, make important decisions on the young adult's behalf, and step in to prevent difficulties before they arise. The same study turned up a finding that complicates the caricature. Helicopter parenting was positively associated with parental involvement, guidance and emotional support, and with warm relationships between parents and young adults. It was negatively associated with parents granting autonomy and with the young adults' engagement in school. In other words, the parents who hovered were often the same parents who were warm and engaged. Their involvement was not coldness disguised as help. It was care that had not adjusted to the child's age. That distinction matters because it suggests the problem is not the love behind the involvement but its form. A parent who asks about a job interview is involved. A parent who writes the cover letter is over-involved. The difference is whether the involvement supports the young adult in doing something or does the thing for them. Table 1 sets out that difference across several domains of student life, along with the sort of boundary a young adult might set in each. The examples are illustrative rather than exhaustive, and the line between the columns will fall in different places for different families. A parent who helps a student with a learning disability navigate accommodations, for example, may be doing something appropriate that would be over-involvement for another student. Table 1. Supportive involvement versus over-involvement in common areas of student life. Area Supportive involvement Over-involvement A boundary might sound like Academics Asks how classes are going; listens to worries Checks grades daily; contacts professors "I'll tell you about grades at the end of term." Course and major choices Shares views when asked; asks questions Chooses the major; ties support to a field "I want your input, and I'll make the call." Health Encourages care; helps with insurance questions Books appointments; demands details of visits "I'll handle appointments and tell you if it's serious." Social life Takes an interest in friends and partners Vets friends; monitors location to track plans "I'm happy to tell you about people, not to get approval." Problems and conflicts Offers advice, then lets the student act Intervenes directly with roommates or staff "Thanks. I'm going to try handling it myself first." What the research shows, and what it does not Over the past fifteen years, research on helicopter parenting and overparenting has grown substantially. Most of it relies on surveys of college students, sometimes paired with surveys of their parents, and most of it finds that higher levels of parental over-involvement are associated with somewhat worse outcomes for young adults. A representative example is a 2014 study by Holly Schiffrin and colleagues at the University of Mary Washington, which surveyed 297 college students. Students who reported having over-controlling parents reported higher levels of depression and lower satisfaction with life. The researchers traced the link through self-determination theory, introduced in the previous chapter: the effects of helicopter parenting on well-being were largely explained by students' sense that their needs for autonomy and competence were being frustrated. In plain terms, students whose parents did things for them felt less in charge of their lives and less capable, and those feelings accounted for much of the lower well-being. In 2024, the psychologists Shelly McCoy, Laura Dimler and Luiza Rodrigues published a meta-analysis in the Journal of Adult Development that pooled 53 studies involving more than 46,000 emerging adults. They found consistent associations between helicopter parenting and a range of outcomes: more anxiety and depressive symptoms, lower academic adjustment, lower self-efficacy and weaker self-regulation. The associations were similar for mothers and fathers. As meta-analyses go, the findings were robust in direction. It is important to read these results carefully, for three reasons. First, the associations are modest in size. The correlations in the meta-analysis ranged roughly from 0.13 to 0.21. Correlations of that magnitude are meaningful in psychology, but they mean that helicopter parenting explains only a small share of the differences among young adults in anxiety, self-efficacy or academic adjustment. Plenty of students with highly involved parents are doing well, and plenty with hands-off parents are struggling. Second, nearly all the studies are correlational, and many measure both parenting and outcomes at the same moment through the student's own report. That makes it hard to know which way the influence runs. Over-involved parenting may undermine a young adult's confidence. But a young adult who is anxious or struggling may also draw more intervention from parents, who see that their child is having trouble and respond by stepping in. Both processes are plausible, and the likeliest truth is that they feed each other in a loop. Third, some research finds benefits from intensive support. In 2012, the gerontologist Karen Fingerman and colleagues studied 592 grown children with a mean age of about 24, along with 399 of their parents. They examined "intense support," meaning parents providing several kinds of help, such as money, advice and emotional support, several times a week. Grown children who received intense support reported better psychological adjustment and greater life satisfaction than those who did not, even though both parents and children tended to regard that level of help as more than normal. The parents, interestingly, were the ones who seemed to pay a cost: those who believed their grown children needed too much support reported poorer life satisfaction themselves. Put together, the research supports a balanced conclusion. Parental support in young adulthood is, on the whole, good for young adults. What seems to go wrong is support that takes over rather than supports: help that bypasses the young adult's own decisions and efforts, and so deprives her of the chance to develop competence and a sense that her life is her own. The line runs not between involved and uninvolved parents but between involvement that respects autonomy and involvement that overrides it. This is the reason this book avoids treating over-involved parents as a clinical problem. They are, for the most part, loving parents doing too much of a good thing. The goal is not to push them away but to help them shift the form of their involvement. Why parents hover If over-involvement is usually driven by love, it is also usually driven by fear. Understanding the specific fears helps a young adult respond to them rather than only to the behavior they produce. The most common driver is anxiety about the stakes. Parents who believe that a single bad semester, a wrong major or a missed internship could derail their child's future will find it very hard to stand back and watch. That belief is not entirely irrational. College costs are high, many families borrow, and early career paths can feel unforgiving. A parent who watched peers struggle after college, or who struggled themselves, may see danger everywhere. A second driver is the loss of information that comes with a child leaving home. Parents who were used to seeing their child every day now depend on whatever the child chooses to report. Where information is scarce, anxiety fills the gap. Monitoring tools, from grade portals to location-sharing apps, offer a way to restore some of the lost information, and each use can feel harmless. The combined effect can be a level of surveillance the parent never consciously chose. A third driver is cultural. Sociologists have described a shift, particularly among middle-class families in the United States, toward what is sometimes called intensive parenting: a model in which good parents are expected to devote large amounts of time, money and attention to cultivating their children's development. Parents raised in that model, or who absorbed it from other parents around them, may experience stepping back as negligence. Neighborhood and peer norms reinforce it; a parent who does not monitor the grade portal may feel she is the only one. A fourth driver is the parent's own history and temperament. A parent with an anxiety disorder, a history of loss, or an experience of a child's past crisis may have good reasons for heightened vigilance. A parent whose own parents were distant may be determined not to repeat that pattern and overcorrect. A parent whose own identity became wrapped up in the child's achievements may find it hard to separate the two. Finally, over-involvement is sometimes a response to real events. If a young adult has had a serious health problem, a mental health crisis or a period of academic trouble, parents may have stepped in for good reasons and simply not stepped out again. In these cases the young adult's task is partly to demonstrate that the circumstances have changed, and partly to negotiate a plan for how the parent will know if they change back. None of these drivers is the young adult's fault, and none obliges the young adult to accept every intervention. But each suggests a different response. A parent driven by anxiety about stakes may respond to evidence that the student has a plan. A parent starved of information may relax if given a regular, predictable flow of it. A parent operating from cultural norms may need to hear that stepping back is itself a form of good parenting. A parent reacting to a past crisis may need a clear agreement about what warning signs would bring them back in. Responding without rejecting The most effective responses to over-involvement share a common structure: they meet the underlying need while changing the behavior. A few approaches are worth knowing. The first is to feed the information need on your own terms. Many young adults find that proactive sharing reduces monitoring. A regular weekly call in which a student offers news about classes, friends and health, before being asked, often lowers a parent's anxiety enough that the daily checking stops. The key is that the student decides what to share and when, which shifts the flow of information from extraction to offering. Parents who trust that they will hear about important things are less likely to go looking. The second is to give the parent a new role. Parents who are asked to stop doing something often need something to do instead. A father who has been managing his son's course registration might be asked to serve as a sounding board for the final schedule, reviewing it after the son has built it. A mother who has been drafting emails to professors might be asked to read one her daughter has written and offer feedback. These roles keep the parent involved while putting the young adult in charge, and they allow the parent to see the young adult's competence directly. The third is to hand over responsibility in stages. Few parents can move from full involvement to none overnight. A graduated plan, with specific responsibilities transferring to the young adult over a semester or a year, gives both sides time to adjust. "This semester I'll handle my own registration and my own doctor's appointments. Next semester I'd like to take over the insurance paperwork." Stated plans also make it easier to notice progress, which builds trust. The fourth is to decline help warmly and specifically. Many young adults find it hard to turn down a parent's offer without feeling rude. A simple formula helps: thank the parent for the offer, state that you are going to handle it yourself, and, if appropriate, say when you will let them know how it went. "Thanks for offering to call the housing office. I'm going to call them myself tomorrow. I'll text you afterward." The warmth matters; it signals that the refusal is about the task, not the relationship. The fifth is to let some things go badly. Parents intervene to prevent failure, and the most persuasive evidence that a young adult can cope with failure is watching her cope with it. A student who misses a deadline, deals with the consequences and learns from it teaches her parents something that no conversation can. This requires a certain tolerance, on the student's part, for having parents see her struggle without rushing to fix it, and for saying, "I know it didn't go well. I'm dealing with it." Finally, it helps to notice where you are inviting the involvement. The junior in the opening example was annoyed at her father's intervention, but she had also, in earlier semesters, forwarded him emails and asked him what to do. Part of changing the pattern is changing her own half of it: handling the next adviser email herself, and telling her father afterward rather than before. Parents and staff reading this chapter can apply the same logic from the other side. A parent who notices herself drafting her child's emails, checking the grade portal or calling an adviser might ask a simple question before acting: will this help my child do this, or will it do it for her? The first kind of help builds the young adult's competence. The second, however well meant, tends to postpone it. Most over-involved parents do step back eventually, especially when they see their young adult managing well. The process is usually slower than the young adult would like, and it rarely happens without some friction. But it happens far more reliably through patient demonstration than through argument. The next chapter turns to one of the areas where the friction is sharpest: information, and the legal and practical rules that govern what parents can see. Hashtags: #HealthyBoundariesWithParents #HealthyBoundaries #EmotionalIndependence #YoungAdults #ParentChildRelationships #FamilyCommunication #SettingBoundaries #EmotionalAutonomy #EmergingAdulthood #PersonalBoundaries #FamilyRelationships #HealthyCommunication #SelfDifferentiation #FamilySystemsTheory #EmotionalMaturity #PersonalGrowth #IndependenceAndConnection #ParentalSupport #HelicopterParenting #Overparenting #AutonomySupport #SelfDetermination #AssertiveCommunication #FamilyDynamics #MutualRespect #EmotionalWellbeing #ConflictResolution #IntergenerationalRelationships #FamilyObligations #HealthyRelationships

  • Deep Learning for Audio (Speech Recognition and Sound Event Detection)

    Download the Book (PDF): Introduction Say a short phrase to a smart speaker across a kitchen while the tap is running, a pan is sizzling and a radio is playing in the next room. Within a fraction of a second, a chip that draws a few milliwatts has decided that the phrase was its name and not the radio's, woken a larger processor, and handed it a buffer of audio from which a speech recogniser will extract your words. Somewhere else, a microphone on a lamp post is listening for breaking glass, a hospital monitor is flagging an unusual cough, and a wildlife recorder in a rainforest is sorting birdsong from insect noise. All of these systems are built from the same small set of ideas. This booklet is about those ideas. The argument of the book is simple to state and surprisingly easy to forget in practice: in audio, the model is rarely the hard part. What decides whether a system works is how faithfully its input representation respects the physics of sound and the human ear, and how honestly its training and evaluation reflect the acoustic conditions it will meet when deployed. Architectures matter, and the field has produced some genuinely brilliant ones. But a state-of-the-art network trained on clean, close-talking recordings will fail in a reverberant kitchen, and a modest network trained on the right representation with the right data will often succeed there. The engineers who build robust audio systems spend most of their time on front ends, data, augmentation and metrics, and comparatively little on the network in the middle. Why audio is its own discipline Deep learning for audio borrows heavily from computer vision and natural language processing. Convolutional networks designed for photographs are routinely applied to spectrograms; transformers designed for text now dominate speech recognition. It is tempting to conclude that audio is just another input modality, a matrix of numbers to be fed into whatever architecture is currently winning benchmarks. That conclusion misses three things that make sound different. First, sound is a one-dimensional signal sampled very fast. A single second of telephone-quality speech contains 8,000 samples; a second of studio audio contains 48,000. The structure that matters to a listener, such as the pitch of a voice, the identity of a vowel, or the onset of a door slam, is spread across hundreds or thousands of those samples. A model has to integrate over long stretches of signal to see anything meaningful at all, and the choice of how to do that integration is the first and most consequential design decision. Second, the mapping from physical signal to perceived sound is strongly non-linear. Humans hear pitch roughly logarithmically, are far more sensitive to some frequencies than others, and perceive loudness on a compressed scale. A decade of research in psychoacoustics, condensed into tools like the mel scale and the cepstrum, tells us which distinctions in the signal carry information and which do not. Representations that encode this knowledge, such as mel-frequency cepstral coefficients and log-mel spectrograms, make learning easier and more robust. Third, sounds overlap and are smeared by the room. In an image, a cat in front of a sofa occludes part of the sofa. In audio, a voice in front of a television adds to the television, sample by sample, and both are then convolved with the reflections of every wall in the room. Separating what you want from what you do not is not an occasional edge case; it is the normal condition of almost every real recording. What this booklet covers The booklet moves from the signal to the system. Chapter 1 explains what a digital audio signal actually is and how the short-time Fourier transform turns it into a picture of frequency content over time, with the trade-offs that choice involves. Chapter 2 builds mel-frequency cepstral coefficients step by step, explains why they dominated speech technology for thirty years, and explains why deep learning has largely, though not entirely, replaced them with log-mel spectrograms. Chapter 3 turns to WaveNet, the 2016 architecture from DeepMind that showed a neural network could model raw audio one sample at a time. WaveNet matters both for what it did, producing synthetic speech of unprecedented naturalness, and for the ideas it introduced, especially dilated causal convolutions, which reappear throughout audio modelling, including in keyword spotting. Chapters 4 and 5 cover the two great recognition problems. Chapter 4 traces automatic speech recognition from hybrid hidden-Markov systems through connectionist temporal classification, attention-based encoder-decoders and the transducer, to the self-supervised and weakly supervised models that define the field today. Chapter 5 covers sound event detection: recognising and locating non-speech sounds, a problem shaped by weak labels, overlapping events and the difficulty of deciding what it even means to be correct. Chapters 6 and 7 form the practical core. Chapter 6 treats wake-word detection, the always-on, low-power keyword spotting that sits in front of almost every voice interface, as an engineering problem with an unusually harsh set of constraints. Chapter 7 is about robustness: noise, reverberation, distance and device variation, and the toolkit of augmentation, normalisation and multi-microphone processing that lets a model survive them. Chapter 8 closes the loop with evaluation and deployment, because a model is only as good as the measurements used to judge it and the hardware it runs on. What this booklet leaves out Some exclusions are deliberate. Music information retrieval, with its rich traditions of beat tracking, chord recognition and source separation for songs, is mentioned only where its techniques transfer. Speaker recognition and diarisation appear only in passing. Text-to-speech is covered through WaveNet as a vocoder, not as a full topic. The booklet also assumes a working familiarity with the basic vocabulary of neural networks: layers, convolutions, gradient descent, and the idea of a training and test set. It does not assume any background in signal processing; everything needed is built from the ground up. There is one short block of code in the book, in Chapter 2, because the computation of MFCCs is clearest when you can see the steps in sequence. Everything else is explained in prose. Who this is for The intended reader is an engineer, researcher or technically minded product person who has trained a few neural networks and now needs to make one work on sound. Perhaps you have been asked to add voice control to a device, to detect alarms in a factory, or to evaluate a speech recognition vendor. Perhaps you have already tried an off-the-shelf model and found that it works beautifully in the demo and poorly in the field. The aim is to give you a mental model of the whole pipeline, from air pressure to decision, sharp enough that you can diagnose where things are going wrong and make sound choices about what to change. The field moves fast. Models released in the last few years, trained on hundreds of thousands of hours of audio, have reset expectations for what speech recognition can do out of the box. But the questions those models raise for a practitioner are the old ones in new form. What does the model actually hear? What conditions was it trained on? How will it be measured, and does that measurement reflect what users experience? Answering those questions well is the subject of the chapters that follow. Chapter 1: From Air Pressure to Spectrogram Every audio model begins with a microphone, and every microphone does the same humble thing: it converts small fluctuations in air pressure into a fluctuating voltage. Everything a neural network will ever know about a sound arrives through that conversion and the digital processing that follows it. Engineers who skip this layer tend to discover its importance later, usually in the form of a model that works on one device and fails on another for no obvious reason. This chapter builds the foundation: what a digital audio signal is, why the time-frequency representation is the natural way to look at it, and what is gained and lost when we compute one. Sampling, quantisation and what they preserve A sound wave is a continuous variation in pressure. To store it, an analogue-to-digital converter measures the microphone's voltage at regular intervals, the sampling rate, and rounds each measurement to one of a finite number of levels, the bit depth. The sampling rate determines the highest frequency that can be represented. The Nyquist-Shannon sampling theorem says that a signal sampled at rate f can faithfully represent components up to f/2, the Nyquist frequency. Anything above that frequency, if it reaches the converter, does not simply vanish. It folds back and appears as a spurious lower frequency, a distortion called aliasing. Real converters therefore apply an analogue low-pass filter before sampling, and digital resampling routines apply a digital one before reducing the rate. The rates you meet in practice reflect history as much as physics. Telephone networks have long used 8 kHz, which captures speech up to 4 kHz: enough for intelligibility, though it loses the high-frequency energy of fricatives like "s" and "f" that makes speech sound natural. Wideband speech systems, and most speech recognition research, use 16 kHz. Compact discs use 44.1 kHz, and video and professional audio use 48 kHz, comfortably above the roughly 20 kHz upper limit of young human hearing. For machine learning, the practical lesson is that sampling rate is part of the data distribution. A model trained on 16 kHz audio and fed 8 kHz telephone audio that has been upsampled will see a spectrum that is empty above 4 kHz, a condition it has never encountered. A model trained on 48 kHz audio from studio microphones will see energy at frequencies that a cheap embedded microphone simply does not capture. Matching rates and bandwidths between training and deployment is the first of many acts of honesty this booklet will ask for. Bit depth governs the precision of each sample. Sixteen-bit audio, the CD standard and the default for most speech corpora, offers 65,536 levels and a theoretical dynamic range of about 96 decibels. That is plenty for most recognition tasks. What matters more in the field is how the available range is used: a recording made with the gain set too low wastes most of its levels and buries quiet speech in quantisation noise; one with the gain too high clips, flattening the peaks of the waveform and adding harsh distortion that no later processing can undo. Clipping in particular is common in consumer devices when a user speaks close to the microphone, and it is worth simulating in training if your users will do it. Why the raw waveform is hard to learn from Once sampled, a sound is a long sequence of numbers. One second of 16 kHz audio is 16,000 of them. The sequence has some awkward properties for a learning algorithm. It is long relative to the structures of interest. A spoken syllable lasts roughly 150 to 300 milliseconds, which is several thousand samples. A pitch period of a male voice is around 8 to 10 milliseconds; a female voice, around 4 to 5. A network that operates directly on samples must build receptive fields spanning thousands of time steps before it can perceive a phoneme. It is phase-sensitive in ways that perception mostly is not. Two waveforms can look completely different sample by sample yet sound identical to a listener, because they contain the same frequencies at the same strengths with different relative phase. Conversely, a small time shift changes every sample value while changing nothing a listener cares about. A model forced to learn these invariances from data must spend capacity and training examples on them. And it mixes everything together. A voice, a fan and a passing car all add into the same sequence of samples. Separating them in the time domain is possible, but the components are far easier to distinguish when you look at which frequencies are active and when. None of this makes raw-waveform learning impossible. Networks such as WaveNet, discussed in Chapter 3, and front ends such as SincNet and learnable filterbanks, which learn their first layer of filters from data, show that it can be done, and self-supervised speech models like wav2vec 2.0 consume raw audio through a stack of convolutions. But in nearly every case, what those first layers learn turns out to resemble a bank of bandpass filters spread across frequency: they rediscover a time-frequency representation. Starting with one is usually the more efficient path. The short-time Fourier transform The Fourier transform expresses a signal as a sum of sinusoids, each with its own frequency, amplitude and phase. Applied to a whole recording, it tells you which frequencies are present but not when. That is useless for speech, whose frequency content changes every few tens of milliseconds as the mouth moves. The short-time Fourier transform (STFT) solves this by analysing the signal in short overlapping chunks. The procedure is straightforward. Choose a frame length, typically 20 to 32 milliseconds for speech, which is 320 to 512 samples at 16 kHz. Choose a hop, the distance between the starts of successive frames, typically 10 milliseconds. Multiply each frame by a window function that tapers smoothly to zero at both ends, most often a Hann or Hamming window. Compute the discrete Fourier transform of each windowed frame using the fast Fourier transform algorithm. The result is a matrix with one column per frame and one row per frequency bin. Taking the magnitude of each complex value, or its square to get power, gives the spectrogram: a picture of energy as a function of time and frequency. In a spectrogram of speech, voiced sounds show as stacks of horizontal stripes, the harmonics of the speaker's pitch, shaped by broad bands of energy called formants that correspond to resonances of the vocal tract. Fricatives appear as diffuse energy at high frequencies. Plosives like "p" and "t" appear as brief silences followed by vertical bursts. Non-speech sounds have their own signatures: a siren is a curve sweeping up and down, a dog bark is a short harmonic smear, a door slam is a sharp vertical line with a decaying tail. Why the window matters The window function exists because the discrete Fourier transform implicitly treats each frame as one period of an infinitely repeating signal. If the frame is cut off abruptly, the jump between its end and its beginning introduces spurious frequencies, energy that leaks from the true frequency into neighbouring bins. Tapering the frame to zero at the edges reduces this spectral leakage at the cost of slightly blurring each frequency peak. The Hann window, a raised cosine, is a sensible default; the Hamming window, which does not quite reach zero, was the traditional choice in speech recognition and remains common in MFCC implementations. The uncertainty trade-off The frame length embodies a fundamental trade-off. A longer frame contains more cycles of each frequency and so resolves frequency more finely: a 64-millisecond frame separates frequencies about 16 Hz apart, while a 16-millisecond frame separates only those about 62 Hz apart. But a longer frame blurs events in time, smearing a sharp onset across its whole length. This is a version of the time-frequency uncertainty principle, and no choice of frame length escapes it. Speech recognition settled on frames of around 25 milliseconds because that is short enough for the vocal tract to be roughly stationary within a frame, yet long enough to resolve the formants that distinguish vowels. Music analysis often uses longer frames, because separating closely spaced notes matters more than timing to the millisecond. Sound event detection sits between the two and sometimes benefits from computing representations at more than one resolution. Hop length and the frame rate The hop determines the frame rate of the spectrogram, and hence the time resolution of everything downstream. A 10-millisecond hop gives 100 frames per second, which has become close to universal in speech. Some modern recognisers subsample further inside the network, down to 25 or even 12.5 frames per second, because the information rate of speech, at roughly ten to fifteen phonemes per second, does not require more. For event detection, a finer hop may matter if precise onset times are needed, while keyword spotting on a microcontroller may use a coarser one to save computation. Magnitude, phase and the logarithm The STFT produces complex numbers, which encode both magnitude and phase. Most recognition systems discard the phase and keep only the magnitude or power. This is partly a matter of convenience and partly a judgement about perception: for recognising what was said or what happened, magnitude carries most of the information. Phase does matter for some tasks, especially for reconstructing audio from a spectrogram and for localising sound sources with multiple microphones, which compare phases between channels. Chapter 7 returns to that second use. Having kept the magnitude, almost every system then takes its logarithm. There are three good reasons. The dynamic range of audio is enormous: the power of a loud sound can be a million times that of a quiet one in the same recording, and a network fed linear power will be dominated by the loudest bins. The logarithm compresses that range into something a network can handle. Human loudness perception is itself roughly logarithmic, which is why we measure sound in decibels. And the logarithm turns multiplication into addition, which, as the next chapter shows, is the key to separating the source of a sound from the filter that shaped it. A small constant is usually added before taking the logarithm, to avoid the logarithm of zero in silent bins. Its value is not as innocent as it looks. Too small, and silent or digitally zeroed regions produce extreme negative values that dominate normalisation statistics; too large, and quiet but meaningful detail is flattened. A constant around 10 to the power of minus 6 relative to full-scale power is a common compromise, but the right answer depends on your input levels. Thinking about the spectrogram as an image Once computed, a log-magnitude spectrogram looks like a greyscale image, and it is tempting to treat it as one. Much of the success of deep learning for audio has come from doing exactly that: convolutional networks pioneered on photographs work remarkably well on spectrograms, and the audio spectrogram transformer adapts the vision transformer almost unchanged. But the analogy has limits, and knowing them prevents mistakes. In a photograph, the two axes are equivalent; a cat shifted upward is still a cat. In a spectrogram, the axes mean different things. Shifting a pattern along the time axis does not change what it is: a word said a second later is the same word. Shifting it along the frequency axis can change it entirely: raising every frequency of a vowel turns it into a different vowel or a different speaker. Convolution's translation equivariance is therefore well matched to time and only partly matched to frequency, which is one reason many audio architectures use filters that are tall in frequency and narrow in time, or that pool differently along the two axes. Sounds in a spectrogram also do not occlude one another; they add, approximately, in the power domain. A cat in front of a sofa hides part of the sofa, but a voice over a fan leaves the fan's energy fully present in the bins where the voice is quiet. Augmentations designed for images, such as rotations or colour shifts, have no sensible meaning for spectrograms. Augmentations designed for audio, like adding noise or masking frequency bands, which Chapter 7 discusses, do. Finally, the linear-frequency spectrogram wastes resolution. Its bins are evenly spaced, so it devotes as many rows to the band between 7 and 8 kHz as to the band between 100 Hz and 1 kHz, where most of the information in speech lives. Correcting that imbalance, in a way informed by how human hearing works, is the subject of the next chapter. Alternatives to the STFT The STFT is not the only way to obtain a time-frequency picture, and two alternatives appear often enough to be worth knowing. The constant-Q transform uses analysis windows whose length varies with frequency: long windows for low frequencies, short ones for high. Its frequency bins are spaced geometrically, so each octave receives the same number of bins, which matches the structure of musical scales. It is widely used in music analysis, where resolving adjacent semitones in the bass matters, and occasionally in speech anti-spoofing work, where its fine low-frequency resolution helps expose artefacts of synthetic speech. Its uneven time resolution and higher cost make it less common elsewhere. Gammatone filterbanks model the frequency selectivity of the human cochlea more directly than the mel filterbank does, using filters whose shapes approximate measured auditory responses and whose bandwidths follow the equivalent rectangular bandwidth scale derived from psychoacoustic experiments by Brian Glasberg and Brian Moore. Features built on them, such as gammatone-frequency cepstral coefficients and the power-normalised cepstral coefficients of Chanwoo Kim and Richard Stern, were proposed partly for their robustness to noise. In deep learning practice, the differences between gammatone and mel front ends are usually small compared with the differences made by data and augmentation, but auditory-inspired front ends retain a following in hearing research and in hearing-aid and cochlear-implant processing. Wavelet transforms, which decompose a signal into scaled and shifted versions of a short prototype waveform, offer another multi-resolution view. They have found niches in detecting transients, such as clicks and impacts in machine monitoring, but have not displaced the STFT for speech or general sound recognition. Preprocessing pitfalls A handful of mundane preprocessing errors account for a surprising share of the problems seen in applied audio projects, and they are worth listing because none of them produces an error message. Channel handling is the first. Stereo or multi-channel files may be averaged to mono, have one channel taken, or be passed through unchanged, depending on the loading library and its defaults. If training data were averaged and deployment audio uses one channel of a stereo pair, or vice versa, level and phase differences change what the model sees. Resampling quality is the second. Libraries differ in the quality of their anti-aliasing filters, and a cheap resampler can introduce aliasing or roll off high frequencies. Resampling the training data with one library and the deployment audio with another is a small but real source of mismatch. Integer and floating-point scaling is the third. Sixteen-bit audio is often loaded either as integers between −32,768 and 32,767 or as floating-point values between −1 and 1. A model trained on one and fed the other sees inputs scaled by a factor of 32,768, which after the logarithm becomes a constant offset of about 90 dB in every bin. Mean normalisation may hide much of this; a fixed logarithm constant will not. Leading and trailing silence is the fourth. Datasets differ in how tightly utterances are trimmed. A keyword model trained on clips in which the word always starts within the first 100 milliseconds may learn that position as a cue, and then behave poorly when the word appears anywhere in a streaming window. Randomly shifting the content within each training window prevents this. DC offset is the fifth. Some cheap microphones and converters add a constant bias to every sample. It shows up as energy in the lowest frequency bin and can distort level-based normalisation. A high-pass filter at a few tens of hertz, or simple mean removal, deals with it. Practical defaults For readers who want a starting point, the following settings are widely used for 16 kHz speech and are a reasonable baseline for many other tasks: a 25-millisecond Hann or Hamming window, a 10-millisecond hop, a 512-point FFT (padding the 400-sample frame with zeros), magnitude or power spectrum, followed by the mel-scale filterbank and logarithm described in Chapter 2. For general sound event detection, widely used open models trained on AudioSet operate on audio resampled to 16 or 32 kHz with similar 10-millisecond hops; adopting the same front end as a pretrained model you intend to fine-tune is far more important than the particular values. That last point deserves emphasis, because it causes more silent failures than almost anything else in applied audio work. A pretrained model has learned to interpret a particular representation: a particular sampling rate, window, hop, number of mel bands, frequency range, logarithm constant and normalisation. Feed it anything else and it will still produce outputs, confidently, and they will be worse in ways that are hard to diagnose. Before blaming the model, check the front end. Chapter 2: Mel-Frequency Cepstral Coefficients For three decades, from the early 1980s until the deep learning wave of the 2010s, almost every speech recogniser in the world began the same way. It cut the audio into 25-millisecond frames, computed a spectrum for each, warped that spectrum onto a perceptual frequency scale, took a logarithm, applied a discrete cosine transform, and kept the first dozen or so numbers. Those numbers, mel-frequency cepstral coefficients or MFCCs, were the lingua franca of speech technology. They remain in use today in embedded keyword spotting, speaker recognition, and countless classical and teaching pipelines. Understanding MFCCs properly is worthwhile even if you never use them, because each step encodes a specific idea about speech and hearing. Some of those ideas are still built into the log-mel spectrograms that modern networks consume. Others, it turns out, are steps a neural network would rather do for itself. Knowing which is which explains a good deal about how audio front ends have evolved. The source-filter model of speech MFCCs were designed around a particular theory of how speech is produced. In the source-filter model, the voice has two largely independent parts. The source is the excitation: for voiced sounds, the periodic buzzing of the vocal folds, which produces a fundamental frequency and a series of harmonics at integer multiples of it; for unvoiced sounds like "s" or "sh", turbulent noise produced by air forced through a narrow constriction. The filter is the vocal tract, the throat, mouth and nasal cavities, whose shape determines which frequencies are amplified, creating the broad resonant peaks called formants. For recognising words, the filter is what matters. The difference between "beet" and "boot" is the shape of the mouth, which shows up as the positions of the first two or three formants. The source mostly carries information about who is speaking and how: pitch, intonation and emotion. In a language like English, a word means the same thing whether it is spoken in a high or low voice. So a front end for word recognition would ideally keep the shape of the filter and discard the fine detail of the source. In the spectrum, the two are multiplied together. The harmonics of the source appear as a comb of closely spaced peaks; the filter imposes a smooth envelope over them. Separating a product is awkward. Separating a sum is easy. That observation leads directly to the cepstrum. The mel scale The first step particular to MFCCs is warping frequency onto the mel scale. The scale originates in psychoacoustic experiments by Stanley Smith Stevens, John Volkmann and Edwin Newman, published in 1937, in which listeners were asked to adjust tones until they sounded half or twice as high as a reference. The resulting scale of perceived pitch is roughly linear below about 1 kHz and roughly logarithmic above it. Equal steps in mels correspond to equal perceived steps in pitch. Several formulas approximate the scale. The most common in software is mel = 2595 × log10(1 + f / 700), where f is frequency in hertz. By construction, 1,000 Hz maps to about 1,000 mels. At 8 kHz, the Nyquist frequency of 16 kHz audio, the scale reaches about 2,840 mels, which means that the whole upper half of the speech band, 4 to 8 kHz, occupies only around a quarter of the mel range. Different libraries use slightly different formulas, notably the Slaney formula used by default in librosa, which is linear below 1 kHz and logarithmic above. The differences are small but real, and another reason pretrained models must be fed exactly the front end they were trained with. The mel scale is applied through a filterbank. Choose a number of filters, traditionally 20 to 40 for MFCCs and 40 to 128 for modern log-mel spectrograms. Space their centre frequencies evenly on the mel scale between a lower and upper frequency limit. Give each filter a triangular shape in linear frequency that rises from zero at the previous filter's centre to one at its own centre and falls back to zero at the next filter's centre. Multiply each frame's power spectrum by each triangle and sum, giving one energy value per filter per frame. The effect is to summarise the 257 linear frequency bins of a 512-point FFT into a few dozen bands that are narrow at low frequencies, where pitch perception and formant positions demand precision, and wide at high frequencies, where they do not. The filterbank also smooths across individual harmonics, partially removing the fine structure of the source before the cepstral step even begins. The cepstrum Take the logarithm of the filterbank energies. Because the spectrum was the product of a source and a filter, its logarithm is their sum: log of source plus log of filter. Now apply a transform that separates components by how rapidly they vary across frequency. The smooth vocal tract envelope varies slowly from one band to the next; the residual harmonic ripple of the source varies quickly. A Fourier-type transform across the frequency axis puts the slowly varying part into its first few coefficients and the rapidly varying part into later ones. This is the cepstrum, a name coined by Bruce Bogert, Michael Healy and John Tukey in a 1963 paper on detecting echoes in seismic signals. They reversed the first syllable of "spectrum" to signal that this was a spectrum of a spectrum, and introduced a whole vocabulary of similar inversions, of which "quefrency", for the cepstral domain's equivalent of frequency, and "liftering", for filtering in that domain, survive. The joke has outlasted most of the paper. For MFCCs, the transform applied to the log mel energies is the discrete cosine transform (DCT), usually the type-II variant. The DCT is used rather than a full Fourier transform because the log energies are real-valued and the DCT produces real outputs, and because it has a second valuable property: its outputs are largely decorrelated. Adjacent mel filters overlap and their energies are strongly correlated; the cepstral coefficients that emerge from the DCT are much less so. The final step is truncation. Keep only the first 12 or 13 coefficients and throw the rest away. Those low-quefrency coefficients describe the smooth spectral envelope, the filter, which is what speech recognition wants. The discarded high-quefrency coefficients carry pitch harmonics and fine detail. The zeroth coefficient is proportional to the overall log energy of the frame and is often replaced by an explicit energy measure. Putting it together The full pipeline, in the form popularised by Steven Davis and Paul Mermelstein's 1980 comparison of parametric representations for word recognition, which showed MFCCs outperforming alternatives of the time, can be written in a few lines. The following Python sketch uses NumPy and the librosa library's mel filterbank helper; production implementations in toolkits such as Kaldi and torchaudio differ in details but follow the same steps. import numpy as np import librosa from scipy.fftpack import dct def mfcc(signal, sr=16000, n_fft=512, win=400, hop=160, n_mels=40, n_mfcc=13, preemph=0.97): # 1. Pre-emphasis: boost high frequencies x = np.append(signal[0], signal[1:] - preemph * signal[:-1]) # 2. Frame, window and FFT (power spectrum) frames = librosa.util.frame(x, frame_length=win, hop_length=hop).T frames = frames * np.hamming(win) power = np.abs(np.fft.rfft(frames, n=n_fft)) ** 2 / n_fft # 3. Mel filterbank energies mel_fb = librosa.filters.mel(sr=sr, n_fft=n_fft, n_mels=n_mels) mel_energy = power @ mel_fb.T # 4. Logarithm log_mel = np.log(mel_energy + 1e-10) # 5. DCT and truncation return dct(log_mel, type=2, axis=1, norm='ortho')[:, :n_mfcc] Two steps here have not yet been explained. Pre-emphasis applies a simple first-order high-pass filter, subtracting 0.97 times the previous sample from each sample. Voiced speech has a spectrum that falls by roughly 6 decibels per octave, so without pre-emphasis the high-frequency formants would be numerically tiny; boosting them balances the spectrum. In modern pipelines with per-band normalisation, pre-emphasis matters less and is often omitted. The second step is implicit: the 25-millisecond window and 10-millisecond hop described in Chapter 1 determine the frame rate, giving 100 vectors of 13 coefficients per second of audio. Deltas and normalisation Classical systems augmented the static MFCCs with their time derivatives. The delta coefficients estimate the slope of each coefficient across a few neighbouring frames; the delta-delta, or acceleration, coefficients estimate the slope of the slope. Thirteen statics plus thirteen deltas plus thirteen delta-deltas gave the famous 39-dimensional feature vector that fed generations of Gaussian mixture model recognisers. The derivatives mattered because those models treated each frame independently, given the hidden state, and so had no other way to see how the spectrum was changing. Cepstral mean normalisation subtracts, from each coefficient, its mean over an utterance or a sliding window. The rationale is elegant. A fixed linear channel, such as a particular microphone or telephone line, multiplies the spectrum by a fixed frequency response. In the log domain, that becomes an added constant; after the DCT, still an added constant in each cepstral coefficient. Subtracting the mean removes it. A simple subtraction thus provides a large part of the robustness to microphone and channel differences, which is why some form of mean normalisation survives in nearly every modern front end, including those for neural networks. It does nothing, however, for additive noise or for reverberation with a long tail, which are not fixed multiplicative channels and are discussed in Chapter 7. What the coefficients look like It helps to have an intuition for the individual coefficients. The first coefficient after the energy term, often called C1, measures the overall tilt of the log spectrum: whether energy is concentrated at low or at high frequencies. Voiced vowels, with most of their energy below 1 kHz, have large positive values; fricatives like "s", with energy concentrated at high frequencies, have negative values. C2 measures, roughly, whether energy is concentrated in the middle of the band or at its edges, and so on, each successive coefficient describing a finer ripple across the mel bands. By about C12 the ripple is fine enough that it begins to describe harmonic detail rather than formant structure, which is why truncation at around that point works. This intuition also explains a well-known weakness. Because each coefficient summarises the whole spectrum, a narrowband noise, say a hum at 1 kHz, perturbs every coefficient a little. Robustness to noise that affects only part of the spectrum is therefore harder to achieve with MFCCs than with features that keep bands separate, and this was one of the motivations for robust alternatives in the classical era, such as perceptual linear prediction (PLP), proposed by Hynek Hermansky in 1990, and RASTA filtering, which suppresses spectral components that change too slowly or too quickly to be speech. Speaker normalisation The vocal tract of an adult man is typically longer than that of an adult woman, and a child's is shorter still. A longer tract lowers all formant frequencies roughly proportionally, so the same vowel spoken by different people appears at different positions on the frequency axis. Classical systems countered this with vocal tract length normalisation, which warps the frequency axis of each speaker's features by a factor chosen to maximise the likelihood of a reference model. The warp was usually applied by stretching or compressing the mel filterbank itself. Deep networks trained on diverse speakers learn much of this invariance implicitly, but random frequency warping remains a useful augmentation, particularly for recognising children, whose speech is underrepresented in most training corpora. Why deep learning moved to log-mel spectrograms When deep neural networks began replacing Gaussian mixture models in speech recognition around 2010 to 2012, researchers found that the networks often did better if the last steps of the MFCC pipeline were removed. Work from groups at Toronto, Microsoft and elsewhere in that period reported that log mel filterbank energies, the representation just before the DCT, gave lower error rates than MFCCs for deep networks. Within a few years, log-mel features, usually with 40 to 80 bands for speech and 64 to 128 for general audio, became the default. The reasons follow from what each MFCC step was for. The DCT decorrelates the features. Decorrelation was essential for Gaussian mixture models with diagonal covariance matrices, which assumed that feature dimensions were independent and modelled them badly when they were not. A neural network has no such assumption; it can learn correlations directly, and indeed benefits from them. The DCT also destroys locality in frequency. In a log-mel spectrogram, adjacent rows are adjacent bands, so a convolutional filter can learn a local pattern, like the shape of a formant, and recognise it wherever it appears. After the DCT, each coefficient mixes information from every band, and a pattern local in frequency becomes spread across all coefficients. Convolutions over MFCCs make much less sense than convolutions over log-mel spectrograms. Truncation throws away information. The high-quefrency coefficients do carry pitch and fine spectral detail, which is useless noise for a Gaussian model of phonemes but potentially useful for a network deciding, for instance, whether a sound is a voice or a musical instrument, or for tonal languages where pitch distinguishes words. A network with enough data can learn which details to ignore. In short, MFCCs are a hand-engineered compression designed for models that could not learn their own. Deep networks can, and they prefer the richer input. The step that survives intact is the mel filterbank followed by the logarithm: the part that encodes how human hearing allocates resolution, which remains a good inductive bias even for a network with plenty of data. Where MFCCs still win It would be wrong to conclude that MFCCs are obsolete. Their compactness is a real virtue in three settings. The first is tiny devices. A keyword spotter on a microcontroller with a few hundred kilobytes of memory, discussed in Chapter 6, benefits from an input of 10 numbers per frame instead of 40. Much of the published work on keyword spotting for microcontrollers, including the widely cited 2017 study from Arm researchers Yundong Zhang, Naveen Suda, Liangzhen Lai and Vikas Chandra, "Hello Edge", used MFCCs or similarly compact features for exactly this reason. Smaller inputs mean smaller first layers, fewer multiply-accumulate operations and less memory traffic. The second is small data. When you have only a few hours of labelled audio, the inductive bias built into MFCCs, that the spectral envelope matters and pitch harmonics do not, can substitute for training data. Classical speaker verification systems built on i-vectors used MFCCs, and many bioacoustic and medical audio studies with limited recordings still find them competitive. The third is interpretability and compatibility. MFCC pipelines are standardised, fast and understood. When an engineer needs a quick baseline, or a system must interoperate with existing tools, they remain a sensible choice. As Table 1 summarises, the three representations discussed so far trade compactness against fidelity, and the right choice depends on the model and the constraints. Table 1. Common audio input representations compared. Representation Values per 10 ms frame Keeps frequency locality Typical use today Raw waveform 160 samples at 16 kHz Not applicable Self-supervised encoders, vocoders Log-mel spectrogram 40 to 128 bands Yes Most ASR and sound event models MFCC (with deltas) 13 (or 39) No Embedded keyword spotting, small-data tasks Learnable front ends Between fixed MFCCs and raw waveforms lies a family of learnable front ends. SincNet, introduced by Mirco Ravanelli and Yoshua Bengio in 2018, constrains the first convolutional layer of a network to consist of bandpass filters parameterised only by their low and high cutoff frequencies, which are learned. LEAF, a learnable front end published by researchers at Google in 2021, learns the filter shapes, a per-channel compression that replaces the fixed logarithm, and the pooling, while keeping the overall structure of a filterbank. These methods sometimes outperform fixed mel features, particularly on non-speech tasks where the mel scale's assumptions about human hearing are less obviously appropriate: bird calls, machinery, ultrasonic bat echolocation. But the gains are typically modest, and in large-scale speech recognition, fixed log-mel features remain dominant. The lesson is that the mel filterbank is a strong prior, not an arbitrary choice; learning a replacement helps mostly where that prior is wrong. A final caution applies to all of these choices. The representation determines what the model can hear, and also what it cannot. If a sound you care about lives above the upper limit of your filterbank, or below its lower limit, the model will never detect it, however large it is. Industrial monitoring tasks involving high-frequency bearing wear, or infrasound, need front ends designed for them. Defaults inherited from speech are a starting point, not a law of nature. Chapter 3: WaveNet and the Raw Waveform In September 2016, researchers at DeepMind published a paper with an unassuming title, "WaveNet: A Generative Model for Raw Audio", by Aäron van den Oord and colleagues. It described a neural network that generated audio one sample at a time, sixteen thousand times per second, each sample predicted from all the samples before it. The idea seemed computationally absurd. The results were startling. In listening tests reported in the paper, WaveNet's synthetic English and Mandarin speech was rated substantially more natural than the best existing concatenative and parametric systems, closing a large part of the gap between machine and human speech. WaveNet belongs in a booklet about recognition for two reasons. The first is that its central architectural idea, the stack of dilated causal convolutions, turned out to be one of the most useful general tools for processing audio sequences, and reappears in keyword spotting, source separation and speech enhancement. The second is that WaveNet answered a question this book keeps returning to: can a neural network learn directly from the raw waveform, without any hand-designed front end? It can, at a price. Understanding both the achievement and the price clarifies when raw-waveform modelling is worth it. Autoregressive modelling of audio WaveNet is an autoregressive model. It factorises the probability of a whole waveform into a product of conditional probabilities: the probability of the first sample, times the probability of the second given the first, times the probability of the third given the first two, and so on. The network's job is to output, at each time step, a probability distribution over the next sample's value given all previous values. To make this tractable, the original WaveNet quantised each sample to one of 256 values and treated prediction as a 256-way classification. Linear 16-bit audio would have required 65,536 classes, so the authors first applied mu-law companding, a non-linear transformation long used in telephony that allocates finer quantisation steps to quiet sample values and coarser ones to loud values. This matches the way small amplitude differences matter more when the signal is quiet, and it reduced the output to 8 bits without audible degradation of quality for speech. The network ends in a softmax over the 256 levels, trained with ordinary cross-entropy loss. At training time, because the whole waveform is known, the predictions for every time step can be computed in parallel: each output depends only on the true preceding samples, which are all available. At generation time, the network must produce one sample, feed it back as input, produce the next, and so on. That sequential loop is what made the original WaveNet so slow, and it is the price referred to above. Dilated causal convolutions The core difficulty for any raw-audio model is receptive field. To predict a speech sample well, the network needs context spanning at least a pitch period and ideally a syllable or more: hundreds to thousands of samples. A recurrent network can in principle carry such context, but in practice struggles to train over sequences that long. An ordinary convolutional network needs either enormous filters or an impractically deep stack to see that far back. WaveNet's solution combines two ideas. A causal convolution is a one-dimensional convolution in which the output at time t depends only on inputs at time t and earlier, never later. In practice this is achieved by padding the input on the left and shifting the output, so that no information from the future leaks into the prediction. Causality is essential for an autoregressive generator, and also for any streaming recogniser that must produce outputs before the audio has finished. A dilated convolution applies its filter to inputs that are spaced apart, skipping a fixed number of positions between taps. A filter of width two with dilation one looks at positions t and t−1. With dilation two, it looks at t and t−2. With dilation four, t and t−4. Stacking layers whose dilations double at each layer, 1, 2, 4, 8 and so on up to 512, produces a receptive field that grows exponentially with depth while the number of parameters and computations grows only linearly. Ten such layers with filter width two see 1,024 samples, about 64 milliseconds at 16 kHz. WaveNet repeated this block of ten layers several times, extending the receptive field further and adding capacity at each scale. It helps to picture the result in words. The bottom layer combines each sample with its immediate neighbour. The next layer combines pairs that are two samples apart, so each of its outputs summarises four consecutive samples. The next summarises eight, then sixteen. By the top of a block, each output summarises a thousand samples, but because each layer only ever combines two inputs, the computation stays cheap. It is the convolutional equivalent of a tree of pairwise merges. Gated activations and residual structure Each WaveNet layer uses a gated activation unit borrowed from earlier work on the PixelCNN image model by van den Oord and colleagues. The dilated convolution produces two sets of outputs; one passes through a hyperbolic tangent, the other through a sigmoid, and the two are multiplied elementwise. The sigmoid acts as a learned gate controlling how much of the tangent's signal passes through. The authors reported that this worked significantly better than rectified linear units for modelling audio. The output of each layer then passes through a one-by-one convolution and splits two ways. One branch is added back to the layer's input, forming a residual connection that lets gradients flow through deep stacks. The other branch is a skip connection that goes directly to the output. All the skip outputs are summed, passed through a couple of further non-linear layers, and fed into the final softmax. Residual and skip connections are what allowed WaveNet to be trained with dozens of layers. Conditioning: telling WaveNet what to say An unconditioned WaveNet trained on speech produces babble: realistic-sounding voices uttering plausible syllables that form no words. To be useful for text-to-speech, the model must be conditioned on what to say. WaveNet supported two kinds of conditioning. Global conditioning adds a single vector, such as a speaker identity embedding, to every layer, so one model can produce many voices. Local conditioning supplies a time-varying input, such as linguistic features or a mel spectrogram, which is upsampled to the audio sample rate and added inside every gated unit. The second form proved enormously influential. In the Tacotron 2 system described by Jonathan Shen and colleagues at Google in 2017, a sequence-to-sequence network converts text into a mel spectrogram, and a WaveNet conditioned on that spectrogram converts it into a waveform. In this role, WaveNet is a vocoder: a model that turns a spectral representation back into sound. Tacotron 2's reported mean opinion score was close to that of professionally recorded speech. The division of labour, with an acoustic model predicting a spectrogram and a separate neural vocoder rendering it, remains the dominant architecture for high-quality speech synthesis. The vocoder role also illustrates something about the representations discussed in Chapters 1 and 2. A mel spectrogram discards phase and smooths frequency detail. Classical methods for recovering a waveform from such a representation, such as the Griffin-Lim algorithm, which iteratively estimates a consistent phase, produce audibly metallic results. WaveNet showed that a network trained on enough real speech could fill in the missing detail convincingly, because it had learned what speech waveforms consistent with a given spectrogram actually sound like. The speed problem and its solutions The original WaveNet was far too slow to deploy; generating one second of audio required sixteen thousand sequential passes through a deep network. The response to this problem produced a decade of fruitful research. Parallel WaveNet, published by DeepMind in 2017 and deployed in Google Assistant, used a technique called probability density distillation. A fast "student" network, based on an inverse autoregressive flow that can generate all samples in parallel, was trained to match the output distribution of a slow, already trained "teacher" WaveNet. The student generated audio many times faster than real time. WaveRNN, from Nal Kalchbrenner and colleagues in 2018, took the opposite approach: keep autoregression but make each step extremely cheap, with a single small recurrent layer, weight sparsification and clever splitting of each 16-bit sample into coarse and fine halves. It could run in real time on a mobile phone processor. LPCNet, from Jean-Marc Valin and Jan Skoglund at Mozilla and Google in 2019, went further by combining a small recurrent network with classical linear prediction, letting a signal-processing model handle the predictable part of each sample so that the network only had to model the residual. Generative adversarial networks then removed autoregression entirely. MelGAN in 2019 and HiFi-GAN in 2020, the latter by Jungil Kong, Jaehyeon Kim and Jaekyoung Bae, generate entire waveforms in parallel from mel spectrograms, trained with discriminators that judge realism at multiple time scales and periodic structures. HiFi-GAN in particular combined high quality with speed far beyond real time even on a CPU, and became a standard choice. More recent work has explored diffusion-based vocoders and neural audio codecs that compress speech into discrete tokens which language-model-style networks can generate; those codec-based approaches have become central to the newest generation of speech synthesis and spoken dialogue systems. Table 2 lays out how these vocoder families trade quality against generation speed. Table 2. Neural vocoder families and their principal trade-offs. Family Example Generation Main strength Main cost Autoregressive CNN WaveNet (2016) Sample by sample Very high quality Very slow Distilled flow Parallel WaveNet (2017) Parallel Fast inference Complex two-stage training Lightweight RNN WaveRNN, LPCNet Sample by sample Runs on phones Still sequential GAN HiFi-GAN (2020) Parallel Fast and high quality Adversarial training can be unstable Working out a receptive field Because the receptive field matters so much, both for WaveNet and for the recognition models that borrowed its design, it is worth seeing how to compute one. For a stack of causal convolutions with stride one, each layer adds (filter width minus one) multiplied by its dilation to the receptive field, and the total is that sum plus one. A block of ten layers with filter width two and dilations 1, 2, 4 and so on up to 512 therefore has a receptive field of 1 + (1 + 2 + 4 + ... + 512) = 1,024 samples. Repeating the block three times adds 1,023 samples for each extra block, giving 3,070 samples, a little under 200 milliseconds at 16 kHz. The same arithmetic applies when the input is a sequence of spectrogram frames rather than samples. Suppose a keyword spotter operates on 10-millisecond frames and uses six causal layers with filter width three and dilations 1, 2, 4, 8, 16 and 32. Each layer contributes twice its dilation, so the receptive field is 1 + 2 × (1 + 2 + 4 + 8 + 16 + 32) = 127 frames, about 1.27 seconds: enough for most two- or three-syllable wake phrases spoken at a normal rate. Halve the number of layers and the receptive field drops to 15 frames, 150 milliseconds, which is less than a single syllable. A model of that size could still learn to fire on a fragment of the wake phrase, but it would be guessing from part of the evidence, and its false-accept rate would show it. Two caveats apply. The theoretical receptive field is an upper bound; in practice a network's effective receptive field, the region that substantially influences its output, is often much smaller and concentrated near the centre, as Wenjie Luo and colleagues showed for convolutional networks in 2016. And strided or pooled layers multiply the contribution of every subsequent layer, which is why aggressive downsampling early in a network extends its reach cheaply at the cost of time resolution. Designers trade these effects against one another constantly. What WaveNet means for recognition WaveNet is a generator, but the ideas it introduced apply equally to recognition, and they bear directly on the later chapters of this booklet. The first is the dilated causal convolution as a general sequence encoder. A temporal convolutional network built from stacked dilated convolutions can process a stream of audio features with a long receptive field, low latency and fully parallel training. Many keyword spotting architectures, including models in Chapter 6, use dilated or depthwise-separable temporal convolutions for exactly these reasons. The original WaveNet paper itself included a brief experiment applying the architecture to speech recognition on the TIMIT corpus, reporting a phone error rate that was strong for a model operating on raw audio at the time. The second is the demonstration that raw waveforms are learnable. WaveNet's success encouraged work on recognition directly from samples, culminating in self-supervised encoders such as wav2vec 2.0, which begin with a stack of strided convolutions over raw audio, discussed in Chapter 4. Those convolutions, notably, learn something functionally similar to a filterbank, which is a reminder that the network is not abolishing the time-frequency representation so much as learning its own. The third is a lesson about cost. Modelling every sample is expensive. For generation, where every sample must be produced, there is no way around it, only ways to make it cheaper. For recognition, where the output is a handful of words or labels per second, it is usually unnecessary to operate at the sample rate after the first few layers. Almost every practical recogniser therefore reduces the time resolution early, to 100 frames per second or fewer, and does its heavy lifting there. The fourth is causality as a design constraint. A wake-word detector or streaming recogniser must make decisions as audio arrives, with no access to the future. WaveNet's causal padding is the simplest way to enforce that in a convolutional network, and the receptive field of a causal stack tells you exactly how much past context each decision uses. When designing a streaming model, it is worth computing that receptive field explicitly. A model whose receptive field is shorter than the longest wake phrase it must detect cannot possibly detect it reliably, however well it is trained. A short note on what was not solved WaveNet's synthetic speech was natural, but naturalness of a waveform is not the same as correctness of content. The model could not decide what to say, or how to stress and phrase it; that job falls to whatever produces its conditioning input. In recognition, the analogous point is that a powerful acoustic encoder still depends on its training targets and data to know what distinctions matter. Most of the problems that make audio systems fail in the field, such as mismatch between training and deployment conditions, label noise and poor evaluation, are untouched by better architectures. The chapters that follow therefore spend as much time on data and measurement as on networks. Hashtags: #DeepLearningForAudio #DeepLearning #AudioDeepLearning #SpeechRecognition #SoundEventDetection #AudioProcessing #ArtificialIntelligence #MachineLearning #AudioAI #AutomaticSpeechRecognition #ASR #SpeechProcessing #DigitalSignalProcessing #AudioClassification #AcousticModeling #Spectrograms #MelSpectrogram #MFCC #WaveNet #NeuralNetworks #AudioTransformers #ConvolutionalNeuralNetworks #SelfSupervisedLearning #KeywordSpotting #WakeWordDetection #SoundRecognition #SpeechToText #AudioFeatureExtraction #NoiseRobustness #EdgeAI

  • AI in Cybersecurity (Automated Threat Detection and Response)

    Download the Book (PDF): Introduction At three in the morning, somewhere in a security operations center, an analyst is looking at an alert that says a user account in the finance department has just logged in from an unfamiliar country. It is the forty-third alert of the shift. Most of the previous forty-two were nothing: a backup job that touched more files than usual, a developer running a scanning tool against their own test server, a salesperson connecting through a hotel network. The analyst has perhaps ten minutes to decide whether this one is different. If it is a stolen credential, the next few hours matter enormously. If it is a traveling employee, chasing it costs time that the next alert, possibly the real one, will need. That scene, repeated across thousands of organizations every night, is the right place to begin a book about artificial intelligence in cybersecurity. Not with a futuristic picture of autonomous machines battling each other at network speed, and not with a vendor's promise that a model will "stop every attack," but with a tired person, a queue, and a decision under uncertainty. Almost everything that machine learning can genuinely do for network defense comes down to changing what happens in that scene: which alerts reach the analyst, in what order, with what context attached, and which ones never need a human at all. The argument of this book The controlling claim of this book is simple to state and surprisingly easy to forget. Machine learning in cyber defense is best understood not as a replacement for human judgment, nor as a detector that catches what rules miss, but as a mechanism for rationing scarce human attention under adversarial pressure. Its value is set less by how accurate a model looks in a laboratory than by four realities of the operational world: attacks are rare relative to normal activity, the environment drifts constantly, the adversary adapts to whatever the defender deploys, and every output eventually lands on a person who must decide what to do with it. Systems designed around those four realities work. Systems designed around a headline accuracy number tend to fail in ways that are expensive and, worse, quiet. This framing matters because the field has been through several cycles of overpromise. Anomaly detection was proposed as the answer to unknown attacks in the 1980s, and a generation of research systems produced impressive results on benchmark datasets that did not survive contact with real networks. Machine-learning antivirus engines were marketed in the mid-2010s as making signatures obsolete, and while they did transform malware detection, they also introduced new failure modes that attackers learned to exploit. Since 2023, large language models have been folded into security tooling at remarkable speed, and by 2026 vendors routinely describe "agentic" security operations centers in which software agents investigate and close alerts on their own. Some of those claims are well founded and some are not. A reader who understands why earlier waves succeeded or disappointed is far better placed to judge the current one. What the book covers, and what it leaves out The description of this book names three applications, and they form its spine. The first is behavioral anomaly detection: learning what normal looks like for users, hosts and network flows, and flagging departures from it. The second is the identification of previously unseen malicious software through static analysis, meaning the examination of a file's structure and content without running it, so that a program nobody has catalogued before can still be judged likely to be hostile. The third is the automation of incident response triage, the work of sorting, enriching and prioritizing alerts so that the people in a security operations center spend their time where it counts. Around that spine sit the chapters that make the applications intelligible. The book begins with the attention problem itself, because without understanding why defenders drown in alerts, it is impossible to judge whether any tool helps. It then explains, without mathematics, what learning systems actually learn and where their training data in security comes from, since most failures trace back to data rather than algorithms. After the three core applications, it turns to the adversary, who studies defensive models as carefully as the defender studies attacks, and to the problem of measurement: how to tell whether a detection or triage system is genuinely helping. It closes with the organizational question of how to divide work between people and machines in a way that holds up over years rather than quarters. Several things are deliberately left out. This is a defensive book written for professionals who need to understand, buy, deploy, govern or work alongside these systems. It describes attack techniques only at the level needed to understand why a defense works or fails, and it contains no working exploit or malicious code. It does not attempt to survey every product on the market, which would be out of date within months. It does not teach the mathematics of particular algorithms, because the decisive questions in this field are rarely about which algorithm to use. And it does not cover the separate, large topic of securing AI systems themselves, such as protecting a company's own chatbot from manipulation, except where the same ideas illuminate the security of defensive models. Who this book is for The intended reader is an intelligent professional who is not necessarily a data scientist or a security engineer: a chief information security officer weighing a procurement decision, an IT leader whose team is about to inherit a new detection platform, a risk manager or auditor who must judge whether automated controls are trustworthy, a policy specialist, or an analyst early in a security career who wants to understand the tools reshaping the job. Specialists will find the arguments familiar in places, but may find the synthesis useful when explaining their work to others. Technical terms are defined where they first appear. A short glossary at the end collects the ones that recur most often, and the notes point to the real research on which the argument rests. Where precise figures are uncertain or vary widely between organizations, the book says so rather than inventing a number. One of the recurring lessons of this field is that confident-looking statistics are cheap and frequently misleading, and a book about measurement should not add to the pile. A word on optimism It would be easy to read what follows as skeptical, because so much of it concerns failure: false alarms, drifting models, evasion, automation that removes the very human checks it was meant to support. That reading would be mistaken. Machine learning has already changed network defense for the better in concrete ways. Static classifiers catch large volumes of new malicious files that no signature would have matched. Behavioral analytics find compromised accounts that no rule anticipated. Well-designed triage automation has turned unmanageable queues into workable ones, and early controlled evidence suggests that language-model assistants can make analysts both faster and more accurate on specific, well-bounded tasks. The point is that these successes share a pattern. They come from teams that knew what problem they were solving, measured the right things, expected the adversary to respond, and kept a clear line between what the machine decides and what a person decides. The aim of this book is to make that pattern visible, so that the reader can recognize it, insist on it, and build it. Chapter 1: The Attention Problem Security failures are usually described as failures of detection. The attacker was "undetected," the breach went "unnoticed for months," the tools "missed" the intrusion. The phrasing suggests that the defenders lacked a sensor, a signature or a clever enough algorithm. Sometimes that is true. But a striking number of serious incidents show a different pattern: the evidence was collected, an alert was raised, and nobody acted on it in time. The best-known case is the breach of the American retailer Target in late 2013, in which attackers stole payment card data from tens of millions of customers. A report prepared for the United States Senate Commerce Committee in 2014 laid out the sequence in detail. Target had invested in a commercial malware detection system, and that system generated alerts as the attackers installed their tools. The alerts were reviewed by a monitoring team and passed along, but they did not trigger a decisive response, and the theft continued. The lesson most commentators drew was not that Target lacked technology. It was that the technology produced a signal which the organization could not distinguish, in the moment, from the many other signals competing for attention. That is the problem this book is about. Modern defenders are not short of data. They are short of attention, and the central question for any automated system is what it does to the allocation of that attention. Where the alerts come from A medium-sized organization today collects security telemetry from a remarkable range of sources. Endpoint detection and response agents on laptops and servers record process launches, file writes, registry changes and network connections. Firewalls and network sensors summarize traffic flows. Identity providers log every sign-in, with its location, device and outcome. Email gateways record messages, attachments and links. Cloud platforms emit audit logs for every administrative action. Web proxies, DNS resolvers, VPN concentrators and software-as-a-service applications add their own streams. All of this typically flows into a security information and event management platform, usually abbreviated SIEM, which stores it, correlates it and applies detection logic. Each source comes with its own detections, and each detection is written to err on the side of caution, because the cost of missing an attack is visible and the cost of an extra alert is diffuse. The vendor of an endpoint product does not want to be the one whose tool stayed silent during a ransomware outbreak. The engineer who writes a rule for suspicious PowerShell usage would rather it fire on some administrators' legitimate scripts than miss an attacker using the same commands. Every one of those decisions is locally reasonable. Summed across dozens of tools and hundreds of rules, they produce a queue that no team can clear. Analysts have a name for the result: alert fatigue. In a 2022 study presented at the USENIX Security Symposium, researchers from the University of Oxford interviewed security operations center analysts about how they experience alarms. The paper's title, "99% False Positives," came from the analysts themselves, and it captured a view that ran through the interviews: most alerts were not worth the time it took to dismiss them, analysts developed shortcuts and heuristics to cope, and trust in particular tools eroded when they cried wolf too often. The study did not claim that exactly ninety-nine percent of all alerts everywhere are false. Its point was the lived experience of people whose working day is spent mostly confirming that nothing is wrong. Alert fatigue is not merely unpleasant. It changes behavior in ways that make detection worse. When most alerts of a given type are benign, analysts learn to close them quickly, and the occasional true one gets closed along with the rest. When a tool has a reputation for noise, its alerts are deprioritized as a category. When queues back up, alerts age past the point where the evidence they point to is still available. An organization can own excellent sensors and still be, in practice, blind. The arithmetic of rarity To see why the queue fills with false alarms even when each detector seems accurate, it helps to work through the arithmetic once. The argument was set out formally for intrusion detection by Stefan Axelsson in a paper published in 2000, "The Base-Rate Fallacy and the Difficulty of Intrusion Detection," and it remains the single most important idea for anyone evaluating a detection system. Imagine, purely for illustration, an organization that generates ten million events a day that a particular detector examines: sign-ins, process launches, connections. Suppose that on a typical day ten of those events are genuinely malicious. Now suppose the detector is very good by most standards. It catches ninety-nine percent of malicious events, and it wrongly flags only one benign event in a thousand, a false positive rate of 0.1 percent. Run the numbers. Of the ten malicious events, the detector flags about ten. Of the nearly ten million benign events, it flags one in a thousand, which is about ten thousand. The analyst therefore faces roughly ten thousand and ten alerts, of which ten are real. The probability that any given alert is a real attack is about one in a thousand. A detector that sounds excellent when described by its detection rate and its false positive rate produces a queue that is 99.9 percent noise. This is the base-rate fallacy: the mistake of judging an alert by the detector's accuracy while ignoring how rare the thing being detected is. The same arithmetic explains why medical screening tests for rare diseases produce many false positives, and it applies with special force in security, where the ratio of benign to malicious activity is often millions to one. Two consequences follow, and both shape everything later in this book. First, the quantity that matters operationally is not the detection rate or the false positive rate in isolation but the precision of the alerts that reach a human, the fraction of them that are worth acting on. Precision depends on the base rate, which means a detector's usefulness depends on where it is deployed, not just on how it was built. Second, small improvements in the false positive rate are worth far more than they appear. Cutting the false positive rate from one in a thousand to one in a hundred thousand, in the example above, shrinks the noise from ten thousand alerts to about a hundred, and transforms an unusable detector into a valuable one. Much of the practical engineering of machine learning in security is a fight over the far right-hand digits of the false positive rate. Queues that never empty The base-rate argument explains why alerts are mostly noise. A second, equally simple idea explains why noise is so damaging: the behavior of queues. Any system in which work arrives and is processed, whether a supermarket checkout, a hospital emergency department or a SOC, obeys the same basic logic. If work arrives, on average, more slowly than it can be handled, the queue stays short and waiting times stay low. If it arrives faster than it can be handled, the queue grows without limit, and the waiting time for each new item grows with it. The consequence is counterintuitive. A SOC that can handle a hundred alerts a day and receives ninety is in a very different position from one that receives a hundred and ten, even though the difference is only twenty percent. The first clears its queue every day, with some slack for complicated cases. The second falls further behind every day. In practice, no team lets the queue grow forever. Instead, something gives: analysts spend less time on each alert, certain categories are closed in bulk, older alerts are abandoned. These adaptations keep the queue under control, but they do so by lowering the quality of each decision, and they do it invisibly. A dashboard may show that every alert was closed, while revealing nothing about how many were closed without real examination. Queues also interact with time in a way that matters for security specifically. Evidence decays. Logs roll over, memory contents vanish when machines restart, and attackers clean up after themselves. An alert examined within minutes can be investigated thoroughly; the same alert examined three days later may point to evidence that no longer exists. The longer the queue, the less each alert is worth by the time someone reaches it. This is why the language of attention, rather than detection, is the right one. An organization that adds a new detector without considering its effect on the queue may be making itself less safe, if the new alerts push the queue past the point where it can be cleared and the quality of every decision falls. Conversely, an organization that removes a noisy detection, or automates the handling of a high-volume, low-risk category, may become safer without detecting anything new, simply by giving its analysts time to look properly at what remains. Incident responders track dwell time, the interval between an attacker's arrival and their discovery, as one of the most telling measures of a defensive program, and post-incident reviews regularly find that the evidence needed to shorten it was already sitting in the victim's own logs. Why rules alone cannot keep up Before machine learning, and still today for most organizations, the bulk of detection is written by people. Signatures match known malicious files or byte patterns. Rules match known patterns of behavior: a process spawned by a word processor that then launches a command shell, a sign-in followed within minutes by a sign-in from another continent, a server suddenly sending large volumes of data to an address it has never contacted. Rule languages such as Sigma for log data and YARA for file content have made it easier to share these detections across organizations. Rules have real strengths. They are transparent: anyone can read a rule and understand why it fired. They are precise when written well, because they encode an expert's specific knowledge of an attack technique. They are cheap to run. And they connect cleanly to frameworks like MITRE ATT&CK, the widely used catalog of adversary tactics and techniques, which lets a team map what it can and cannot see. Their weaknesses are equally clear. A rule only catches what someone anticipated. Attackers who change a detail, such as renaming a tool, encoding a command differently or moving more slowly, can step around it. Rules also struggle with context. Whether a burst of file encryption is ransomware or a legitimate backup depends on who is running it, on which machine, at what time, with what history, and encoding all of that in hand-written logic quickly becomes unmanageable. And each rule must be tuned to each environment; a rule that is quiet in one company may fire thousands of times a day in another with different software and habits. Machine learning enters at exactly these weak points. It can generalize from examples rather than requiring every pattern to be spelled out, which offers a chance of catching variations nobody wrote down. It can weigh many weak signals at once, which offers a way to bring context into a decision. And it can learn what is normal for a particular environment, which offers a route around the tuning problem. Each of these is a genuine capability. Each also carries a cost, and later chapters examine those costs carefully. The real objective If the scarce resource is attention, then the objective of a detection and response program can be restated. It is not "detect all attacks," which is impossible, nor "minimize alerts," which is trivially achieved by turning the tools off. It is closer to this: given a fixed and expensive amount of skilled human time, arrange the system so that the time is spent on the events most likely to matter, with enough context to decide quickly, and so that the events which can be handled without human judgment are handled reliably without it. Stated that way, machine learning has three distinct jobs, which correspond to the three applications at the center of this book. The first job is to surface things that would otherwise go unseen. Behavioral anomaly detection, covered in Chapter 3, tries to find compromised accounts, insider misuse and stealthy intrusions that match no known pattern. Static malware classification, covered in Chapter 4, tries to recognize hostile software that no signature yet describes. These are the jobs most people mean when they talk about "AI detection," and they are the ones most vulnerable to the base-rate trap, because they operate on enormous volumes of mostly benign data. The second job is to filter and rank what has been surfaced. Of all the alerts generated by rules, models and third-party tools, which deserve attention first? This is the core of triage automation, covered in Chapter 6, and it is often where machine learning delivers the most value for the least risk, because it works on a much smaller, already-filtered population where the base rate of real incidents is far higher. The third job is to do the routine work around each alert: gathering the user's recent activity, checking a file's reputation, looking up whether an address appears in threat intelligence, assembling a timeline, and, for well-understood cases, taking a containment action. Much of this is ordinary automation rather than learning, but language models have recently extended what can be automated, because they can read unstructured evidence and write summaries that previously required an analyst. Keeping these three jobs separate is one of the most useful habits a reader can take from this book. Vendors and headlines tend to blur them into a single claim about "AI-powered security." But they have different data, different failure modes, different appropriate levels of autonomy and different ways of being measured. A model that is excellent at ranking alerts may be useless at finding new attacks, and vice versa. The defender's dilemma, revisited A common saying in security holds that the defender must be right every time while the attacker need be right only once. It is meant to explain why defense is hard, and it often appears in arguments for automation: since humans cannot be right every time, machines must help. The saying is only half true, and the half that is false is important. Real intrusions are not single events. An attacker who gains an initial foothold must still establish persistence, escalate privileges, move laterally to other systems, locate valuable data and get it out. Each step generates evidence, and each is an opportunity for detection. Security practitioners sometimes invert the saying: the attacker must stay hidden at every step, while the defender needs to notice only once. Under that view, the defender's task is not perfection at any single point but sufficient coverage across the chain and, critically, the ability to act when one of many weak signals turns out to be the thread worth pulling. That inversion only holds if signals are noticed and acted upon, which brings the argument back to attention. An organization whose analysts are overwhelmed does not benefit from the attacker's need to take many steps, because the evidence of those steps sits unexamined in a queue. An organization whose attention is well allocated can exploit every one of them. Machine learning, used well, is a way of turning the attacker's long chain into the defender's advantage. Used badly, it adds more unexamined evidence to the pile. The next chapter takes a step back to explain what learning systems actually do with security data, because the rest of the argument depends on a clear picture of what a model can and cannot know. Chapter 2: What Learning Machines Actually Learn Most discussions of machine learning in security begin with algorithms: neural networks, random forests, gradient boosting, transformers. Practitioners who have built these systems tend to begin somewhere else, with data. What was collected, how it was labeled, what period it covers, what environment it came from and what it leaves out determine most of what a model will do in production. The algorithm matters, but it matters in the way that the choice of engine matters to a car with no fuel. This chapter explains, in plain terms, what a learning system does, and why security data makes the job unusually hard. Learning from examples At its simplest, a machine learning model is a function built from examples rather than written by hand. A rule-writer looks at an attack and writes down a condition that matches it. A learning system is shown many examples, each described by a set of measurable properties called features, and adjusts its internal parameters until its outputs match the examples as closely as possible. The resulting function can then be applied to new cases it has not seen. The features are the bridge between raw security data and the model. A model cannot look at a sign-in event the way an analyst does. It needs numbers or categories: the hour of day, whether the device has been seen before, the distance from the user's last location, the number of failed attempts in the previous hour, whether the sign-in used multi-factor authentication, how many other users signed in from the same address. For a file, the features might be its size, the number of sections it contains, the libraries it imports, statistical measures of how random its contents are, and the presence of particular strings. Choosing and computing these features, a task called feature engineering, has historically been where most of the domain expertise in security machine learning lives. Deep learning methods can learn some features directly from raw data, as Chapter 4 explains, but even they depend on decisions about how the raw data is presented. There are three broad families of learning, and the distinction between them runs through the rest of this book. In supervised learning, every training example comes with a label: this file is malicious, that one is benign; this alert was a real incident, that one was a false positive. The model learns to predict the label from the features. Supervised learning is powerful when labels are plentiful and trustworthy, and static malware classification is its great success story in security, because large collections of labeled files exist. In unsupervised learning, there are no labels. The model is asked to find structure in the data: clusters of similar items, or a description of what typical data looks like so that atypical items stand out. Most behavioral anomaly detection is unsupervised, because labeled examples of attacks within a particular organization's own environment are scarce. In semi-supervised and weakly supervised learning, a small number of labels is combined with a large amount of unlabeled data, or labels come from imperfect sources such as the verdicts of other tools. Much practical security work lives here, including most triage models, which learn from the dispositions analysts record when they close alerts. A fourth approach has become prominent since 2023: large pretrained models, especially language models, that were trained on vast general-purpose data and are then applied to security tasks with little or no task-specific training. These models do not fit neatly into the older categories. They bring broad knowledge, such as what a suspicious command line tends to look like or how a phishing email tends to read, but they also bring their own failure modes, discussed in Chapter 6. A worked example: scoring a sign-in It helps to follow a single, simplified model from beginning to end. Suppose a security team wants to score every sign-in to its cloud applications for the likelihood that it is being made by someone other than the account's owner. The team starts with data. The identity provider logs each sign-in with the user, the time, the source network address, an approximate location derived from that address, the device and browser, whether multi-factor authentication was used and whether the attempt succeeded. From these raw fields, the team computes features designed to capture what an analyst would notice: whether this device has been seen for this user before, how far the location is from the user's usual locations, whether the source address belongs to a residential provider, a corporate network, a cloud hosting company or an anonymizing service, how many distinct users have signed in from the same address recently, how many failed attempts preceded the success, and whether the time of day is typical for this user. Next, the team needs labels. It has a few hundred sign-ins from past incidents that were confirmed as account takeovers, and many millions that were never investigated and are presumably legitimate. The confirmed cases are precious but few, and they are skewed toward the kinds of takeover the team has previously caught. The unlabeled millions almost certainly include some takeovers nobody noticed. This is the normal situation in security, and it is already a warning: the model will learn what past detected takeovers looked like, which is not the same as what takeovers look like. The team trains a model, perhaps a gradient-boosted tree ensemble, a reliable choice for this kind of tabular data, and evaluates it on sign-ins from a later period than those it trained on. It chooses a threshold not by maximizing some abstract score but by asking how many sign-ins per day the team can afford to review, and setting the threshold so that roughly that many exceed it. It then examines the highest-scoring sign-ins by hand, and discovers, as nearly every team does, that many of them share an innocent explanation: an employee using a new phone, a partner organization whose staff sign in through a cloud proxy, a sales team at a conference abroad. Each discovery leads to a new feature or a piece of context that the model lacked. This cycle of building, deploying, examining and refining is what applied machine learning in security actually consists of. The algorithm is chosen in an afternoon. The features, labels, thresholds and context take months, and they are never finished. The label problem Supervised learning needs labels, and in security, good labels are both scarce and treacherous. Consider malware. A common way to label a large set of files is to submit them to a multi-engine scanning service and count how many antivirus products flag each one. A file flagged by many engines is labeled malicious; one flagged by none is labeled benign. This is practical and widely used, but it has two problems. First, it is circular. A model trained on labels produced by existing detectors learns, to a significant degree, to imitate those detectors, including their blind spots. The files that matter most, the ones no existing product recognizes, are precisely the ones whose labels are wrong at the time of collection. Second, labels change over time. A file that no engine flags on the day it appears may be flagged by dozens a month later, once researchers have examined it. Training data labeled too early contains mislabeled malware; data labeled long after the fact gives an unrealistically rosy view of what was knowable at the time. Consider alerts. A triage model learns from past analyst decisions: this alert was escalated, that one was closed as benign. But those decisions were made by tired people under time pressure, and some were wrong. Worse, the errors are not random. If analysts habitually closed a certain type of alert without investigation, the model learns that this type is benign, and it will deprioritize future instances even more aggressively, which makes it less likely that anyone ever discovers the habit was mistaken. A model trained on human decisions inherits human biases and can harden them. Consider network attacks. Public datasets for network intrusion detection have existed since the late 1990s, most famously the KDD Cup 1999 dataset derived from a DARPA evaluation, and later collections such as those produced by the Canadian Institute for Cybersecurity. These datasets have been invaluable for teaching and for early research. But they were generated in laboratory conditions, with attacks injected into synthetic or semi-synthetic background traffic, and models trained on them have repeatedly been shown to exploit artifacts of the data collection rather than genuine properties of attacks. A model can achieve near-perfect scores on such a dataset by learning, for instance, that malicious traffic in the dataset happens to come from particular address ranges or to have particular timing quirks. None of that transfers to a real network. Common ways to fool yourself In 2022, a group of researchers led by Daniel Arp published a paper at the USENIX Security Symposium titled "Dos and Don'ts of Machine Learning in Computer Security." They reviewed a large sample of published security research using machine learning and found that subtle methodological pitfalls were widespread, often in combination. The pitfalls they identified are worth knowing, because they appear in vendor claims and internal evaluations just as often as in academic papers. Sampling bias occurs when the training data does not represent the conditions the model will face. A malware classifier trained mostly on one family of threats, or on files collected from one region or industry, may perform poorly elsewhere. Label inaccuracy is the problem already described: labels that are wrong, unstable or derived from the very detectors the model is meant to improve upon. Data snooping is the use of information during training that would not be available in practice. The most common form in security is temporal: mixing old and new samples randomly between training and test sets, so that the model is effectively trained on the future and tested on the past. Because malware and attack techniques evolve, this makes a model look far better than it will be when deployed, where it will always be facing samples newer than anything it trained on. Spurious correlations arise when a model learns an artifact that happens to separate the classes in the data but has nothing to do with maliciousness: a compiler version, a timestamp pattern, the network that a test lab used. Biased parameter selection and inappropriate baselines occur when a model's settings are tuned on the test data, or when it is compared only against weak alternatives. A complex deep learning model that beats a poorly configured older method is less impressive than one that beats a well-tuned simple model. Inappropriate performance measures and base-rate neglect, the subject of the previous chapter, occur when a model is evaluated on a balanced dataset with equal numbers of malicious and benign samples, and its accuracy is then quoted as though it applied to a real environment where benign activity outnumbers malicious by many orders of magnitude. Lab-only evaluation is the failure to test the system in anything resembling production conditions, with real data volumes, real latency constraints and real analyst workflows. The practical value of this list is that it turns vague skepticism into specific questions. When someone reports that a model achieves ninety-eight percent accuracy, the reader can ask: on what data, labeled how, split by time or at random, at what base rate, compared to what, and measured in what environment? The answers usually reveal far more than the number. What the data cannot show A further limit on every security model is visibility. Models can learn only from what sensors record, and modern environments hide a great deal from them. Most network traffic is now encrypted, which protects users but also means that a network sensor sees who is talking to whom, when, and how much, but not what is said. Detection has adapted by learning from metadata: the timing and size of packets, the destinations contacted, and characteristics of the encryption handshake itself. One widely used technique, published by researchers at Salesforce in 2017 under the name JA3, fingerprints the way a piece of client software sets up an encrypted connection, so that a particular malware family's traffic may be recognizable even when its contents are not. Such methods work, but they work on indirect evidence, and they can be defeated by attackers who make their software's handshake mimic a common browser. Endpoint telemetry has its own gaps. Agents record a selection of events rather than everything, because recording everything would overwhelm storage and slow the machine. The selection reflects the vendor's judgment about what matters, and an attacker who knows which events are recorded can favor actions that are not. Cloud platforms log administrative actions in detail but may log data access only if specifically configured to do so, and many organizations leave such logging switched off for cost reasons. Software-as-a-service applications vary widely in what they expose. The consequence is that a model's view of the world is shaped not only by what happened but by what was recorded, and the boundaries of the record are often invisible to the people using the model's output. A behavioral system that reports no anomalies on a server may mean that nothing unusual happened, or that the server's agent stopped reporting two weeks ago. Good systems make the absence of data as visible as its presence. How the approaches compare It helps at this point to set the main detection approaches side by side. Signatures, hand-written behavioral rules, supervised models and anomaly detection each make a different trade between precision, coverage of the unknown, transparency and the effort needed to maintain them, as Table 1 summarizes. None dominates the others, which is why mature programs use all four. Table 1. Main approaches to automated threat detection compared. Approach Basis Strength Main weakness Upkeep Signatures Known threat patterns Very few false alarms Blind to the new Feed updates Behavioral rules Expert-written logic Transparent Misses variants Local tuning Supervised models Labeled examples Generalizes to variants Label quality, drift Retraining Anomaly detection Learned normal activity Can surface the novel Unusual is not malicious Baselines, triage The table hides an important subtlety. The approaches are not independent layers stacked on top of each other; they interact. A supervised model may use the output of rules as features. An anomaly score may be passed to a supervised model that has learned which anomalies analysts care about. Signatures may be generated automatically from clusters found by unsupervised methods. The most effective systems are pipelines in which each method compensates for the weaknesses of the others, and much of the craft lies in how they are wired together. What a model cannot know One more idea completes the picture, and it is the most important limit of all. A learning system knows only what is in its data. It has no independent understanding of why an action is malicious. A model that has learned to flag sign-ins from unfamiliar countries does not know that the concern is credential theft; it knows only that such sign-ins were labeled suspicious in training, or that they are rare. If attackers begin routing their access through infrastructure in the victim's own country, which many sophisticated groups now do as a matter of routine, the model has no way to reason that the same underlying threat has changed its surface appearance. Analysts, by contrast, reason about intent and capability. They know that an attacker who has stolen a password will try to use it, will look for more privileged accounts, and will want to move data out. That knowledge lets them recognize an attack expressed in unfamiliar ways. This is the deep reason that machine learning works best as an instrument for directing human attention rather than replacing human judgment: the model is very good at noticing statistical regularities and departures from them across volumes no person could scan, while the person is good at asking whether those departures mean what an adversary would mean by them. Large language models blur this line somewhat, because they carry a great deal of general knowledge about attacker behavior absorbed from public writing about security. A language model asked to explain a suspicious command line can often describe what it does and why an attacker might use it. But that knowledge is general rather than specific to the organization, and it is retrieved by pattern rather than by verified reasoning. Chapter 6 returns to what this means for automated triage. For now, the key point is that every learning system is bounded by the world its data describes, and in security, the adversary is constantly trying to move to a world the data does not describe. With that foundation in place, the next chapter turns to the first of the three core applications: learning what normal looks like, and noticing when something departs from it. Chapter 3: Learning What Normal Looks Like The idea behind behavioral anomaly detection is older than most of the people who now practice it. In 1987, Dorothy Denning published "An Intrusion-Detection Model" in the IEEE Transactions on Software Engineering, proposing that intrusions could be detected by building statistical profiles of how users and systems normally behave and flagging significant departures. Her argument was that attackers, whether outsiders using stolen credentials or insiders abusing their access, would inevitably do things the legitimate owner of an account would not. Nearly four decades later, that remains the founding intuition of the field, and it remains both correct and incomplete in roughly the same proportions. This chapter explains how behavioral anomaly detection works in practice, why it has a reputation for noise, and what distinguishes the deployments that earn their keep from those that are quietly switched off after a few months. The promise and the closed world The appeal of anomaly detection is that it does not require anyone to have seen the attack before. A signature needs a sample; a rule needs an expert who anticipated the technique; a supervised model needs labeled examples. An anomaly detector needs only a description of normal behavior, and the description can be learned automatically from the organization's own data. In principle, then, it offers a defense against the novel: new tools, new techniques and the patient attacker who uses only legitimate administrative software. In 2010, Robin Sommer and Vern Paxson published a paper at the IEEE Symposium on Security and Privacy that became the standard reference for why this promise had largely failed to materialize in network intrusion detection. Titled "Outside the Closed World: On Using Machine Learning for Network Intrusion Detection," it observed that despite many years of academic research reporting excellent results, anomaly-based systems were rarely deployed in operational networks. The authors traced the gap to several features of the security problem that distinguish it from the domains where machine learning had succeeded. The first was that machine learning is far better at finding similarities than at identifying activity that has never been seen. A spam filter or a product recommender works by recognizing things like what it has seen before. Anomaly detection asks the reverse, and the space of things not seen before is vast and mostly harmless. The second was the very high cost of errors, both false positives, which consume analyst time, and false negatives, which may be catastrophic. The third was what they called the semantic gap: an anomaly detector reports that something is statistically unusual, but an operator needs to know whether it is a security problem and what to do about it, and the detector usually cannot say. The fourth was the enormous natural variability of real network traffic, in which unusual events happen constantly for benign reasons. The fifth was the difficulty of sound evaluation, given the lack of realistic data. The paper did not argue that anomaly detection was useless. It argued that it had to be scoped narrowly, with a clear idea of what kind of attack it was meant to catch, and that operators needed results they could interpret. The most successful modern deployments follow exactly that advice, even when they do not cite it. Baselines for people, machines and traffic In current practice, behavioral anomaly detection takes three main forms, differing by the entity whose behavior is modeled. User and entity behavior analytics, usually shortened to UEBA, builds profiles of individual accounts and devices. For a user, the profile might cover typical sign-in times, locations, devices and applications; the systems and file shares normally accessed; the volume of data normally downloaded; and the administrative actions normally performed. For a server, it might cover the processes that normally run, the accounts that normally log in and the destinations it normally contacts. New activity is compared against the profile, and also against peer groups: other members of the same team, other servers with the same role. Peer comparison matters because individual baselines are thin for new employees and rarely used accounts, and because an action that is unusual for one person may be normal for their role. Network behavior analysis models traffic. Its raw material is usually flow records, summaries that say which address talked to which, over which port and protocol, for how long and with how much data, without recording the content. From flows, a system can learn which internal hosts normally talk to which others, what volumes are typical, and which external destinations are routinely contacted. It can then flag hosts that begin scanning internal ranges, connections between segments that never normally communicate, or unusual outbound volumes. Process and host behavior modeling, increasingly built into endpoint detection products, examines sequences of actions on a single machine: which programs launch which others, what files and registry keys they touch, which network connections they make. The question is whether a sequence is typical for that software on that kind of machine. The statistical techniques used range from simple to sophisticated. At the simple end are per-entity statistics with thresholds, such as flagging a user whose daily download volume exceeds their own historical average by a large margin. Clustering methods group similar entities or events and flag those that fit no cluster well. Isolation-based methods, such as the isolation forest algorithm, exploit the fact that unusual points can be separated from the rest of the data with fewer random partitions than typical points. Autoencoders, a type of neural network, learn to compress and reconstruct normal data and flag inputs they reconstruct poorly. Sequence models learn the typical order of events and flag improbable sequences. The choice among these matters less than is often claimed. What matters far more is what is being modeled, at what granularity and for which threat. Detections that work The behavioral detections with the best operational track records share a property: each is anchored to a specific attacker need. They do not ask "is anything unusual?" but "is the thing an attacker would have to do happening?" Consider beaconing. Malicious implants on a compromised machine typically need to contact their operators for instructions, and they often do so at regular intervals, sometimes with deliberate random variation, a property called jitter. A network model that looks for connections to rarely contacted external destinations with suspiciously regular timing is asking a narrow question tied to a real attacker requirement. It still produces false positives, because plenty of legitimate software also checks in on schedules, but the population of candidates is small enough to review, and the legitimate check-ins are stable enough to allow-list. Consider credential misuse. An attacker who has stolen a password, a session token or a key must use it, and the use will usually differ in some way from the owner's: a new device, a new location, a new time, a new set of resources accessed, or a combination. The famous "impossible travel" detection, which flags sign-ins from two places too far apart for the user to have traveled between them, is a crude version. Better versions combine many such signals into a risk score that reflects how many independent things are unusual at once. Consider unusual administrative actions. Attackers who reach a privileged account tend to perform a recognizable set of actions: creating new accounts, adding themselves to groups, registering new authentication devices, changing logging settings, exporting mailboxes. Modeling which administrators normally perform which actions makes deviations stand out. A widely reported example came in December 2020, when the security company FireEye disclosed that it had been breached as part of the campaign that compromised the SolarWinds Orion software supply chain. Press accounts at the time reported that the intrusion first came to light when the company's security staff noticed that a new device had been registered for multi-factor authentication on an employee's account, and contacted the employee, who had not registered it. Whatever the full internal story, the detection pattern is instructive: a narrow, attacker-necessary action, checked against the expected behavior of a specific person, followed by a human confirming with that person. The same campaign also illustrates the limits. Researchers who analyzed the implant described an adversary who went to considerable lengths to look normal: blending command traffic with the legitimate protocol of the compromised product, choosing infrastructure close to victims and giving machines names consistent with the victim's environment. Against an adversary who studies what normal looks like, generic anomaly detection is at a disadvantage. The defender's advantage lies in the narrow places where the attacker cannot avoid doing something abnormal, such as registering a device, touching a sensitive system for the first time or moving data off the network. Consider, finally, the domain name system, which translates names into network addresses and which nearly all software uses constantly. Two attacker needs show up in DNS. Some malware families, rather than contacting a fixed address that defenders could block, use an algorithm to generate large numbers of pseudo-random domain names each day, of which the operators register only a few; the implant tries them in turn until one answers. Such names tend to look statistically unlike names chosen by people, with unusual distributions of letters, lengths and syllables, and classifiers trained on these properties have proved effective at flagging them. Other attackers hide data inside DNS queries themselves, encoding stolen information in long, high-entropy subdomains sent to a server they control. A model that learns the normal length, character mix and volume of DNS queries per host can flag such tunneling. Both are again narrow questions anchored to something the attacker needs to do. A worked case: the departing employee Insider data theft illustrates how these ideas come together, and why it is one of the harder problems behavioral analytics addresses. Imagine an engineer who has accepted a job at a competitor and, in their final weeks, decides to take design documents with them. They have legitimate access to the documents. They will use their own account, their own laptop and familiar tools. No signature or rule describes what they are doing, because everything they do is individually permitted. A well-designed behavioral system might notice several things. The engineer begins accessing project folders they have not opened in months, including some belonging to projects they were never assigned to, which is unusual for them and for their peers. Their download volume rises well above their historical range. Files are compressed into archives, which the engineer rarely did before. An archive is copied to a removable drive, or uploaded to a personal cloud storage account. Separately, none of these is alarming; engineers revisit old projects, download large files and use cloud storage. Together, within a short window, and coinciding with a signal from the human resources system that the employee has resigned, they form a pattern worth a careful look. This example also shows the limits of what the system should do on its own. It should not block the employee or accuse them; there may be an innocent explanation, such as an approved handover of documentation, and the consequences of a wrong accusation are serious for the individual and the organization. It should assemble the evidence, explain it clearly, and route it to people who have the authority and context to judge it, including, in many organizations, human resources and legal colleagues as well as security staff. Behavioral detection of insiders also raises privacy questions that must be settled in policy before any model is switched on, a theme Chapter 8 returns to. Turning anomalies into decisions Even well-designed behavioral detections generate far more anomalies than incidents, for the base-rate reasons laid out in Chapter 1. Organizations that make anomaly detection work tend to use four techniques to convert the raw stream into something an analyst can act on. The first is aggregation by entity. Rather than raising an alert for each unusual event, the system accumulates evidence on each user or host over a period of time, often as a risk score, and raises a single case when the accumulated evidence crosses a threshold. A user who signs in from a new device is unremarkable. A user who signs in from a new device, then accesses a file share they have never touched, then compresses a large volume of data and uploads it to an external storage service, is a story. Aggregation converts many low-precision signals into fewer, higher-precision cases. The second is context enrichment. An anomaly is far easier to judge when it arrives with the information an analyst would otherwise have to fetch: who the user is, what their role is, whether they are on leave or traveling, whether the device is managed, whether the destination is known to threat intelligence. Some of that context can be fed back into the model itself, so that, for example, a sign-in from a new country is scored lower when the human resources system records an approved business trip. The third is explanation. An alert that says only "anomaly score 0.94" is close to useless, because the analyst cannot tell what was unusual. An alert that says "first access to this database by this account in ninety days; volume is twelve times this account's typical maximum; no peer in the same team has accessed it" can be judged in a minute. Explanation is not a luxury added on top of anomaly detection; it is what makes the semantic gap that Sommer and Paxson described crossable in practice. The fourth is feedback. Every time an analyst marks an anomaly as benign and records why, that information can be used to suppress similar anomalies in future, or to adjust baselines. Without feedback, an anomaly system keeps rediscovering the same harmless oddities, and analysts lose faith in it. With it, the system gradually learns the shape of the organization's legitimate irregularity. The risk, flagged in Chapter 2, is that feedback can also teach the system to ignore a real attack that analysts habitually dismissed, so suppression should be specific and periodically reviewed rather than broad and permanent. Drift, poisoning and the slow attacker A baseline is a picture of the past, and the past is a moving target. Organizations reorganize, adopt new software, move workloads to the cloud, and change working patterns, as the sudden shift to remote work in 2020 demonstrated dramatically: overnight, the normal location, device and network for most office workers changed, and many behavioral systems spent weeks flagging what had become routine. Baselines must therefore be relearned continually, and that creates a vulnerability. If a baseline is continuously updated from recent activity, a patient attacker can shift it. Activity that begins slowly and increases gradually may be absorbed into the definition of normal before it ever looks anomalous. An attacker who has compromised an account and accesses one new file share a week, instead of ten in an afternoon, may never stand out. This is a form of what the machine learning literature calls poisoning, the deliberate manipulation of training data, and Chapter 5 examines it in more general terms. The practical defenses are to keep long-term reference baselines alongside short-term ones, so that slow drift is visible when compared against a period months earlier; to treat certain changes, such as first-ever access to particularly sensitive systems, as notable regardless of the baseline; and to periodically review which behaviors have been newly absorbed into normal. What behavioral detection is for The fair verdict on behavioral anomaly detection, after nearly forty years, is that Denning's intuition was right but needed to be narrowed. Attackers do have to do things the legitimate owner of an account would not. But the space of things legitimate users do that are also unusual is so large that a general search for anomalies drowns in them. The successful approach starts from the attacker's unavoidable needs, models normal behavior specifically around those needs, aggregates weak signals into entity-level stories, explains itself, and learns from the people who judge its output. Used that way, behavioral detection is one of the few tools capable of finding an intruder who uses only legitimate credentials and legitimate software. Used as a generic "find anything unusual" engine, it becomes the noisiest component in the security stack. The difference lies almost entirely in design choices that have little to do with the choice of algorithm. The next chapter turns from behavior to artifacts: the files an attacker brings, and the problem of recognizing hostile software that nobody has seen before. Hashtags: #AIInCybersecurity #ArtificialIntelligence #Cybersecurity #MachineLearning #ThreatDetection #AutomatedThreatDetection #IncidentResponse #SecurityAutomation #CyberThreatIntelligence #BehavioralAnalytics #AnomalyDetection #MalwareDetection #MalwareClassification #SecurityOperationsCenter #SOC #SecurityInformationAndEventManagement #SIEM #EndpointDetectionAndResponse #EDR #UserAndEntityBehaviorAnalytics #UEBA #ThreatHunting #AlertTriage #AutomatedIncidentResponse #CyberDefense #NetworkSecurity #AdversarialMachineLearning #ZeroDayThreats #FalsePositiveReduction #SecurityOrchestration #AIThreatIntelligence

  • 3D Bioprinting Technologies (Scaffolds, Bioinks, and Tissue Engineering)

    Download the Book (PDF): Introduction On any given day in the United States, roughly 110,000 people are registered on the national transplant waiting list. In 2025 surgeons performed more than 49,000 transplants, a record, and yet the federal organ donation program still estimates that twelve people die each day waiting, and that someone new joins the list every seven minutes [1]. Kidneys account for most of that list. Behind each number is a person on dialysis three times a week, or a person with a failing liver who will be too sick for surgery by the time an organ arrives. The shortage is not a scandal of logistics that better allocation could fix. It is a structural gap between the number of organs that become available when people die and the number of people whose organs fail while they live. Bioprinting is one of several attempts to close that gap by manufacturing, rather than harvesting, the tissue a patient needs. The idea is easy to state and remarkably hard to execute. A bioprinter deposits living cells, suspended in a gel that can hold a shape, layer by layer according to a digital design. In principle the design can come from the patient's own scans, the cells from the patient's own body, and the result can be a piece of tissue that fits, functions, and is never rejected. In January 2026 the US Advanced Research Projects Agency for Health committed up to $176.8 million over five years to five teams trying to do exactly this for the liver and the kidney, with the stated aim of producing immune-matched organs on demand [2]. That a federal agency would write such a check tells you the field has matured. That the target is five years for the first clinical-grade liver tissue, and not for a finished, transplantable liver, tells you how far it still has to go. Why now? Three developments of the past fifteen years have converged to make the ambition credible. The first is the ability to reprogram adult cells into stem cells that can become almost any tissue, which removed the old ceiling on where specialised human cells could come from. The second is a family of printing methods, using light, supporting baths and sacrificial materials, that can build soft, intricate structures including networks of hollow channels at scales that were impossible a decade ago. The third is money and institutional commitment: large pharmaceutical partnerships, dedicated government programmes, and a US regulatory shift since 2022 that has begun to accept human tissue models in place of some animal tests. None of these, alone or together, solves the hard problems. But they have turned bioprinting from a promise into an engineering programme with measurable milestones. The argument of this book The thesis of this book is simple, and it runs against the way bioprinting is usually presented. The hard part of bioprinting is not printing. Machines that place material in three dimensions with micrometre precision are a solved problem; you can buy one for the price of a good car. The hard part is biology at density and scale: keeping enormous numbers of cells alive and doing their jobs inside a printed object, from the moment they leave the nozzle until the day the tissue is integrated into a body. Every important problem in the field is a version of that one. Bioinks are a compromise between what a printer needs and what a cell needs. Vascular networks matter because without them cells more than a fraction of a millimetre from a nutrient supply suffocate. Regulation is hard because a living, changing product cannot be specified and tested the way a hip implant can. If you hold onto that idea, much of the noise around bioprinting resolves. You will understand why the first bioprinted products to reach patients have been thin, avascular, or structurally simple tissues such as cartilage and skin, and why a printed heart that beats in a dish is a different thing from a printed heart that can sustain a person. You will understand why the most commercially durable use of bioprinting so far has been in drug testing, where a small piece of human tissue that lives for a few weeks is already valuable. And you will be able to read the next breathless headline with a working sense of what was actually achieved. What the book covers The chapters move from the physical to the biological to the institutional. Chapter 1 establishes what bioprinting is, how it grew out of tissue engineering, and why the organ shortage frames its ambitions. Chapter 2 explains the printing methods themselves: extrusion, droplet-based, laser-assisted, light-based and embedded printing, with attention to what each does to the cells passing through it. Chapter 3 is about bioinks, the hydrogels and other materials that carry cells, and the tension between printability and biocompatibility that shapes every formulation. Chapter 4 turns to the cells: where they come from, how many are needed, how they survive the printing process, and how a printed object becomes a working tissue in the days and weeks afterwards. Chapter 5 deals with scaffolds and architecture, the question of how much structure must be supplied from outside and how much the cells can build for themselves. Chapter 6 confronts the central obstacle, vascularisation, in detail: the physics of oxygen diffusion, the techniques for printing channels that blood or culture medium can flow through, and the newer computational approaches to designing vascular trees. Chapter 7 surveys what has actually left the laboratory, from an ear implant made of a patient's own cartilage cells to printed liver tissue used by pharmaceutical companies to bioprinted insulin-producing tissue in animal studies. Chapter 8 traces the regulatory path that any printed tissue must travel in the United States and Europe, and explains why the rules for cell therapies, not the rules for 3D-printed devices, are the ones that govern. The conclusion considers what follows from all this: what kinds of printed organs are plausible, on what timescale, and how bioprinting fits alongside its competitors, including genetically engineered pig organs that entered formal clinical trials in 2025. A note on scope This book concentrates on bioprinting for human tissue replacement and on the closely related use of printed tissue as a model for testing drugs. It does not cover the large and mature business of 3D-printing non-living medical devices such as titanium spinal cages or dental aligners, except where those devices serve as scaffolds for cells. It also says little about food printing or cultivated meat, which use some of the same tools but face entirely different economics. Where the evidence comes from animal studies or cell cultures rather than human patients, the text says so, because that distinction is the single most common casualty of popular reporting on the field. Technical vocabulary is introduced as it is needed and collected in a short glossary at the back. No background in biology or engineering is assumed beyond what an attentive reader of a good newspaper science section would have. What is assumed is a willingness to follow a mechanism step by step, because in this field the mechanisms are the story. A cell does not care how impressive a printer looks. It cares how much force it felt in the nozzle, how far it sits from the nearest supply of oxygen, and whether the gel around it gives it something to hold onto. The rest of this book is about those three questions and what engineers, biologists and regulators have learned in trying to answer them. Chapter 1: From Tissue Engineering to Bioprinting In 1993 the chemical engineer Robert Langer and the surgeon Joseph Vacanti published a short article in Science that gave a name and a programme to a field that barely existed. They called it tissue engineering, and they defined it as the application of engineering and the life sciences to building biological substitutes that restore, maintain or improve the function of tissues [3]. The recipe they described has three ingredients that are still the vocabulary of the field: cells, a scaffold for the cells to live on, and signals, chemical or mechanical, that tell the cells what to become. Four years later a photograph made the programme famous. It showed a hairless laboratory mouse with what looked like a human ear growing on its back. The "ear" was a biodegradable polymer scaffold in the shape of an ear, seeded with cartilage cells from a cow and implanted under the mouse's skin. It was not a human ear and it was not grown from human cells, but it made an argument visible: give cells the right shape to occupy and they will fill it. Bioprinting is best understood as the attempt to put that argument under digital control. The classical tissue engineering approach made a porous scaffold first and then poured or pipetted cells onto it, hoping they would migrate inside and distribute themselves evenly. They often did not. Cells settled at the surface, the interior stayed empty or died, and there was no way to place one cell type here and another there. Bioprinting reverses the order of operations. Cells and their supporting material are deposited together, at defined positions, so that the architecture of the tissue is set at the moment of fabrication rather than left to chance. Three lines of descent The technology has three ancestors, and each still shows in how the field works today. The first is additive manufacturing. Charles Hull's stereolithography patent in the mid-1980s described building solid objects by curing a liquid resin with ultraviolet light, one thin layer at a time, guided by a computer model. Fused deposition modelling, in which a heated nozzle extrudes a plastic filament, followed soon after. By the 2000s these methods were routine in engineering and were beginning to be used in medicine for anatomical models and custom implants. They brought with them a workflow that bioprinting inherited almost unchanged: a three-dimensional digital model, software that slices the model into layers, and a machine that turns each layer into a set of toolpath instructions. The second ancestor is the inkjet printer. In the early 2000s Thomas Boland and colleagues, then at Clemson University, modified commercial desktop inkjet printers to dispense proteins and living cells instead of ink [4]. The cartridges were cleaned, refilled with cell suspensions, and the paper feed was replaced with a stage that held a dish of gel. The early results were crude, but they established two important facts: mammalian cells could survive passage through a printhead in large proportions, and droplets of cells could be placed in patterns with a resolution measured in tens of micrometres. The researchers who followed, including Vladimir Mironov and Gabor Forgacs, began to talk about "organ printing" as a coherent goal. The third ancestor is developmental biology. Forgacs, a physicist by training, was interested in how embryonic tissues fuse and sort themselves. He observed that small spheres of cells, placed next to one another, would merge in a matter of days, much as droplets of liquid coalesce. This suggested a different philosophy of printing: rather than building every microscopic detail, place cell aggregates in roughly the right arrangement and let the cells' own tendency to self-organise do the fine work. Forgacs co-founded the company Organovo in 2007 on this premise. It remains an influential idea, because it recognises that cells are not inert pixels. They move, divide, pull on their surroundings, remodel them, and talk to their neighbours. These three lines produce a definition. Bioprinting is the computer-controlled, layer-by-layer deposition of living cells, alone or together with biomaterials and biological molecules, to create three-dimensional structures that are intended to function as tissue. The word "intended" matters. Most printed constructs in the scientific literature are not yet tissue in the full sense. They are arrangements of cells that will, if conditions are right, mature into something tissue-like over days or weeks. What an organ actually is The phrase "printing an organ" suggests that an organ is a shape. It is not. An organ is a hierarchy of structures, each of which has a job, organised across a range of sizes from the molecular to the macroscopic. Consider the kidney. Each human kidney contains roughly a million nephrons, the microscopic filtering units. Each nephron begins with a glomerulus, a tuft of capillaries a fraction of a millimetre across, whose walls are specialised to let water and small molecules through while holding back blood cells and most proteins. The filtrate then passes through a long tubule lined with at least a dozen distinct cell types, which reabsorb glucose, salts and water in carefully regulated amounts. Every nephron is wrapped in its own capillary network, and the whole organ is served by an arterial tree that branches from a vessel the width of a pencil down to capillaries narrower than a red blood cell. The kidney also produces hormones, responds to signals from the brain and the heart, and adjusts its function minute by minute. No printer places a million nephrons. The question for bioprinting is therefore never just whether a shape can be reproduced. It is which levels of the hierarchy must be built by the machine, and which can be left to the cells. A printed kidney does not need to have every capillary drawn into the design file, if the cells can be persuaded to sprout their own capillaries. But it does need the large vessels, because cells cannot grow a pencil-width artery fast enough to keep themselves alive, and it needs the right cell types in roughly the right places, because a mixed soup of kidney cells will not sort itself into a million nephrons. This is why the useful way to classify tissues for bioprinting is by complexity, a ladder that has been described in similar terms by many researchers including Anthony Atala at the Wake Forest Institute for Regenerative Medicine. The lowest rung is flat tissue such as skin, which is a few cell layers thick and can be nourished from below. Next come tubular structures such as blood vessels, the windpipe and the urethra, which are hollow and carry fluid or air but have relatively simple walls. Next come hollow non-tubular organs such as the bladder or stomach, which have more complex walls and must stretch and contract. At the top are solid organs such as the liver, kidney, heart and lung, which are dense with cells, packed with blood vessels, and perform many functions at once. Every step up the ladder multiplies the difficulty, and the steps are not evenly spaced. The jump from hollow organs to solid ones is far larger than all the others combined, because solid organs are where the vascular problem becomes overwhelming. Atala's group showed in 2006 that the lower rungs were reachable even before bioprinting. They built bladders for seven young patients by seeding a bladder-shaped scaffold of collagen and synthetic polymer with the patients' own bladder muscle and lining cells, growing the construct in the laboratory for several weeks, and then implanting it [5]. The engineered bladders functioned for years in follow-up. That work was hand-seeded rather than printed, but it set the template for what bioprinting promises to do faster, more reproducibly, and for more complex tissues. Why print, and what printing cannot do A sceptic could reasonably ask why tissue needs to be printed. Cells can be grown on scaffolds; scaffolds can be moulded or spun into fibres. The answer lies in four capabilities that printing provides and other methods do not. The first is spatial control of composition. A printer can lay down cartilage cells in one region and bone-forming cells in the adjacent region, which matters for an interface such as the end of a long bone where the two tissues meet. It can place liver cells next to the support cells that keep them functioning, in a repeating pattern that resembles the liver's own microscopic architecture. A moulded or seeded scaffold cannot do this. The second is internal architecture. A printer can create channels, pores and voids inside an object, with sizes and positions specified in advance. That matters most for vascularisation, the subject of Chapter 6, but it also matters for allowing nutrients to reach cells and for controlling how the construct degrades. The third is patient specificity. Because the design is a digital file, it can be generated from a CT or MRI scan of the individual patient. A child with microtia, a congenital malformation of the outer ear, can receive an ear shaped like a mirror image of the healthy ear on the other side. A patient with a defect in the jaw after cancer surgery can receive a graft that fits the exact contour of the bone that was removed. This is the most mature advantage of the technology and it is the one that 3D printing of non-living implants has already proved in clinical practice. The fourth is automation and reproducibility. Hand-seeding scaffolds is an artisanal craft. Two technicians, or the same technician on two days, produce different results. A printer running a validated protocol produces the same object every time, within its tolerances. For a laboratory this is a convenience. For a regulator deciding whether to approve a product made from living cells, it is close to a precondition, for reasons Chapter 8 will make clear. The same honest accounting requires naming what printing does not provide. A printer does not make cells; they must be obtained, expanded and kept healthy beforehand, which is often the most expensive and time-consuming part of the whole process. A printer does not make tissue mature; a freshly printed construct is closer to a scaffold dotted with cells than to a functioning organ, and it must spend days to weeks in a bioreactor or in the body before it behaves like tissue. And a printer does not guarantee survival. Every printing method imposes some stress on cells, and every printed object above a certain thickness faces a nutrient supply problem that the printer itself does nothing to solve. The field's history is partly a history of learning these limits. In 2011 Atala gave a widely viewed public talk in which a printer on stage built a kidney-shaped object. It was a demonstration of shape, not of function, and Atala said as much, but the image travelled further than the caveat. A decade and a half later, no printed kidney has filtered blood in a human being. What has happened instead is slower and more instructive: the gradual mapping of what cells need in a printed environment, and the invention of materials and methods to provide it. The organ shortage as context, not deadline The organ shortage gives bioprinting its moral urgency and much of its funding. It also distorts expectations. Because the need is so stark, it is tempting to measure progress by asking how close the field is to a transplantable printed kidney or liver. That is the wrong measure for most of the work being done. A more useful measure asks which clinical problems can be solved by tissues that are already within reach. There are many. Children born with microtia currently undergo reconstruction using cartilage carved from their own ribs, a painful operation that leaves a chest scar and depends heavily on the surgeon's artistry. Burn patients need skin cover faster than donor sites can regenerate. Patients with osteoarthritis need cartilage repair. People with type 1 diabetes need insulin-producing cells that can be implanted without lifelong immune suppression. Patients with failing livers sometimes need only temporary support to survive until their own liver regenerates. Each of these is a problem that a partial, simpler printed tissue could address, and each provides a stepping stone of regulatory precedent, manufacturing experience and clinical data toward the harder goals. Pharmaceutical development provides another context in which printed tissues are valuable long before they are transplantable. Most experimental drugs fail in human trials, and a substantial share of those failures come from toxicity that animal studies did not predict, liver toxicity in particular. A small piece of human liver tissue that survives for a few weeks in a dish and metabolises drugs the way a human liver does can catch some of those failures early. Organovo built its first commercial business around exactly such a product in the mid-2010s. The economics proved difficult, as Chapter 7 describes, but the scientific logic was sound, and US regulatory reforms since 2022 that loosen the requirement for animal testing have strengthened it. By the end of this chapter the outline of the field should be clear. Bioprinting is additive manufacturing applied to living material. Its tools come from engineering, its materials from polymer chemistry and biology, its ambitions from medicine. It can control where cells go, what they sit in, and what shape the result takes. It cannot, by itself, keep cells alive at the densities found in real organs or make them behave like a mature tissue. Those are biological problems, and they set the real pace of progress. The chapters that follow take the problem apart in the order a bioprinted tissue meets it. First comes the machine and how it handles cells. Then comes the material the cells are suspended in, then the cells themselves, then the structure that holds everything together, then the blood supply that keeps it alive, then the evidence from patients and laboratories, and finally the regulatory path from a laboratory construct to an approved therapy. At each step the same question recurs: what does the cell need, and how much of that can a manufacturing process provide? Chapter 2: How Bioprinters Place Living Cells Every bioprinter solves the same physical problem. It must move a material containing living cells from a reservoir to a precise position in space, and then make that material stay where it was put. The methods differ in how they move the material, how they fix it in place, and, crucially, what they do to the cells along the way. A printing method that produces beautiful shapes but kills half the cells is not a bioprinting method in any useful sense. Nor is one that keeps every cell alive but can only make structures a few hundred micrometres thick. This chapter walks through the five families of technique that matter today, and judges each by the three criteria that actually determine its usefulness: resolution, the density of cells it can handle, and the fraction of those cells that survive. Extrusion: the workhorse The great majority of bioprinting work in academic laboratories and in early commercial products uses extrusion. The principle is the same as squeezing icing from a piping bag. A cartridge, usually a plastic syringe, is filled with a cell-laden gel. Pressure is applied, by compressed air, by a mechanical piston, or by a rotating screw, and the gel emerges from a fine nozzle as a continuous filament. The nozzle moves over the build platform, tracing each layer of the design, and the platform drops or the nozzle rises before the next layer is drawn on top. Extrusion has three great virtues. It handles very viscous materials, which means it can print gels thick enough to hold their own shape. It can print at high cell densities, including dense pastes of cells with little or no added material, and even pre-formed clusters of cells called spheroids. And it is mechanically simple and cheap, so that commercial extrusion bioprinters from companies such as CELLINK, part of the Swedish group BICO, and 3D Systems, which acquired the bioprinter maker Allevi in 2021, are found in hundreds of university laboratories. Many machines carry several printheads, each loaded with a different material or cell type, so that one object can contain several compositions. The weaknesses of extrusion follow from the same physics. Filaments are rarely finer than about 100 micrometres, and more often 200 to 400 micrometres, which is coarse compared with the scale of capillaries or individual cells. And extrusion exposes cells to mechanical stress. As gel flows through a narrow nozzle, the layers of fluid near the wall move more slowly than those in the centre, and the resulting shear stretches and tears cells caught in the gradient. The stress rises steeply as the nozzle narrows and as pressure increases. A study by Andreas Blaeser and colleagues in 2016 quantified the effect directly, showing that cell viability stayed high at modest shear stresses but fell sharply once stresses rose above roughly 5 to 10 kilopascals, and that even cells that survived suffered reduced ability to multiply [6]. This sets up a trade-off that runs through all extrusion printing: a finer nozzle gives better resolution but harsher shear; a stiffer gel holds its shape better but needs more pressure to push. Designers mitigate the problem with tapered conical nozzles, which reduce the length of the high-shear region, and with gels that thin under shear and recover afterwards, a property discussed in Chapter 3. A refinement worth knowing about is coaxial and microfluidic extrusion. Instead of a single channel, the printhead contains concentric or merging channels, so that, for instance, a cell-laden alginate solution flows in the core while a calcium chloride solution flows around it. The two meet at the tip and the alginate solidifies instantly into a fibre or a hollow tube. The Vancouver company Aspect Biosystems built its platform around microfluidic printheads of this kind, which allow rapid switching between materials within a single filament. Droplets and lasers Droplet-based printing places material as a sequence of tiny discrete drops rather than a continuous filament. The original form, as noted in Chapter 1, borrowed directly from office inkjet printers. In a thermal inkjet head, a tiny resistor heats a thin film of liquid for a few microseconds, vaporising it and creating a bubble that expels a droplet through a nozzle. The temperatures at the resistor surface are high, but the heating is so brief and so localised that the bulk of the liquid, and the cells in it, warm by only a few degrees. In a piezoelectric head, a crystal that changes shape when voltage is applied squeezes the chamber mechanically instead. In both cases droplets are measured in picolitres, and positions can be controlled to tens of micrometres. A related approach uses microvalves, which open briefly to release a drop from a pressurised reservoir and tolerate somewhat thicker fluids. The strength of droplet printing is precision and speed of placement for low-viscosity materials. It is well suited to depositing patterns of cells, growth factors or drugs onto a surface, and to building thin layered tissues such as skin, where one can deposit successive layers of different cell types. Its fundamental limitation is that it works only with thin, watery fluids; a thick gel will not form clean droplets. Thin fluids hold little shape, so droplet-printed structures must be solidified immediately, by a chemical crosslinker in the receiving bath or by light, and tall constructs are difficult. Dense cell suspensions also cause trouble: cells settle in the reservoir, clump, and clog nozzles a few tens of micrometres wide. In practice, droplet methods work best at cell densities well below those of real tissue. Laser-assisted bioprinting, also called laser-induced forward transfer, takes a different approach. A transparent glass slide, the "ribbon", is coated on its underside with a thin layer of laser-absorbing metal such as gold or titanium, and below that a layer of cell-laden gel. A pulsed laser is focused through the glass onto the metal. Each pulse vaporises a tiny spot of the absorbing layer, generating a high-pressure bubble that propels a jet of gel and cells downward onto a receiving surface a short distance below. Because there is no nozzle, nothing clogs, and because the energy is absorbed by the metal layer rather than the cells, survival is typically very high, often above 95 percent in published work. The technique can place cells with a resolution approaching that of a single cell, and it handles a range of viscosities. Its drawbacks are cost, complexity, and throughput: laser systems are expensive, each ribbon must be prepared with cells in advance, and building a large object drop by drop is slow. The French company Poietis, based near Bordeaux, has developed laser-assisted printing toward clinical use, with a focus on skin, and installed a printing platform in a Marseille public hospital system in collaboration with Assistance Publique–Hôpitaux de Marseille to prepare a clinical trial of bioprinted skin. Light and supporting baths Light-based methods descend from stereolithography. A vat contains a liquid that solidifies when exposed to light because it contains photoreactive polymers and a photoinitiator, a molecule that absorbs light and starts the chemical reaction that links polymer chains together. In digital light processing, a projector of the kind used in conference rooms displays an entire cross-sectional image of the object at once, solidifying a whole layer in a few seconds. The platform then moves by one layer thickness and the next image is projected. Resolution is set by the pixel size of the projector and the depth to which light penetrates, and is typically in the range of tens of micrometres, considerably finer than extrusion. Because there is no nozzle, there is no shear stress. Early photocrosslinking used ultraviolet light and photoinitiators such as Irgacure 2959, which raised concerns about damage to cell DNA. The field has largely moved toward visible blue light at around 405 nanometres and more efficient initiators such as lithium phenyl-2,4,6-trimethylbenzoylphosphinate, universally called LAP, which allow shorter exposures at lower intensity. The remaining concerns are the reactive molecules generated during crosslinking, which can harm cells if their concentration is too high, and the scattering of light by cells themselves, which blurs the image when cell densities are high. The most striking development in light-based printing came in 2019, when Paulina Núñez Bernal, Riccardo Levato and colleagues at Utrecht, working with the EPFL group that developed the underlying optics, published volumetric bioprinting [7]. Instead of building layer by layer, the method builds the whole object at once. A transparent vial of cell-laden gel rotates while a projector shines a carefully computed sequence of images through it from the side, much as a CT scanner reconstructs an image from many angles but in reverse. Each image deposits a small dose of light; only where the accumulated dose from all angles crosses a threshold does the gel solidify. The result was centimetre-scale, anatomically shaped constructs, including a model of a meniscus and structures with internal channels, printed in seconds to tens of seconds with cell viability above 85 percent. The Swiss company Readily3D now sells instruments based on the method. Speed matters here for biological reasons as much as convenience: cells sitting in a cartridge for hours lose viability, so a process that finishes in under a minute removes an entire source of damage. At the opposite extreme, two-photon polymerisation uses a tightly focused femtosecond laser in which crosslinking occurs only at the tiny focal point where two photons are absorbed simultaneously. It can write features smaller than a micrometre, finer than a single cell, but only very slowly, which restricts it to microscopic scaffolds and research questions rather than tissue-scale objects. A different line of innovation attacked a problem that limited every method above. Soft gels, the kind cells like best, cannot support their own weight. Print a tall structure from a gel as soft as brain tissue and it slumps into a puddle before it can be solidified. One answer, explored in Chapter 3, is to make the gel stiffer. Another is to print the soft gel inside a supporting medium that holds every part of the object in place until it sets. Embedded printing places the nozzle inside a bath of a granular material, a slurry of microscopic gel particles packed together. At rest, the packed particles behave like a soft solid and hold whatever is deposited within them. When the nozzle moves through, the particles locally yield and flow like a liquid, letting the nozzle pass, then immediately re-pack behind it. The printed filament is trapped exactly where it was laid. Two groups described versions of the idea in 2015, Thomas Angelini's group at the University of Florida using a granular microgel, and Adam Feinberg's group at Carnegie Mellon University using a slurry of gelatin microparticles in a method they named Freeform Reversible Embedding of Suspended Hydrogels, or FRESH [8]. The gelatin bath has a convenient property: it melts at body temperature, so once printing is complete the whole block can be warmed and the support simply flows away, leaving the printed object behind. The significance of FRESH became clear in 2019, when Feinberg's group used it to print structures from pure collagen, the most abundant protein in the human body and the main structural material of most tissues [9]. Collagen is extremely difficult to print on its own because it is runny until it gels, and it gels slowly. In the gelatin support bath, the team used a pH change to trigger collagen gelling and printed components of the human heart, including a tri-leaflet valve and a model of a neonatal heart's anatomy derived from an MRI scan, with features reported at around 20 micrometres. They also printed small ventricles containing heart muscle cells that contracted in synchrony. A Pittsburgh spinout, FluidForm Bio, is now developing FRESH-printed tissues toward therapy. Embedded printing also enables a related strategy used in vascularisation, in which a sacrificial ink is printed inside a living bath of cells and later removed to leave hollow channels. Chapter 6 returns to it. Comparing the methods, and the problem of speed No single method dominates. Table 1 summarises the families discussed in this chapter. Ranges are representative values drawn from review literature, notably the overview by Sean Murphy and Anthony Atala in Nature Biotechnology [10], and from the primary studies cited in this chapter; individual systems vary widely. Table 1. The main bioprinting methods compared. Method Typical resolution Cell density tolerated Main stress on cells Best suited to Extrusion 100–400 µm filaments High, including spheroids Shear in the nozzle Thick, multi-material constructs Inkjet and microvalve 20–100 µm droplets Low to moderate Brief heat or pressure pulses; nozzle clogging Thin layers, patterning on surfaces Laser-assisted transfer Near single-cell Moderate Minimal; jet impact High-precision placement, skin Projection and volumetric light Roughly 20–80 µm Moderate; cells scatter light Light exposure and reactive species Fine architecture, rapid builds Embedded (FRESH and similar) Down to about 20 µm in collagen Moderate to high Shear, as in extrusion Very soft materials, complex anatomy Resolution and viability dominate most discussions of printing methods. Speed deserves equal attention, because it becomes decisive as constructs grow toward the size of real organs. A simple calculation makes the point. Suppose an extrusion printer builds a solid cube 10 centimetres on a side, roughly the scale of a large piece of liver, with filaments 200 micrometres wide stacked in 200-micrometre layers. Each layer needs 500 parallel lines, each 10 centimetres long, which is 50 metres of filament. At a typical bioprinting speed of 10 millimetres per second, one layer takes about 5,000 seconds, nearly an hour and a half. The cube needs 500 layers, so the total is around 2.5 million seconds, or roughly a month. Cells sitting in a cartridge, or in the lower layers of a construct that is not yet perfused, will not survive a month. The practical consequences are threefold. First, organ-scale printing will need methods that are orders of magnitude faster than single-nozzle extrusion, which is why volumetric light-based printing and multi-nozzle arrays attract so much interest. Second, it pushes designers toward strategies in which the printer builds only the architecture that matters, such as large vessels and compartment boundaries, while densely packed cells or cell aggregates fill the rest in bulk. Third, it means that keeping cells alive during printing, not just after it, is a design requirement. The Stanford group led by Mark Skylar-Scott, which is developing methods to print heart tissue, has made exactly this point in describing its efforts to scale up both cell production and printing speed for a human-sized organ. Choosing a printing method is never a neutral technical decision. It constrains which materials can be used, how many cells can be included, how fine the architecture can be, and how large the final object can become. An extrusion system commits the designer to materials that thin under shear and recover quickly. A light-based system commits the designer to photocrosslinkable materials and to managing light scattering. An embedded system commits the designer to a compatible support bath and a gentle way of removing it. In every case the cells come second to the physics of the process, and the art of bioprinting lies in finding a process whose physics the cells can tolerate. That art is concentrated, above all, in the material the cells are suspended in. The next chapter turns to the bioink, the substance that must satisfy the printer and the cell at once. Chapter 3: Bioinks and the Biofabrication Window A bioink is the material that carries cells through a printer and holds them in place afterwards. It is the single most consequential choice in any bioprinting project, and it is a compromise from the start. The printer wants a material that flows easily under pressure, solidifies instantly and completely once deposited, and is stiff enough to support the layers above it. The cell wants something quite different: a soft, wet, porous environment that resembles the natural matrix of the tissue it came from, that it can grip, migrate through, remodel and eventually replace with material of its own. Most materials that satisfy the printer are hostile to cells, and most materials cells love are nearly impossible to print. In 2013 Jos Malda and colleagues gave this tension a name that the field has used ever since: the biofabrication window [11]. Picture a chart with printability rising along one axis and cell compatibility along the other. Stiff, densely crosslinked polymers sit high on printability and low on cell compatibility; they print crisp shapes but trap cells in a mesh too tight to move or divide. Very dilute, soft gels sit at the other end; cells thrive in them but they spread into puddles. The traditional practice was to choose a point somewhere in the middle and accept mediocrity on both counts. Much of the progress of the past decade has come from finding ways to widen the window, so that a material can be printable during fabrication and cell-friendly afterwards. What makes a material printable Three physical properties determine whether a gel will print well, and understanding them explains most bioink design decisions. The first is viscosity, a measure of resistance to flow. Honey is more viscous than water. A bioink must be viscous enough that it does not drip from the nozzle or spread once deposited, but not so viscous that pushing it through a nozzle requires pressures that tear cells apart. The second, and the most important, is shear thinning. Many gels become runnier when they are forced to flow and thicken again when the flow stops. Ketchup is a familiar example: it sits in the bottle until shaken, then pours. For bioprinting this behaviour is close to ideal. In the nozzle, where the material is sheared, it thins and flows at modest pressure, reducing the stress on cells. Once deposited, it thickens and holds its filament shape. Polymers with long, entangled chains, such as alginate and hyaluronic acid at sufficient concentrations, shear thin naturally, and additives such as nanocellulose fibres or Laponite clay nanoparticles are used to strengthen the effect. The third is yield stress and recovery. A material with a yield stress behaves as a solid until a threshold force is applied, then flows. Toothpaste is the textbook example. A bioink with a modest yield stress will not slump under its own weight after printing, and the speed with which it recovers its solid-like behaviour after leaving the nozzle determines how sharp the printed shape will be. These properties get the material onto the build platform in the right shape. But a shear-thinning gel is still a gel that can be pulled apart, and the printed object must survive handling, culture and implantation. So nearly every bioink also undergoes a second, more permanent solidification called crosslinking, in which chemical or physical bonds tie the polymer chains together into a network. There are four main crosslinking strategies, and each carries its own implications for the cells. Ionic crosslinking is the simplest and most widely used. Alginate, a sugar polymer extracted from brown seaweed, consists of chains carrying negative charges. When a solution containing doubly charged calcium ions meets it, each calcium ion bridges two chains, and the solution sets into a gel within seconds. This is the same chemistry used in molecular gastronomy to make fruit-juice "caviar". In bioprinting, calcium may be added to the bath, sprayed onto each layer, or delivered through the outer channel of a coaxial nozzle. The reaction is mild and fast, which is why alginate became the default material of early bioprinting. Its weakness is that the bonds are reversible: in the body, calcium gradually exchanges with sodium and the gel slowly loses strength in an uncontrolled way. Thermal gelation exploits materials that change state with temperature. Gelatin, which is collagen that has been partly broken down by heat, dissolves when warm and sets when cooled below roughly room temperature, which is why jelly sets in the refrigerator. Collagen itself does the opposite in a sense: acidic collagen solutions gel when neutralised and warmed toward body temperature. A synthetic material, Pluronic F-127, is liquid when cold and gels when warmed, and is useful precisely because the process reverses, as Chapter 6 will show. Thermal gelation is gentle, but it is slow compared with ionic crosslinking, and gelatin on its own melts at body temperature, which means it cannot hold a shape inside an incubator or a patient without additional crosslinking. Photocrosslinking uses light, as described in Chapter 2. A polymer is chemically modified with reactive groups, most often methacrylate groups, and mixed with a photoinitiator. Exposure to light of the right wavelength links the groups into a permanent network. The most important example is gelatin methacryloyl, universally known as GelMA. First described in 2000 by a group in Ghent and developed extensively in the following decade, notably by Ali Khademhosseini's laboratory, GelMA has become the most widely used bioink in academic research [12]. It combines the cell-friendliness of gelatin with the ability to be fixed permanently by light. Crucially, its stiffness can be tuned by changing the polymer concentration, the degree of methacrylation, or the light dose. Enzymatic crosslinking borrows the body's own chemistry. Fibrinogen, a blood protein, is converted to fibrin, the structural material of a blood clot, by the enzyme thrombin. Mixing the two produces a soft, natural gel that cells readily invade and remodel. Other enzymes, such as transglutaminase, can crosslink gelatin. These reactions are very gentle but harder to time precisely during printing, so fibrin is often used in combination with other materials that provide printability while it provides biology. The main materials Bioink materials fall broadly into natural polymers, which come from living organisms, and synthetic polymers, which are made in a chemical plant. Natural materials tend to offer the biochemical cues cells recognise; synthetic materials tend to offer control and consistency. Collagen is the gold standard of biological relevance. It is the main protein of the extracellular matrix, the material between cells that gives most tissues their strength. Cells bind to collagen through surface receptors called integrins, and collagen can be degraded and remodelled by enzymes that cells secrete, which is how cells move through tissue and replace old matrix with new. The obstacle to printing collagen is its slow gelation and low viscosity at the concentrations cells tolerate, which is why the embedded FRESH method, which held liquid collagen in place long enough to gel, was such a significant advance. Gelatin and GelMA keep much of collagen's biological activity. Gelatin retains the short amino-acid sequences, the best known being the three-letter sequence arginine-glycine-aspartic acid abbreviated RGD, that integrins bind to, as well as the sites at which cell enzymes cut the matrix. That is why cells spread and migrate in soft GelMA when they would sit as isolated spheres in alginate. Alginate is cheap, gentle and easy to print, but it is biologically inert: mammalian cells have no receptors for it and no enzymes to break it down. Cells embedded in plain alginate remain rounded and isolated. To overcome this, chemists graft RGD peptides onto the alginate chains, or mix alginate with gelatin or collagen. Alginate's inertness can also be an advantage, for example in encapsulating insulin-producing cells, where the goal is to shield transplanted cells from the immune system rather than invite cells in. Hyaluronic acid is a large sugar polymer abundant in cartilage, skin and the fluid that lubricates joints. It is biologically active, influencing cell behaviour through specific receptors, and like gelatin it can be chemically modified for photocrosslinking. Jason Burdick's group, first at the University of Pennsylvania, has made extensive use of modified hyaluronic acid, including versions that crosslink through reversible "guest–host" interactions, which make it shear thinning and self-healing. Decellularised extracellular matrix offers the most complete biological signal. Tissue from an animal, often a pig, is washed with detergents and enzymes until the cells are removed, leaving the protein and sugar framework behind. The matrix is then dried, ground and digested into a solution that can be printed and gelled. Falguni Pati, Dong-Woo Cho and colleagues showed in 2014 that bioinks made from decellularised heart, cartilage and fat tissue supported cell behaviour specific to each tissue of origin [13]. The drawback is variability: matrix from different animals, or different batches of the same process, differs in composition, and the gels are mechanically weak. Synthetic polymers, chief among them polyethylene glycol (PEG), are the opposite case. PEG is chemically defined, reproducible, and almost completely inert to cells. That inertness is a blank canvas: chemists can attach exactly the adhesion sequences, degradable links and growth factors they want, at controlled densities, and study how each affects cells. Synthetic gels are valuable when reproducibility and regulatory clarity matter most, and they are often used as the base for "designer" matrices. Matrigel, a protein mixture secreted by a mouse tumour cell line, deserves a brief mention because it is so widely used in biology for growing organoids. It is biologically rich and cells love it, but its composition varies from batch to batch and its tumour origin makes it unsuitable for clinical products. Its prominence in laboratory work is a reminder that the bioinks that produce the best research results are not always the ones that can be used in patients. Table 2 summarises the materials most often used, comparing how each sets, whether cells can bind to it, and its principal limitations. The characterisations are qualitative summaries from the review literature cited in this chapter. Table 2. Common bioink materials and their trade-offs. Material Source How it sets Cell adhesion Main limitation Alginate Brown seaweed Calcium ions, seconds None unless modified Inert; slow, uncontrolled loss of strength Gelatin / GelMA Animal collagen, processed Cooling; light for GelMA Yes (RGD sites) Animal-derived; batch variation Collagen type I Animal or recombinant Warming and neutral pH Yes, native Runny and slow to gel Fibrin Blood proteins Thrombin enzyme Yes Soft; degrades quickly Hyaluronic acid (modified) Bacterial fermentation Light or guest–host bonds Partial, via receptors Requires chemical modification Decellularised matrix Animal tissue Warming and neutral pH Yes, tissue-specific Weak; variable composition PEG-based Synthetic Light or click chemistry None unless modified Must be engineered for biology What cells feel, and how to widen the window Once a gel is set, three further properties determine what the cells experience. Stiffness is perhaps the most influential. In a landmark 2006 study, Adam Engler, Dennis Discher and colleagues showed that mesenchymal stem cells grown on gels of different stiffness tended toward different fates: soft gels resembling brain tissue favoured nerve-like cells, intermediate stiffness resembling muscle favoured muscle-like cells, and stiff gels resembling the matrix of developing bone favoured bone-like cells [14]. Cells sense stiffness by pulling on their surroundings through their integrin attachments and gauging the resistance. A bioink for cartilage or bone therefore needs to be stiffer than one for liver or brain. Native soft tissues range from well under one kilopascal for brain to tens of kilopascals for muscle, while cartilage is far stiffer still. The difficulty is that many bioinks that are stiff enough to print well are stiffer than the tissue they are supposed to mimic. Porosity, at the scale of the polymer network, determines how readily oxygen, nutrients and waste diffuse through the gel and whether cells can extend processes or migrate. A dense network with a mesh size of a few nanometres lets small molecules through but traps cells in place. A cell embedded in such a gel can only move by digesting the gel, which brings in the third property. Degradation must be matched to the pace at which cells build their own matrix. If a gel degrades too fast, the construct loses its shape before the cells have replaced it. If it degrades too slowly, the cells remain imprisoned and the tissue never matures. Natural materials such as collagen, gelatin and fibrin are degraded by enzymes that cells produce, so degradation tracks cell activity. Synthetic gels can be built with peptide links that the same enzymes cut, giving them the same responsive behaviour. Alginate, by contrast, degrades on its own timetable, with no connection to what the cells are doing. The most interesting bioink research of the past decade has not been the search for a single perfect material, which probably does not exist, but strategies that decouple printability from the final environment. One strategy is to print in one state and use in another. GelMA, for example, can be printed cool, when the gelatin component has partly set and gives the ink body, and then fixed permanently by light, after which it is warmed to body temperature without melting. Printability is supplied by the temporary thermal gel; stability by the permanent photocrosslinks. A second strategy uses sacrificial components. A bioink may contain a thickener that makes it printable and is then washed out. Gelatin, which melts at 37 degrees Celsius, is commonly blended into other inks for this purpose, so that after printing and crosslinking the gelatin dissolves away, leaving a softer, more porous network for the cells. A third strategy is to change the material's structure from a continuous gel to a packed bed of microscopic gel particles, a so-called granular or microgel bioink. Packed particles flow under shear and jam when stationary, giving excellent printability, while the spaces between particles provide room for cells to migrate and for nutrients to flow. Once printed, the particles can be bonded to one another to stabilise the structure. A fourth strategy is to print into a supporting bath, as described for FRESH in Chapter 2, which removes the need for the ink to support itself at all. With the bath doing the structural work, the bioink can be as soft as the cells require. A fifth strategy reduces the bioink to a minimum. If cells are packed so densely that they behave as a paste, the material between them can be a thin film. This is the logic of printing cell spheroids or dense cell slurries, and it brings bioprinting closer to the cell densities found in real organs, a question taken up in Chapter 4. A worked example: formulating a cartilage bioink To see how these considerations combine, consider a laboratory designing a bioink for printing cartilage to repair a defect in a knee. The cells are chondrocytes, cartilage cells, obtained from a small biopsy of the patient's own cartilage and expanded in culture. The team first chooses a base material. Cartilage matrix is rich in collagen type II and in hyaluronic acid and related sugars, so a hyaluronic acid derivative or GelMA, or a blend of the two, is a natural starting point. GelMA provides attachment sites; hyaluronic acid provides tissue-specific signals that help chondrocytes keep making cartilage matrix rather than drifting toward the scar-like fibrous tissue that expanded chondrocytes tend to produce. Next the team sets the concentration. Too dilute and the construct will be too soft to survive in a load-bearing joint and will not print cleanly; too concentrated and the dense network will restrict the cells from depositing new matrix. Published formulations commonly use GelMA somewhere in the range of 5 to 10 percent by weight, with the exact choice found by experiment. The photoinitiator, typically LAP, is added at a fraction of a percent, and the light dose is set to the minimum that gives a stable gel, to limit exposure of cells to reactive molecules. The team then checks printability. It measures the ink's viscosity across a range of shear rates to confirm shear thinning, prints test lattices to see whether filaments keep their width and whether pores between them stay open, and adjusts the printing temperature to use gelatin's thermal setting as a temporary support. It counts living and dead cells immediately after printing and at intervals afterwards, because good survival on the first day does not guarantee survival after a week. Finally, because even a stiff hydrogel is far softer than native cartilage, which must withstand forces several times body weight, the team may print the bioink together with a reinforcing frame of a stronger, slowly degrading polymer such as polycaprolactone. That hybrid approach, combining a structural scaffold with a biological bioink, is the subject of Chapter 5. A final consideration moves bioinks from the laboratory toward the clinic. Most natural bioink materials come from animals, typically cows and pigs. For research this is unproblematic. For a product implanted in patients, animal origin raises concerns about immune reactions, transmission of infectious agents, and batch-to-batch variability that regulators expect manufacturers to control. One response has been recombinant production. The Israeli company CollPlant, for example, produces human collagen in genetically engineered tobacco plants, and has used it to make bioinks; it has worked with United Therapeutics on printed lung scaffolds. Synthetic and recombinant materials trade some biological richness for reproducibility and traceability, and as products approach regulatory review, that trade usually looks better. The bioink, in short, is where the printer and the cell negotiate. The next chapter turns to the other party in that negotiation: the cells themselves, how many are needed, where they come from, and what happens to them after printing. Hashtags: #3DBioprintingTechnologies #3DBioprinting #Bioprinting #TissueEngineering #RegenerativeMedicine #Bioinks #BiomaterialScaffolds #Hydrogels #Biofabrication #AdditiveManufacturing #CellBiology #StemCellResearch #Biocompatibility #CellViability #Vascularization #ExtrusionBioprinting #InkjetBioprinting #LaserAssistedBioprinting #VolumetricBioprinting #EmbeddedBioprinting #FRESHBioprinting #GelMA #ExtracellularMatrix #BiomaterialsScience #OrganBioprinting #ArtificialOrgans #TissueRegeneration #BiomedicalEngineering #OrganOnAChip #FutureOfMedicine

  • Web3 Infrastructure (IPFS, Arweave, and Decentralized Storage)

    Download the Book (PDF): Introduction Every link on the web is a small promise. When a writer cites a page, a court quotes a document, or a developer points a token at an image, the link says: go to this place and you will find this thing. The promise is made by one party and kept, or broken, by another. The person who publishes the link has no control over whether the server at the other end will still be running next year, whether its owner will move the file, change it, or delete it, or whether someone with power over that server will decide the file should no longer be seen. The promise is broken constantly. In 2014 a team at Harvard Law School led by Jonathan Zittrain examined the links cited in legal scholarship and in opinions of the United States Supreme Court and found that a large share of them no longer led to the material originally cited, a finding that prompted the creation of the Perma.cc archiving service. A decade later, in 2024, the Pew Research Center reported that 38 percent of the web pages it sampled from 2013 were no longer accessible. These are not exotic failures. They are what happens, by default, to information whose existence depends on a particular machine at a particular address being kept alive by someone with a reason to keep it. The decentralized storage systems that are the subject of this book begin from a simple observation about that problem. The trouble with a web link is that it names a location, and locations are owned. A different kind of name is possible: one that identifies a piece of content by what it is rather than by where it is. Compute a cryptographic hash of a file and you have a short string that, for practical purposes, could only have come from that exact sequence of bytes. Use that string as the address and two things change at once. Anyone who has a copy of the file can serve it, because the name no longer belongs to one server. And anyone who receives the file can check, without trusting the sender, that it is the file they asked for. That idea, content addressing, is the foundation of the InterPlanetary File System, IPFS, which Juan Benet described in a 2014 paper and which Protocol Labs has developed since. It underlies Filecoin, a blockchain designed to pay people to store data, and in a different form it underlies Arweave, a network that sells storage meant to last for centuries in exchange for a single payment. Around these protocols has grown an infrastructure of gateways, pinning services, naming systems and developer tools that now hosts the front ends of financial applications, the metadata of millions of non-fungible tokens, archives of public records, and mirrors of websites that governments have tried to block. The argument of this book This book makes one argument and follows it through the whole stack. Content addressing solves the problem of integrity completely and the problem of availability not at all. A content identifier tells you exactly what a file is. It tells you nothing about whether anyone, anywhere, still has a copy. Those are two different properties, and almost every misunderstanding about decentralized storage, and almost every failure of a project built on it, comes from confusing them. The confusion is understandable. "Stored on IPFS" sounds like a statement about where data lives and how long it will stay there. It is actually a statement about how the data is named. An IPFS address can point to a file that has existed on thousands of machines for years, or to one that sat briefly on a laptop that has since been wiped. The name looks the same in both cases. The difference lies entirely in who has chosen to keep a copy, and why. Once the two properties are separated, the landscape becomes legible. IPFS is a protocol for naming, finding and moving content; it makes no promise about keeping it. Pinning services turn availability back into an ordinary commercial relationship, with the advantage that the customer can switch providers without breaking a single link. Filecoin attempts to make storage a verifiable market, in which providers prove cryptographically, on a schedule, that they still hold what they were paid to hold. Arweave makes a bolder bet: that a one-time payment, invested in an endowment and spent down as storage gets cheaper, can fund persistence indefinitely. Each of these is an answer to the question that content addressing leaves open, and each answer has a particular shape of risk. The same distinction governs the two applications the book treats at length. A censorship-resistant website is not one that cannot be blocked, but one that can be re-served, verifiably, by anyone who holds a copy, so that blocking any single route does not remove the content. And an NFT whose metadata points to an IPFS address is not thereby permanent; it is tamper-evident, which is valuable and different. Builders who understand the difference design accordingly. Those who do not discover it when an image stops loading. What the book covers and what it leaves out The chapters move from the foundations upward. The first explains why location-based addressing fails and what content addressing actually guarantees, down to the bytes of a content identifier. The second follows a file through IPFS: how it is split into blocks and arranged into a Merkle graph, how peers find each other and the data they want, and what gateways do. The third confronts persistence directly, through pinning, garbage collection and the services that have grown up to keep data alive. The fourth and fifth examine the two main economic answers: Filecoin's market of proofs, with a glance at erasure-coded networks such as Storj and Sia, and Arweave's endowment model of permanent storage. The sixth turns to hosting websites, including the naming systems that let a stable address point to changing content and the gateway problem that shadows all of it. The seventh deals with NFT metadata, where the gap between integrity and availability has been most publicly exposed. The eighth draws the threads together into a way of deciding, for a given piece of data, what combination of these tools will actually keep it safe, and examines the legal and moral complications of storage that is hard to delete. The book does not attempt a survey of every decentralized storage project, nor does it offer investment views on the tokens that some of these networks issue. Token prices matter here only where they shape the incentives of the people storing data. It also does not assume that decentralization is always the right answer. A recurring theme is that the most robust arrangements combine decentralized naming and verification with quite ordinary operational discipline, and that a centralized cloud bucket with good backups will outlast a careless decentralized deployment. The reader this book has in mind is technically curious but not necessarily a protocol engineer: a developer deciding where to put an application's assets, a product manager inheriting an NFT project, an archivist or journalist thinking about how to keep material available under pressure, or anyone who has heard that the decentralized web is "permanent" and wants to know what that claim really means. Where a short snippet of configuration or code makes a mechanism clearer, it appears; otherwise the explanations are in prose. The decentralized web has been described in grand terms for more than a decade. Its real achievements are more specific and, in some ways, more interesting than the slogans. It has given the internet a way to name information that does not depend on anyone's continued goodwill, and a way to verify information that does not depend on trusting whoever delivers it. What it has not done, and cannot do by protocol alone, is make anyone care enough to keep the bytes. That part remains a matter of incentives, institutions and choices, and it is the part this book spends most of its time on. Chapter 1: Names and Places A URL is an instruction for finding something. Take https://example.org/reports/2023/annual.pdf. Read from left to right, it says: use the HTTPS protocol, ask the domain name system which machine currently answers for example.org, connect to that machine, and request whatever it chooses to return for the path /reports/2023/annual.pdf. Every step in that chain depends on a party other than the person who wrote the link. A registrar must keep renewing the domain. A DNS provider must keep resolving it. A hosting company must keep the server running. The site's owner must keep the file at that path and resist the temptation to replace it with something else. A certificate authority must keep vouching for the server's identity. None of this is a design flaw in the ordinary sense. The web was built to let anyone publish without asking permission, and location-based addressing was the natural way to do that in 1990: you put a file on your machine and told people where your machine was. The flaw is that the address and the content are bound together only by the continued behaviour of the publisher. The address does not describe the content. It describes a place where, at the time of writing, the content could be found. How location fails There are three distinct ways a location-based link stops doing its job, and it helps to keep them apart because decentralized storage addresses them differently. The first is disappearance. The server goes offline, the company folds, the domain lapses, or the file is deleted during a site redesign. This is link rot in its plainest form, and it is overwhelmingly the most common failure. Most lost web content was not suppressed by anyone; it simply stopped being paid for. When a hosting bill goes unpaid, there is no notice to the thousands of pages elsewhere that linked to the site. The links remain, pointing at nothing. The second is drift. The link still resolves, but what it returns has changed. A news organisation quietly edits an article. A company replaces the terms of service at the same URL. A file named logo.png is overwritten with a new logo, and every page that embedded the old one now shows the new one. Drift is in some ways worse than disappearance, because nothing signals that it has happened. A reader who follows a citation and finds a page has no way to know whether it is the page the author saw. Researchers who study the problem call this content drift, and it is common in academic and legal citation, where the integrity of what was cited matters as much as its existence. The third is control. Because a location is owned, whoever controls it can decide what it returns and to whom. A government can order a domain seized or require internet providers to block an IP address. A platform can remove a file in one country and leave it up in another. A hosting company can terminate a customer under pressure. In each case the content may still exist somewhere, on the publisher's own disk perhaps, but the address everyone has been using no longer leads to it, and there is no general way to tell readers where else to look. Notice that the three failures share a root. In each, the reader is relying on a particular party to keep a particular address associated with particular bytes. Disappearance is that party giving up. Drift is that party changing its mind. Control is a third party overriding it. The reader has no independent way to check what they receive, and no general way to get it from anywhere else. Naming by content The alternative is to make the name a function of the content itself. The tool for this is the cryptographic hash function, a procedure that takes an input of any length and produces a fixed-length output, called a digest, with two crucial properties. It is deterministic: the same input always produces the same digest. And it is, for practical purposes, impossible to find two different inputs that produce the same digest, or to construct an input that produces a digest chosen in advance. SHA-256, the most widely used such function, produces a 256-bit digest. Change a single bit of a multi-gigabyte file and its SHA-256 digest changes completely and unpredictably. If the address of a file is its hash, the three failures look different. Drift becomes impossible to conceal: a modified file has a different hash, and therefore a different address. Anyone holding the old address will either receive the old bytes or, if they receive anything else, will detect the substitution by hashing what arrived and comparing. The name has become a commitment that the content cannot violate. Control is weakened, though not eliminated. Because the address does not refer to any particular machine, any machine that holds the bytes can serve them, and the recipient can verify them regardless of who the sender is. Blocking one server does not invalidate the address; it removes one source. A censor would have to find and block every source, or block the protocols used to reach them, which is a harder and more visible undertaking. Disappearance is not solved at all. If nobody holds the bytes, the address points to nothing, exactly as a dead URL does. A content address is a perfect description of a file and no guarantee of its existence. This asymmetry is the central fact of the subject, and it will recur in every chapter. The idea is not new. Version control systems have used content addressing for decades; Git identifies every file, directory and commit by a hash of its contents, which is why two developers can compare repositories by exchanging a single commit identifier. Package managers record hashes of the archives they download so that a tampered mirror is detected. BitTorrent identifies a torrent by an infohash derived from its contents. Research into what came to be called information-centric or named-data networking, associated with Van Jacobson and others in the late 2000s, proposed rebuilding the internet's routing around named content rather than host addresses. What IPFS added was a general, extensible format for content identifiers and a working network for finding and moving the content they name. Anatomy of a content identifier A raw SHA-256 digest is not quite enough to serve as a long-lived address. Hash functions age; SHA-1, once standard, is now considered broken for collision resistance, and a format that assumed one function forever would be stranded when that function failed. A bare digest also says nothing about how to interpret the bytes it identifies: is this a file, a directory, a fragment of a larger file, a structured data record? IPFS addresses both problems with the content identifier, or CID, built from a family of small self-describing formats that Protocol Labs grouped under the name Multiformats. A CID is a sequence of fields, each announcing what the next part means. The four components are set out in Table 1. Table 1. The parts of a version 1 content identifier. Component What it says Common values Multibase prefix How the binary CID is written as text b for base32, z for base58btc Version Which CID format follows 1 (version 0 is implicit) Content codec How to interpret the identified bytes dag-pb, raw, dag-cbor, dag-json Multihash Which hash function, digest length, and the digest sha2-256, 32-byte digest The multihash is the heart of it. Rather than storing a bare digest, it prefixes the digest with a code identifying the hash function and a number giving the digest's length. A system that encounters a CID made with a function it has never heard of can at least recognise that fact, rather than misinterpreting the bytes. If SHA-256 is ever weakened, new CIDs can use a different function without any change to the format, and old CIDs remain parseable. The codec tells the reader how to decode the block. raw means the bytes are opaque data, typically a chunk of a file. dag-pb means the bytes are a Protocol Buffers–encoded node in the UnixFS format that IPFS uses to represent files and directories, containing links to other blocks. dag-cbor and dag-json are encodings for arbitrary structured data that can link to other content by CID, which is what makes it possible to build linked data structures, not just file trees, on top of the same addressing scheme. The multibase prefix exists because CIDs are binary but frequently need to appear in text: in URLs, in JSON, in DNS records. The single leading character announces which text encoding follows. Base32, signalled by a lowercase b, is the default for version 1 CIDs because it is case-insensitive, which matters when a CID is placed in a domain name, since DNS ignores case. This explains the two visual families of CID that a newcomer encounters. Older identifiers, version 0, begin with Qm and are 46 characters long. They have no explicit version, codec or multibase field; they are always base58-encoded SHA-256 multihashes of dag-pb nodes, and the Qm is simply what the multihash prefix for SHA-256 with a 32-byte length looks like in base58. Version 1 identifiers in the default encoding typically begin with bafy for dag-pb content or bafk for raw blocks. The two can identify exactly the same data; a version 0 CID can be converted losslessly into version 1. They are different spellings, not different content. The same file, different names One consequence of this design surprises nearly everyone who works with IPFS for long: the same file does not always have the same CID. A CID identifies a block, or more precisely the root block of a graph of blocks. When a large file is added to IPFS it is not hashed as a single unit. It is split into chunks, each chunk becomes a block with its own CID, and a tree of link nodes is built above them, with the CID of the top node standing for the whole file. The next chapter explains this process in detail. What matters here is that the shape of that tree depends on choices: how large each chunk is, whether chunks are stored as raw blocks or wrapped in UnixFS nodes, how many links each internal node holds, whether the tree is balanced or skewed, and which CID version and hash function are used. Change any of these and the root CID changes, even though the file's bytes are identical. In practice this means that two tools, or two versions of the same tool with different defaults, can produce different CIDs for the same file. Kubo, the reference IPFS implementation, historically defaulted to version 0 CIDs with 256 KiB chunks wrapped in UnixFS nodes; other tools default to version 1 with raw leaves. Someone who adds a file with one tool and then checks it with another may conclude, wrongly, that the file has changed. The IPFS community has worked on standard profiles of import settings so that tools can agree, but the general lesson stands: a CID is a hash of a particular encoding of content, not of the content in the abstract. This is not a reason to distrust content addressing. Within a given encoding, the guarantee is absolute: if you hold a CID and receive blocks that hash to it, you have exactly what the creator of that CID had. It is a reason to record, alongside any CID that matters, how it was produced, and to be careful about assuming that "the same file" will always yield the same address. A project that publishes the plain SHA-256 of a file alongside its CID gives future readers a second, encoding-independent check. What verification buys The value of content addressing is easy to underestimate because, when it works, nothing visible happens. Consider what it removes. On the location-based web, a reader who downloads a file has to trust every party between them and the publisher: the DNS resolver, the network, the certificate authority, the hosting company, any content delivery network in front of it, and the publisher's own security. HTTPS protects the connection, but it only proves that you are talking to the server the certificate names, not that the server is returning what the publisher originally intended. A compromised server serves compromised files over a perfectly valid encrypted connection. With content addressing, the trust question collapses to a single point: did I get the right CID? Once the reader has a CID from a source they trust, perhaps from a signed message, a blockchain record, a printed paper, or a friend, the bytes can come from anywhere. A stranger's laptop, a public gateway run by an unknown party, a cache on the local network, a USB stick passed hand to hand: each is as good as the original publisher, provided the reader checks the hash. The transport becomes untrusted by design. This changes the economics of distribution. Caching becomes safe without coordination, because no cache can lie undetected. Popular content can be served by whoever happens to be nearby and have it, rather than by a single origin bearing all the bandwidth cost. Archives can be audited, because the identifier recorded years ago can still be checked against the bytes held today. And intermediaries lose a particular kind of power: the power to alter content in transit without anyone noticing. It also creates a new and important discipline. Because content-addressed data is immutable, anything that needs to change must be handled by a separate layer: a mutable pointer that can be updated to reference a new CID. A website that publishes a new version produces a new root CID; a naming system, discussed in Chapter 6, is needed to let readers find the latest one. This separation of immutable content from mutable references is a feature. It makes every change explicit, and it means the history of a thing can be preserved simply by remembering old CIDs. But it is also the source of a great deal of operational complexity, and a common point at which systems that look decentralized turn out to depend on a single party after all. The open question Content addressing turns a link from a promise about a place into a precise description of a thing. It eliminates undetected drift. It weakens control by letting any holder serve the content. It makes verification cheap and the transport untrustworthy by design. All of this follows directly from naming content by its hash, and none of it depends on any particular network, company or token. What remains is the question content addressing cannot answer from within itself: who is holding the bytes? A CID written into a smart contract or printed in a footnote is as durable as the paper or the blockchain it is written on, which may be very durable indeed. The data it names is exactly as durable as the willingness of someone, somewhere, to keep a copy and to answer when asked for it. The rest of this book is about the systems that have been built to find those copies, to reward the people who keep them, and to make their persistence something more reliable than goodwill. Before that, it is worth understanding in some detail how IPFS actually finds and moves content once it has a name, because the mechanics of retrieval shape everything that follows. Chapter 2: How IPFS Moves Data IPFS is often described as a distributed file system, which is accurate in spirit and misleading in detail. It is better understood as three things layered together: a way of representing data as a graph of content-addressed blocks, a way of discovering which peers hold which blocks, and a way of transferring blocks between peers. Each layer can be replaced independently, and in the decade since the protocol was introduced each has been reworked several times. Following a single file through all three is the clearest way to see what IPFS does and, just as importantly, what it leaves to someone else. From file to graph Suppose a user adds a 10-megabyte PDF to an IPFS node. The node does not store the file as one object. It first passes the bytes through a chunker, which divides them into pieces. The default in Kubo has long been fixed-size chunks of 256 KiB, so a 10-megabyte file becomes about forty chunks. Alternative chunkers exist, including content-defined chunking based on a rolling hash, which places chunk boundaries according to patterns in the data rather than at fixed offsets. Content-defined chunking has the advantage that inserting a few bytes near the start of a file shifts only one or two chunk boundaries rather than every one after the insertion, so a lightly edited file shares most of its blocks with the original. Each chunk becomes a leaf block. Its CID is computed from its bytes. The node then builds a tree above the leaves: an internal node lists the CIDs of its children, along with the size of the data each child represents, and that internal node is itself encoded as a block with its own CID. If there are more leaves than one internal node can reference, another level is added. The CID of the single node at the top, the root, is the CID of the file. Kubo's default arrangement is a balanced tree with up to 174 links per node, a number chosen so that internal nodes stay below a quarter of a megabyte; an alternative "trickle" layout favours streaming, placing early parts of the file close to the root. This structure is a Merkle DAG, a directed acyclic graph in which every node is identified by a hash that covers its own content and, through the CIDs it contains, the content of everything beneath it. The name comes from Ralph Merkle, whose hash trees, published in the late 1980s, showed how a single root hash could commit to an arbitrarily large collection of data while allowing any piece to be verified independently. The consequence for IPFS is that a reader who knows only the root CID can verify every block as it arrives. Fetch the root, check it hashes correctly, read the CIDs of its children, fetch those, check each, and so on down. No block need be trusted before it is checked, and no block can be substituted without changing a hash somewhere above it. Directories work the same way. A UnixFS directory node maps names to CIDs: this directory contains index.html with CID such-and-such, style.css with another, and a subdirectory images whose CID points to a further directory node. Very large directories, with many thousands of entries, are sharded across a hash array mapped trie so that no single node grows too large. The CID of the top-level directory commits to the entire tree, every file in it and every byte of every file. This is what makes it possible to publish a whole website, or an archive of millions of documents, under one identifier. Two properties fall out of the graph structure that matter later. The first is deduplication. If two files share a chunk, or two versions of a website share most of their files, the shared blocks have the same CIDs and need be stored and transferred only once. Publishing a new version of a large site that changes one page creates only the handful of new blocks along the path from that page to the root. The second is partial retrieval. A reader who wants only one file from a large directory, or only a byte range from a large file, can walk the graph to the relevant blocks without fetching the rest. Finding who has it Having a CID is not the same as knowing where to get the blocks. IPFS needs a way to answer the question: which peers on the network are able to provide this CID? This is content routing, and it has proven to be the hardest part of the system to make fast at scale. The main public mechanism is a distributed hash table based on Kademlia, a design published by Petar Maymounkov and David Mazières in 2002. Every peer has an identifier derived from its public key. Identifiers and CIDs are mapped into the same numerical space, and the "distance" between two identifiers is defined by the bitwise exclusive-or of their values. Each peer keeps a routing table of other peers, organised so that it knows many peers close to itself and progressively fewer at greater distances. To find something, a peer asks the closest peers it knows for anyone closer still, and repeats. Because each step roughly halves the remaining distance, a lookup in a network of many thousands of peers completes in a small number of hops. When a node holds content and wishes to make it available, it publishes a provider record: a small statement that this peer can provide this CID. The record is stored on the peers whose identifiers are closest to the CID, typically twenty of them. A peer looking for the content does a DHT lookup for the CID, reaches those peers, obtains the provider records, and then connects directly to a provider. Provider records expire, after about two days in Kubo's defaults, and must be republished periodically while the node still has the content. This expiry is deliberate. A network in which records lived forever would accumulate pointers to peers long gone. The DHT has well-known weaknesses. Lookups can be slow, often taking more than a second, because they involve several network round trips to peers spread across the world, some of which are unreachable. Publishing provider records for every block of a large dataset is expensive; a node holding millions of blocks may struggle to reprovide them all within the expiry window. For this reason Kubo offers strategies to announce only root CIDs, or only pinned content, trading discoverability of individual blocks for lower overhead. Measurement work by Dennis Trautwein and colleagues, published at the ACM SIGCOMM conference in 2022 and the most thorough public study of the deployed network, found that the DHT functioned at substantial scale but that a large fraction of nodes were behind network address translation or otherwise hard to reach, and that retrieval latency varied widely. Because of these limits, real deployments rarely rely on the DHT alone. Network indexers, which aggregate provider records from large storage providers and answer queries over HTTP, have become an important complement, particularly for content held by Filecoin storage providers who may announce enormous numbers of CIDs. The IPFS specifications define a generic "delegated routing" interface over HTTP, so that a client can ask a routing service which peers have a CID without running a DHT node itself. This is a pragmatic concession. It makes lookups faster and makes IPFS usable from browsers and mobile devices, at the cost of reintroducing services that someone has to run. Moving the blocks Once a peer knows who has the content, it needs to fetch the blocks. The original IPFS exchange protocol is Bitswap. A peer that wants blocks sends a want-list to the peers it is connected to. In its modern form Bitswap distinguishes between asking whether a peer has a block, a "want-have", and asking for the block itself, a "want-block", which lets a client discover which of several peers hold content before committing bandwidth to any of them. Peers that have requested blocks send them; the receiver verifies each against its CID and, as it learns the children of each node, adds them to its want-list. Bitswap has an interesting property: it often works without the DHT at all. A node that is already connected to peers will broadcast its wants to them, and if any of them happens to have the content, it arrives without any lookup. Nodes in the same office, or a client connected to a large well-provisioned peer, often find content this way. The weakness is that Bitswap is block by block. Walking a deep graph means waiting for each level before requesting the next, and the per-block overhead adds up for content made of many small pieces. For this reason a second transfer method has become prominent: fetching over plain HTTP from a "trustless gateway". Instead of exchanging blocks over IPFS's own protocols, the client requests a CID from an HTTP endpoint and asks for either a single raw block or a CAR file, a Content Addressable aRchive, which packs a whole graph or a selected part of it into one stream. The client verifies every block it receives against the requested root, so the server need not be trusted. Large storage providers, content delivery networks and ordinary web servers can all serve content this way without running a full IPFS node. Many current IPFS clients, including Helia, the JavaScript implementation, combine both: they try Bitswap with connected peers and HTTP retrieval from known trustless gateways in parallel and take whichever answers first. Underneath all of this sits libp2p, the networking library that grew out of IPFS and is now used by other systems, including Ethereum's consensus clients. Libp2p handles the plumbing of peer-to-peer connections: multiple transports such as TCP, QUIC and WebTransport; encryption and authentication of peers by their public keys; multiplexing many logical streams over one connection; and, crucially, getting through the network address translation devices that sit in front of most home and mobile connections. It includes relays, through which two peers that cannot reach each other directly can communicate, and a hole-punching protocol that uses a relay to coordinate a direct connection between two peers behind NAT. These features are what allow ordinary laptops to participate as providers, though in practice the bulk of reliably reachable IPFS content sits on servers with public addresses. Gateways: the bridge and the bottleneck Most people who have ever loaded content from IPFS did not run an IPFS node. They clicked an HTTP link to a gateway: a server that runs an IPFS node and translates ordinary web requests into IPFS retrievals. A request for https://ipfs.io/ipfs//index.html causes the gateway to find and fetch the blocks for that CID, verify them, reassemble the file, and return it to the browser as a normal web response. Gateways were essential to adoption. They let IPFS content appear in web pages, in wallet interfaces and in NFT marketplaces without asking users to install anything. They also reintroduce, at the point of delivery, the very properties content addressing was meant to remove. A browser fetching from a gateway receives an HTTP response and cannot itself verify that the bytes match the CID; it trusts the gateway, just as it would trust any web server. The gateway's operator can block content, log requests, be overloaded or go offline. A popular public gateway becomes a single point of failure for every application that hard-codes its domain. The history of public gateways illustrates this. Protocol Labs has long run ipfs.io and dweb.link; Cloudflare operated a widely used public gateway for several years before announcing in 2024 that it would wind it down and redirect traffic to gateways operated by Interplanetary Shipyard, the team that took over maintenance of core IPFS implementations from Protocol Labs. Applications that had written Cloudflare's gateway domain into their content, rather than the underlying CID or an ipfs:// URI, found themselves dependent on a redirect they did not control. The CIDs remained valid throughout; what broke, or threatened to break, were the HTTP wrappers around them. Gateways also come in two styles with different security properties. A path gateway serves all content under a single origin, so that gateway.example/ipfs/ and gateway.example/ipfs/ share cookies, storage and other browser privileges. That is harmless for static images and dangerous for web applications, since a malicious page at one CID could interfere with another. A subdomain gateway puts the CID in the hostname, as in .ipfs.dweb.link, giving each piece of content its own browser origin and isolating applications from each other. This is why version 1 CIDs in case-insensitive base32 matter: a version 0 CID, with its mixed-case base58, cannot survive being placed in a hostname. The direction of travel is to move verification back to the user. Browser-based IPFS clients, and service-worker gateways that run inside the browser tab, fetch blocks from trustless HTTP endpoints and verify them locally before rendering, so that the gateway becomes a mere source of bytes rather than an authority. Native IPFS support in browsers has had a more halting history. Brave shipped an embedded IPFS node in 2021 and removed it in 2024, citing low usage and maintenance cost; Opera experimented with IPFS support in its crypto-focused browser. The protocol works, but the default path for most readers remains an HTTP gateway, and anyone building on IPFS should design on the assumption that most users will arrive that way. Beyond files The block-and-link model is not limited to files and directories, and seeing it applied elsewhere clarifies what is general about it. The data model underneath IPFS, called IPLD, treats any structured record that contains CIDs as a node in a graph that can be linked, traversed and verified in the same way as a UnixFS tree. A record encoded in dag-cbor might describe a social media post, with a CID linking to an attached image, another to the previous post in the author's history, and a signature over the whole. Anyone holding the root of such a structure can verify everything beneath it. The most prominent recent use of this model outside the IPFS network itself is Bluesky's AT Protocol. Each user's data is held in a repository whose records are encoded as dag-cbor and identified by CIDs, arranged in a Merkle tree whose signed root commits to the whole repository. When a user moves their account from one hosting provider to another, the new host can verify that it has received exactly the repository the user signed. The protocol does not use IPFS's DHT or Bitswap to move data; it uses its own HTTP-based synchronisation. But it relies on the same insight: that naming data by its hash lets it move between hosts without anyone having to trust the host in between. That separation, between the data model and the network that moves it, is the most durable part of the design. Routing systems have been replaced, exchange protocols rewritten, and gateways redesigned, but a CID created in 2016 still identifies the same content today, and will continue to do so in any system that understands the format, whether or not it is called IPFS. What IPFS is and is not Following the PDF through the system clarifies what IPFS actually provides. It gives the file a verifiable name that commits to every byte. It provides a structure that deduplicates and allows partial retrieval. It offers several mechanisms by which a reader can discover a peer holding the content and fetch it, verifying as they go. It allows anyone who holds the blocks to serve them, and anyone who wants them to accept them from anyone. What it does not do is keep the file. When the user who added the PDF shuts down their node, the provider records it published will expire within days, and unless some other peer has fetched the blocks and chosen to keep and announce them, the CID will resolve to nothing. IPFS nodes cache content they retrieve, but they also discard cached content to free space. There is no global replication, no redundancy target, and no mechanism by which the network as a whole decides that a file is important and should be preserved. Those are not omissions in the protocol so much as deliberate boundaries. IPFS is a way to name and move data. Keeping it is a separate problem, with its own tools and its own economics, and it is to that problem that the next chapter turns. Chapter 3: The Persistence Problem There is a sentence that has appeared, in one form or another, in countless project announcements, pitch decks and NFT listings: the data is stored on IPFS, so it will be there forever. The sentence is wrong in a specific and instructive way. IPFS does not store data. Nodes store data, and each node decides for itself what to keep and for how long. A CID is a name that anyone can use to ask for content; whether the request succeeds depends on whether some reachable node has chosen to hold that content and announce it. This chapter is about the machinery of that choice. It covers how an individual IPFS node decides what to keep, how the practice of pinning emerged to make that decision explicit, how a market of pinning services grew up to sell persistence as a service, and why the resulting arrangement, though it reintroduces commercial dependence, is still a real improvement over the location-based web. Caches, garbage, and pins An IPFS node keeps blocks in a local store called the blockstore. Blocks arrive there in two ways. Some are added deliberately, when the node's operator imports a file. Others arrive incidentally, when the node retrieves content on someone's behalf, whether its own user browsing or, in the case of a gateway, any visitor making a request. Incidental blocks are a cache. Keeping them makes repeat requests faster and lets the node serve those blocks to other peers, which is part of how popular content becomes widely available. Caches grow without limit unless something prunes them. IPFS nodes therefore run garbage collection, which deletes blocks that are not marked as needed. In Kubo, garbage collection can be triggered manually or set to run automatically when the blockstore passes a size threshold. Anything not protected is eligible for deletion. Protection is called pinning. A pinned CID is one the node has been instructed to keep. Pins come in kinds. A recursive pin on a root CID protects that block and every block reachable from it, so pinning the root of a directory protects the whole tree. A direct pin protects only the single block. Files added through the normal import command are pinned recursively by default, which is why a user who adds a file and leaves their node running will find that it persists across garbage collection. The pin, not the act of adding or retrieving, is what keeps content alive on a node. The logic is simple, and it has a direct implication for anyone who publishes content. If you want a CID to remain retrievable, at least one node must pin it, that node must stay online, it must be reachable by the people who will request the content, and it must keep announcing the content to the routing system. Each of those is an operational commitment. A laptop that sleeps, a server behind a restrictive firewall, a node whose provider records lapse, or a disk that fills up will each make content unavailable, even though no one has deleted anything. There is a further subtlety. Incidental caching gives popular content a natural tendency to spread, since every gateway and every user who fetches it holds a copy for a while. But that spread is temporary and uneven. Caches are cleared; gateways are configured to keep content for hours or days, not years. The long tail of content that is rarely requested, which is most content, benefits from almost none of it. A CID that nobody has asked for in six months is likely to be held only by the nodes that pinned it. Pinning as a service Running an always-on, well-connected IPFS node with enough storage and bandwidth is not hard for an engineering team, but it is a real cost and a real responsibility. For most publishers, especially the many NFT projects and small applications that adopted IPFS from 2020 onward, it was easier to pay someone else. Pinning services emerged to meet that need: companies that run fleets of IPFS nodes and, for a fee or under a free tier, pin whatever CIDs their customers ask them to. Pinata, Infura's IPFS service, Filebase, Fleek and the service now called Storacha, which grew out of web3.storage, are among the names that have dominated this market at various times. Some have exited it. Infura restricted its public IPFS gateway in 2022. NFT.Storage, launched by Protocol Labs in 2021 as a free service that stored NFT data on IPFS and in Filecoin storage deals, stopped accepting uploads to its original free service in 2024, and its users were encouraged to migrate their data to other providers. These changes were not failures of IPFS. They were the ordinary churn of service businesses. But they show plainly that a pinning service is a vendor relationship like any other, with prices, terms, and a business model that may change. To reduce the cost of switching, the IPFS community defined a common Pinning Service API, a simple HTTP interface for asking a remote service to pin a CID, check its status, and remove a pin. A client that supports the API can be pointed at any compliant service, and Kubo can manage remote pins alongside local ones. Many services also offer S3-compatible interfaces, so that existing tools designed for Amazon's storage API can upload to IPFS with minimal change. Why this is still better than a bucket At first glance this arrangement looks like the cloud with extra steps. A project pays a company to keep files on its servers and serve them over HTTP. If the company goes away, so do the files. In what sense is that decentralized? The answer lies in what happens at the moment of failure. Suppose a project has hosted its images in an ordinary cloud bucket and linked to them by URL. The cloud provider terminates the account. The project still has copies on a developer's laptop. To restore service it must upload them somewhere new, and then update every reference to point at the new location. Where the references are in a database the project controls, this is tedious but possible. Where they are in other people's websites, in archived social media posts, in printed materials, or in an immutable smart contract, it is impossible. The old URLs are permanently broken. Now suppose the same images were added to IPFS, the project recorded their CIDs, and those CIDs were written into all the places that refer to the images. The pinning service shuts down. The project re-pins the same files with a different service, or on its own node. Because the CIDs are derived from content, they are identical. Every reference that used the CID, or an ipfs:// URI, resumes working as soon as the new provider announces the content. No reference anywhere needs to change. The vendor was replaceable because the name did not belong to the vendor. This is the practical meaning of decentralization for most users of IPFS: not that no company is involved, but that no company owns the address. It converts vendor failure from a catastrophe into an inconvenience, provided someone kept the original bytes and acts before every copy is gone. The protection is only as good as its weakest assumption, however. It fails if the project linked to a specific gateway URL rather than the CID itself, since then the references embed a location after all. It fails if no one kept a copy of the original data and every pinning service holding it has deleted it. And it fails, subtly, if the data cannot be reproduced into the same CID. A project that kept the source images but not the exact import settings may re-add them and find that, because of a different chunk size or CID version, the new root CID is different from the one written into its contract. The bytes are safe; the name is orphaned. The cure is to keep the content in its content-addressed form, most simply as a CAR file, which preserves the exact blocks and therefore the exact CIDs. Who else pins A healthier pattern is redundancy across independent parties. Because the CID is the same wherever the content lives, there is no coordination cost in having several organisations pin it. A project can pin with two commercial services on different infrastructure and run its own node. Collectors who care about a set of NFTs can pin the metadata and images themselves. Archives, libraries and community groups can pin material they consider important. Each additional pinner is an independent bet on persistence, and the content survives as long as any one of them does. Tools exist to make this cooperative pinning easier. IPFS Cluster, maintained alongside the core implementations, lets a group of nodes share a pin set and replicate content among themselves according to a policy, such as keeping at least three copies. Collaborative clusters have been used to let volunteers donate disk space to pin public datasets. Some projects publish their pin sets openly and invite holders to mirror them. This is the closest IPFS comes to the folk idea that "the network" keeps data: not as a protocol guarantee, but as a social practice that the protocol makes cheap. Redundancy has to be checked, not assumed. Pins can silently fail. A service might accept a pin request and never manage to fetch the content because the original provider was unreachable at the time. A node's disk might be corrupted. A routing announcement might lapse. The only reliable test of availability is to try retrieving the content, from outside the infrastructure holding it, on a schedule. Several services now offer retrieval checks that query the network for providers of a CID and attempt to fetch it, and a project that cares about its data should run them, or write its own, and treat a failure as an incident. A worked audit It helps to make the abstractions concrete. Imagine inheriting a project that launched two years ago. Its smart contract, documentation and marketing all refer to a single root CID for a directory of several thousand image files. The original team has moved on. Nobody is sure which pinning service was used, or whether the account is still paid. The task is to find out whether the data is safe and, if not, to make it so. The first step is to ask the network who claims to have it. With a Kubo node running, the command ipfs routing findprovs performs a content-routing lookup and lists the peer identifiers that have published provider records for the root. Public tools offer the same check through a web interface, querying both the DHT and the large network indexers. Three outcomes are possible. If several providers appear, belonging to recognisably different operators, the data is probably held in more than one place, though that still needs confirming. If one provider appears, the data's survival depends on a single party, and that party's identity should be established. If none appears, the data may already be gone, or may sit on nodes that have stopped announcing it. A provider record is a claim, not a proof. The second step is to fetch the content. Retrieving the root alone proves little; a provider might hold the top of the graph and have lost the leaves. A full check walks the whole DAG. The command ipfs dag export > collection.car does exactly this, retrieving every block reachable from the root and writing them into a single CAR file. If it completes, every byte is available somewhere, and the project now holds a complete local copy in exact content-addressed form. If it stalls, the blocks it cannot find are missing from every reachable provider, and the audit has located the damage. The third step is to secure what has been recovered. The CAR file is the canonical artefact: it can be imported into any IPFS node with ipfs dag import, or uploaded to any pinning service that accepts CAR files, and the resulting root CID will match the original exactly, because the blocks are byte-for-byte the same. This sidesteps the import-settings problem described earlier. Nothing is re-chunked; nothing is re-encoded. The CAR file should be kept in at least one place the project controls, and pinned with at least two independent services. The fourth step, too often skipped, is to repeat the retrieval check from somewhere else after the new pins are in place, ideally from a machine that does not share a network with any of the pinning providers, and then to schedule it. A weekly automated job that exports the DAG, or at least samples blocks from it, and alerts someone when it fails, is cheap insurance. The audit also clarifies what running one's own node involves, for projects deciding whether to do so. An IPFS node that reliably serves content needs a public IP address or working NAT traversal, enough bandwidth for expected demand, storage with backups, and an operator who notices when it goes down. It must keep reproviding its content to the routing system, which for a large pin set means tuning the reprovider strategy. None of this is exotic. It is the ordinary discipline of running any server. But it is a reminder that "self-hosting on IPFS" is self-hosting, with all the responsibility that implies, and that the protocol's contribution is to make that hosting interchangeable with anyone else's, not to make it unnecessary. The limits of goodwill and invoices Pinning, whether by a paid service or a volunteer, rests on one of two things: a contract or a commitment. A pinning service keeps data while it is paid and while it remains in business. A volunteer keeps data while they care. Neither offers any way for an outsider to verify, short of fetching the content, that the data is actually being held, nor any consequence beyond the commercial or social for failing to hold it. For many purposes that is enough. Most of the internet's important data is kept by organisations with contracts and commitments, and the content-addressed version is more robust than the location-based one because the vendor is replaceable. But two harder questions remain. First, can storage be made into a market where providers prove that they hold the data, on an ongoing basis, and are penalised automatically if they do not? Second, can the payment problem be solved once, so that storage does not depend on someone continuing to pay an invoice decades from now? Filecoin is the most developed attempt at the first question. Arweave is the most developed attempt at the second. Both are answers to the gap that pinning leaves, and both are examined in the next two chapters. It is worth closing this chapter with the arrangement that serves most real projects best, because it is less glamorous than either. Keep the original data, in CAR form, in at least one location you control. Pin it with at least two independent providers. Refer to it everywhere by CID or ipfs:// URI, never by a particular gateway's URL. Check retrieval regularly from outside your own systems. This is not permanence. It is something more modest and more achievable: availability that does not depend on any single company, and that can be restored, without breaking a single reference, by anyone who still has the bytes. Hashtags: #Web3Infrastructure #Web3 #DecentralizedStorage #IPFS #Arweave #Filecoin #BlockchainTechnology #DecentralizedWeb #DistributedStorage #ContentAddressing #ContentIdentifiers #CID #MerkleDAG #PeerToPeerNetworks #DistributedFileSystems #DataIntegrity #DataAvailability #PermanentStorage #IPFSPinning #PinningServices #CryptographicHashing #ContentVerification #CensorshipResistance #DecentralizedHosting #NFTMetadata #SmartContracts #DataPersistence #Web3Development #DecentralizedApplications #BlockchainInfrastructure

  • Vector Databases and Semantic Search (Architecting AI-Powered Retrieval Systems)

    Download the Book (PDF): Introduction Every search system makes a bet about what a query means. For most of the history of computing, that bet was lexical: a query means the words in it, and a document is relevant to the degree that it contains those words, weighted by how rare they are. The bet paid off for decades. Inverted indexes, the data structures behind every library catalogue, web search engine and log analytics tool, are among the most successful inventions in software. They are compact, fast, explainable and easy to update. When a user types "invoice 4471" into an accounting system, nothing beats them. But the lexical bet loses in a familiar set of cases. A customer asks a support bot "why was I charged twice" and the relevant article is titled "Duplicate payment authorisations". A clinician searches for "heart attack" and the record says "myocardial infarction". A shopper uploads a photograph of a chair and wants chairs that look like it. A music service needs to know that two songs with no words in common belong on the same playlist. In each case, the thing that matters is not the surface form of the data but something underneath it: its meaning, its style, its function, its audience. Keyword matching cannot see that layer. Over the past decade, machine learning has produced a practical way to see it. An embedding model reads a piece of data, a sentence, an image, a product listing, a user's listening history, and outputs a list of numbers, typically a few hundred to a few thousand of them. The model is trained so that items humans would consider similar end up with similar lists of numbers. Once data has been turned into these vectors, "find things like this" becomes a geometric question: which points in a high-dimensional space lie closest to this one? Answering that question quickly, over millions or billions of points, while respecting filters, permissions and freshness, is the job of the systems this book is about. Why this matters now Vector search is not new. Recommendation engines at large consumer companies have relied on nearest-neighbour lookups over learned embeddings for at least ten years; Google's 2016 paper on YouTube recommendations described exactly this architecture, and Spotify open-sourced its Annoy library for approximate nearest-neighbour search in 2013. What changed after 2022 was the arrival of large language models and, with them, retrieval-augmented generation. Lewis and colleagues introduced the term in 2020 to describe a model that retrieves passages from an external corpus and conditions its output on them. Once chat assistants became mainstream, nearly every organisation with documents wanted one that could answer questions about those documents, and nearly every such project needed a way to find the right passages. Semantic search became infrastructure almost overnight. The market responded with a wave of specialised products. Pinecone, Weaviate, Milvus, Qdrant, Chroma and others marketed themselves as "vector databases", a new category alongside relational, document and graph stores. At the same time, the incumbents moved. PostgreSQL gained the pgvector extension, which added an HNSW index in 2023 and has since become one of the most widely deployed vector engines in the world simply because it lives where the data already is. Oracle shipped AI Vector Search in its 23ai release. Microsoft made a native vector type generally available in Azure SQL and SQL Server 2025. Elasticsearch, OpenSearch, MongoDB, Redis and Cassandra all added approximate nearest-neighbour indexes. In December 2025 Amazon made S3 Vectors generally available, putting vector indexes directly into object storage. By the time of writing, in late 2026, "should we buy a vector database?" has quietly become "where should the vectors live, and what else must the retrieval path do?" That shift is the starting point of this book. The questions that determine whether an AI retrieval system works are rarely questions about which product has the fastest index on a public benchmark. They are questions about whether the embedding model understands the domain, whether the index's accuracy losses are measured, whether filters by tenant or date break the index's guarantees, whether keyword signals are combined with semantic ones, whether results are reranked by a model that can afford to read them carefully, and whether anyone knows, week to week, if retrieval quality is getting better or worse. The argument of this book The controlling idea of this book is that a retrieval system is only as good as its weakest stage, and the vector index is rarely that stage. Semantic search succeeds when the embedding model, the approximate index, the filtering strategy, the lexical signals, the reranker and the evaluation loop are designed as one system, and that system increasingly belongs inside the data platforms an organisation already runs rather than beside them. That is a claim with practical consequences. It means a team should spend its first week building an evaluation set, not benchmarking databases. It means that understanding how HNSW behaves under deletes and filters matters more than knowing its asymptotic complexity. It means that the choice of an embedding model is a long-term commitment with a migration cost, not a configuration flag. And it means that the old disciplines of information retrieval, relevance judgement, lexical matching and ranking, are not displaced by embeddings but become more important once embeddings are in the loop. The book is written for practitioners: software engineers, data engineers, architects and technical leads who are building or inheriting a system that retrieves things by similarity. It assumes comfort with databases and some familiarity with machine learning vocabulary, but not a background in information retrieval or computational geometry. Where mathematics carries the explanation, it is given in words. How the book is organised The chapters move from representation, through indexing, to systems. Chapter 1 establishes what an embedding is and why geometry can stand in for meaning, tracing the line from word2vec to modern sentence encoders and explaining the distance measures that every later decision depends on. Chapter 2 treats the embedding model as an engineering component: how models are trained, how to read benchmark results without being misled, what dimensionality and quantisation trade away, and why changing models later is so expensive. Chapter 3 explains why nearest-neighbour search in high dimensions is hard at all, why the classical spatial data structures fail, and what "approximate" means in a precise, measurable sense. Chapter 4 is a close study of HNSW, the graph algorithm that dominates production systems, together with its disk-resident cousin DiskANN. Chapter 5 covers the other great family of techniques, partitioning and compression: inverted file indexes, product quantisation, and the binary quantisation schemes that have recently changed the economics of storage. Chapter 6 turns to the parts of retrieval that sit around the index: filtering by structured attributes, hybrid search that blends keyword and semantic signals, and reranking with more expensive models. Chapter 7 examines the convergence of vector search and relational databases, comparing what PostgreSQL, Oracle, SQL Server and MySQL now offer with the dedicated engines, and offering a way to decide between them. Chapter 8 steps back from document search to recommendation engines, where vector retrieval has its longest production history and where some of the hardest lessons about freshness, bias and scale were first learned. Chapter 9 covers evaluation and operations: how to measure whether retrieval is good, how to run it reliably, and what security risks embeddings carry. The conclusion draws out what follows from the whole, including what remains genuinely unsettled in the field. A word on currency. This is a fast-moving area, and specific product capabilities change monthly. The book names versions and dates where they matter and explains the underlying mechanisms in enough depth that a reader can evaluate the next release on their own terms. Algorithms such as HNSW and product quantisation have been stable for years; the products that wrap them are not. The reader who understands the mechanisms will be able to read a vendor's release notes and know what has actually changed. CHAPTER 1 Meaning as Geometry The central trick of semantic search is easy to state and surprisingly hard to internalise. A model converts each item into a point in a space with hundreds or thousands of dimensions, and similarity between items becomes closeness between points. Everything else in this book, the indexes, the filters, the database integrations, the recommendation pipelines, is machinery for exploiting that trick at scale. Before turning to the machinery, it is worth understanding the trick properly: where it came from, what kind of "meaning" it captures, and what the choice of distance measure quietly assumes. From counting words to learning representations The oldest way to turn text into numbers is to count. In the vector space model that Gerard Salton and his colleagues developed for the SMART retrieval system in the 1960s and 1970s, each document becomes a vector with one dimension for every word in the vocabulary. The value in each dimension reflects how often the word appears, usually adjusted by how rare the word is across the collection, the familiar TF-IDF weighting. A query is turned into a vector the same way, and documents are ranked by the cosine of the angle between their vector and the query's. This is already geometry, and the cosine similarity that Salton used is still the most common measure in modern semantic search. But these early vectors are sparse and literal. A vocabulary of a hundred thousand words yields a hundred-thousand-dimensional space in which almost every coordinate of every document is zero, and in which "car" and "automobile" occupy entirely separate axes. Two documents that say the same thing in different words are orthogonal. The geometry is real, but it encodes spelling, not meaning. Researchers tried for decades to compress these sparse vectors into denser ones that captured latent topics. Latent semantic analysis, introduced by Deerwester and colleagues in 1990, applied a singular value decomposition to the term-document matrix and kept only the strongest few hundred dimensions. Words that appeared in similar documents ended up near one another, so "car" and "automobile" could finally be close. The method worked well enough to be used in essay grading and patent search, but it was linear, expensive to update, and limited by the bag-of-words input it started from. The shift to learned representations arrived in 2013 with word2vec, from Tomas Mikolov and colleagues at Google. Word2vec trained a shallow neural network to predict a word from its neighbours, or the neighbours from the word, across billions of words of text. The weights of that network, a few hundred numbers per word, turned out to be a remarkably good description of each word's usage. Words used in similar contexts landed near one another, and the space had striking regularities: the vector offset from "man" to "woman" was roughly parallel to the offset from "king" to "queen". The analogy examples became famous, and they somewhat oversold the regularity, but the underlying lesson held. A model trained on a simple predictive task can learn a geometry in which distance tracks semantic relatedness. Word vectors had an obvious limitation: each word had one vector regardless of context, so "bank" meant the same thing beside a river and in a financial statement. Contextual models fixed this. ELMo in 2018, and then BERT from Devlin and colleagues later that year, produced a different vector for every occurrence of a word, computed from the whole surrounding sentence by a deep transformer network. BERT transformed natural language processing benchmarks almost overnight. Yet BERT on its own was a poor tool for semantic search, which surprised many people who tried it. The obvious approach, averaging BERT's token vectors to get a sentence vector and comparing sentences by cosine similarity, performed badly, in some evaluations worse than averaging old word2vec-style vectors. The reason is that BERT was never trained to make sentence-level distances meaningful. Its pretraining tasks, predicting masked words and judging whether two sentences follow one another, shape the internal representations for those tasks, not for comparison. BERT was strong at comparing two sentences when both were fed into it together as a pair, so that its attention layers could look across them, but that requires running the full model once for every pair. Finding the most similar sentence in a collection of ten thousand meant around fifty million model runs for all pairwise comparisons. Nils Reimers and Iryna Gurevych, who quantified this cost in their 2019 Sentence-BERT paper, estimated it at about 65 hours on a modern GPU. Sentence-BERT's solution defines the architecture still used by most semantic search systems. Instead of feeding pairs into the model, it feeds each sentence through the network separately, pools the output into a single vector, and fine-tunes the network so that the cosine similarity between two sentence vectors predicts whether the sentences mean the same thing. The training data came from natural language inference and semantic similarity datasets, pairs of sentences labelled by humans as related or unrelated. After fine-tuning, each sentence in a collection can be encoded once, offline, and the search for the most similar sentence becomes a comparison between one new query vector and a set of stored vectors. Reimers and Gurevych reported that the same ten-thousand-sentence task fell from 65 hours to about five seconds. This design is called a bi-encoder, or a dual encoder, because queries and documents are encoded independently. Its counterpart, the cross-encoder, which reads query and document together, is far more accurate per comparison and far too slow to apply to a whole corpus. Most production retrieval systems use both: a bi-encoder to retrieve a few hundred candidates from millions, and a cross-encoder to rerank them. That division of labour recurs throughout this book, because it reflects a fundamental tension. Independence is what makes precomputation and indexing possible, and independence is also what limits accuracy. A bi-encoder must compress everything it might ever need to know about a document into one fixed-length vector before it has seen the query. Dense passage retrieval, introduced by Karpukhin and colleagues at Facebook AI in 2020, demonstrated that this kind of dual encoder, trained on question and answer pairs, could beat the strong lexical baseline BM25 on open-domain question answering by a substantial margin in top-20 retrieval accuracy. That result, alongside the retrieval-augmented generation work of Lewis and colleagues the same year, set the template for the retrieval systems built around large language models from 2023 onwards. What the geometry actually encodes It is tempting to say that embeddings capture "meaning", and this book uses the word as shorthand, but the claim needs care. An embedding captures whatever notion of similarity its training objective rewarded. That is a narrower and more useful idea. A model trained on pairs of questions and their answers learns that a question should be close to its answer. A model trained on pairs of paraphrases learns that paraphrases should be close. A model trained on product listings and the queries that led to purchases learns that a query should be close to what people bought after typing it. These are different geometries. In the first, "How do I reset my password?" should sit near a paragraph that explains the reset procedure. In the second, it should sit near "What's the procedure for changing a forgotten password?" A model trained for one purpose can perform surprisingly poorly when used for the other, and much of the practical work of choosing an embedding model, the subject of the next chapter, is matching the model's notion of similarity to the application's. Two consequences are worth stating plainly. First, embeddings encode association more readily than logic. Negation is the classic example. "Flights that are not delayed" and "flights that are delayed" share almost all their content and frequently sit very close together in embedding space, because most of the training signal says that sentences about delayed flights belong together. A bi-encoder has no mechanism for treating "not" as an operator; it must learn negation statistically, and it often fails. The same applies to numeric constraints, dates, exact identifiers and Boolean combinations. "Laptops under 1,000 dollars" retrieves laptops and prices, not a filter. These are not bugs to be fixed by a better model so much as signs that some parts of a query belong in a structured filter or a keyword match rather than in a vector. Chapter 6 returns to this. Second, there are hard limits on what a single vector can express. In a 2025 paper, Orion Weller and colleagues at Google DeepMind and Johns Hopkins showed formally that the number of distinct top-k result sets a single-vector embedding can produce is bounded by its dimensionality. They built a deliberately simple dataset, called LIMIT, in which documents state which things people like and queries ask who likes a given pair of things, so that the relevant documents for each query form arbitrary combinations. State-of-the-art embedding models that rank highly on standard benchmarks scored below 20 percent recall at 100 on it, while a classical sparse lexical model did far better. The tasks in LIMIT are artificial, but the lesson generalises: when a query's relevant set is defined by combinations of conditions rather than by a coherent topic, dense vectors struggle, and the remedy is architectural rather than a matter of waiting for the next model. None of this diminishes the power of the approach. For the large class of queries where users describe what they want in natural language, where vocabulary mismatch is the main failure of keyword search, and where "more like this" is the actual question, dense embeddings are dramatically better than anything that came before them. The point is to know which class of query a system is serving. Embeddings are also not confined to text. Image models trained with contrastive objectives, notably OpenAI's CLIP from 2021, map images and their captions into a shared space, so that a text query can retrieve images and vice versa. Audio, code, molecules, user behaviour sequences and graph nodes can all be embedded. The search machinery described in the rest of this book does not care where the vectors came from. A nearest-neighbour index over product photographs works the same way as one over support articles. What changes is the training objective that gave the space its shape, and therefore what "close" means. Distance, similarity and normalisation Once items are vectors, the system needs a way to measure closeness. Three measures dominate practice, and the differences between them matter more than their simplicity suggests. Euclidean distance, also called L2 distance, is the straight-line distance between two points: subtract the vectors coordinate by coordinate, square the differences, add them up, and take the square root. Since the square root does not change the ordering, systems usually work with the squared distance. Smaller is closer. The inner product, or dot product, multiplies corresponding coordinates and adds the results. Larger is closer. Unlike Euclidean distance, it depends on the lengths of the vectors as well as their directions: a long vector pointing roughly the right way can outscore a short vector pointing exactly the right way. That property is sometimes exactly what is wanted. In recommendation models, as Chapter 8 discusses, the length of an item's vector often absorbs its popularity, so that a dot product ranks popular items higher, all else being equal. Cosine similarity is the dot product of the two vectors divided by the product of their lengths, which equals the cosine of the angle between them. It ignores length entirely and measures only direction. It ranges from minus one, for vectors pointing in opposite directions, to one, for vectors pointing the same way. The useful fact that connects these measures is that once every vector is normalised to unit length, they all agree on ranking. For unit vectors, the squared Euclidean distance equals two minus twice the dot product, and the dot product equals the cosine. So the nearest neighbour by Euclidean distance, the highest dot product, and the highest cosine similarity are the same item. Many embedding providers return vectors that are already normalised; OpenAI's documentation, for example, states that its embeddings are normalised to length one, so cosine similarity and dot product give the same result. When vectors are normalised, a system can use the cheapest computation, the plain dot product, with no loss. When vectors are not normalised, the choice matters and must match the model's training. A model trained with a cosine objective expects cosine at query time; using raw Euclidean distance on its outputs can produce noticeably different rankings, because the lengths it produces carry no intended meaning. A model trained with a dot-product objective, as many recommendation models are, expects length to matter; normalising its vectors throws away information the model deliberately put there. The rule is simple: use the metric the model was trained with, and check the model's documentation rather than assuming. A surprising number of disappointing deployments trace back to a mismatch here, often introduced when a vector index was created with a default metric different from the one the embedding provider recommended. The metric also constrains the index. Some approximate nearest-neighbour methods are designed for Euclidean distance and need a transformation to handle maximum inner product search. The problem of finding the vector with the largest dot product, which is not a true distance because a vector need not be its own best match, received its own research literature for exactly this reason. Shrivastava and Li's 2014 work on asymmetric locality-sensitive hashing for inner products, and later Google's ScaNN, treat it as a first-class case. Practically, most modern libraries and databases support all three measures directly, but the choice is made when the index is built and cannot be changed without rebuilding. There is one more subtlety that catches people out. Similarity scores from embedding models are not calibrated probabilities. A cosine similarity of 0.82 does not mean the document is 82 percent relevant, and the same score can mean different things for different queries and different models. Some models produce scores clustered in a narrow band, so that nearly every document scores between 0.7 and 0.9 against nearly every query. Thresholds such as "only return results above 0.8" are therefore fragile; they need to be set empirically for the specific model and corpus, and they should be re-examined whenever the model changes. Ranking by score is reliable in a way that absolute score values are not. Why high-dimensional space is strange Embedding spaces have hundreds or thousands of dimensions, and intuitions formed in two or three dimensions mislead in specific, predictable ways. Three are worth carrying into the rest of the book. First, almost all the volume of a high-dimensional ball lies close to its surface, and randomly chosen directions are nearly orthogonal. Two random unit vectors in a space of a thousand dimensions will almost always have a cosine similarity very close to zero. This is why embeddings can pack so many distinct concepts into a few hundred dimensions without collision: there is an enormous number of nearly orthogonal directions available. It is also why the useful structure in an embedding space is concentrated; the model places related items in a small region of an otherwise vast and empty space. Second, as dimensionality grows, distances between random points concentrate around a single value. Beyer and colleagues showed in 1999 that, under broad conditions on the data distribution, the ratio between the distance to a query's farthest neighbour and its nearest neighbour approaches one as dimensions increase. If all points are roughly equally far from the query, then "nearest" stops being meaningful. Real embeddings escape this trap, because they are not random: they lie close to lower-dimensional structures shaped by the data, and their intrinsic dimensionality is far lower than their nominal one. But the result explains why indexing high-dimensional data is so hard, as Chapter 3 shows, and why embeddings of poor quality, which look more like noise, produce search results that feel arbitrary. Third, a small number of points can become "hubs" that appear in the nearest-neighbour lists of a disproportionate number of other points. Radovanović and colleagues documented this hubness phenomenon in 2010 as an inherent property of high-dimensional data. In a search system it shows up as a handful of documents that are retrieved for everything, often generic or boilerplate passages such as a legal disclaimer or a table of contents. Recognising hubness as a geometric effect rather than a content problem helps, because the remedies are geometric too: centring the vectors, removing boilerplate before embedding, or reranking with a model that reads the text. These properties are not obstacles to using embeddings. They are the reasons embeddings work at all and the reasons searching them efficiently requires the specialised structures described in Chapters 3 to 5. A practitioner who keeps them in mind will read benchmark results, debug strange rankings and choose index parameters with much better judgement. The core idea of this chapter is that the geometry is learned, and it reflects the objective that shaped it. Distance in an embedding space means exactly what the training data taught it to mean and nothing more. The next chapter treats that training as an engineering decision: how to choose a model whose notion of similarity matches the application, and what the choice commits a system to for years afterwards. CHAPTER 2 Choosing and Living With an Embedding Model Most teams spend more time choosing a vector database than choosing an embedding model, and most of them have the priorities backwards. The index determines how fast a system finds the nearest vectors. The embedding model determines whether the nearest vectors are the right answers. No index, however clever, can recover relevance that the model failed to encode, and the model is also the component that is hardest to change later, because every stored vector depends on it. This chapter treats the embedding model as what it is: the most consequential and least reversible decision in a retrieval system. How embedding models learn similarity Almost every modern text embedding model is trained with some form of contrastive learning. The idea is straightforward. Take a batch of pairs that should be similar, such as a question and the passage that answers it, a search query and the product a user bought, or a title and the body of the same article. Encode everything. For each anchor, push its vector towards its true partner and away from all the other items in the batch, which serve as negatives. The usual loss function, often called InfoNCE or multiple negatives ranking loss, treats the problem as a classification: out of all the candidates in the batch, which one is the real partner? The model gets better by making the true partner's similarity score stand out. Two details of this recipe explain a great deal about why some models are better than others. The first is the use of in-batch negatives. Because every other item in the batch serves as a negative example, larger batches give the model more and harder comparisons per step, and contrastive models tend to improve with batch sizes in the thousands or tens of thousands. The second is hard negatives. Random negatives are too easy; any model quickly learns that a passage about tax law is not the answer to a question about tennis. What teaches fine distinctions is a negative that looks relevant but is not, such as a passage about the same topic that does not answer the question. Good training pipelines mine such hard negatives deliberately, often using an earlier model or BM25 to find near-misses. The quality and quantity of hard negatives is one of the main differences between a mediocre embedding model and an excellent one. The large modern models are trained in stages. A first stage uses enormous quantities of weakly paired data scraped from the web: titles and bodies, questions and accepted answers from forums, citations and the passages around them. Wang and colleagues' E5 models, published by Microsoft in 2022, used a curated set of around 270 million such pairs. A second stage fine-tunes on smaller, high-quality labelled datasets with hard negatives. Since 2023, a third ingredient has become standard: synthetic training data generated by large language models, which can produce millions of realistic queries for passages across many languages and task types. The architecture has also shifted. Early sentence encoders were BERT-sized models of around a hundred million parameters. Since 2024, the strongest models are increasingly built on decoder-only large language models, fine-tuned for embedding. Alibaba's Qwen3-Embedding series, released in June 2025 under the Apache 2.0 licence, comes in sizes of 0.6, 4 and 8 billion parameters; the 8-billion-parameter model was ranked first on the multilingual MTEB leaderboard at release. Larger models encode more nuance but cost more to run, and for a system that must embed every query in real time, the difference between a 100-million and an 8-billion-parameter encoder is a difference in hardware budget and latency, not only quality. Another important development is instruction-tuning. Many current models accept a short task description alongside the text, such as "Given a web search query, retrieve relevant passages that answer the query" or a simpler prefix like "query:" versus "passage:". The instruction tells the model which notion of similarity to apply, so that a single model can serve retrieval, clustering, classification and duplicate detection. This flexibility comes with a trap: if the model expects a query prefix and the application omits it, or uses the document prefix for queries, retrieval quality drops, sometimes sharply, with no error message. Reading the model card and following its prompting conventions exactly is one of the cheapest quality improvements available. Asymmetry deserves emphasis. A search query is short, underspecified and phrased as a request; the document that answers it is long, declarative and full of detail. Models trained on symmetric tasks, where both sides are sentences of the same kind, can perform poorly on asymmetric retrieval. Instruction prefixes are one way of telling the model which side of the asymmetry each input is on. Another approach, used in some systems, is to generate hypothetical questions for each document at indexing time and embed those instead of, or alongside, the document text, so that queries are compared with questions. Gao and colleagues' 2022 HyDE method runs the idea in the other direction, using a language model to write a hypothetical answer to the query and embedding that. Both are workarounds for the same gap. Reading benchmarks without being misled The Massive Text Embedding Benchmark, MTEB, introduced by Niklas Muennighoff, Nouamane Tazi, Loïc Magne and Nils Reimers in 2022, became the standard scoreboard for embedding models. It covered eight task types, including retrieval, classification, clustering, reranking and semantic textual similarity, across 58 datasets in the original release. Its public leaderboard on Hugging Face is where most teams first look when choosing a model. A substantially larger multilingual successor, MMTEB, extended the benchmark to hundreds of tasks across many languages in 2025, and the leaderboard now offers several views, including English, multilingual, code and domain-specific subsets. The leaderboard is genuinely useful, and also easy to misuse. Four cautions apply. First, the headline average mixes tasks that matter for a given application with tasks that do not. A team building document retrieval should look at the retrieval columns, not the overall average, because a model can rank highly by excelling at classification and clustering while being merely good at retrieval. The retrieval subset itself draws heavily on BEIR, a benchmark assembled by Nandan Thakur and colleagues in 2021 specifically to test zero-shot retrieval across diverse domains such as biomedical questions, financial questions, argument retrieval and fact checking. One of BEIR's most important findings, often forgotten, was how strong BM25 remained: many dense retrievers of the time underperformed it on domains they had not been trained on. Second, benchmark scores are increasingly affected by training on data that overlaps with the benchmark. Because many benchmark datasets are public and the training pipelines of large models are not, it is often impossible to know whether a model has seen test-like data. Small differences of a point or two between top models should not decide anything. Third, benchmark data is not your data. A model that excels at Wikipedia-style questions may stumble on internal engineering tickets full of product codes, on legal contracts with dense cross-references, or on customer messages written in a mix of languages and slang. Domain shift is the norm, not the exception. Fourth, benchmarks say nothing about operational fit: licence terms, hosting options, latency, cost per million tokens, maximum input length, the provider's deprecation policy, and whether the model can be run inside a particular jurisdiction. The practical conclusion is that the leaderboard is for shortlisting, not choosing. The choice should be made on a small evaluation set drawn from the application's own data, typically a few hundred real or realistic queries with judged relevant documents. Chapter 9 describes how to build one. Running three or four shortlisted models against such a set is usually a day's work, and it regularly overturns leaderboard rankings. Teams that skip this step are choosing on someone else's data. Table 1 sets out the basic specifications of several widely used models that span the range from small open models to large hosted ones. It is not a ranking; it shows the dimensions of the decision. Table 1. Specifications of selected text embedding models as published by their providers. Model Provider and licence Default dimensions Reduced dimensions Maximum input tokens all-MiniLM-L6-v2 Sentence Transformers, Apache 2.0 384 Not supported 256 BGE-M3 BAAI, MIT 1,024 Not supported 8,192 text-embedding-3-small OpenAI, hosted API 1,536 Yes, by parameter 8,191 text-embedding-3-large OpenAI, hosted API 3,072 Yes, by parameter 8,191 gemini-embedding-001 Google, hosted API 3,072 128 to 3,072 2,048 embed-v4.0 Cohere, hosted API 1,536 256, 512 or 1,024 128,000 Qwen3-Embedding-8B Alibaba Qwen, Apache 2.0 4,096 32 to 4,096 32,768 Source: model cards and API documentation from Hugging Face, OpenAI, Google, Cohere and Alibaba Qwen, accessed October 2026. Input limits for all-MiniLM-L6-v2 reflect its documented truncation length. The spread is striking. The smallest model produces vectors one-tenth the size of the largest and accepts a few paragraphs of input rather than a long document. It is also small enough to run on a CPU at high throughput, which is why it remains popular for prototypes, edge devices and cost-sensitive workloads despite being several years old. At the other end, a model like Qwen3-Embedding-8B produces vectors that are far more expressive but costs real GPU capacity to run on every query and every document. Size, precision and input length Vectors are not free to store or compare. A single 1,536-dimensional vector of 32-bit floating point numbers occupies 6,144 bytes. Ten million of them take about 61 gigabytes before any index overhead, and a graph index such as HNSW, discussed in Chapter 4, typically wants the full-precision vectors in memory for fast search. At 3,072 dimensions the figure doubles. For a hundred million documents split into chunks, raw vector storage alone can run to terabytes. Comparison cost scales with dimension too: every distance computation touches every coordinate. Three techniques now let a system trade some quality for large savings, and all three are widely supported. The first is shortening the vector. Matryoshka representation learning, introduced by Aditya Kusupati and colleagues in 2022, trains a model so that the first few dimensions of its output form a usable embedding on their own, the first 64 a slightly better one, the first 256 better still, and so on, like a set of nested dolls. A system can store a truncated prefix of the full vector, re-normalise it, and accept a modest loss in quality for a large saving in space. OpenAI adopted this for its third-generation models in January 2024 and reported that text-embedding-3-large shortened to 256 dimensions still outperformed its predecessor, text-embedding-ada-002, at 1,536 dimensions on MTEB. Google, Cohere, Alibaba and several open model families now support the same approach, which is why Table 1 lists reduced dimension options. Truncation only works for models trained this way; cutting dimensions from a model not trained with a Matryoshka objective degrades it badly. The second is reducing numeric precision. Storing each coordinate as a 16-bit float instead of a 32-bit float halves storage with negligible quality loss for almost all retrieval purposes; pgvector's halfvec type, added in version 0.7.0 in April 2024, is one example. Going further, each coordinate can be mapped to an 8-bit integer, a technique called scalar quantisation, cutting storage by a factor of four with typically small accuracy loss. Some providers, including Cohere, return embeddings directly in int8 or binary form for this reason. The third is binary quantisation: keep only the sign of each coordinate, one bit, a 32-fold reduction. Comparisons become bit operations, using the Hamming distance, which modern CPUs compute extremely quickly. Raw binary quantisation loses meaningful accuracy for many models, but it works remarkably well as a first pass. A common pattern is to search over binary codes to retrieve a few hundred candidates and then rescore them with the full-precision vectors held on disk or in cheaper storage. Chapter 5 examines the more sophisticated binary schemes, such as RaBitQ, that have recently made this approach much more accurate. These techniques compound. A 3,072-dimensional float32 vector truncated to 1,024 dimensions and stored at int8 occupies 1,024 bytes instead of 12,288, a twelvefold saving, and on many retrieval tasks the quality loss is smaller than the gap between two competing models. The right combination for any system depends on the model and the data, which is another reason to have an evaluation set before making the choice. Embedding models accept input up to a maximum length, and many real documents are longer. Even when they are not, compressing a twenty-page document into a single vector loses detail: the vector becomes an average of everything the document discusses and matches nothing in particular very well. Retrieval systems therefore split documents into chunks, embed each chunk, and retrieve chunks rather than whole documents. Chunking is one of the least glamorous and most consequential decisions in a semantic search pipeline. Chunks that are too small lose context: a sentence like "The fee was waived for the second year" means nothing without knowing which fee and which customer. Chunks that are too large dilute the signal and waste the context window of whatever language model reads them afterwards. Splitting in the middle of a table, a list or a code block can destroy the structure that made the content intelligible. Practitioners have converged on a few defensible patterns. Splitting along the document's own structure, headings, sections and paragraphs, generally beats splitting at fixed token counts. Modest overlap between adjacent chunks reduces the risk of cutting an idea in half. Attaching document-level metadata, such as the title, section heading and date, to each chunk, either in the text that gets embedded or in fields used for filtering, restores some of the lost context. A more recent technique goes further. In September 2024, Anthropic described "contextual retrieval", in which a language model writes a short explanation of each chunk's place within its document, typically fifty to a hundred tokens, and that explanation is prepended to the chunk before embedding and before keyword indexing. In Anthropic's experiments across several datasets, contextual embeddings alone reduced the rate of failed retrievals, measured as one minus recall at 20, by 35 percent; combined with contextual keyword search the reduction was 49 percent; and adding a reranking step brought it to 67 percent. The specific numbers come from one company's evaluation, but the mechanism is general: the chunk that gets embedded should carry enough context to be understood on its own. Long-context embedding models, such as those accepting 8,000 or even 128,000 tokens, do not remove the need for chunking. They make it possible to embed whole documents when that is useful, for instance for document-level clustering or deduplication, but a single vector for a long document still averages over everything in it. For retrieving precise passages, chunk-level vectors remain the norm. A related approach, late chunking, runs the whole document through a long-context model first and then pools the token vectors for each chunk separately, so that each chunk vector is informed by its surroundings. Committing to a model The decision that most teams underestimate is not which model to choose but what choosing it commits them to. Vectors produced by different models live in different spaces. A query embedded with one model cannot be meaningfully compared with documents embedded with another, even if both produce vectors of the same length. There is no general way to convert one model's vectors into another's with high fidelity. Changing the model therefore means re-embedding the entire corpus and rebuilding every index. For a corpus of a few hundred thousand chunks this is an afternoon's work and a modest API bill. For hundreds of millions of chunks it is a migration project, with real compute costs, a period of running two indexes side by side, and a cutover that has to be coordinated with every service that generates query vectors. Hosted models add a further dependency: the provider may deprecate a model on its own schedule. OpenAI's text-embedding-ada-002, released in December 2022, was succeeded by the text-embedding-3 models just over a year later, and every team that wanted the improvement had to re-embed. Several practices reduce this lock-in. Store the original text, or a reference to it, alongside every vector, so that re-embedding never depends on reconstructing source data. Record the model name and version as a field on every stored vector, so that a mixed state during migration is detectable rather than silent. Keep the embedding call behind a single internal service, so that queries and documents always use the same model and prompting conventions. Design the indexing pipeline so that a full re-embed is a routine, tested batch job rather than a heroic effort. And when evaluating a model, include the cost of switching away from it. The choice between hosted and self-hosted models also deserves deliberate thought. Hosted APIs offer strong models with no infrastructure and pay-per-token pricing; OpenAI listed text-embedding-3-small at two cents per million tokens at launch, which makes embedding even large corpora cheap. They also send every document and every query to a third party, add network latency to every search, and tie the system to an external deprecation schedule. Self-hosted open-weight models remove those concerns and allow fine-tuning on domain data, at the cost of running GPU or CPU inference reliably. Fine-tuning is worth considering more often than it is. When a domain has its own vocabulary, such as medicine, law, chip design or internal product names, a general model can confuse terms that matter. A few thousand query and document pairs from the domain, mined from search logs or generated synthetically, are often enough to improve a mid-sized open model substantially on in-domain retrieval. The improvement is measurable only with an evaluation set, which brings the argument back to where it started. The embedding model gives a corpus its geometry. The next three chapters turn to the problem of searching that geometry quickly. That problem, it turns out, is much harder than it looks. CHAPTER 3 Why Nearest-Neighbour Search Is Hard Finding the vectors closest to a query sounds like a solved problem. Databases have answered "find the nearest restaurant to this location" for decades, and computational geometry offers elegant structures for partitioning space. Yet none of those structures works well for embeddings, and the systems that do work all give up exactness to get speed. Understanding why, and understanding precisely what is given up, is essential for anyone who has to tune, evaluate or explain a vector search system. This chapter lays the groundwork for the specific algorithms of Chapters 4 and 5. The honest baseline: exact search The simplest possible nearest-neighbour search compares the query with every stored vector and keeps the best k. It is called brute-force, flat or exhaustive search, and it is exact by construction: if the distance computations are correct, it always returns the true nearest neighbours. Its cost is easy to calculate. For a collection of N vectors of d dimensions, each query requires N distance computations of d multiply-add operations each. A million 768-dimensional vectors means about 768 million multiply-adds per query. That sounds large, but modern hardware is very good at exactly this operation. A CPU core using vector instructions can perform tens of billions of floating-point operations per second, and the comparison is perfectly parallel across cores. A GPU, which is built for dense linear algebra, can do the same work for a batch of queries as a single matrix multiplication. The FAISS library, released by Facebook AI Research in 2017 and described in detail by Matthijs Douze and colleagues in a 2024 paper, includes highly optimised flat indexes for both CPUs and GPUs precisely because exhaustive search is often good enough. The limiting factor is usually memory bandwidth rather than arithmetic. A million 768-dimensional float32 vectors occupy about three gigabytes, and an exhaustive scan must read all of it for every query. At a few tens of gigabytes per second of memory bandwidth, that puts a hard floor of something like a tenth of a second per query on a single machine, before any other work. Batching many queries together amortises the read, which is why exhaustive search on GPUs can achieve high throughput, but interactive applications with one query at a time cannot batch much. So exact search is the right answer more often than marketing suggests. For collections of up to a few hundred thousand vectors, it is typically fast enough for interactive use and has no index to build, tune or maintain. It is the only way to get ground truth when evaluating an approximate index. And, as Chapter 6 shows, it becomes the best strategy again when a filter narrows the candidates to a small subset, because scanning a few thousand vectors exactly is cheaper than traversing an approximate index that was built for the whole collection. A team with fifty thousand documents that adopts a distributed vector database is solving a problem it does not have. Beyond a few million vectors, or with strict latency targets, exhaustive search stops being practical. Something must avoid looking at most of the data. That is where the trouble starts. Why spatial trees fail, and the turn to approximation The classical approach to avoiding most of the data is to organise space hierarchically. A k-d tree, introduced by Jon Bentley in 1975, recursively splits the data along one coordinate at a time: everything with a first coordinate below the median goes left, everything above goes right, then each half is split along the second coordinate, and so on. To find the nearest neighbour of a query, the search descends to the leaf containing the query, finds the best candidate there, and then backtracks only into branches whose region could contain something closer. In two or three dimensions this prunes almost the whole tree and is extremely fast. R-trees, introduced by Antonin Guttman in 1984 and used for geographic data in most spatial databases, follow the same principle with bounding rectangles. These structures degrade as dimensionality increases, and the degradation is not gradual. The pruning step depends on being able to rule out regions because they are too far away. In high dimensions, as Chapter 1 described, distances concentrate: the region around the query that might contain a closer point grows to intersect almost every cell of the partition. The search must backtrack into nearly every branch, and it ends up examining most of the data while paying the overhead of the tree on top. Roger Weber, Hans-Jörg Schek and Stephen Blott analysed this in a 1998 paper and showed that, for uniformly distributed data, tree-based and partitioning methods are outperformed by a simple sequential scan once dimensionality exceeds roughly ten. Their proposed remedy was not a better tree but a faster scan over compressed approximations of the vectors, an idea that anticipated the quantisation methods of Chapter 5. Real data is not uniform, and k-d trees do somewhat better on data with low intrinsic dimensionality. But embeddings with hundreds of dimensions and intrinsic dimensionalities in the tens are well beyond the range where exact tree search is useful. This is the "curse of dimensionality" as it applies to search: there is no known data structure that answers exact nearest-neighbour queries in high dimensions substantially faster than a linear scan, in the worst case, without using an impractical amount of memory. The way out, proposed in the late 1990s, was to stop insisting on the exact answer. Piotr Indyk and Rajeev Motwani's 1998 paper on approximate nearest neighbours introduced locality-sensitive hashing, and it reframed the problem. Instead of guaranteeing the true nearest neighbour, guarantee a neighbour whose distance is within some factor of the true nearest distance, with high probability. That relaxation turns out to permit search in time that grows sub-linearly with the size of the collection. The mechanism is elegant. Choose a family of hash functions with the property that nearby points are more likely to receive the same hash value than distant points. For cosine similarity, a simple family works: pick a random direction and hash each vector to one bit according to which side of the corresponding hyperplane it falls on. Two vectors at a small angle will usually fall on the same side; two vectors at a large angle often will not. Concatenating several such bits gives a bucket identifier, and vectors in the same bucket are likely to be close. Because any single hash table misses some true neighbours, the method builds many tables with independent random functions and checks the query's bucket in each. Locality-sensitive hashing has strong theoretical guarantees and remained the dominant approach in research for a decade. Spotify's Annoy library, released in 2013, took a related approach using forests of trees built from random hyperplane splits. But in practice, LSH has been largely displaced in production systems. It typically needs many hash tables to reach high recall, which costs memory, and its random projections ignore the structure of the data. Methods that learn from the data distribution, such as clustering-based partitions and graph indexes, reach the same accuracy with far less work. LSH's lasting contribution is conceptual: it established that approximate answers, with measurable quality, are an acceptable and powerful contract. What "approximate" means and how it is measured Every production vector index today is an approximate nearest-neighbour index, usually abbreviated to ANN. The word approximate is often used loosely, so it helps to be precise about what is being approximated and how the error is measured. The standard measure is recall. Given a query, compute the true k nearest neighbours by exhaustive search. Run the same query through the approximate index and take its top k results. Recall at k is the fraction of the true neighbours that the approximate index found. If the true top ten are documents A through J and the index returns eight of them plus two others, recall at ten is 0.8. Averaging over a few thousand test queries gives a single number for the index at a particular parameter setting. This definition is narrower than it may appear, and confusion about it causes real problems. Recall in the ANN sense measures agreement with exact search over the same vectors. It says nothing about whether those vectors' nearest neighbours are relevant to the user. An index can have perfect ANN recall and terrible search quality, if the embedding model is poor; an index can have 90 percent ANN recall and excellent search quality, if the missing ten percent were marginal anyway. Information retrieval also uses the word recall, meaning the fraction of all relevant documents that were retrieved, and the two are frequently conflated in vendor material and internal discussions. This book uses "ANN recall" for the first and "retrieval recall" for the second when the distinction matters. Chapter 9 returns to measuring the second. The literature uses several variants of the measure, and they are not interchangeable. Some papers report "1-recall at 1", the fraction of queries for which the single true nearest neighbour is returned in first place. Others report "10-recall at 10", the overlap between the true and returned top ten, as described above. Still others report recall of the true top ten within a longer returned list of, say, 100, which is a much easier target and the relevant one when a reranker will reorder the candidates anyway. A system that achieves 0.99 on one of these may achieve 0.85 on another. When comparing vendor claims, the first question is always which variant was measured, at what k, on what data. A second subtlety is that the average hides the distribution. A mean ANN recall of 0.95 can mean that every query loses one result in twenty, or that most queries are perfect while a minority, perhaps those in sparse or unusual regions of the space, lose half their neighbours. The second pattern is common in graph indexes and matters a great deal in practice, because the queries that fail are often the unusual ones a user cared most about. Plotting the per-query distribution, or at least reporting the fraction of queries below some floor such as 0.8, gives a much better picture than the mean alone. Measuring ANN recall requires ground truth, which means running exhaustive search over the same vectors for a set of test queries. For a static collection this is a one-off batch computation. For a collection that changes continuously, the ground truth goes stale as soon as vectors are added or removed, so it must be recomputed against a snapshot taken at the same moment as the index being measured. Chapter 9 describes how to do this continuously in production by sampling live queries. ANN recall is not a property of an index type; it is a property of an index type at a particular configuration, on a particular dataset, at a particular operating point. Nearly every ANN method has a parameter that trades recall for speed: how many graph nodes to explore, how many clusters to probe, how many candidates to rescore. Turn it up and recall rises while throughput falls. The meaningful description of an index is therefore a curve, plotting queries per second against recall, not a single number. A claim like "our index does a million queries per second" is meaningless without the recall at which it was measured, and comparisons between systems are only fair at matched recall. The ANN-Benchmarks project, started by Erik Bernhardsson and formalised in a paper by Martin Aumüller, Bernhardsson and Alexander Faithfull, published in its journal version in 2020, made this curve the standard way to compare algorithms. It runs dozens of implementations against public datasets such as SIFT, a collection of a million 128-dimensional image descriptors assembled by Hervé Jégou and colleagues, and GloVe word vectors, and plots each library's throughput against recall. The resulting charts settled several questions in the field; graph-based methods, especially HNSW, sat at or near the top of most of them for years. The larger Big-ANN-Benchmarks effort, run as a NeurIPS competition in 2021 and again in 2023, extended the comparison to billion-scale datasets and to scenarios such as filtered and streaming search, where data changes during the benchmark. These benchmarks are valuable and also limited. Their datasets are older and, in several cases, lower-dimensional than modern text embeddings, which commonly have 768 to 3,072 dimensions and behave differently. They usually measure a single machine with the whole index in memory, a static dataset and no metadata filters, whereas production systems face updates, deletes, filters and multi-tenancy. A team selecting an index should treat public benchmarks as evidence about algorithms and run their own measurement, with their own vectors and query patterns, before relying on a particular configuration. The five costs every index trades Approximate indexes do not just trade recall against speed. A complete picture requires five quantities, and the art of choosing and tuning an index is understanding which of them a given application can afford to spend. The first is query latency, and specifically tail latency. Average latency hides the slow queries; in a system that calls retrieval once per user request, the 99th percentile determines the experience of a meaningful fraction of users. Graph indexes in particular can show long tails when a query lands in a poorly connected region and the search wanders. The second is throughput: how many queries per second a given amount of hardware can serve at a target recall and latency. For high-traffic applications such as recommendation, throughput often dominates the hardware bill. The third is memory. Indexes that hold full-precision vectors and auxiliary structures in RAM are fast and expensive. For large collections, RAM, not CPU, is usually the binding constraint and the largest cost. Much of the innovation of the past five years, from DiskANN to binary quantisation, has been about reducing the memory needed per vector while keeping recall high. The fourth is build time. Some indexes take hours to construct over a large dataset, and building them competes with query serving for CPU and memory. A system that must rebuild nightly, or that receives a new embedding model and must re-index from scratch, feels this cost acutely. The fifth is mutability: how well the index handles inserts, updates and deletes without degrading or requiring a rebuild. Academic benchmarks have historically assumed a static dataset. Production data changes constantly, products go out of stock, documents are revised, users delete their accounts, and some index structures handle this far better than others. These five costs explain why there is no single best index. An index for a nightly-rebuilt product catalogue with a hundred million items and strict latency targets is a different engineering problem from an index over a few million continuously edited support articles, and both differ from an index over a billion images that is rarely queried but must be cheap to store. The next two chapters examine the two families of methods that dominate practice, graph indexes and partition-and-compress indexes, with these five costs in view. One more principle deserves stating before turning to specific algorithms. ANN error stacks on top of embedding error. If the embedding model ranks the truly relevant document fifteenth, an ANN index at 95 percent recall might drop it entirely from the top twenty. If the model ranks it first, the index will almost always find it. This suggests a practical sequence for diagnosing a retrieval failure: first check whether exhaustive search over the same vectors finds the right answer. If it does not, the problem is the model, the chunking or the query, and no amount of index tuning will help. If it does, the problem is the index or the filter, and the parameters described in the next chapters are the place to look. Teams that skip this step routinely spend weeks tuning the wrong component. Hashtags: #VectorDatabasesAndSemanticSearch #VectorDatabases #SemanticSearch #AIPoweredRetrieval #ArtificialIntelligence #MachineLearning #InformationRetrieval #VectorSearch #VectorEmbeddings #EmbeddingModels #SimilaritySearch #NearestNeighborSearch #ApproximateNearestNeighbors #ANN #HNSW #DiskANN #FAISS #ProductQuantization #HybridSearch #BM25 #RetrievalAugmentedGeneration #RAG #Reranking #SentenceTransformers #DenseRetrieval #VectorIndexing #Pgvector #Pinecone #Weaviate #SearchArchitecture

  • Explainable AI in Practice (Demystifying the Black Box)

    Download the Book (PDF): Introduction: The Question Before the Method A loan officer at a mid-sized bank receives a model score for an applicant: probability of default within eighteen months, 0.31. The approval threshold is 0.20, so the application is declined. Within thirty days the bank must send the applicant a letter stating the principal reasons. The model is a gradient-boosted ensemble of six hundred trees fed by two hundred and forty variables, several of them engineered from bureau tradelines, a few derived from transaction histories the applicant authorised the bank to read. Somebody has to turn that number into four sentences an ordinary person can understand and, if they choose, act on. Somebody else, a year later, may have to defend those four sentences to an examiner. Down the road, a radiologist opens a chest film flagged by a triage algorithm as likely to show a pneumothorax. The vendor's interface overlays a warm-coloured heat map on the upper left lung field. The radiologist glances at it, agrees, and moves the study to the top of the list. Was the heat map telling her where the model looked, where the pathology was, or neither? Would the heat map have looked much the same if the model had been trained on random labels? She does not know, and the interface does not say. These two scenes contain the whole problem this booklet addresses. In both, a complex model produces an output that a human must act on and that some third party may later scrutinise. In both, a tool called an "explanation" sits between the model and the human. And in both, the explanation is only as good as the answer to a question that is rarely asked out loud: what, exactly, is this explanation a measurement of? Explanations are measurements The central claim of this booklet is simple to state and surprisingly demanding to live by. An explanation of a machine learning model is not a window into the model's mind. It is a measurement, taken under specific assumptions, that answers one particular question about the model's behaviour. SHAP values answer a question about how a prediction changes when features are revealed one at a time against a chosen reference. LIME answers a question about which linear function best mimics the model in a neighbourhood whose shape you picked. Integrated gradients answer a question about how the output accumulates along a straight path from a baseline input. A counterfactual answers a question about the nearest point on the other side of a decision boundary, under a distance metric someone chose. These are different questions. They have different answers. When practitioners treat them as interchangeable views of a single underlying truth called "feature importance," they get into trouble: explanations that disagree with each other, explanations that can be manipulated, and explanations that satisfy a compliance checklist while telling the reader nothing true about why the decision went the way it did. Treating explanations as measurements has three practical consequences, and the chapters that follow work through each of them. First, you must choose the question before you choose the method. A data scientist debugging a model needs to know which inputs drive its errors. A credit applicant needs to know what would have changed the outcome. A model validator needs to know whether the model relies on anything it should not. A regulator needs to know whether the firm understands and controls what it has deployed. Each of these is a different question, and the best method for one is often poor for another. Second, every measurement depends on its reference point and its assumptions, and those must be stated. A Shapley value is a contribution relative to a baseline, and the same model and the same applicant produce different attributions against a population average than against an approved-applicant average. A counterfactual is "nearest" only under a metric, and a metric that ignores the cost of changing a feature produces advice nobody can follow. Hiding these choices does not remove them; it only makes them unaccountable. Third, measurements must be validated. Nobody would trust a thermometer that had never been calibrated, yet many teams deploy attribution methods without ever checking whether the attributions change when the model changes. The research literature contains a sobering list of explanation methods that produce attractive, plausible output that turns out to be nearly independent of what the model has learned. Testing an explainer is not optional rigour; it is the only thing that separates an explanation from an illustration. Who this booklet is for The reader I have in mind is technically literate and has a practical problem. Perhaps you are a machine learning engineer who has been told that the credit model you built must produce adverse action reasons, or a data scientist at a health system asked whether the vendor's sepsis alert can "explain itself" to clinicians. Perhaps you work in model risk management, compliance, or clinical informatics and need to understand what the engineers are handing you well enough to challenge it. Perhaps you are a regulator, or advise one, and want a clear view of what the current tools can and cannot support. I assume you know what a neural network and a gradient-boosted tree are, and that a model maps inputs to outputs through parameters fitted to data. I do not assume any prior knowledge of interpretability methods, of cooperative game theory, or of the regulatory frameworks in finance and healthcare. Each is developed from the ground up, because each is necessary to the argument and because the most common errors in practice come from half-understood foundations. What the booklet covers, and what it leaves out The first chapter sets out what explanations are for: the different audiences, the different questions, and the distinction between an explanation that is faithful to the model and one that is merely plausible to a human. It also takes seriously the strongest objection to the whole enterprise, the argument that in high-stakes settings you should not be explaining black boxes at all but building models that need no explaining. The next three chapters treat the main families of local attribution. Chapter 2 develops Shapley values from first principles, including the choice of baseline and the treatment of correlated features, which together account for most of the confusion in practice. Chapter 3 covers LIME and the broader idea of local surrogate models, with an honest account of their instability. Chapter 4 moves inside deep neural networks, where gradients make attribution cheap and where the evidence that cheap attributions can be misleading is strongest. Chapter 5 turns from attribution to counterfactual explanation and algorithmic recourse: not "why did this happen?" but "what would have to change?" That shift matters enormously for the people on the receiving end of automated decisions, and it maps onto legal requirements more naturally than attribution does. Chapter 6 is about testing explanations: the sanity checks, faithfulness metrics, and stability tests that should accompany any explanation method into production. Chapters 7 and 8 apply all of this to the two regulated domains where the stakes and the scrutiny are highest. In finance, the adverse action requirements of United States credit law, model risk management expectations, European data protection law and the EU AI Act each ask for something slightly different, and the chapter shows how to build reason codes that are defensible under all of them. In healthcare, the Food and Drug Administration's approach to clinical decision support and machine learning devices, together with the realities of clinical workflow and automation bias, shape what an explanation can usefully do. Chapter 9 draws the technical and regulatory threads together into an engineering discipline: how to build, document, version, monitor and audit an explanation system so that it survives contact with an examiner. Several adjacent topics are left out or treated only in passing. Fairness auditing deserves its own book; it appears here only where it intersects with explanation. Mechanistic interpretability, the effort to reverse-engineer the internal circuits of large neural networks, is a fascinating and fast-moving research programme, but its tools are not yet the ones a bank or a hospital uses to meet a legal obligation, and it receives only a brief mention. Explanations for large language models, and the question of whether a model's own stated reasoning can be trusted, are touched on in the final chapter without being treated in depth. The focus throughout is on the supervised predictive models, tabular and imaging above all, that make consequential decisions about individual people today. A word on regulation and dates The regulatory landscape has moved quickly and continues to move. Within the eighteen months before this booklet was completed, the United States banking agencies replaced their long-standing model risk guidance, the Consumer Financial Protection Bureau withdrew a set of circulars that had addressed algorithmic adverse action notices, the European Union agreed to postpone the application of the AI Act's high-risk obligations, and the Food and Drug Administration revised its guidance on clinical decision support software. Where the text describes a rule, it describes the position as of the autumn of 2026, and it tries to distinguish between what the binding law requires and what guidance or supervisory expectation adds. The statutory core in both domains has proved far more stable than the guidance layered on top of it, and the technical practices recommended here are designed to satisfy that core regardless of which way the guidance moves next. No book can substitute for legal advice on a specific deployment. What this one aims to give you is the technical understanding needed to have that conversation well: to know what your explanations actually say, what they cannot say, and how to prove the difference. CHAPTER 1 What an Explanation Is For In 2015 a group of researchers led by Rich Caruana published an account of a model that had been built, some years earlier, to predict the risk of death among patients with pneumonia. The idea was sensible: identify low-risk patients who could be safely treated as outpatients and reserve hospital beds for those who needed them. One of the candidate models, a rule-based system, learned a rule that patients with asthma had a lower risk of dying from pneumonia than patients without it. The rule was not a bug in the learning algorithm. It reflected the data faithfully. Asthmatic patients who arrived with pneumonia were, in the hospitals that produced the data, routinely admitted and often sent directly to intensive care, where aggressive treatment lowered their mortality. The model had learned the consequence of a treatment policy and presented it as a property of the patient. Deployed as intended, it would have sent the patients at highest risk home. The rule was caught because the rule-based model was readable. A neural network trained on the same data, which performed better on held-out accuracy, almost certainly learned the same pattern, but nobody could see it. Caruana's team later built an intelligible model class, a generalised additive model with pairwise interactions, precisely so that patterns like this one could be inspected and, where necessary, edited by hand. The story is usually told as an argument for interpretability, and it is one. But it is worth being precise about what the readable rule did. It did not explain the model's prediction for any particular patient. It did not tell a clinician what to do. It did not satisfy any regulator. What it did was let a domain expert inspect a learned relationship and recognise it as a confound. That is one job an explanation can do. There are several others, and they are not the same job. Five questions, five audiences The single most useful habit in applied explainability is to name the question before reaching for a method. In practice, almost every request for an "explanation" turns out to be one of five questions, each with a characteristic audience. The first is the debugging question: what is the model relying on, and is it relying on anything it should not? The audience is the model developer and the validator. The question is usually global or semi-global, concerned with patterns across many predictions, and the useful answers are often surprising: a hospital identifier embedded in an image, a proxy for a protected characteristic, a leaked feature that encodes the label. Caruana's asthma rule is an answer to the debugging question. The second is the justification question: why did the model produce this output for this case? The audience is an operator, such as a loan officer or a clinician, who must decide whether to act on the output. The question is local, concerned with one prediction, and the useful answer is one that helps the operator decide whether this case is one where the model is likely to be right. The third is the recourse question: what would have to be different for the outcome to change? The audience is the person subject to the decision. This question is also local, but it is about the decision rather than the score, and it is forward-looking. An applicant who is told that "credit utilisation" contributed most to the decline has learned something; an applicant who is told that reducing revolving balances by a stated amount would have led to approval has learned something they can use. The fourth is the assurance question: does the organisation understand and control this model well enough to deploy it? The audience is a model risk committee, an auditor, or a supervisor. The answer is less about any individual explanation than about the system of explanations: whether they exist, whether they are tested, whether they are documented, whether they are monitored, and whether anyone acts on them. The fifth is the contestation question: is this decision lawful and fair, and can it be challenged? The audience is the affected individual, their representative, an ombudsman, or a court. The answer must be specific enough to reveal an error if one occurred, and honest enough that the explanation itself does not become a vehicle for disguising one. These questions overlap, but they pull methods in different directions. The debugging question rewards global summaries and is tolerant of technical complexity because its audience is technical. The recourse question demands actionability and punishes explanations that point at immutable features like age. The assurance question cares more about reproducibility and documentation than about any single attribution. The contestation question cares about faithfulness above all, because an unfaithful explanation offered to a person challenging a decision is worse than none. A team that builds one explanation method and pipes its output to all five audiences will serve none of them well. The same SHAP values that help a developer see that a model leans heavily on the length of an applicant's credit history may, presented unmodified to the applicant, tell them that the most important reason they were declined is something they cannot change in less than a decade. Faithful versus plausible An explanation can fail in two ways. It can be unintelligible: correct, perhaps, but not something its audience can absorb or act on. Or it can be unfaithful: intelligible and persuasive, but not an accurate account of how the model actually behaves. The first failure is visible. People complain about it. The second failure is invisible, and that makes it far more dangerous. A heat map over a chest radiograph that highlights the lung field looks like an explanation of a pneumonia classifier. A clinician who sees it will feel reassured. But if the heat map would have looked substantially the same for a model that had learned nothing at all, it is an image of the input, not an explanation of the model, and the reassurance is false. Chapter 4 describes experiments showing that some popular attribution methods behave exactly this way. The distinction between faithfulness and plausibility was articulated sharply by Alon Jacovi and Yoav Goldberg in 2020, and it has a practical corollary. Human evaluation of explanations, in which people rate how convincing or useful they find them, measures plausibility. It does not measure faithfulness and can actively reward unfaithful explanations that happen to match human intuition. An explanation method that highlights the pixels a radiologist would have looked at will score well with radiologists whether or not the model looked at those pixels. Faithfulness has to be measured against the model, by perturbing the model or its inputs and checking whether the explanation tracks the change. That is the subject of Chapter 6. There is a related distinction between explaining the model and explaining the world. Suppose two features, income and education, are strongly correlated in the training data, and a model uses only income. A method that respects the data's correlation structure may still attribute some of the prediction to education, because knowing someone's education tells you something about their income and hence about the model's output. A method that intervenes on features independently will attribute nothing to education, because changing education while holding income fixed does not move the model. Hugh Chen, Scott Lundberg and Su-In Lee framed this as the choice between being "true to the model" and "true to the data." Neither is wrong. They answer different questions, and the right choice depends on which question you are asking. For the debugging and contestation questions, where the issue is what the model actually computes, being true to the model is usually what you want. For some scientific questions about the phenomenon the model was trained on, being true to the data may be more informative. Chapter 2 returns to this choice in detail, because it determines how Shapley values are computed. Local and global, post hoc and intrinsic Two further distinctions organise the field. A local explanation concerns a single prediction: why this applicant, this image, this patient. A global explanation concerns the model's behaviour across its input space: which features matter on average, what shape the relationship between a feature and the output takes, where the model is unreliable. The two are connected, since aggregating local explanations is one way to build a global picture, but they are not interchangeable. A feature can be globally unimportant and locally decisive. Most applicants in a credit portfolio have no bankruptcies on file, so bankruptcy contributes little on average; for the few who do, it may dominate everything else. Global explanation has its own toolkit, which this booklet touches only where it bears on the local methods. Permutation importance measures how much a model's accuracy falls when one feature's values are shuffled across the dataset, breaking its relationship with the outcome. Partial dependence plots trace the model's average output as one feature is varied across its range, and accumulated local effects plots, proposed by Daniel Apley and Jingyu Zhu, do the same while avoiding the unrealistic feature combinations that partial dependence creates when features are correlated. These are valuable for the debugging and assurance questions. They are not substitutes for local explanations when the question concerns a particular person, because an average effect can conceal very different effects for different individuals. A post hoc explanation is computed after a model has been trained, by a separate procedure that treats the model as an object to be probed. An intrinsic or interpretable-by-design explanation comes from the model's structure itself: the coefficients of a logistic regression, the shape functions of an additive model, the rules of a decision list, the points table of a credit scorecard. Intrinsic explanations are faithful by construction, because they are the model. Post hoc explanations are approximations of the model, and their faithfulness must be established. This booklet spends most of its length on post hoc methods for complex models, because that is where most practitioners find themselves and where the technical difficulty lies. But it would be dishonest to proceed without confronting the argument that post hoc explanation of black boxes is, in high-stakes settings, the wrong approach altogether. The case against explaining black boxes In 2019 Cynthia Rudin published a paper in Nature Machine Intelligence with an unambiguous title: "Stop explaining black box machine learning models for high stakes decisions and use interpretable models instead." Her argument has several strands, and each deserves a serious answer. The first strand is that the accuracy cost of interpretable models is often much smaller than assumed. On structured tabular data with meaningful features, which is the data most credit and many clinical decisions rest on, well-regularised logistic regression, sparse additive models, and carefully constructed scorecards frequently perform within a small margin of gradient-boosted ensembles and deep networks. Rudin's own work with colleagues on the FICO Explainable Machine Learning Challenge in 2018 produced a globally interpretable model for a home equity credit dataset that was competitive with black-box entries. The assumption that a meaningful trade-off exists should be tested, not taken for granted. The second strand is that post hoc explanations are, by definition, not perfectly faithful. If an explanation were perfectly faithful to the model everywhere, it would be the model, and you could use it instead. Any gap between the explanation and the model is a place where the explanation can mislead, and in high-stakes decisions, those gaps are where harm hides. The third strand is that post hoc explanations can be gamed. Chapter 3 describes how researchers built classifiers that behave in a discriminatory way on real inputs but in an innocuous way on the synthetic inputs that LIME and KernelSHAP use for probing, so that the explanations report nothing amiss. A firm that wants to hide something from a regulator, or a model that has learned something its developers did not intend, can produce explanations that look clean. The fourth strand is about accountability. An interpretable model can be checked, line by line, by a domain expert. A black-box model with an explanation layer asks the expert to trust two systems rather than one. These arguments are strong, and for many tabular decision problems they are decisive. A practitioner who has not tried a well-tuned interpretable baseline before reaching for a deep network has skipped a step. In credit scoring in particular, the industry spent decades building points-based scorecards precisely because their reasons are transparent, and the burden of proof should sit with whoever wants to replace them. But the arguments do not settle every case. In imaging, audio, and free text, there are no meaningful hand-built features to make an additive model over; the raw inputs are pixels or tokens, and the representational power of deep networks is not something an interpretable model of pixels can match. Large institutions also inherit complex models that they cannot simply retire, and must govern them in the meantime. And some interpretable model classes become uninterpretable at scale: a decision tree of depth twenty is as opaque as a small neural network, and a logistic regression over three thousand engineered features is not readable in any meaningful sense. The pragmatic position, and the one this booklet takes, is that the choice between an interpretable model and an explained black box is itself a decision that must be justified and documented. Where the data are tabular and the features are meaningful, start with an interpretable model and require evidence that a more complex one is materially better before adopting it. Where a complex model is used, treat its explanations as measurements subject to the same validation as the model itself. And in both cases, be clear about which of the five questions each explanation is meant to answer. What an explanation cannot do It is worth closing this chapter with a list of things that explanations are frequently asked to do and cannot. An explanation cannot make a bad model good. If a model is inaccurate, miscalibrated, or trained on data that do not represent the population it serves, a faithful explanation will faithfully describe a bad model. That has value for debugging, but it does not substitute for fixing the model. An explanation cannot establish causation in the world. Attribution methods describe the model's input-output behaviour. If the model has learned a correlation, its explanation will report the correlation. The asthma rule was a faithful explanation of a model that had learned a non-causal pattern. Explanations can help reveal such patterns but cannot by themselves distinguish them from causal ones; that requires domain knowledge and, often, study design. An explanation cannot, on its own, establish fairness. A model may produce explanations that never mention a protected characteristic while still producing systematically different outcomes across groups, because the information is carried by proxies or by interactions among permitted features. Fairness requires outcome testing as well as explanation. An explanation cannot make an operator use a model well. There is good evidence, discussed in Chapter 8, that showing clinicians explanations does not reliably protect them from a model's systematic errors, and some evidence that explanations increase trust in the model regardless of whether the model is right. Explanation is one input to a well-designed decision process, not a substitute for one. And an explanation cannot be correct in general. It can only be correct as an answer to a specific question, posed with specific assumptions, about a specific model. That is the thread running through every chapter that follows. The next three chapters build the main tools, starting with the one that has become the default: the Shapley value. CHAPTER 2 Shapley Values from First Principles In 1953 the mathematician Lloyd Shapley asked a question about cooperative games. Suppose a group of players can form coalitions, and each coalition, acting together, can secure some payoff. If all the players cooperate and secure the total payoff, how should it be divided among them in a way that reflects each player's contribution? Shapley showed that if you insist on a small number of reasonable properties, there is exactly one answer. That answer, now called the Shapley value, earned him a share of the 2012 Nobel Memorial Prize in Economic Sciences, though for related work on matching rather than this result alone. Sixty years later, the question was repurposed. Treat the features of a model's input as the players. Treat the model's prediction as the payoff. Ask how much of the difference between this prediction and some reference prediction each feature is responsible for. Erik Štrumbelj and Igor Kononenko developed this idea for machine learning in 2010 and 2014, and in 2017 Scott Lundberg and Su-In Lee unified it with several other attribution methods under the name SHAP, short for SHapley Additive exPlanations, and released an open-source library that made it practical. SHAP has since become the default local attribution method in industry, the one most likely to sit behind a credit reason code or a feature-importance panel in a clinical dashboard. Its popularity rests on a real strength: it is the only attribution method of its type that satisfies a short list of properties most people would want. Its pitfalls rest on something less often appreciated: the Shapley value is defined only once you have specified what it means for a feature to be "absent," and that specification is a modelling choice with large consequences. This chapter builds the method from the ground up so that both the strength and the choice are visible. The game and its axioms Begin with the game-theoretic setting. There are n players. For every subset S of players, a value function v(S) gives the payoff that coalition can secure on its own. The empty coalition gets v(∅), the grand coalition of everyone gets v(N), and the task is to divide v(N) − v(∅) among the players. The natural idea is to look at what each player adds when they join a coalition. Player i's marginal contribution to coalition S is v(S ∪ {i}) − v(S). The trouble is that this depends on S: a player who adds a great deal to a small coalition may add little to a large one, or the reverse. The Shapley value resolves this by averaging. Imagine the players arriving one at a time in a random order. Each player, on arrival, is credited with their marginal contribution to whoever has already arrived. Average that credit over all possible orderings, and you have the Shapley value. Written as a formula, player i's Shapley value is a weighted sum over all coalitions S not containing i of the marginal contribution v(S ∪ {i}) − v(S), where the weight is |S|!(n − |S| − 1)!/n!. The weight is simply the fraction of orderings in which exactly the members of S arrive before i. Shapley proved that this is the only allocation satisfying four properties. Efficiency: the values sum to v(N) − v(∅), so the whole payoff is divided and nothing is left over. Symmetry: two players who make identical contributions to every coalition receive identical values. Dummy (sometimes called null player): a player who adds nothing to any coalition receives zero. Additivity: if the payoff is the sum of two games, each player's value is the sum of their values in the two games. Translated into machine learning, these properties are attractive. Efficiency means the attributions add up exactly to the difference between the prediction and the reference, so nothing is unexplained. Symmetry means features that play the same role get the same credit. Dummy means a feature the model ignores gets no credit. Additivity means that for an ensemble that averages several models, the attribution for the ensemble is the average of the attributions for the members, which is useful for tree ensembles. Lundberg and Lee restated these as local accuracy, missingness and consistency, and showed that within the class of additive feature attribution methods, the Shapley value is the unique solution. A worked example The arithmetic is worth doing once by hand, because it reveals something that the summary formulas hide. Consider a credit model with three features for one applicant: a high debt-to-income ratio (D), high revolving utilisation (U), and a recent delinquency (M). Suppose we have defined a value function, about which more shortly, and it gives the following expected model outputs, expressed as probability of default. With no features revealed, the output is the reference value 0.20. Revealing D alone gives 0.30; U alone gives 0.26; M alone gives 0.20. Revealing D and U together gives 0.42; D and M gives 0.32; U and M gives 0.28. Revealing all three gives the applicant's actual prediction, 0.46. The total to be divided is 0.46 − 0.20 = 0.26. For D, there are four coalitions not containing it. Joining the empty coalition, D adds 0.10, and this happens in one-third of orderings (those where D arrives first). Joining {U}, D adds 0.42 − 0.26 = 0.16, which happens in one-sixth of orderings. Joining {M}, it adds 0.32 − 0.20 = 0.12, also one-sixth. Joining {U, M}, it adds 0.46 − 0.28 = 0.18, in one-third of orderings. The weighted average is 0.10/3 + 0.16/6 + 0.12/6 + 0.18/3 = 0.14. The same calculation for U gives 0.06/3 + 0.12/6 + 0.08/6 + 0.14/3 = 0.10. For M it gives 0/3 + 0.02/6 + 0.02/6 + 0.04/3 = 0.02. The three values sum to 0.26, as efficiency guarantees. Now look at M. On its own, a recent delinquency changes nothing: v({M}) equals v(∅). Yet it receives a positive Shapley value, because in combination with the other features it adds a little. The model has learned an interaction: a recent delinquency matters more for an applicant who is already stretched. The Shapley value has distributed the credit for that interaction among the participating features. This is both a feature and a limitation. It means nothing is left unexplained, but it also means that a single number per feature cannot tell you whether that feature's contribution is a main effect or the product of an interaction. For tree models, SHAP interaction values extend the idea to pairs of features and can separate the two, at extra computational cost. What does it mean for a feature to be absent? The worked example began, "suppose we have defined a value function." That supposition is where all the modelling choices live. A model is a function of all its inputs. It cannot be evaluated with a feature missing. So to compute v(S), the expected output when only the features in S are known, we must decide what to put in place of the features not in S. There are several reasonable answers, and they produce different Shapley values for the same model and the same input. A single baseline. Replace each absent feature with a fixed reference value: zero, the population mean, the median, or the values of some specific reference individual. This is cheap and easy to explain, and it is what many gradient-based methods for neural networks implicitly do. Its weakness is that it evaluates the model on synthetic points that may be unrealistic. Setting income to its mean while keeping the applicant's actual occupation and age may produce a combination the model never saw in training. The interventional or marginal expectation. Replace the absent features with values drawn from a background dataset, independently of the present features, and average the model's output over those draws. This is what the KernelSHAP and the default "interventional" TreeSHAP algorithms do. Formally, it computes the expectation of the model output when the present features are fixed by intervention and the absent ones follow their marginal distribution. It is true to the model: a feature the model does not use always gets zero, because changing it never changes the output. But because absent features are drawn independently of present ones, it, too, evaluates the model at unrealistic combinations when features are correlated. The observational or conditional expectation. Replace the absent features with values drawn from their distribution conditional on the present features. This respects the data's correlation structure, so the model is evaluated only on realistic points. It is true to the data. But it means a feature the model never uses can receive non-zero credit, because knowing it changes the conditional distribution of features the model does use. Kjersti Aas, Martin Jullum and Anders Løland developed methods for estimating conditional Shapley values with dependent features; the cost is substantial computation and the need to model the conditional distributions themselves. Dominik Janzing, Lenon Minorics and Patrick Blöbaum argued in 2020 that from a causal perspective the interventional version is the right one for explaining what a model does, because a model is a mechanism whose inputs can be set independently, and asking how its output responds to such setting is a well-posed causal question about the model. That is persuasive for the debugging and contestation questions. For questions about the world the model was trained on, the conditional version may be more meaningful. What matters is that the choice is made deliberately and documented. A model card that says "SHAP values" without saying which value function was used is like a laboratory report that gives a concentration without the units. The baseline is a policy decision Even within the interventional approach, there is a further choice: what background distribution to draw from. This is where the technical question becomes a policy question, and it is the single most consequential choice in deploying Shapley values for regulated decisions. Shapley values explain the difference between a prediction and the reference. Change the reference and you change what is being explained. Suppose the background is the whole applicant population, with an average predicted default probability of 0.08. A declined applicant's attributions then explain why they look riskier than an average applicant. Now suppose the background is the set of applicants who were approved, with an average of 0.04. The attributions now explain why they look riskier than a typical approved applicant. Or suppose the background is a set of applicants who sat just above the approval threshold. The attributions then explain what separates this applicant from someone who narrowly made it. These produce different rankings. A feature on which the declined applicant is unremarkable relative to the population but noticeably worse than marginal approvals will rank higher against the third background than the first. For a person asking "why was I declined?", the third framing is arguably the most relevant, since it compares them to the people who were not. United States credit law anticipated this decades before SHAP existed. The official interpretation of Regulation B, which implements the Equal Credit Opportunity Act, describes two acceptable ways for a creditor using a points-based scoring system to select the principal reasons for denial: identify the factors where the applicant fell furthest below the maximum points available, or identify the factors where the applicant fell furthest below the average points scored by applicants, or by approved applicants. Each is a choice of baseline. A modern implementation using Shapley values has to make the same choice and should be able to explain why it chose as it did. Chapter 7 develops this connection in full. Estimating Shapley values in practice Computing exact Shapley values requires evaluating the value function for every subset of features, which means 2n subsets for n features. For three features that is eight; for thirty, about a billion; for two hundred, more than the number of atoms in the observable universe. Every practical method is therefore an approximation, a specialisation to a model class, or both. The main estimators differ in what they assume about the model and how they define absence, as Table 1 summarises. Table 1. Principal Shapley value estimators compared. Estimator Applies to Value function Main trade-off Permutation sampling Any model Interventional or fixed baseline Many model calls; sampling variance KernelSHAP Any model Interventional, features independent Costly; off-manifold samples; noise TreeSHAP (with background) Trees Interventional over background set Exact and fast; background still chosen TreeSHAP (path-dependent) Trees Approximate conditional via tree paths Fastest; may credit unused features DeepSHAP or GradientSHAP Neural nets Baseline or background expectation Fast but approximate; layer rules matter Source: Lundberg and Lee (2017); Lundberg et al. (2020); SHAP library documentation. Permutation sampling follows the definition directly: sample random orderings of the features, walk through each ordering adding features one at a time, and record each feature's marginal contribution. Averaging over enough orderings converges on the Shapley value. It works for any model but needs many model evaluations, and its error shrinks only with the square root of the number of samples. KernelSHAP reframes the problem as a weighted linear regression. Sample coalitions, evaluate the value function on each, and fit a linear model whose coefficients are the attributions, with weights chosen so that the solution coincides with the Shapley value. Lundberg and Lee showed that a particular weighting kernel achieves this. KernelSHAP is model-agnostic and more sample-efficient than naive permutation, but it still requires many model evaluations per explanation and, in its standard form, assumes features are independent when drawing absent values. TreeSHAP, introduced by Lundberg and colleagues in a 2020 Nature Machine Intelligence paper, exploits the structure of decision trees to compute exact Shapley values in time polynomial in the tree depth and number of leaves, rather than exponential in the number of features. For gradient-boosted ensembles and random forests, which dominate tabular modelling in finance and much of healthcare, this makes exact Shapley values cheap enough to compute for every prediction in production. It comes in two flavours. The interventional version uses a background dataset and is true to the model. The original "path-dependent" version uses the proportion of training samples that went down each branch to approximate a conditional expectation without needing a background set; it is faster but can assign credit to features the model does not use for that prediction, which surprises people who expect the dummy property to hold in the interventional sense. DeepSHAP and GradientSHAP approximate Shapley values for neural networks by combining ideas from gradient-based attribution, discussed in Chapter 4, with background expectations. DeepSHAP builds on DeepLIFT's rules for propagating contributions backwards through layers; GradientSHAP averages gradients along paths from background samples to the input. Both are fast but approximate, and their faithfulness to true Shapley values depends on the network's architecture. Where Shapley values mislead Shapley values have become so standard that their limitations are sometimes forgotten. Several are worth stating plainly. Correlated features share credit in unstable ways. When two features carry nearly the same information, an interventional Shapley computation will split credit between them according to how the model happens to use each, which can change substantially between two models trained on the same data with different random seeds. A gradient-boosted model may split on one in the first few trees and on the other later, producing attributions that shift with retraining even though predictions barely change. For reason codes this is a real problem: an applicant may be told one reason this month and a different but equivalent reason next month. The usual remedy is to group correlated features into meaningful clusters, such as all utilisation measures together, and to report attribution at the group level. Shapley values for groups of features are well defined and are often more stable and more meaningful than those for individual columns. Attributions are not effects. A large Shapley value for a feature means the feature contributed a lot to the difference between this prediction and the reference, under the chosen value function. It does not mean that changing the feature would change the prediction by that amount, and it certainly does not mean that changing it in the world would change the outcome the model predicts. Kumar and colleagues, in a 2020 critique, showed that the counterfactual reading people naturally give to Shapley values is often wrong, and that the values can be insensitive to features that would, if changed, flip the decision. For recourse, counterfactual methods, discussed in Chapter 5, are the appropriate tool. Signs depend on the reference. A feature can push the prediction upward relative to one background and downward relative to another. An applicant with a moderate credit history length may have that feature attributed as risk-increasing relative to approved applicants, who tend to have long histories, and risk-decreasing relative to the full population, which includes many thin-file applicants. Any report that says a feature "increased" or "decreased" risk is implicitly a statement about the reference. Off-manifold evaluation can be exploited. Because the interventional value function evaluates the model on combinations of feature values that may not occur in reality, a model can behave differently on those combinations than on real data. Chapter 3 describes how this has been weaponised to hide discriminatory behaviour from explanation methods. Estimation noise is real. Sampling-based estimators produce attributions with variance. Two runs of KernelSHAP on the same input with different random seeds can produce visibly different rankings for features with similar contributions. If those rankings determine which reasons appear on a regulatory notice, the noise must be quantified and controlled, either by fixing seeds and sample sizes in a documented configuration or, preferably, by using an exact method where one exists. What Shapley values are good for None of this diminishes the method. It clarifies when to use it. Shapley values are an excellent default for the justification question in tabular models, especially tree ensembles where TreeSHAP makes exact computation cheap. They support global summaries by aggregation: the mean absolute Shapley value across a dataset is a reasonable measure of overall feature importance, and plotting a feature's Shapley values against its own values gives a dependence curve that reveals the shape of the learned relationship and its variation across individuals. They provide a principled foundation for reason codes, provided the baseline is chosen to match the regulatory question and correlated features are grouped. And their efficiency property means they can be audited: the attributions must sum to the difference between prediction and reference, and if they do not, something in the pipeline is broken. The discipline required is to write down, for every deployment, the answers to four questions. Which value function: interventional, conditional, or baseline? Which background distribution, and why does it match the question being asked? How are correlated features grouped? And how is estimation error controlled? A Shapley value reported with those answers is a well-specified measurement. Without them, it is a number whose meaning nobody can check. CHAPTER 3 Local Surrogates: LIME and Its Limits In 2016 Marco Tulio Ribeiro, Sameer Singh and Carlos Guestrin published a paper whose title captured a mood: "Why Should I Trust You?" Their method, Local Interpretable Model-agnostic Explanations, or LIME, rested on an idea that is easy to state and appealing to anyone who has stared at a complex model. Even if a model's decision surface is wildly nonlinear globally, in a small enough neighbourhood around any single input it can be approximated by something simple, such as a linear function. Fit that simple function, read off its coefficients, and you have an explanation of the prediction at that point. The paper included a memorable demonstration. The authors trained a classifier to distinguish wolves from huskies and deliberately chose training images in which wolves appeared against snow. The classifier performed well. LIME's explanations showed that it was largely detecting snow. When the explanations were shown to participants, many who had initially trusted the model changed their minds. Here was an explanation answering the debugging question in a way non-specialists could grasp, and in a few lines of code. LIME's influence has been enormous, and its open-source library remains widely used. It is also, of all the mainstream methods, the one whose instability is best documented. Understanding why requires looking at the choices hidden inside the simple idea. How LIME works Given a model f and an input x to explain, LIME proceeds in four steps. First, it generates a set of perturbed samples around x. For tabular data, the default implementation draws samples from a distribution based on the training data's feature statistics; continuous features are typically discretised into quartile bins, and samples are created by drawing bin values, which are then mapped back to representative continuous values. For text, perturbation means removing random subsets of words. For images, the image is first segmented into "superpixels," contiguous patches of similar colour and texture, and perturbation means greying out random subsets of those patches. Second, it queries the model on every perturbed sample to get its output. Third, it weights each sample by its proximity to x, using an exponential kernel on some distance measure. Samples close to x count heavily; distant ones count little. The kernel has a width parameter that determines how quickly weight falls off with distance. In the reference tabular implementation, the default width is three-quarters of the square root of the number of features, a heuristic rather than a principled choice. Fourth, it fits a simple, interpretable model, usually a sparse linear regression, to the weighted samples, predicting the complex model's output from an interpretable representation of the input: binary indicators for "this word is present," "this superpixel is visible," or "this feature is in the same bin as the original." The coefficients of that surrogate are the explanation. The simplicity is genuine, and so is the generality. LIME needs nothing but the ability to query the model, so it works on any classifier or regressor, including models behind an API. It also allows the interpretable representation to differ from the model's raw input, which is a real advantage in text and imaging, where the model sees token embeddings or pixel intensities but a human thinks in words and regions. The choices hidden in the method Every one of LIME's four steps involves a choice that changes the explanation, and the defaults are not neutral. The neighbourhood. What counts as "near" x depends on the kernel width and on the distance measure. A narrow kernel looks at a tiny region where the model may be nearly flat, producing coefficients dominated by noise. A wide kernel looks at a large region where the model may curve sharply, producing a linear fit that describes no particular place well. There is no general rule for the right width, and researchers have shown that changing the width can change not only the magnitudes but the signs of the leading coefficients. Since the width is rarely reported alongside an explanation, a reader has no way to know which neighbourhood was used. Damien Garreau and Ulrike von Luxburg put this on a theoretical footing in 2020 with an analysis of tabular LIME under its default sampling scheme. Among their findings was that, for simple models whose true behaviour is known, the explanation depends strongly on the kernel width, and that for poorly chosen widths, features that genuinely affect the model's output can receive coefficients close to zero. In other words, the method can, with default-looking settings, report that a feature does not matter when it plainly does. That result does not condemn LIME, but it does mean that the width is a parameter to be tuned and validated for each model, not a constant to be inherited from a library. The sampling distribution. For tabular data, perturbed samples are typically drawn feature by feature, independently, from the training distribution. This means the samples ignore correlations. An applicant aged twenty-two might be perturbed into a sample that keeps their age but has thirty years of credit history. The model is then queried at points that could never occur. Whatever it does there feeds into the surrogate fit. This is the same off-manifold problem that affects interventional Shapley values, and it has the same consequences. The interpretable representation. Discretising continuous features into quartiles means LIME's tabular explanations are statements of the form "income is in the bottom quartile" rather than "income is 31,000." This is often more readable, but the bin boundaries are arbitrary, and an applicant just above a boundary gets a different explanation from one just below it. For images, the superpixel segmentation algorithm and its parameters determine which regions can be highlighted at all. A tumour boundary that happens to split across two superpixels will be explained differently from one contained in a single segment. The surrogate's complexity. LIME usually limits the explanation to the top K features, selected by a procedure such as forward selection or the lasso. The value of K and the selection procedure affect which features appear. A feature that would have ranked sixth disappears entirely from a top-five explanation. The random seed. Because perturbation is random, running LIME twice on the same input generally produces different samples and therefore different explanations. With few samples, the difference can be large. The default of five thousand samples in the tabular implementation reduces but does not eliminate this. Studies examining LIME's stability across repeated runs have found that the top-ranked features can change from run to run on the same input, particularly when several features contribute similar amounts. None of these problems is unique to LIME, but LIME exposes them more directly because its defaults are heuristic and its sampling is coarse. The relationship between LIME and SHAP One of the central results of Lundberg and Lee's 2017 SHAP paper is that LIME and Shapley values are close relatives. If you run LIME with a particular choice of kernel, loss function and regularisation, and use a binary representation of "feature present" versus "feature replaced by background," the coefficients of the weighted linear fit are exactly the Shapley values. That choice of kernel, the Shapley kernel, is what KernelSHAP uses. This is illuminating in both directions. It shows that KernelSHAP is a specific, principled instance of the LIME framework. And it shows that standard LIME, with its heuristic exponential kernel, gives up the properties that make Shapley values attractive. Standard LIME attributions do not, in general, sum to the difference between the prediction and the reference. They do not satisfy the symmetry or dummy properties in any guaranteed way. What standard LIME offers in exchange is flexibility: the freedom to define neighbourhoods and representations suited to a domain. In practice, for tabular models, most teams that would once have used LIME now use SHAP, and that is generally the right call. Where an exact or near-exact Shapley method exists for the model class, it is more stable and better founded. LIME retains a place where a custom interpretable representation genuinely helps, as in text classification where explanations in terms of words and phrases are more useful than explanations in terms of embedding dimensions, and where the team is prepared to tune and report its parameters. Fooling the explainers In 2020 Dylan Slack, Sophie Hilgard, Emily Jia, Sameer Singh and Himabindu Lakkaraju published a paper that ought to be required reading for anyone who relies on perturbation-based explanations in a regulated setting. Its title asked how LIME and SHAP could be fooled, and its answer was disturbingly simple. The authors observed that the perturbed samples LIME and KernelSHAP generate look different from real data. Because features are perturbed independently, the samples fall off the manifold of realistic inputs, and a simple classifier can learn to tell the two apart with high accuracy. They then built what they called an adversarial scaffold. The scaffold first checks whether an input looks like real data or like an explainer's perturbation. If the input looks real, it is passed to a biased model that makes decisions based on a sensitive attribute such as race. If it looks like a perturbation, it is passed to an innocuous model that uses only unrelated features. Because the explainer only ever sees the innocuous model's behaviour on its perturbations, it reports that the sensitive attribute plays no role. Meanwhile, every real decision is made by the biased model. Using real datasets for criminal justice risk assessment and credit, the authors showed that the scaffolded models' explanations ranked the sensitive attribute as unimportant in nearly all cases, while the actual decisions depended on it entirely. It would be a mistake to read this as an accusation that firms routinely build such scaffolds. The point is subtler and more important. The attack works because perturbation-based explainers evaluate the model at points that differ systematically from the points where it makes real decisions. A model does not need to be deliberately adversarial to behave differently off-manifold. A complex model trained only on realistic data has simply never been constrained in unrealistic regions, and its behaviour there is arbitrary. An explanation built from that arbitrary behaviour may describe very little about the decisions that matter. Sebastian Bordt and colleagues extended this line of argument in 2022, asking whether post hoc explanations can serve their stated purpose in adversarial contexts, meaning any setting where the party producing the explanation has interests that diverge from the party receiving it. Their conclusion was that, because many explanation methods admit a range of valid outputs depending on parameter choices, the party producing the explanation can often select among them, and the receiving party cannot tell. Regulatory compliance is, by its nature, such a context: the regulated firm generates the explanations, and the regulator or consumer receives them. Beyond linear surrogates: rules and anchors A linear surrogate answers the question "which features push the prediction up or down near here, and by how much?" Operators often want something different: "under what conditions will the model keep making this prediction?" A loan officer reviewing a referral wants to know whether the decision is robust, whether small changes in the applicant's file would leave it unchanged, or whether it hangs on a single borderline value. Ribeiro, Singh and Guestrin returned to this question in 2018 with a method they called Anchors. An anchor is a rule, a conjunction of conditions on the input such as "debt-to-income above 45 percent and two or more delinquencies in the past year," with a guarantee attached: among inputs that satisfy the rule, the model makes the same prediction with high probability, typically 95 percent or more. The method searches for the shortest such rule, estimating its precision by sampling and its coverage, meaning how much of the input distribution it applies to. Anchors have two attractive features. Their meaning is unambiguous: a rule either holds or it does not, and the precision guarantee says what it means for the rule to "explain" the prediction. And they answer a question that linear surrogates do not, about the stability of the decision rather than the contribution of each feature. When an anchor is short and has high precision, the prediction is robustly determined by a few conditions. When no short anchor can be found, the prediction depends on a delicate combination of many features, which is itself useful information for an operator deciding how much to trust it. Anchors share LIME's dependence on a sampling distribution. Their precision is estimated on perturbed samples, and if those samples are unrealistic, the precision estimate describes the model's behaviour on unrealistic inputs. The same off-manifold concerns apply, and they have the same remedies. What follows for practice Three practical lessons follow from LIME's history. The first is that parameters must be reported and fixed. If a local surrogate method is used in any setting where its output matters to someone outside the development team, the kernel width, sampling distribution, number of samples, representation, feature selection procedure and random seed must be documented and held constant in production. An explanation whose parameters can drift is not a reproducible measurement, and an explanation whose parameters were chosen after seeing the results is not an honest one. The second is that stability must be measured. For every explanation method in production, run it repeatedly on a sample of inputs and measure how much the top-ranked features change. If the rank order of the leading reasons is not stable across runs, either the method's sample size must increase, the features must be grouped, or the explanation must be presented with less precision, for example by naming categories of factors rather than ranking individual columns. Chapter 6 describes stability metrics. The third is that perturbations should stay on the data manifold where possible. Several responses to the fooling attack have been proposed. One is to generate perturbations that respect the data distribution, by sampling from conditional distributions or a generative model trained on the data, so that the model is evaluated only where it would plausibly be used. Another is to restrict the background or neighbourhood to real data points. A third, for tree ensembles, is to use exact methods such as interventional TreeSHAP with a real background dataset, which still evaluates hybrid points but in a controlled, documented way. None is a complete defence; a model can behave differently on any distribution it has not been tested on. But each reduces the gap between where explanations look and where decisions happen. There is a fourth lesson that applies beyond LIME. When the purpose of an explanation is to let a third party verify that a model does not rely on something it should not, post hoc explanation is a weak tool on its own. It should be paired with direct testing of the model's behaviour: outcome analysis across groups, testing the model on matched pairs of real or realistic inputs that differ only in the attribute of concern, and examination of the training data and feature pipeline. An explainer can be fooled. A well-designed outcome test on real decisions is much harder to fool, because it looks at what the model actually did. LIME for text and images It is worth noting where LIME's ideas remain most useful, because the critique above can create the impression that the method has no remaining role. For text classifiers, LIME's representation of an input as a bag of present or absent words aligns well with how people read. An explanation that says "the words refund, cancel and unacceptable pushed this message toward the complaint class" is directly useful to an operator triaging customer correspondence. The off-manifold problem is milder for text, because removing words from a sentence produces something that, while ungrammatical, is not wildly unlike real inputs. Stability still needs checking, but the method is a reasonable first tool for debugging a text classifier. For images, LIME's superpixel explanations are coarser than gradient-based heat maps but have one advantage: they are computed by actually occluding regions and observing the model's response, rather than by reading off local derivatives. This makes them a useful cross-check on gradient methods. If a gradient-based heat map highlights a region but occluding that region with LIME's procedure barely changes the output, one of the two is misleading, and finding out which is worth the effort. The next chapter turns to those gradient methods and the particular challenges of explaining deep neural networks from the inside. Hashtags: #ExplainableAIInPractice #ExplainableAI #XAI #ArtificialIntelligence #MachineLearning #InterpretableAI #ModelInterpretability #BlackBoxModels #AITransparency #ResponsibleAI #TrustworthyAI #SHAP #ShapleyValues #LIME #FeatureAttribution #FeatureImportance #ModelExplainability #LocalExplanations #GlobalInterpretability #CounterfactualExplanations #AlgorithmicRecourse #IntegratedGradients #ExplainableMachineLearning #ModelValidation #AIAccountability #AlgorithmicFairness #ModelRiskManagement #RegulatoryCompliance #HealthcareAI #FinancialAI

Latest Book Releases:

WELCOME TO THE INTERNATIONAL STUDENTS LIBRARY

bottom of page