AI Can Write Your RAG Pipeline. It Can’t Teach You to Build a Good One.
From the publisher’s feed, collected in the ZeroLabs newsroom.
I drafted this article with the help of Claude, Anthropic’s AI assistant, and checked every number against rag-lab’s own benchmark runs.Writing a RAG pipeline is the easy part nowAsk any AI coding assistant for a RAG pipeline and you will have one in a few minutes. It will load your documents, split them into chunks, embed them, put them in a vector store, retrieve the top matches for a question and hand them to an LLM. It runs, it answers, and the demo looks great.A year or two ago that took days of reading docs and gluing libraries together. Today it is a prompt. The code is no longer the hard part of Retrieval-Augmented Generation.So what is then? Let’s see.So how do you learn RAG?The usual path is tutorials. You follow a notebook, swap in your own PDFs, maybe try a different vector database. You learn the vocabulary: chunking, embeddings, hybrid search, reranking, agents.But a tutorial ends where the real questions start. Should your chunks be 300 characters or 1,200? Is hybrid search worth it on your data? Does the reranker everyone recommends actually help? Is the new pipeline better, or did it just answer the three questions you tried?None of those has a universal answer. They depend on your documents and your questions. The only way to answer them is to measure.Why AI-written RAG is not enoughAn AI assistant writes a pipeline that is plausible. It picks sensible defaults: a popular embedding model, a common chunk size, a well-known reranker. Plausible is not the same as good for your data, and the assistant has no way to know the difference without measuring either.What separates a good RAG engineer from someone with working code is judgement:Knowing what to measure. Did search find the right document (recall)? Did it rank it near the top (nDCG, MRR)? Did it reach the prompt (context recall)? Was the final answer correct?Knowing where it fails. Reading the questions a pipeline gets wrong, and seeing why: a missing keyword, a paraphrase, a chunk cut in the wrong place.Knowing when a gain is real. A pipeline that scores 2 points higher on 20 questions has usually not improved. You need a significance test, not a bigger average.Knowing that defaults can hurt. A component that helps on one dataset can make another one worse.You cannot get that judgement by reading generated code. You get it by running experiments and looking at the results.How to actually learn RAG techniquesThe way to learn RAG is the way scientists learn anything: run controlled experiments. That needs four things.A benchmark with an answer key. Real documents, questions, and for each question the gold documents (and ideally a gold answer). Without gold data you are judging by feel.A pipeline you can see and change. Every step, from chunking to generation, should be code you can read and edit, not a black box.One change at a time. Change the chunk size, or the retriever, or the reranker. Run again. Compare with the run before.Honest comparison. Look at which questions got fixed and which broke, and check whether the difference could be noise.AI is still very useful in this loop. It can write the script for your experiment in seconds. What it cannot do is decide what the experiment shows. That part is yours, and it is the skill worth learning.I could not find a tool that made this loop easy, so I built one.Meet rag-lab: a lab for learning RAG by measuring itrag-lab is an open-source playground that runs on your own machine. You build ingestion and retrieval pipelines on a node canvas in the browser, run them against real benchmarks, and see exactly what each change did.Here is how a RAG experiment flows through it:Dataset. Every benchmark has three parts: the raw documents, the questions, and the gold documents and gold answers for each question. rag-lab downloads public ones (SciFact, the BEIR sets, EnterpriseRAG-Bench with 512,000 company documents) or loads your own files.Ingestion pipeline. The raw documents are cleaned, chunked and optionally embedded.Target. The chunks go into an index: a local store, a knowledge graph, PostgreSQL with pgvector, Qdrant, OpenSearch, Elasticsearch, any SQL database, or your own Python script.Retrieval pipeline. Each question is retrieved with BM25, vectors, a graph or a hybrid of them, optionally reranked, and answered by Claude in one pass or as an agent that searches again.Compare with the gold set. Retrieved documents are scored against the gold documents; generated answers against the gold answers by an LLM judge.Benchmark. Scores for every run and every question, a matrix of every target against every pipeline, and a comparison of any two runs.Three design choices make it a learning tool rather than a framework:Every node is Python you can read. Built-in nodes open in an editor as plain Python. Change one, save it, and it runs as your own script.Every run is recorded. Its full config, scripts, dataset version, per-step timings and logs, tokens and cost. Only what changed re-runs.Every comparison is honest. The Compare page runs a paired permutation test and a bootstrap interval, and says plainly when a gap could be noise.How the benchmark works: gold documents and gold answersA benchmark is an answer key. For every question it lists the documents that hold the answer (the gold documents) and, in some datasets, the right answer itself (the gold answer). rag-lab scores two things separately: did retrieval find the gold documents, and does the generated answer match the gold answer.The gold recordEach question in a dataset is one line like this:{"question_id": "q1", "question": "…", "expected_doc_ids": ["doc-17", "doc-42"], "gold_answer": "…", "category": "…"}Auto (JSON)SciFact, for example, has gold documents but no gold answers: the claim “0-dimensional biomaterials show inductive properties.” has one gold document, 31715818. EnterpriseRAG-Bench has both, for 500 questions in 10 categories. Without gold answers you still get every retrieval score, for free and with no API key.How retrieval is scored against the gold documentsRetrieval returns chunks, best first. rag-lab turns them into a ranked list of documents: each document takes the rank of its best chunk, and later chunks of the same document are dropped. That list is compared with the gold documents:recall@k: the share of the question’s gold documents found in the top k. Two gold documents, one in the top 10, gives recall@10 = 50.nDCG@10: like recall@10, but rank matters. A gold document at rank 1 counts 1, at rank 2 counts 0.63, at rank 3 counts 0.5, at rank 10 only 0.29 (1 / log2(rank + 1)). The total is divided by the best possible score, with every gold document at the top, so a perfect ranking scores 100.MRR@10: 1 / the rank of the first gold document. Rank 1 gives 100, rank 2 gives 50, rank 4 gives 25, nothing in the top 10 gives 0.context_recall: the share of gold documents that actually reached the LLM’s prompt, after reranking.answer_recall and extra_docs: the gold documents the answer cites, and the non-gold documents it cites.A worked example: a question has one gold document, and retrieval ranks it third. Then recall@1 = 0, recall@5 = 100, recall@10 = 100, nDCG@10 = 50 and MRR@10 = 33.3. The document was found, but not first, and nDCG and MRR say so where recall does not.How answers are scored against the gold answersWhen a dataset has gold answers, an LLM judge (Claude) reads the question, the gold answer and the generated answer, and returns two scores:correctness: the answer is correct if it states the same key facts as the gold answer with nothing contradicting or invented. If the gold answer says the information is not available, the answer is correct only if it also declines.completeness: the share of the gold answer’s facts that the answer states, from 0 to 100.EnterpriseRAG-Bench questions can be graded by that benchmark’s own published judge instead.From questions to a benchmarkEvery metric is computed per question, then averaged over all questions to give the run’s score, and per question category. Two runs are compared question by question on the same questions, which is how rag-lab can list the questions a change fixed and broke, and test whether the difference is real.Reading the benchmark in rag-labFour pages turn those scores into something you can learn from. The examples below are real runs on the EnterpriseRAG-Bench dev subset (20 questions) and SciFact.1. The results matrix. The latest score for every target against every retrieval pipeline, coloured by score, with any metric picked from the menu. It shows things you would never guess from code. The same vector search pipeline gets recall@10 67.4 on the local store, pgvector and Elasticsearch, but 61.1 on OpenSearch, because each database searches its index in its own approximate way. Tick two cells to compare them.2. One run. Everything that produced the score: each node’s settings, which steps came from the cache and how long the others took, the metric for each question category, and the tokens and cost. In this run, with Claude as an agent, recall@10 was 83.8 overall but 0 in the high_level and info_not_found categories, which is where to look next. The 20 questions cost $0.75.3. One question. The question, the generated answer, the judge’s verdict and reasoning, and the gold answer with the facts the judge checks. On the right, the gold documents, each tagged with where it got to: its retrieval rank, whether it reached the prompt, whether the answer cited it. Below them, the reranked chunks in order: green for a chunk from a gold document, amber for one that is not. This is where you see why a question failed.4. Comparing two runs. Pick two runs and a metric. rag-lab shows both means, the difference, a 95% confidence interval, how many questions each run won, and a plain verdict from a paired permutation test. Then it lists the questions that were fixed, broken or unchanged. In this example, Claude as an agent scored 85% correct against 65% for a single pass: 20 points better, 4 questions fixed, none broken. Yet the verdict is “no significant difference (p = 0.13)”, because 20 questions are too few to tell. That one screen teaches more about evaluating RAG than any tutorial I have read.What you learn: ten lessons with goal scoresA lab with every tool still leaves you asking what to try next, so rag-lab comes with ten guided lessons. Each one is a small experiment with a goal score that is checked automatically against your runs: vector search, hybrid search, reranking, writing your own retriever, chunking, GraphRAG, single-pass answers and agentic RAG.The goals come from real measurements. Here is what each technique scores on SciFact (5,000 scientific abstracts, 300 questions) with default settings, as recall@10 / nDCG@10:BM25 keyword search: 81.8 / 68.9Vector search (bge-small): 82.8 / 71.1Hybrid, BM25 + vectors: 85.0 / 72.8Hybrid + knowledge graph: 85.7 / 69.9Knowledge graph alone: 60.0 / 43.0Two results surprised me, and they are exactly the kind of thing you only learn by measuring:The popular reranker made things worse. A cross-encoder trained on web search queries lowered the share of gold documents reaching the prompt from 82.7 to 79.8. Scientific claims are not web queries. The lesson on reranking is now called “Does Reranking Help Here?”The knowledge graph barely helped. Adding it to hybrid search raised recall by 0.7 points and lowered nDCG by 2.9. SciFact asks about one claim at a time, which keyword and vector search already handle. Graphs are built for questions that connect facts across documents, and the GraphRAG lesson asks you to find out where they pay off.An AI assistant would happily have added both to your pipeline.Try it in two minutesYou need uv and Node 20+. No API key is needed for the first lessons.git clone https://github.com/kkfaisal/rag-lab.git && cd rag-labuv syncuv run rag-lab quickstart --serveAuto (Bash)The quickstart downloads SciFact (4 MB), builds a BM25 index, answers all 300 questions and prints your first scores, about 15 seconds after the download. Then open http://127.0.0.1:8000, go to Lessons, and start changing things.Let AI write your pipelines. Use rag-lab to learn which ones are actually good.The code is MIT-licensed and on GitHub: github.com/kkfaisal/rag-lab. Issues, ideas and new lessons are welcome.AI Can Write Your RAG Pipeline. It Can’t Teach You to Build a Good One. was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.