Free guide

AI Engineering from First Principles

LLM basics, retrieval, evals, agents and production LLM systems, built up from the mechanism, with annotated code from 4 real production projects in the margin. Written for shipping, and for the interview after it.

34 chapters409 sections325 real-code examples from 4 projects167 sections shown in real code85 open-licence readings

Start the fast track →Interview prepWhat to build next GitHub

★★★ core: ships daily, asked in most loops★★ important★ literacyfast = on the interview fast track

Part I

Foundations

01What AI Engineering IsFoundation models vs classical ML · Three-layer AI stack (app/model/infra) · AI eng vs ML eng vs full-stack · Probabilistic software: non-determinism as a design constraint …★★2written02Text as Numbers: TokenizationWhy discrete tokens · Chars/bytes/words/subwords · BPE step by step · WordPiece/Unigram/SentencePiece …★★3written03Embeddings and Vector SpaceOne-hot to dense · Distributional hypothesis and word2vec · Cosine/dot/L2 · Contextual vs static …★★★written · fast04Language Modeling and SamplingNext-token prediction · Logits, softmax · Entropy/cross-entropy/perplexity · Greedy, temperature, top-k, top-p, min-p …★★7written05Transformer IntuitionRNN limits · Attention as soft lookup (Q/K/V) · Scaled dot-product and multi-head · Causal masking …★★written06Pretraining, Data and ScalingObjective at scale · Web data · Filtering, dedup, quality classifiers · Data mix …★written07Post-Training and AlignmentWhy post-train · SFT · Chat templates · Reward models …★★2written08Reasoning Models and Test-Time ComputeCoT origins · Self-consistency and best-of-n · Prompted vs trained reasoning (o1/R1 lineage) · RL for reasoning …★★4written09Fine-Tuning in PracticePrompt vs RAG vs fine-tune decision · Training memory math · Numeric formats · Full vs PEFT …★★written
Part II

Inference and serving economics

10Inference MechanicsPrefill vs decode · KV cache and memory · Compute- vs memory-bound · TTFT, TPOT/ITL, throughput …★★★2written · fast11Serving, Model Selection and EconomicsAPI vs self-hosted open weights · Engines (vLLM, SGLang, TGI, llama.cpp/Ollama) · Local and edge · Pricing (input/output/cached/thinking) …★★★16written · fast
Part III

Talking to models

12Prompting FundamentalsSystem/user/assistant anatomy · Zero/few-shot ICL · Clear instructions · Providing context …★★★17written · fast13Structured OutputLLM as a typed function · JSON mode vs schema-enforced · Constrained/grammar decoding · Pydantic/Zod validation …★★★18written · fast14Multimodal and Realtime VoiceVision inputs (images, screenshots) · PDF/document understanding · STT/TTS · Realtime voice pipelines (cascade vs speech-to-speech) …★★3written
Part IV

Retrieval and RAG

15Information Retrieval FoundationsQueries, documents, relevance · Inverted index · TF-IDF · BM25 …★★★14written · fast16Vector Search and IndexingExact kNN limits · IVF, PQ · HNSW · Recall/latency/memory trade-offs …★★2written17RAG PipelinesWhy RAG · Architecture end to end · Ingestion and parsing · Chunking …★★★13written · fast18Advanced and Agentic RAGQuery decomposition and multi-hop · HyDE and expansion · Text-to-SQL and query construction · GraphRAG …★★★4written · fast
Part V

Evaluation

19Evals I: Methodology and Error AnalysisEvals as the core loop · Model vs system evals · Benchmarks and contamination · Trace review …★★★10written · fast20Evals II: Judges, RAG/Agent Evals and Continuous EvaluationLLM-as-judge design · Pairwise vs pointwise · Validating judges (TPR/TNR vs humans) · Judge biases …★★★11written · fast
Part VI

Agents

21Tool Use / Function CallingTools: text to action · Call protocol · Agent-computer interface design · Names, descriptions, examples …★★★8written · fast22The Agent Loop and ArchitecturesWorkflows vs agents · The augmented LLM · Chaining, routing, parallelization · Orchestrator-workers; evaluator-optimizer …★★★27written · fast23MemoryWhy stateless models need memory · Conversation buffer · Summarization and compaction · Episodic/semantic/procedural stores …★★★18written · fast24Planning and Reasoning in AgentsPlanning vs reacting · Plan-then-execute · Decomposition and todo lists · Tree/graph search …★★5written25Multi-Agent SystemsWhen multiple agents help (and don't) · Orchestrator/sub-agent · Handoffs · Parallel sub-agents and context isolation …★★1written26MCP and Agent ProtocolsThe N×M integration problem · Host/client/server architecture · Transports (stdio, streamable HTTP) · Tools, resources, prompts …★★★1written27Context EngineeringFrom prompt to context engineering · Context as a finite attention budget · Context rot · Anatomy of agent context …★★★10written · fast28Coding and Computer-Use AgentsWhy coding is the flagship domain · Agent-computer interfaces · Repo navigation · Edit formats and patching …★★written
Part VII

Production

29Guardrails and SafetyTaxonomy (input/output, sync/async) · Moderation classifiers · PII detection and redaction · Scope restriction …★★★28written30ObservabilityWhy APM isn't enough · Traces and spans for LLM calls · OpenTelemetry GenAI conventions · Logging prompts, completions, tool calls …★★★17written · fast31Cost and Latency EngineeringUnit economics per task/user · Token budget accounting · Prompt caching · Semantic and exact caching …★★★22written · fast32Deployment and LLMOpsReference architecture · Prompts and config as code · Environments and staged rollout · A/B tests and shadow traffic …★★★25written · fast33Security: Prompt Injection and Agent SecurityThreat model · Direct injection and jailbreaks · Indirect injection · System-prompt extraction …★★★7written · fast34Product UX for AI and the Feedback LoopDesigning for probabilistic output · Expectation setting · Chat vs embedded vs ambient vs agentic UX · Streaming and progress UX …★★28written
esc

Narrow with repo:jm layer:eval q:naive mine · ↑↓ to move, enter to open