Foundations: how AI apps work.
Three short lessons on the ideas every AI system builds on: how a model writes an answer, how it answers from your documents, and how an agent takes actions safely.
- Every figure sourced and dated
- Same 2D and 3D diagram engine
- A checkpoint after each lesson
The system you’ll build
RAG: answers from your documents · 7 components
Why start here
Every topic after this one assumes these three ideas. Learn them once, properly.
- 3
lessons, each built around one diagram you step through.
Counted from the Foundations lessons · read 18 Nov 2026
- 22 min
of stepping in all, at your own pace.
Counted from the Foundations lessons · read 18 Nov 2026
- 21
steps across the three lessons, each with its own narration.
Counted from the Foundations lessons · read 18 Nov 2026
- 9
checkpoint questions, three per lesson, scored in your browser.
Counted from the Foundations lessons · read 18 Nov 2026
Lessons
3 interactive · 0 coming
- 1How an LLM answersTokens in, one token out, again and again: prompts, tokenizers, scores and sampling.
- 2RAG: answers from your documentsDocuments become chunks and embeddings; the closest chunks join the prompt so the model can answer from them.
- 3The agent loopThe model picks an action, the app checks it's allowed, a tool runs, and the loop goes round until it's done.
Current with
Every fact in this topic, with its source and date
- Claude docs · GlossaryClaude's glossary says tokens can correspond to words, subwords, characters, or even bytes.read 18 Nov 2026
- Attention Is All You NeedThe Transformer's decoder is auto-regressive, consuming previously generated symbols as input when generating the next, and masking stops a position attending to later ones.read 18 Nov 2026
- Hugging Face · Generation strategiesSampling randomly selects a token from the probability distribution over the vocabulary, as opposed to greedy search, which takes the most likely token.read 18 Nov 2026
- Hugging Face · Utilities for generationA temperature below 1 decreases randomness, and 0 is equivalent to shifting all probability mass to the most likely token.read 18 Nov 2026
- Claude docs · API version 2026-10-21From Claude API version 2026-10-21, a request that sends temperature, top_p or top_k returns a 400 error, even at the default value; prompting guides behaviour instead.read 18 Nov 2026
- Hugging Face · Text generationGeneration runs up to a predefined length or until the model produces an end-of-sequence token.read 18 Nov 2026
- Claude docs · Handling stop reasonsClaude reports why it stopped: end_turn when it completed naturally, max_tokens when it reached your limit, stop_sequence when it emitted one of your stop sequences.read 18 Nov 2026
- RAG paper (Lewis et al., 2020)RAG models combine a pre-trained seq2seq generator (parametric memory) with a dense vector index (non-parametric memory) accessed by a neural retriever.read 18 Nov 2026
- Anthropic · Contextual RetrievalAnthropic's Contextual Retrieval post describes breaking the knowledge base into smaller chunks of text, usually no more than a few hundred tokens.read 18 Nov 2026
- Claude docs · EmbeddingsClaude's docs describe text embeddings as numerical representations of text that let you measure semantic similarity; Anthropic does not offer its own embedding model.read 18 Nov 2026
- Voyage AI · Text embeddingsVoyage AI says all embeddings created with its 4 series are compatible with each other; queries and documents are embedded with compatible models.read 18 Nov 2026
- Claude docs · CitationsClaude's citations return the exact passages from provided documents that support each claim in an answer.read 18 Nov 2026
- Claude docs · Reduce hallucinationsAnthropic's guide suggests allowing Claude to say it doesn't know, using direct quotes and restricting answers to provided documents, and notes these techniques reduce hallucinations but don't eliminate them.read 18 Nov 2026
- Anthropic · Building effective agentsAnthropic describes agents as typically just LLMs using tools based on environmental feedback in a loop.read 18 Nov 2026
- Claude docs · How tool use worksClaude responds with stop_reason tool_use; your application runs each tool and sends tool_result blocks back; this repeats while the stop reason is tool_use.read 18 Nov 2026
- Claude docs · Bash toolClaude's bash tool docs say your application runs whatever command Claude requests, so treat it as untrusted input and validate it with an allowlist rather than a blocklist.read 18 Nov 2026
- Claude docs · Computer use toolClaude's computer use docs suggest asking a human to confirm decisions that might result in meaningful real-world consequences.read 18 Nov 2026