Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 2 of 5 · Worked example · 20 min · revision 2

Reading a Reference Capstone Repository

Read a small reference RAG repository the way a reviewer does: the README as a contract, what is committed and what is ignored, where every input comes from, one reported number traced back to its inputs, hidden state such as Python hash randomisation, and the CI job that repeats the dry run.

Contentsand lesson path

What you will learn

  • Explain what makes an integrated RAG application reproducible by someone else.

Prerequisites: AI Evaluation, AI Security, App Deployment, Observability

01. The problem

Your capstone will be reviewed by someone who has your repository and nothing else. Before you write your own README, practise on a reference: a deliberately tiny RAG repository that does what lesson 1 asked for. It answers questions about five pages of documentation for Larkspur, the small job scheduler from the Chunking skill, scores retrieval on a 12-question set and writes an evaluation report. So that it runs without an API key, a GPU or a model download, it uses a stand-in embedder (a hashed bag of words) instead of a neural embedding model. Everything else has the shape of the guided project.

The question to answer in 20 minutes: could a second person get the same report from this repository alone, and if not, where would they get stuck? Read in this order, because each step tells you what to look for in the next:

  1. the README, as a contract
  2. what is committed and what is not
  3. where every input comes from
  4. one number, traced back to its inputs
  5. hidden state in the code
  6. the automation that repeats the check

In lab 4 you build this repository yourself, minus the CI workflow, so the outputs below are the ones you will see there.

02. Step 1: Read the README as a contract

Markdown · README.md
# Larkspur assistant

Finds the Larkspur documentation page that answers a question, or says it
cannot, and reports how well that works on a versioned question set.

## Reproduce the evaluation report

You need Python 3.12 and Git. No API key, no GPU, no model download.

    git clone <repository-url> larkspur-assistant
    cd larkspur-assistant
    python3.12 -m venv .venv
    source .venv/bin/activate            # Windows: .venv\Scripts\activate
    python -m pip install -r requirements.txt
    python reproduce.py
    git diff --exit-code eval/report.md

`reproduce.py` checks every input, rebuilds `build/index` from `data/raw` and
rewrites `eval/report.md`. If the last command prints nothing and exits with
status 0, you got the same results as the committed report.

## What decides the results

- `data/raw/`: the document snapshot. Origin and licence in `data/SOURCES.md`,
  checksums in `data/checksums.sha256`.
- `config/rag.toml`: every setting (chunking, embedder, k, abstain threshold).
- `eval/queries-v1.csv`: the questions; a changed set gets a new file name.
- `requirements.txt` and `.python-version`: the environment.

## Known limitations

- The stand-in embedder matches words, not meanings: "jobs" does not match "job".
- 12 questions: one held-out question moves recall@3 by 0.25.

Read it as a contract with four clauses and check each one:

  • What you need. Python 3.12 and Git, and explicitly no key, GPU or download. A README that does not say what is not needed leaves the reader wondering whether a missing key is their fault.
  • Every step is a command. From git clone to the last line, nothing says build the index or download the model without the command that does it.
  • One command does the work. python reproduce.py runs the checks, the indexing and the evaluation in the right order, so the reader never needs to know that order.
  • Success is observable. The last command prints nothing and exits with status 0 when the regenerated report equals the committed one. You should see good results is not a success condition.

The README also says which files decide the results and what the known limitations are, which tells a reviewer where to look next.

03. Step 2: List what is committed, and what is not

git ls-files lists exactly what a clone will contain. Your file browser shows more, because it also shows ignored and untracked files, and those never reach anyone else.

Terminal
git ls-files
Expected output
.gitattributes
.github/workflows/reproduce.yml
.gitignore
.python-version
README.md
config/rag.toml
data/SOURCES.md
data/checksums.sha256
data/raw/api.md
data/raw/configuration.md
data/raw/install.md
data/raw/retries.md
data/raw/schedules.md
docs/REPRODUCIBILITY.md
docs/decisions/0001-abstain-threshold.md
eval/queries-v1.csv
eval/report.md
rag.py
reproduce.py
requirements.txt

Sort the list into four groups. Inputs: data/, config/rag.toml, eval/queries-v1.csv, requirements.txt and .python-version. Code: rag.py and reproduce.py. The claim: eval/report.md, generated but committed on purpose, because it is what a reader checks their own run against. Documentation: README.md and docs/. Then ask Git about the files that are missing from the list:

Terminal
git check-ignore -v build/index/vectors.npy .venv/bin/python rag.py
Expected output
.gitignore:3:build/	build/index/vectors.npy
.gitignore:1:.venv/	.venv/bin/python

git check-ignore -v prints the file, line and rule that ignores each path. The index under build/ and the virtual environment are derived: they are rebuilt, never committed. rag.py gets no line because nothing ignores it.

The rule to check is short: everything the one command reads must either be in git ls-files or be written by the one command. An index file committed without the script that builds it breaks the rule; so does an input folder that .gitignore quietly excludes.

04. Step 3: Follow the inputs

Find every place where the code reads a file. In a small repository, a search for the usual calls is enough:

Terminal
grep -n 'open(\|read_text(\|glob(' rag.py reproduce.py
Expected output
rag.py:15:    with open(path, "rb") as f:
rag.py:28:    for line in Path(checksums).read_text(encoding="utf-8").splitlines():
rag.py:31:    files = sorted(Path("data/raw").glob("*.md"))
rag.py:68:        pieces = chunk(path.read_text(encoding="utf-8"), size, overlap)
reproduce.py:24:    wanted = Path(".python-version").read_text(encoding="utf-8").strip()
reproduce.py:34:    with open(EVAL_SET, encoding="utf-8", newline="") as f:

The reads are the configuration, the checksum file, the documents under data/raw, .python-version and the evaluation set, and all of them are in git ls-files. Now read the inputs themselves, starting with the configuration:

TOML · config/rag.toml
# Every setting that can change a result lives here, and nowhere else.
[chunking]
size = 300       # characters per chunk
overlap = 60     # characters shared by neighbouring chunks

[embedding]
model = "hashing-bow"   # stand-in; a real project names its model here
revision = "v1"         # bump when the embedder changes
dims = 256

[retrieval]
k = 3
min_score = 0.20        # abstain when the best chunk scores lower

One file holds every setting that can change a result. The stand-in embedder still has a name and a revision: when its tokenisation changes, the revision changes, and so does every report made with it. In your project this file is where the embedding model and its Hub revision, the prompt version and the name of the environment variable that holds the generation model ID belong. Next, the data:

Markdown · data/SOURCES.md
# Sources

All five pages in data/raw were written for this sample and are released
under CC0 1.0. Snapshot taken 2026-10-19; checksums in data/checksums.sha256.
Terminal (Linux; on macOS use shasum -a 256 -c)
sha256sum -c data/checksums.sha256
Expected output
data/raw/api.md: OK
data/raw/configuration.md: OK
data/raw/install.md: OK
data/raw/retries.md: OK
data/raw/schedules.md: OK

SOURCES.md records origin, licence and date; the checksum file pins the bytes. reproduce.py repeats the checksum check in Python on every run, so nobody has to remember it. One more file protects the checksums: .gitattributes contains * text=auto eol=lf. Without it, Git on Windows may convert line endings to CRLF on checkout, every checksum fails, and the person reproducing your work is told that their data is corrupt.

05. Step 4: Trace one number back to its inputs

Terminal
head -n 16 eval/report.md
Expected output
# Evaluation report

Generated by `python reproduce.py`. Do not edit by hand.

## Inputs

- eval set: eval/queries-v1.csv, sha256 5209a3ad75c6
- data: 5 files, checksums sha256 07c0f21f3272
- config: fingerprint de5fe0c9e1e9
- embedder: hashing-bow v1, 256 dims, 8 chunks
- runtime: Python 3.12, numpy 2.5.4

## Results

- dev: recall@3 1.00 on 6 answerable, out of scope abstained 1/1
- held_out: recall@3 0.75 on 4 answerable, out of scope abstained 1/1

Take the held-out line: recall@3 of 0.75. The five lines under Inputs say what produced it: a hash of the evaluation set, a hash of the data checksums, a fingerprint of the configuration, the embedder with its revision, and the runtime. Someone who regenerates the report and sees a different value on any of those lines knows which input differs before comparing a single metric. The fingerprint is computed from the parsed settings:

Python · rag.py (excerpt)
def fingerprint(settings: dict) -> str:
    """Short hash of the parsed settings: comments and key order do not change it."""
    text = json.dumps(settings, sort_keys=True)
    return hashlib.sha256(text.encode("utf-8")).hexdigest()[:12]

Hashing the parsed settings rather than the file bytes means that editing a comment leaves the fingerprint alone, while changing any value changes it. Then read the question lines behind the number:

eval/report.md (continued)
## Per question

- q01 dev: found at rank 1, top score 0.298
- q02 dev: found at rank 1, top score 0.464
- q03 dev: found at rank 1, top score 0.363
- q04 dev: found at rank 1, top score 0.707
- q05 dev: found at rank 2, top score 0.276
- q06 dev: found at rank 1, top score 0.250
- q07 dev: abstained, correct, top score 0.146
- q08 held_out: found at rank 1, top score 0.487
- q09 held_out: found at rank 3, top score 0.393
- q10 held_out: found at rank 1, top score 0.217
- q11 held_out: abstained, wrong, top score 0.149
- q12 held_out: abstained, correct, top score 0.072

Held-out recall@3 of 0.75 is three of four answerable questions: q11 abstained although its answer is in retries.md. The README lists the reason as a known limitation, since the stand-in embedder does not match jobs with job. A number that leads to four named question lines is a number a reviewer can argue with, and that is the point of the report.

06. Step 5: Hunt for hidden state

Hidden state is anything that changes a result without being in the repository: environment variables, files outside the project (a cache in your home folder, an absolute path), the network (a model downloaded by name only), the clock, the order in which the operating system lists files, and randomness. Search for the usual suspects:

Terminal
grep -n "environ\|getenv\|random\|datetime\|time()\|hash(" rag.py reproduce.py
echo "exit status $?"
Expected output
exit status 1

No matches (grep exits with status 1): the code reads no environment variables, no clock and no random numbers. One suspect deserves a demonstration, because it hides in innocent-looking code. A hashing embedder must map each word to a position in the vector, and Python's built-in hash() looks like the obvious tool. Compare it with a hashlib digest, each in five fresh Python processes:

Python · hash_check.py
"""Run each snippet in five fresh Python processes and count the different results."""
import subprocess
import sys

SNIPPETS = {
    "hash()": "print(hash('dead-letter'))",
    "hashlib": "import hashlib; print(hashlib.blake2b(b'dead-letter').hexdigest())",
}


def run(code: str) -> str:
    done = subprocess.run([sys.executable, "-c", code], capture_output=True, text=True)
    return done.stdout


for name, code in SNIPPETS.items():
    outputs = {run(code) for _ in range(5)}
    print(f"{name:8} {len(outputs)} different result(s) from 5 runs")
Terminal
python hash_check.py
Expected output (with PYTHONHASHSEED unset)
hash()   5 different result(s) from 5 runs
hashlib  1 different result(s) from 5 runs

For strings and bytes, hash() is salted with a random value every time Python starts, unless the PYTHONHASHSEED environment variable fixes it; the salt protects dictionaries against crafted collisions. An embedder built on hash() would put words in different positions on every run, and the index would change silently. A hashlib digest depends only on the input bytes, which is why the reference uses blake2b.

Ordering needs the same care. The reference sorts the document list before reading it, and its search rounds scores and breaks ties by chunk ID, so tiny floating-point differences between machines cannot swap two results:

Python · rag.py (excerpt)
def search(question: str, chunks: list[dict], vectors: np.ndarray, cfg: dict):
    """Top-k unique documents and the best score. Rounding plus a tie-break on the
    chunk ID give the same order on every machine."""
    query = embed([question], cfg["embedding"]["dims"])[0]
    scores = np.round(vectors @ query, 6)
    order = sorted(range(len(chunks)), key=lambda i: (-scores[i], chunks[i]["id"]))
    docs: list[str] = []
    for i in order:
        if chunks[i]["doc"] not in docs:
            docs.append(chunks[i]["doc"])
    return docs[: cfg["retrieval"]["k"]], float(scores[order[0]])

In a full-size project the same risks sit in other places: a set turned into a list, os.listdir without sorted, a train and test split drawn without a seed, or a reranker loaded by name without a revision.

07. Step 6: Check that a machine repeats the dry run

YAML · .github/workflows/reproduce.yml
name: reproduce
on: [push, pull_request]
permissions:
  contents: read

jobs:
  reproduce:
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1  # v7.0.1
      - uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0  # v7.1.0
        with:
          python-version-file: .python-version
      - run: python -m pip install -r requirements.txt
      - run: python reproduce.py
      - name: The committed report must match the regenerated one
        run: git diff --exit-code eval/report.md

The workflow is the dry run, done by a machine on every push: a fresh checkout on Ubuntu and on Windows, Python chosen from .python-version, packages from requirements.txt, the one command, and then git diff --exit-code, which fails the job if the regenerated report differs from the committed one. The Windows runner is a cheap second person: it catches line-ending and path problems that your own machine would not show. Each action is pinned to a full commit SHA, with its tag as a comment, so a moved tag cannot change what runs, and permissions: contents: read gives the job's token read access only, which is all a check needs. This workflow runs on GitHub and was not run for this lesson; lab 4 performs the same steps by hand.

It complements the CI regression gate from the AI Evaluation skill. That gate blocks a change that makes quality worse; this job only checks that the claim committed in the repository is still true.

08. Check your understanding

Practice check · 3 questions

Reading a repository for reproducibility

Use what the reference repository showed you. Each question has one best answer.

Q1. A repository's generated report starts with the line 'generated: 2026-10-19 14:03:22', and its CI job runs the one command followed by git diff --exit-code on the report. What happens?
Q2. A teammate clones a repository like the reference on Windows, and every data file fails the checksum check although nobody changed the documents. The repository has no .gitattributes file. What is the most likely cause?
Q3. Which line in a hashing embedder makes the index differ from one run to the next?
Practice only: not graded, not saved, not evidence.

09. Apply it

Review your own Build a Grounded RAG Assistant repository the way you read the reference, and note what you find in docs/review-notes.md:

  1. Read your README as a contract: what is needed, every step a command, one command doing the work, an observable success condition. Mark every clause that fails.
  2. Search your code for file reads (open(, read_text(, glob(, np.load, SentenceTransformer() and check each path with git ls-files and git check-ignore -v. Anything read that is neither committed nor written by your one command is a gap.
  3. Trace one number in your M4 report back to the evaluation set version, the data, the configuration, the embedding model revision and the generation model ID. If you cannot, make the report generator write the missing line.
  4. Search for environ, random, datetime, time.time, hash( and listdir, and decide for each match whether it is a documented input, a recorded seed or a bug.

Fix the first gap you find. Lesson 4 tests the rest with a real dry run.

10. Review prompt

Without looking back, answer in your own words:

  1. In what order do you read a capstone repository, and what does each step tell you to look for in the next?
  2. Which four groups do the committed files fall into, and which rule must every file read by the one command satisfy?
  3. How does the report let a reader see which input changed before comparing any metric?
  4. Name five sources of hidden state, and explain why hash() is one of them while hashlib is not.
  5. What does the CI workflow check, and why run it on a second operating system?

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

4 questions · about 5 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check