Tagging Chunks With File and Line Numbers

chunk metadata

Part of: Codebase Assistant

A chunk of code is useless as evidence unless you know exactly where it came from. This lesson adds the metadata that turns a chunk of text into a citable fact: which file, and which lines. What we're building Every chunk from lesson 2 knows its own start and end line, but only within one file. To answer questions across a whole repo, each chunk also needs its file path and a stable ID that identifies it: path:start-end. That ID is what shows up in the final answer as [src/app.py:12-18]. Building the corpus RAG systems call this collection of tagged, chunked documents the corpus . You build it by walking every source file, chunking each one, and stamping every chunk with its origin: The id is deterministic and readable on purpose. A random UUID would work too, but a UUID tells a user nothing when it shows up in an answer. src/app.py:12-18 tells them exactly where to look, with no lookup table. Why this matters: citations are just IDs, shown The whole answer-with-file-and-line feature comes down to this: keep the ID attached to every chunk from the moment it's created, through embedding, retrieval, and the final prompt, then print it back out next to whatever text it produced. Separ

Challenge: Build the Citation Index