Foundations · The math + ML survival kit
Why this matters
You don't need a PhD to ship AI products. You do need enough math to read a paper, debug a similarity-search bug, and know when an evaluation result is statistical noise. This chapter is the minimum.
Linear algebra: vectors, dot products, cosine
An embedding is a vector — a list of floats, typically 384 to 3072 dimensions. Two embeddings are "similar" if their cosine similarity is high. Cosine similarity is the cosine of the angle between two vectors:
cos(a, b) = (a · b) / (‖a‖ × ‖b‖)
= sum(a_i × b_i) / (sqrt(sum(a_i²)) × sqrt(sum(b_i²)))
If both vectors are normalised (length 1), cosine similarity equals the dot product, and you can use much faster ANN indexes that operate on dot products. Most modern embedding models return normalised vectors — you can assert it.
Probability — the three numbers you need
- Independent events:
P(A and B) = P(A) × P(B). Used everywhere in retrieval calibration ("if I retrieve 5 chunks each with 0.6 precision, P(all 5 wrong) = 0.4⁵ ≈ 1%"). - Bayes' rule:
P(A|B) = P(B|A) × P(A) / P(B). Why "spam filter says spam" doesn't mean "is spam". - Entropy: how uncertain is a distribution? Lower entropy = more confident. LLM logit distributions are the practical place this matters.
ML fundamentals that still matter
Even if you'll never train a model from scratch, two concepts keep mattering:
- Train/validation/test split. Don't tune prompts on your final eval set — you'll fool yourself. Build the eval set first, freeze it, then iterate prompts on a separate dev set.
- Overfitting. A prompt that scores 95% on 20 hand-picked examples will score 60% on a new sample. Same disease, prompt-engineering edition.
Gradients — just enough
A gradient is "how does loss change if I nudge this parameter?". Backprop propagates that signal backwards through the network. You will not implement this — but you'll occasionally read about gradient checkpointing, gradient accumulation, gradient clipping. They're operational knobs in fine-tuning recipes. Read about them when you need them.