The Complete Guide to Understanding, Building and Deploying Production-Ready AI Systems
Introduction
- What You Will Know After This Book
- How This Book Is Structured
- Cumulative Projects
- Prerequisites and How to Use This Book
- A Note on Toolchains and Versioning
- Getting Started
Chapter 1: The AI Engineering Landscape
- What Is AI Engineering
- Three Categories of AI Applications
- Capabilities, Limitations and Common Failure Modes
- How This Book Is Structured
- What Makes a Good AI Engineer
Chapter 2: Setting Up the Development Environment
- Installing Python and Managing Versions
- Virtual Environments and Dependency Isolation
- Package Management with pip and Poetry
- Code Editors and IDEs
- Terminal and Shell Fundamentals
- Git Basics for Version Control
- Creating the Project Workspace
- GPU Setup (Optional but Recommended)
- Verifying Your Setup
Chapter 3: Python for AI Engineering
- Data Structures for AI Work
- Functions, Scope and Modular Design
- Object-Oriented Programming for System Design
- Configuration Files and Data Formats
- Error Handling and Logging
- Type Hints and Static Analysis
- Asyncio for Concurrent Workflows
- Summary
Chapter 4: Essential Mathematics for AI
- Functions and Algebra
- Exponents, Logarithms and Growth
- Vectors and Matrices
- Probability Fundamentals
- Statistical Thinking
- Calculus Intuition: Derivatives as Gradients
- Summary
Chapter 5: Linear Algebra for Neural Networks
- Vectors and Geometric Interpretation
- Matrices as Linear Transformations
- Matrix Multiplication and Computational Patterns
- Dot Products and Similarity
- Norms and Distances
- Eigenvalues, Eigenvectors and Decompositions
- Numerical Linear Algebra in Practice
- Summary
Chapter 6: Probability and Statistics for AI
- Random Variables and Distributions
- Expectation, Variance and Moments
- Conditional Probability and Bayes Theorem
- Maximum Likelihood Estimation
- Common Probability Distributions
- Information Theory: Entropy and Cross-Entropy
- Statistical Foundations of Evaluation
- Summary
Chapter 7: The Mechanics of Machine Learning
- What Machine Learning Is and Is Not
- Supervised, Unsupervised and Reinforcement Learning
- The Training Loop: Data, Loss, Optimization, Evaluation
- Overfitting, Underfitting and Generalization
- Data Splits and Preventing Data Leakage
- Feature Engineering and Representation
- Evaluation Metrics for Classification and Regression
- Summary
Chapter 8: Optimization and Gradient Descent
- The Optimization Problem
- Loss Landscapes and Minima
- Gradient Descent: Derivation and Intuition
- Learning Rates and Momentum
- Stochastic and Mini-Batch Gradient Descent
- Regularization Techniques
- Convergence Diagnostics and Learning Rate Scheduling
- Summary
Chapter 9: Classical Machine Learning Methods
- Linear Regression: Formulation and Solutions
- Logistic Regression and Classification
- k-Nearest Neighbors
- Decision Trees and Random Forests
- Support Vector Machines
- Clustering Methods
- When to Use Classical Machine Learning
- Summary
Chapter 10: Neural Network Fundamentals
- The Perceptron as a Computational Unit
- Feedforward Networks and Layered Computation
- Activation Functions and Non-Linearity
- Loss Functions and Their Choices
- Universal Approximation and Expressivity
- Practical Network Design Choices
- Summary
Chapter 11: Backpropagation and Training
- The Chain Rule and Gradient Flow
- Step-by-Step Backpropagation Derivation
- Gradients for Each Network Component
- Weight Initialization Strategies
- Numerical Stability and Gradient Clipping
- Practical Training Procedures
- Debugging Training Problems
- Summary
Chapter 12: Convolutional Neural Networks
- Why Convolutions: Translation Invariance and Efficiency
- The Convolution Operation: Kernels, Strides, Padding
- Pooling and Downsampling
- Classic CNN Architectures
- Modern Architectures: ResNet and Beyond
- Transfer Learning for Vision
- Practical Computer Vision Applications
- Summary
Chapter 13: Recurrent Neural Networks and Sequence Models
- Why RNNs: The Challenge of Sequences
- RNN Fundamentals and Hidden States
- LSTM Architecture and Gating Mechanisms
- GRU: The Simpler Alternative
- Sequence-to-Sequence and Encoder-Decoder
- Practical Applications and Limitations
- Summary
Chapter 14: The Attention Mechanism
- Why Attention: Limitations of Previous Approaches
- Attention as Weighted Lookup
- Self-Attention: Queries, Keys and Values
- The Mathematics of Attention Scoring
- Multi-Head Attention Architecture
- Attention Complexity and Efficiency
- The Full Attention Block
- Summary
Chapter 15: Transformer Architecture
- The Full Transformer Architecture
- Positional Encoding and Order Information
- Layer Normalization and Residual Connections
- The Decoder: Causal Masking and Generation
- Why Transformers Excel at Language
- Next-Token Prediction at Scale
- Transformer Variants and Specializations
- Summary
Chapter 16: Tokenization and Text Representation
- Why Tokenization: Text as Numbers
- Character, Word and Subword Tokenization
- Byte Pair Encoding Algorithm
- WordPiece and SentencePiece
- Vocabulary Size and Unknown Tokens
- Context Length and Computational Implications
- Cross-Lingual and Special-Purpose Tokenizers
- Summary
Chapter 17: Large Language Models
- The Evolution from BERT to Modern LLMs
- Pretraining Objectives and Their Implications
- Scale: Parameters, Data and Emergent Abilities
- How Modern LLMs Are Trained
- Decoder-Only, Encoder-Decoder and Instruction-Tuned Models
- The Open-Weight Movement
- Capabilities and Fundamental Limitations
- Summary
Chapter 18: Working with Language Model APIs
- Model Providers and Their Offerings
- API Authentication and Cost Management
- Prompt Construction and Message Structure
- Generation Parameters: Temperature, Top-p and Beyond
- Streaming Responses
- Robust API Usage: Retries and Error Handling
- Model Selection Criteria
- Summary
Chapter 19: Open-Weight Models and Local Inference
- Local vs. API: Trade-offs and Use Cases
- Model Formats and Standards
- Quantization Formats and Quality Impact
- Local Inference Libraries
- Hardware Requirements and Trade-offs
- Serving Models as APIs
- Model Selection for Local Deployment
- Summary
Chapter 20: Prompt Engineering and Context Engineering
- How LLMs Interpret Instructions
- System Prompts and Role Conditioning
- Few-Shot Prompting and In-Context Learning
- Chain-of-Thought and Structured Reasoning
- Managing Long Context Windows
- Structured Outputs and Schema Enforcement
- Prompt Templates and Testing
- Common Failure Patterns
- Summary
Chapter 21: Embeddings and Semantic Search
- Word Embeddings and Semantic Representation
- Sentence and Passage Embeddings
- How Embeddings Capture Similarity
- Vector Search and Approximate Nearest Neighbor
- Embedding Models and Quality
- Building a Semantic Search System
- Evaluating Retrieval Performance
- Summary
Chapter 22: Vector Databases and Retrieval Systems
- Why You Need a Vector Database
- Managed vs Self-Hosted Vector Databases
- Comparing Major Vector Databases
- Hybrid Search: Combining Vector and Keyword
- Metadata Filtering and Structured Queries
- Reranking and Result Refinement
- Scaling Vector Databases
- Summary
Chapter 23: RAG (Retrieval-Augmented Generation)
- The RAG Architecture
- Document Ingestion and Parsing
- Chunking Strategies
- Query Processing and Transformation
- Context Assembly and Prompt Construction
- Building a Complete RAG System
- Summary
Chapter 24: Advanced RAG Techniques
- Hierarchical Chunking and Parent-Child Retrieval
- Graph-Based RAG and Knowledge Graphs
- Query Routing and Specialized Retrieval
- Multi-Hop Retrieval
- Optimizing Retrieval Quality
- Caching and Performance Optimization
- Summary
Chapter 25: Integrating Model APIs into Applications
- Service Architecture Around AI Models
- Robust Error Handling
- Circuit Breakers and Bulkheads
- Rate Limiting and Cost Management
- Multi-Provider and Multi-Model Strategies
- Streaming Responses
- Observability for AI Calls
- Summary
Chapter 26: Multimodal AI Systems
- Vision Models and Image Understanding
- Speech and Audio Models
- Multimodal Language Models
- Building Multimodal Applications
- Handling Multiple Modalities Efficiently
- Multimodal RAG
- Summary
Chapter 27: AI Agent Fundamentals
- What Is an AI Agent?
- The ReAct Pattern
- Tool Use and Function Calling
- Action Space and Constraints
- Agent Memory and State
- Controlling Agent Behavior
- Summary
Chapter 28: Agent Architectures and Frameworks
- Agent Patterns
- LangGraph: Structured Agent Workflows
- Tool Orchestration
- Multi-Agent Systems
- Frameworks and Libraries
- Building Reliable Agent Systems
- Summary
Chapter 29: Memory, State and Multi-Agent Systems
- Types of Agent Memory
- Conversation Memory and Context Management
- Shared State in Multi-Agent Systems
- Agent Communication Patterns
- Coordinating Multi-Agent Workflows
- Summary
Chapter 30: Workflow Orchestration
- Why Workflow Orchestration Matters
- Directed Acyclic Graphs (DAGs) for AI Workflows
- Temporal for AI Workflows
- Prefect for AI Data Pipelines
- LangGraph for AI Agent Workflows
- Conditional Execution and Dynamic Workflows
- Error Handling and Resilience
- Summary
Chapter 31: Fine-Tuning LLMs
- When to Fine-Tune vs Prompt
- Preparing Training Data
- Supervised Fine-Tuning (SFT)
- Instruction Tuning
- Loss Landscape and Training Dynamics
- Evaluation of Fine-Tuned Models
- Cost Considerations
- Deploying Fine-Tuned Models
- Summary
Chapter 32: Parameter-Efficient Fine-Tuning: LoRA and QLoRA
- The Problem with Full Fine-Tuning
- LoRA: Low-Rank Adaptation
- QLoRA: Quantized LoRA
- Other PEFT Methods
- Merging LoRA Adapters
- Training LoRA on Consumer Hardware
- Using Trained Adapters
- Summary
Chapter 33: Model Distillation and Compression
- Why Distill and Compress?
- Knowledge Distillation Fundamentals
- Distillation Data Generation
- Output Distillation vs Process Distillation
- Instruction Distillation
- Preference Optimization (DPO, RLHF)
- Pruning
- Quantization for Deployment
- Distillation vs LoRA vs Quantization
- Evaluating Compressed Models
- Summary
Chapter 34: Inference Optimization and Serving
- Inference vs Training
- The Inference Bottleneck
- Batching Strategies
- KV Cache Optimization
- Speculative Decoding
- Flash Attention
- GPU Memory Management
- Production Inference Servers
- Monitoring Inference Performance
- Cost Optimization for Inference
- Summary
Chapter 35: Application Architecture for AI Systems
- Architectural Characteristics of AI Systems
- Layered Architecture for AI Applications
- Microservices vs Monolith for AI
- AI-Specific Architectural Patterns
- Data Flow in AI Applications
- Database Architecture for AI Applications
- Error Handling Architecture
- Scalability Considerations
- Summary
Chapter 36: Containerization and Cloud Infrastructure
- Docker for AI Applications
- Docker with GPU Support
- Docker Compose for Local Development
- Kubernetes for Production Deployment
- Cloud Providers for AI Workloads
- Infrastructure as Code
- Deployment Environments
- Summary
Chapter 37: CI/CD for AI Systems
- CI/CD Challenges for AI Systems
- Testing AI Application Code
- Testing AI Quality
- Model and Prompt Versioning
- CI Pipeline for AI Applications
- CD Pipeline for AI Applications
- Rollback Strategies
- ML-Specific CI/CD Tools
- Summary
Chapter 38: Monitoring, Observability and Evaluation
- Why Monitoring AI Is Different
- Key Metrics for AI Systems
- Logging for AI Systems
- Distributed Tracing for AI Systems
- Production Evaluation
- Drift Detection
- Alerting and Incident Response
- Diagnostic Tools and Techniques
- Summary
Chapter 39: AI Reliability Engineering
- The Reliability Problem in AI
- Managing Nondeterminism
- Preventing and Detecting Hallucinations
- Reliable Retrieval
- Reliable Tool Execution
- Output Validation and Guards
- Guardrails
- Building Reliability into Architecture
- Summary
Chapter 40: AI Security
- OWASP Top 10 for LLM Applications
- Prompt Injection
- Data Leakage
- Authentication and Authorization
- Secure Tool Execution
- Adversarial Attacks
- Model Misuse
- Security Architecture for AI Systems
- Summary
Chapter 41: Responsible AI and Governance
- Why Responsible AI Matters
- AI Ethics Principles
- Bias in AI Systems
- Transparency and Explainability
- Regulatory Landscape
- AI Governance Frameworks
- Building Responsible AI into Engineering Practice
- Summary
Chapter 42: End-to-End Reference Architecture
- Architecture Overview
- Service Layer
- AI Orchestration Layer
- Retrieval Layer
- Data Layer
- Observability Layer
- Infrastructure
- Security
- Summary
Chapter 43: Production-Readiness Framework
- Why Production Readiness Matters
- Production-Readiness Checklist
- Load Testing
- Cost Analysis
- Incident Response
- Blue-Green and Canary Deployments
- Monitoring and Alerting
- Post-Deployment Checklist
- Summary
Chapter 44: The AI Engineering Methodology
- The AI Engineering Process
- Decision Frameworks
- Common Pitfalls and How to Avoid Them
- The AI Engineering Mindset
- Summary
Chapter 45: Glossary
Chapter 46: Annotated Bibliography
- Core AI and Deep Learning
- Transformers and Language Models
- Fine-Tuning and Adaptation
- RAG and Retrieval
- Agents and Planning
- MLOps and Infrastructure
- Security
- Official Documentation
- Research Platforms
- Practice and Projects