Module 17 / 17
RAG & LLM Application Evaluation
Ground LLM answers in your own documents, then measure retrieval and answer quality systematically.
01 Why RAG
An LLM only knows its training data, has a knowledge cutoff and can hallucinate with confidence. Retrieval-Augmented Generation (RAG) searches for relevant document passages when a question arrives and inserts them into the prompt, so the model answers from those sources. Knowledge can be updated without retraining, and every answer can carry citations. Fine-tuning suits changing the style or format of answers; RAG suits knowledge that changes often, such as company policies.
02 Chunking, Embeddings and Vector Search
Documents are split into chunks of roughly 200 to 800 tokens with a little overlap so sentences keep their meaning. An embedding model turns each chunk into a vector, stored in a vector database such as pgvector, Qdrant or FAISS. The question is embedded too, and the system retrieves the top-k chunks with the highest cosine similarity. Hybrid search combines vector search with BM25 for exact terms such as product codes, and a reranker reorders the candidates before they reach the model.
03 Building the Prompt and Citations
Put the selected chunks in the prompt with their IDs and source titles, then instruct the model to answer only from that context, cite sources such as [doc-3], and say "I don't know" when the answer is not there. Very long context costs more and can make the model miss information in the middle, so send only the most relevant chunks. Apply metadata and access-control filters during retrieval, not afterwards, so users never receive content from documents they are not allowed to see.
04 Evaluating LLM Applications
Build a golden dataset of dozens to hundreds of real questions with their source documents and correct answers. Measure retrieval with recall@k and MRR: was the right chunk retrieved at all? Measure answers with faithfulness (every claim is supported by the sources) and answer relevance (it actually answers the question). LLM-as-a-judge with a clear rubric speeds up grading, but calibrate it against human ratings first. Run these evaluations in CI whenever the prompt, model or pipeline changes, and monitor latency and cost in production.