Reading Mode
CH 14·Lesson 7
Phase 7 — AI/LLM Engineering — Checkpoint Answer Guide
This is a grading guide, not a script to memorize. Equivalent designs earn credit when their assumptions and evidence are correct.
advanced10 min read
Learning Objectives
- LLM Basics
- LangChain
- RAG Pipelines
- LangGraph & Agents
- CAPSTONE: DocuMind AI Platform
This is a grading guide, not a script to memorize. Equivalent designs earn credit when their assumptions and evidence are correct.
LLM Basics
- Tokens, temperature & sampling: Tokenization maps text to model vocabulary IDs; sampling converts next-token logits into a selected continuation under temperature and probability truncation. A strong answer also explains that temperature rescales logits before softmax. Top-p keeps the smallest probability mass above a threshold; generation repeats one token at a time using the growing context. The main warning is: A seed or temperature zero does not guarantee identical results across model revisions and infrastructure.
- Prompt engineering: A prompt is an untrusted, versioned instruction-and-data contract; examples demonstrate the desired mapping more concretely than prose alone. A strong answer also explains that system and developer instructions, conversation messages, retrieved text, and tool results form a precedence-aware context consumed by the model. The main warning is: Retrieved or user text can contain prompt injection; never grant it instruction authority.
- System prompts & few-shot: A prompt is an untrusted, versioned instruction-and-data contract; examples demonstrate the desired mapping more concretely than prose alone. A strong answer also explains that system and developer instructions, conversation messages, retrieved text, and tool results form a precedence-aware context consumed by the model. The main warning is: Retrieved or user text can contain prompt injection; never grant it instruction authority.
- Function calling / tool use: Tool calling lets the model propose typed arguments while ordinary code validates authorization and performs the action. A strong answer also explains that the application sends JSON schemas, receives zero or more calls, executes allowed functions, appends results, and asks the model to continue until a bounded stop condition. The main warning is: The model's tool choice and arguments are untrusted input.
- OpenAI & Anthropic APIs: Tokenization maps text to model vocabulary IDs; sampling converts next-token logits into a selected continuation under temperature and probability truncation. A strong answer also explains that temperature rescales logits before softmax. Top-p keeps the smallest probability mass above a threshold; generation repeats one token at a time using the growing context. The main warning is: A seed or temperature zero does not guarantee identical results across model revisions and infrastructure.
- Sampling math & cost controls: Tokenization maps text to model vocabulary IDs; sampling converts next-token logits into a selected continuation under temperature and probability truncation. A strong answer also explains that temperature rescales logits before softmax. Top-p keeps the smallest probability mass above a threshold; generation repeats one token at a time using the growing context. The main warning is: A seed or temperature zero does not guarantee identical results across model revisions and infrastructure.
LangChain
- LCEL (LangChain Expression Language): LCEL composes components implementing a common Runnable interface into sequences, maps, parallel branches, retries, and streaming pipelines. A strong answer also explains that the pipe operator constructs a graph; invoke, batch, stream, and async variants drive it. Tracing records run trees and metadata. The main warning is: A chain abstraction does not remove provider failures or the need to validate outputs.
- Memory types: Conversation memory is a policy for selecting or compressing prior application messages before a new model call. A strong answer also explains that buffer strategies retain text, windows drop older turns, summaries replace them with a lossy model-generated state, and hybrids combine recent detail with a summary. The main warning is: Summaries can lose constraints or accumulate hallucinations; they are not an audit log.
- Document loaders & splitters: Loaders normalize source documents and splitters produce retrievable chunks with provenance metadata. A strong answer also explains that recursive splitters try separators in priority order; token splitters bound model input more directly; header splitters preserve document hierarchy. The main warning is: Fixed characters do not equal fixed tokens, and extraction order can differ from visual order in PDFs.
- Output parsers: An output parser turns model text into an explicit application type and rejects malformed or semantically invalid results. A strong answer also explains that structured-output modes constrain generation where supported; otherwise parsing and a bounded repair attempt happen after generation. The main warning is: Repeated repair can hide a bad prompt and increase latency and cost.
- Custom extensions: Loaders normalize source documents and splitters produce retrievable chunks with provenance metadata. A strong answer also explains that recursive splitters try separators in priority order; token splitters bound model input more directly; header splitters preserve document hierarchy. The main warning is: Fixed characters do not equal fixed tokens, and extraction order can differ from visual order in PDFs.
RAG Pipelines
- Chunking & embedding strategies: Fixed-size chunking uses a token/character window; recursive chunking prefers increasingly smaller structural separators; semantic chunking splits where meaning shifts. A strong answer also explains that a splitter produces overlapping retrieval units. Smaller chunks improve targeting but lose surrounding context; larger chunks preserve context but dilute similarity and consume more prompt tokens. The main warning is: Choosing chunk size by intuition alone can improve one demonstration while reducing retrieval recall across the evaluation set.
- Hybrid search (BM25 + semantic): Lexical retrieval ranks exact and related terms using an inverted index; BM25 rewards term evidence while controlling for document length and common terms. A strong answer also explains that the engine analyzes text into tokens, stores postings, and calculates a score from term frequency, inverse document frequency, and length normalization. The main warning is: Applying inconsistent analyzers to indexed text and queries or using stop-word rules blindly can remove the only discriminating evidence.
- Re-ranking & evaluation: A re-ranker scores the query and each candidate together, usually improving top-result precision at higher per-candidate cost. A strong answer also explains that unlike independent embeddings, a cross-encoder attends jointly to query and passage. It runs only on a limited candidate set and returns a new ordering. The main warning is: Re-ranking too many long passages increases latency and cost; re-ranking cannot recover a relevant document that retrieval never returned.
- Vector store & embedding choices: Vector-store choice combines operational ownership, filtering, scale, consistency, cost, and index lifecycle; Matryoshka-trained embeddings can retain useful ranking quality when deliberately truncated to supported dimensions. A strong answer also explains that managed stores own distribution and index operations; pgvector shares PostgreSQL transactions and filters; local stores simplify prototypes. Every embedding belongs to a model/version/dimension namespace. The main warning is: Mixing vector versions or applying tenant filters after retrieval can return incorrect or unauthorized results.
LangGraph & Agents
- Graph architecture: A LangGraph application defines explicit typed state, node transitions, conditional routing, and termination. A strong answer also explains that each node returns a state update; reducers resolve concurrent updates; routing functions select edges; the compiled graph drives execution. The main warning is: A route without a bounded termination condition can loop indefinitely.
- State & checkpointing: Checkpointing persists graph state at execution boundaries so a thread can resume, inspect history, or branch from a prior state. A strong answer also explains that the checkpointer associates state snapshots and pending transitions with a thread identifier and checkpoint lineage. The main warning is: Replaying a checkpoint can repeat side effects unless nodes use idempotency records.
- Multi-agent patterns: A decorator receives a callable or class and returns a replacement, usually adding cross-cutting behavior. A strong answer also explains that decoration runs when the definition is executed, not at each call; the returned wrapper is what the name references.
wrapspreserves metadata and the wrapped chain. The main warning is: Keep retries bounded and restricted to transient, idempotent operations. - Compilation, tools & handoff: Compiling a LangGraph validates and turns declared nodes, edges, reducers, entry points, and checkpoint behavior into an executable graph; visualization exposes that topology for review. A strong answer also explains that compilation resolves routes and creates a runtime plan. A Mermaid representation is derived from graph metadata, but it does not execute tools or prove that conditional routes terminate. The main warning is: A diagram can look correct while a routing function creates an infinite loop or an unreachable recovery node.
CAPSTONE: DocuMind AI Platform
- Sprint 1: Core RAG backend: The first DocuMind sprint creates a durable ingestion-to-answer pipeline: streamed upload, asynchronous extraction/chunking, versioned embeddings, tenant-filtered hybrid retrieval, reranking, and citation-aware streaming generation. A strong answer also explains that a transaction records the document and outbox identity; workers replace the document's indexed chunks idempotently. Query-time lexical and vector candidates fuse, a reranker narrows evidence, and generation streams only after provenance is attached. The main warning is: Publishing work before the document transaction commits or mixing embedding versions creates phantom jobs and inconsistent retrieval.
- Sprint 2: LangGraph agent: The DocuMind agent is an explicit state graph whose nodes analyze a question, retrieve and rerank evidence, synthesize an answer, format citations, and route incomplete or no-context cases. A strong answer also explains that each node consumes typed state and returns a partial update; conditional edges select the next node; checkpoints make interruption, inspection, approval, and resume reproducible. The main warning is: A no-context route is not GraphQL resolver context; letting generated prose silently decide state transitions makes the graph untestable.
- Sprint 3: Production: Reranking applies a slower query-document model to a small candidate set; evaluation measures retrieval and answer quality separately. A strong answer also explains that a cross-encoder jointly scores query and chunk. RAG evaluation compares answer claims, retrieved context, and reference expectations. The main warning is: LLM judges are noisy and biased; calibrate them with human-reviewed examples.
Professional standard
A complete response identifies the boundary, guarantee, state owner, lifecycle, failure, and proof. Award less credit to answers that name tools without explaining why their guarantees fit the requirement.
Mastery check
How well can you recall this?
Finished this lesson?