# Chapter 8 — Diagram sources

## Figures in the current chapter

The chapter uses a toy corpus of four short documents about methods from earlier chapters (D1 chain-of-thought, D2 Toolformer, D3 ReAct, D4 Tree of Thoughts) and one main question: *"Which method makes the model show its work?"* Part 4 and Part 5 add two follow-up questions on the same corpus. The documents are short summaries written for this chapter, not quoted text. No similarity score, model input, or answer in the chapter is a recorded model output.

| File | Section | Purpose |
|---|---|---|
| `knowledge-sources.svg` | 1.3 | Training writes parametric knowledge into weights; retrieval places non-parametric knowledge into the current input. |
| `pipeline.svg` | 1.3 | Preparation when documents are added or changed, then retrieval and generation for each question. |
| HTML example box | 1.4 | The question, retrieved D1, and a cited answer. Styles: `reading-concepts.html`. |
| `chunking.svg` | 2.1 | One long document split into four overlapping chunks, each kept as a record with text, position, and source; one toy-corpus line plays the role of one chunk. |
| `embedding-space.svg` | 2.2 | Related meanings receive nearby vectors; D2 shares a word with the question but lies in another group. Conceptual: positions are drawn by hand, not computed. |
| `top-k.svg` | 3.1 | D1–D4 ranked by score with cut-offs at k = 1 and k = 3. Scores are illustrative. |
| `retrieval-stages.svg` | 4.1 | Hybrid search merges keyword and embedding candidates; reranking reorders them. |
| `claim-support.svg` | 4.2 | Claim-by-claim check of an answer against the full D1; the 100B-parameter claim is not established. |
| `control.svg` | 5.1 | Fixed retrieve-then-generate workflow compared with an agent loop. |
| `self-rag.svg` | 5.2 | Self-RAG decisions and assessments (redraw; attribution below). |

All SVGs are generated by `scripts/build_w9_rag_figures.py`. Regenerate them with:

```bash
python scripts/build_w9_rag_figures.py
```

The two-dimensional cosine example (Section 3.1) and the chunk-count formula (Section 2.1) are computed in the text. The 298 chunks of the EU AI Act in Section 2.1 come from the lab's splitter ([lab preview](../../lab.html)).

Concept sources:

- RAG, parametric/non-parametric knowledge, RAG-Sequence: [Lewis et al.](https://arxiv.org/abs/2005.11401).
- Chunk sizes and overlap: [LangChain text splitting](https://docs.langchain.com/oss/python/integrations/splitters/recursive_text_splitter).
- Embedding comparison and reranking: [Sentence Transformers semantic search](https://www.sbert.net/examples/sentence_transformer/applications/semantic-search/README.html) and [retrieve & rerank](https://www.sbert.net/examples/sentence_transformer/applications/retrieve_rerank/README.html).
- Keyword retrieval and recall: [Introduction to Information Retrieval](https://nlp.stanford.edu/IR-book/).
- Retrieval control: [LangChain RAG architectures](https://docs.langchain.com/oss/python/deepagents/retrieval#rag-architectures).
- Self-RAG and its reflection tokens: [Asai et al.](https://arxiv.org/abs/2310.11511) and the [authors' overview](https://selfrag.github.io/).

The course-authored diagrams follow these sources: the knowledge-source distinction follows Lewis et al.; the retrieval and reranking diagram follows the component roles in Sentence Transformers, Retrieve & Re-Rank; the retrieval-control comparison follows LangChain's RAG architecture explanation.

## Self-RAG

`self-rag.svg` is a simplified conceptual redraw based on the **Self-RAG authors' overview** by Akari Asai, Zeqiu Wu, Yizhong Wang, Avirup Sil, and Hannaneh Hajishirzi.

- [Authors' overview and original diagram](https://selfrag.github.io/)
- [Research paper](https://arxiv.org/abs/2310.11511)
- The source website and this adapted diagram use [Creative Commons Attribution-ShareAlike 4.0](https://creativecommons.org/licenses/by-sa/4.0/).
- Changes: replaced the detailed U.S.-state examples with conceptual nodes; omitted special-token labels and candidate rankings; retained the retrieval choice, passage relevance, answer support, response utility, and continuation of generation.

The diagram shows the mechanism at an introductory level. It does not reproduce the paper's training or decoding algorithm. The token names and values in the chapter's table follow the paper.

## Archived artwork

`semantic-search.png` is not displayed by the current chapter; `embedding-space.svg` replaces it. It is reproduced unchanged from the **Sentence Transformers documentation**, maintained by the Sentence Transformers project.

- [Explanation and original figure](https://www.sbert.net/examples/sentence_transformer/applications/semantic-search/README.html)
- [Image at its source revision](https://github.com/huggingface/sentence-transformers/blob/fc963d6e45643fd2b32f931ecb3b6d102897e3d0/docs/img/SemanticSearch.png)
- License: Apache License 2.0; [full license](SENTENCE-TRANSFORMERS-LICENSE.txt).
- SHA-256: `2e0d6b8e97325fd312f61359e9aa12213cddaff31ce7b6df1b7bdc59902a7511`.

The image is a conceptual illustration. Its point coordinates do not report an embedding experiment.

Sources were checked during the Chapter 8 work on 2026-09-20; the figure set was revised on 2026-10-20.
