Loading codebase...
Complete Source Code
Every single line of code behind Build Atlas, organized across all 9 parts. From tensor math, autograd, and byte-level BPE to TinyGPT training, LoRA chat tuning, hybrid RAG, autonomous agents, and continuous-batch serving.
Runnable checkpoint: executes 78 evaluation questions against the hybrid retriever and measures recall@k and MRR.
"""Part 7 · Ground it in your documents: chunk, index, retrieve (BM25, LSA, hybrid), answer with citations."""
import common # noqa: F401
from atlas.data import load_lessons
from atlas.evals import Case, run_eval, table
from atlas.prompts import ExtractiveLLM
from atlas.rag import Retriever, answer, chunk_lessons, retrieval_metrics
common.banner("Part 7 · Ground it in your documents")
lessons = load_lessons()
cases = [Case(q, a, l.slug) for l in lessons for q, a in l.qa]
chunks = chunk_lessons(lessons)
r = Retriever(chunks)
print(f"{len(chunks)} chunks (each keeps its heading path) · {len(cases)} questions with a known source lesson")
print(f"\n{'retrieval':<10}{'recall@5':>10}{'MRR':>8}")
for mode in ["bm25", "dense", "hybrid"]:
m = retrieval_metrics(r, cases, k=5, mode=mode)
print(f"{mode:<10}{m['recall@5']:>10.1%}{m['mrr']:>8.3f}")
llm = ExtractiveLLM()
res = run_eval("RAG (hybrid, top 3) + extractive", lambda c: answer(c.question, r, llm)[0], cases, need_citation=True)
print("\n" + table([res]))
q = "Why does asyncio code get slower when a task calls time.sleep?"
out, used = answer(q, r, llm)
print(f"\nQ: {q}\nA: {out}\nsources: " + " | ".join(f"[{i}] {c.lesson} > {c.heading.split(' > ')[-1]}" for i, c in enumerate(used, 1)))
print("\nReading it: retrieval finds the right lesson for almost every question, while answers pass far less often.")
print("The bottleneck is the generator, not the search. Swap ExtractiveLLM for any real model via the LLM")
print("interface (one complete(prompt) method) and the same evals will show the gain.")
print("\nCheckpoint: retrieval-augmented answers with citations, measured separately from generation.")