This is Part 8 of a series that builds up Retrieval Augmented Generation (RAG) from the ground up.
Seven parts of concepts is enough. This one builds the thing.
The repo holds a single notebook that runs a full RAG pipeline end to end on your own machine no cloud services, no API keys, no per-token cost. Documents get parsed, chunked, embedded with all-MiniLM-L6-v2 , indexed in ChromaDB, retrieved, reranked with a cross-encoder, and answered by llama3.1:8b running locally through Ollama. Every decision has its reasoning written inline, so the notebook is meant to be read as much as run.
Building it locally first is deliberate. Managed RAG services abstract away exactly the parts worth understanding, so when Part 10 moves to AWS Bedrock Knowledge Bases, you'll recognise what it's doing under the hood instead of clicking through a configuration screen and hoping. For the same reason there's no LangChain or LlamaIndex here chunking is written by hand, because a framework would hide the decisions this series spent four parts explaining.
What surprised me most while building it was how many failures are completely silent. python-docx skips every table in a Word file with no warning at all, which would have quietly dropped an entire product table from the corpus while character counts still looked healthy. The embedding model truncates anything past 256 tokens without complaint the chunk still prints complete, only its vector is short. And chunking took four attempts before it stopped cutting sentences and words in half. None of those threw an error. The first version produced 138 perfectly reasonable-looking chunks. You only find these by reading the output, which is why the notebook keeps all four chunking versions and runs them side by side.
A couple of claims from earlier parts also held up under measurement. Part 7 said generation dominates latency measured, it was 85 to 95% of total query time, with retrieval and reranking making up the rest. And Part 2's grounding argument works exactly as described: asked "What is the capital of France?" against this corpus, the model replied that it didn't have that information. Llama 3.1 knows the capital of France perfectly well. One detail made that possible beyond the obvious instruction to use only the retrieved context explicitly giving the model permission to refuse. Without a stated escape hatch, a model produces something, because being helpful is its default.
Two honest limitations remain, and both are Part 9's subject. Exact identifiers like product codes work by luck here reranking rescued a query the retriever had ranked wrongly, but only because the corpus was small enough that the right chunk reached the candidate set at all. Reranking reorders; it can't retrieve what stage one never found. And nothing in the notebook was actually measured: every judgement about chunk size, reranking, and thresholds was made by reading output and forming an impression. That works for six documents and four test queries, and stops working shortly after.
Setup takes about ten minutes, most of it downloading model weights.
Next in this series (Part 9): Hybrid search and evaluation combining keyword and semantic retrieval, and replacing impressions with measurements.
Loading article