In the final part of The AI Engineering Playbook, we look under the bonnet at the elegant maths that makes it all possible. A conceptual guide to the linear algebra, statistics, and machine learning principles that power modern AI.
This is the final post in The AI Engineering Playbook series. We have covered system architecture, prompt engineering, RAG, fine tuning, performance, evaluation, and security. Now we look at the foundation upon which everything else is built. To me, it is obvious: the basis of all LLMs is maths.
You do not need to be a mathematician to be a great AI engineer, but a conceptual grasp of the core principles is a superpower. It allows you to move from simply using the tools to truly understanding them.
1. The Language of AI: Linear Algebra
When we talk about embeddings and vectors, we are talking about linear algebra. It is the language of AI. Creating code and using tools like NumPy is obvious to me because, at their core, it is all just algebra formulas. Operations like the dot product and matrix multiplication are the workhorses that allow a model to process relationships between data at a massive scale.
I have always looked at things from a mathematical way, and the concept of semantic search is a perfect example. When learning about LLMs, it was the simplest and obvious choice to use maths to check between two vectors. This, of course, is cosine similarity, which simply measures the angle between two vectors in a high dimensional space. It is the elegant mathematical principle that powers every RAG system.
2. The Logic of AI: Probability & Statistics
An LLM is not a "thinker" in the human sense, it is a probabilistic engine. This was another core realisation for me, it was about how it predicts the next most likely word or token. That is it.
Every seemingly creative sentence or complex piece of code it generates is the result of a massive statistical calculation to find the most probable sequence of tokens. This is why parameters like temperature, which we discussed in Part 1, exist. They allow us to control the sampling process, telling the model to either stick to the most probable path (low temperature) or explore less likely, more "creative" paths (high temperature).
3. How AI "Learns": A Glimpse into Machine Learning
Finally, how does a model get so good at predicting the next token? The answer lies in the fundamentals of machine learning, and I think one of the most foundational concept here is the Loss Function.
A loss function is simply a way of measuring how "wrong" a model's prediction is compared to the correct answer in the training data. For different tasks, you use different measures. For example, you might use Mean Squared Error (MSE) for a regression task (predicting a number) or Cross Entropy loss for a classification task.
The entire goal of the training process is to adjust the model's billions of internal parameters to make the value of this loss function as low as possible. The process of "nudging" these parameters in the right direction over millions of examples is called Gradient Descent, a core concept from calculus and optimisation.
Conclusion: From Engineer to Architect
Linear algebra gives our AI a way to represent meaning. Probability and statistics give it a way to reason. And the principles of machine learning give it a way to learn.
Understanding these concepts, even at a high level, is what completes the journey from developer to architect in the age of AI. It allows you to debug more intelligently, design more effective systems, and appreciate the elegant, mathematical reality behind the magic.
