The Agentic AI Codex
Ch 19 · Evaluation Metrics & AI Glossary
Chapter 19 · Reference

Evaluation Metrics & AI Glossary

A single chapter to bookmark — every metric you'll be quoted plus a glossary of AI terms. Grouped by where each one is used: classification, regression, ranking, generation, RAG, agents, safety, serving, and the AI vocabulary that ties the platform together.

19.1 · Classification metrics

The confusion matrix — the source of every classifier metric

TP (predicted +, actually +) FP (predicted +, actually −) FN (predicted −, actually +) TN (predicted −, actually −) Actually + Actually − Predicted + Predicted −
MetricFormulaDefinitionUse when
Accuracy$(TP+TN)/N$Fraction of all predictions that are correct.Balanced classes.
Precision$TP/(TP+FP)$Of what we flagged positive, how many really are?False positives are costly.
Recall (Sensitivity, TPR)$TP/(TP+FN)$Of all real positives, how many did we catch?False negatives are costly.
Specificity (TNR)$TN/(TN+FP)$Recall on the negative class.Drug tests; you must not flag healthy people.
F1$2 \cdot \tfrac{P \cdot R}{P+R}$Harmonic mean of P and R.Imbalanced classes when you care about both.
F-β$(1+\beta^2) \cdot \tfrac{P \cdot R}{\beta^2 P + R}$Weights recall β times more than precision.β=2 if recall matters more.
ROC-AUCArea under TPR vs FPR curveProbability the model ranks a random + above a random −.Threshold-free ranking quality.
PR-AUCArea under Precision–RecallBetter than ROC when classes are very imbalanced.1:1000 positives (fraud).
Log-loss / Cross-entropy$-\tfrac{1}{N}\sum y\log\hat{p} + (1-y)\log(1-\hat{p})$Penalises confident wrong predictions.You care about calibrated probabilities.
Brier score$\tfrac{1}{N}\sum (\hat{p}-y)^2$Mean squared error of probability predictions.Forecasting; weather-style scoring.
Matthews CC (MCC)—Balanced score from -1 to +1; robust on imbalance.Benchmarks where one number must summarise everything.
Cohen's κ$\tfrac{p_o - p_e}{1 - p_e}$Agreement above chance.Inter-rater / human-vs-model agreement.

19.2 · Regression metrics

MetricFormulaWhat it tells you
MAE$\tfrac{1}{n}\sum |y - \hat{y}|$Average error in original units; robust to outliers.
MSE$\tfrac{1}{n}\sum (y - \hat{y})^2$Penalises large errors quadratically; differentiable.
RMSE$\sqrt{\text{MSE}}$Same units as $y$; the most-reported regression metric.
MAPE$\tfrac{100}{n}\sum |y - \hat{y}| / |y|$Percentage error; intuitive but breaks near 0.
R²$1 - \tfrac{\sum (y-\hat{y})^2}{\sum (y-\bar{y})^2}$Fraction of variance explained by the model.
Quantile loss (pinball)$\sum \max(q (y-\hat{y}), (q-1)(y-\hat{y}))$For quantile regression / prediction intervals.

19.3 · Ranking / Information-Retrieval metrics

MetricDefinitionUse case
Recall@kFraction of relevant docs retrieved in the top-k.RAG retrieval quality.
Precision@kFraction of top-k that are relevant.Search results page.
MRR (Mean Reciprocal Rank)Average of $1/\text{rank of first relevant doc}$.Q&A where one right answer matters.
MAPMean of average precisions across queries.Classic IR benchmarks.
nDCG@kDiscounted cumulative gain, normalised by ideal.Graded relevance with position discount.
Hit@k1 if any relevant doc appears in top-k, else 0.Recommendations.

19.4 · Text-generation metrics

MetricDefinitionWhen
Perplexity$\exp(\text{cross-entropy})$ — average uncertainty per token.Language-model fit on held-out text.
BLEUn-gram overlap with reference(s), with brevity penalty.Machine translation.
ROUGE-N / ROUGE-LRecall of n-grams or longest-common subsequence.Summarisation.
METEORAligns tokens including synonyms and stems.MT alternative to BLEU.
BERTScoreCosine similarity of BERT embeddings between candidate and reference.Semantic similarity beyond surface overlap.
LLM-as-judgeA strong LLM scores outputs against a rubric.Free-form generation when no single ground-truth exists.
Pairwise preference rate% of times judges prefer model A over model B.Side-by-side model comparison.

19.5 · RAG-specific metrics

MetricDefinition
Context recallOf all chunks needed to answer, how many were retrieved?
Context precisionOf retrieved chunks, how many are relevant?
FaithfulnessDo all claims in the answer follow from the retrieved context?
Answer relevanceDoes the answer actually address the question?
Citation accuracyAre the cited passage IDs correct?
Groundedness% of claims supported by at least one retrieved chunk.
Retrieval latency p95Time the retriever takes to return top-k.

Common frameworks: Ragas, TruLens, DeepEval, Phoenix.

19.6 · Agent & tool-use metrics

MetricDefinition
Task success rate% of tasks where the final artefact meets the rubric.
Tool selection accuracy% of steps where the chosen tool matches the ideal tool.
Argument validity% of tool calls whose arguments pass the schema.
Tool error rate% of tool calls that error.
Loop / no-progress rate% of runs that hit the step cap without finishing.
Average steps per taskMean number of LLM+tool calls per successful run.
Average cost per task$ per completed task.
Refusal rate / over-refusal rate% of valid requests refused.
Human-takeover rate% of conversations escalated to a human.

19.7 · Safety & alignment metrics

MetricDefinition
Jailbreak success rate% of red-team prompts that bypass safety policy.
Toxicity scoreProbability output is toxic per a classifier.
PII leak rate% of outputs that contain detectable PII not in the prompt.
Prompt-injection success rate% of cases where untrusted content overrides system instructions.
Bias gapPerformance difference across demographic groups.
Calibration error (ECE)Gap between predicted confidence and observed accuracy.
Hallucination rate% of factual claims unsupported by source / world facts.

19.8 · Serving / SRE metrics

MetricDefinition
TTFTTime-To-First-Token. UX metric users feel.
ITLInter-Token Latency — average ms between successive tokens.
Tokens / secondGeneration throughput; per-request and aggregate.
TPM / RPMTokens-per-minute / requests-per-minute throughput.
p50 / p95 / p99 latencyPercentile latencies — p95/p99 are the only ones that matter for SLOs.
Success rate / Availability% of 2xx responses over total.
GPU utilisation% of GPU SM time in use; aim 60–80% on serving fleets.
KV-cache hit ratio% of prefill saved via prompt caching.
Cost per 1k tokensUnit-economics metric; track per model and per tenant.

19.9 · Statistical & experiment metrics

TermDefinition
p-valueProbability of observing the data (or more extreme) if the null hypothesis is true.
Confidence intervalRange of values that captures the true parameter with probability 1−α.
Effect size (Cohen's d)Standardised magnitude of difference.
Statistical powerProbability of detecting a real effect of given size.
Bias–varianceDecomposition of expected error into systematic + variability + noise.
LiftTreatment effect over control in an A/B test, often %.
MDEMinimum Detectable Effect — smallest effect your experiment can reliably detect.

19.10 · AI glossary — A → Z

Agent

Software that perceives, reasons, acts (via tools), and updates state toward a goal — usually with an LLM controller.

Alignment

Techniques (SFT, RLHF, DPO) that make a model helpful, harmless, and honest.

Attention

Mechanism letting a token "look at" every other token; the heart of the Transformer.

Batch size

Number of examples processed before a single weight update during training.

Beam search

Decoder that keeps the top-k partial sequences at each step.

Chunking

Splitting documents into smaller pieces for embedding/retrieval in RAG.

Context window

Max tokens an LLM can process in one call (input + output).

CoT — Chain-of-Thought

Prompting style that makes the model reason step by step before answering.

Cross-entropy

Loss function $-\sum p_i \log q_i$ used to train classifiers and LLMs.

Dataset card

Standard doc describing a training/eval dataset: source, licence, biases.

DPO

Direct Preference Optimisation — alignment from (chosen, rejected) pairs.

Embedding

Learned vector placing similar inputs near each other in space.

Eval harness

A reproducible suite of tasks + scorers used to gate model releases.

Fine-tuning

Continuing to train a pre-trained model on task-specific data.

Function calling

API where the LLM emits a structured call to a registered tool.

Guardrails

Input/output policies enforced outside the model: filters, schemas, allow-lists.

Hallucination

Confident but unsupported model output.

HITL

Human-In-The-Loop — a checkpoint that requires human approval before action.

HNSW

Hierarchical Navigable Small Worlds — fast graph-based vector index.

Inference

Running a trained model on new inputs (the cost centre of LLM products).

KV cache

Per-request store of attention keys/values to avoid recomputing earlier tokens.

LoRA

Low-Rank Adaptation — tiny trainable add-on that fine-tunes a frozen base model.

MCP

Model Context Protocol — open standard so any model can use any tool/resource.

Model card

Standard doc for a model: intended use, evals, limitations, ethical notes.

PEFT

Parameter-Efficient Fine-Tuning — LoRA, adapters, prefix-tuning, IA³.

PII

Personally Identifiable Information — redact before LLM.

Provenance

Auditable trail of what data + code + run produced an artefact.

Quantisation

Storing weights in lower precision (INT8 / INT4 / FP8) for size and speed.

RAG

Retrieval-Augmented Generation — retrieve relevant snippets then generate with them.

ReAct

Pattern: Reason → Act (tool) → Observe → repeat.

Re-ranker

Cross-encoder that re-scores top-k retrieved chunks for precision.

RLHF

Reinforcement Learning from Human Feedback — PPO-driven alignment.

RoPE

Rotary Position Embeddings — modern positional encoding used in Llama.

SFT

Supervised Fine-Tuning on (prompt, ideal answer) pairs.

SLA / SLO / SLI

Contract / objective / indicator for service quality.

System prompt

Persistent instruction at the top of context that shapes model behaviour.

Temperature

Sampling parameter; higher → more diverse outputs.

Token

Sub-word unit; LLM's atomic input/output element.

Top-p / Top-k

Nucleus / top-k sampling — truncate the tail before sampling.

TTFT

Time To First Token — the UX-critical latency metric for chat.

Triton (NVIDIA)

Multi-framework inference server for mixed model types.

vLLM

High-throughput open LLM serving engine using PagedAttention.

Vector DB

Database optimised for nearest-neighbour search on embeddings.