How would you build a system for evaluating the quality of a RAG pipeline and agents, including comparing versions when chunking changes and finding facts without using LLM-as-a-judge?
Asked at
AI answer
I would build the evaluation as a multi-layered offline and online loop, with quality broken down into retrieval, answer generation, and agent behavior. To compare versions, I would fix the corpus, queries, settings, and model versions, and save results together with metadata: chunking configuration, index, filters, and generation parameters.
1. Reference set. I would collect representative queries from logs and manually create edge cases: a fact appears in one document; a fact is distributed across several chunks; similar but conflicting sources; the fact is absent; data is outdated; the query requires clarification or multiple steps. For each query, I would annotate the expected facts and links to the source documents or text ranges. I would split the set into development and held-out test sets to avoid tuning the system to a single set.
2. Retrieval without LLM-as-a-judge. I would use verifiable metrics on labeled relevant documents and facts:
Recall@kandHitRate@k— whether at least one relevant source appears in the topkresults;MRRornDCG@k— how highly relevant sources are ranked;- fact retrieval precision — the share of retrieved items that are target facts, if irrelevance is also labeled.
To evaluate chunking, I would annotate facts as ranges in the source document. A chunk counts as containing a fact if it covers the required range or its predefined semantic context. I would calculate the share of queries for which the fact can be recovered from the top k, fact coverage, and context duplication. This makes it possible to compare, for example, fixed-size chunks, structure-based chunks, and different overlap values without subjectively evaluating the answer. Matching thresholds are best defined according to data type: normalization of dates and numbers, exact matching of identifiers, and a dictionary of acceptable variants for entities. For complex cases, I would retain manual annotation rather than try to replace it with invalid automatic matching.
3. Answers and citations. If answers must be grounded in sources, I would evaluate these separately:
- factual accuracy of answers against structured references: numbers, dates, names, statuses, and relationships;
- completeness of required facts;
- citation correctness: whether the cited source exists and whether its excerpt supports the specific claim;
- correct refusal or clarification request when the answer is not in the corpus or sources contradict one another.
For domains with a clear schema, this is convenient to do in code: extract fields from the answer and compare them with the reference using specified tolerances and normalization. For free-form text, atomic claims can be annotated and manually checked on a test sample. Text similarity metrics alone do not prove factual correctness.
4. Agents. I would add scenario tests with expected end conditions, permitted tools, and constraints: whether the agent called the required tool, passed correct arguments, completed the task, and avoided unnecessary or prohibited actions. It is better to replace tools in tests with deterministic fixtures. For side effects, I would use separate test environments and check idempotency. In addition to successful scenarios, tests should cover timeouts, tool errors, empty results, and retries.
5. Version comparison. For each version, I would run the same fixed set with the same parameters and save metrics by slice: query type, source, language, document length, answer availability, and difficulty. I would compare not only averages but also regressions in individual scenarios, and set minimum acceptable values and degradation limits. For stochastic components, I would fix the seed; for generation, I would record parameters and, where possible, run repeated trials. With small samples, I would report confidence intervals or at least the number of observations.
6. Operational loop. I would run offline evaluations whenever chunking, the model, prompt, or ranking changes; before release, I would use shadow or canary traffic with safe comparisons. In production, I would collect de-identified queries, retrieval results, citations, latency, cost, refusals, and explicit feedback, then periodically add them to the test set after annotation. Versioning the data and annotations is critical: otherwise, comparing two pipelines will be confounded by changes to the corpus.
The final report should show, for example, that the new chunking improved Recall@5 but reduced citation precision or increased context size and cost. This makes it possible to make decisions based on measurable trade-offs rather than a single aggregate score.
Also asked at Т1 Иннотех
- What enables the OpenSearch engine to return results quickly across a huge database (what algorithm is it based on)?
- How are Recall and Precision metrics calculated in the context of document retrieval?
- Design an architecture for an enterprise GPT (a chat with an LLM and document uploads for RAG) for 5,000 users per week.
- How would you organize load testing for the designed service: what baseline scenarios, signs of degradation, and Kubernetes container metrics should be monitored?
- Give an example from your experience (resume) of a task similar to the asynchronous pipeline being designed.
Similar questions
- How would you build a system for evaluating the quality of a generator, agents, and pipelines? Have you ever configured such a system?
- How would you create a chunking-agnostic eval benchmark (a benchmark that does not depend on how the text is split into chunks)?
- How to measure the quality of RAG-system responses if we cannot physically test all use cases and are not experts in the domain?
- Could you tell me how you tested and evaluated the quality of an AI system?
- How did you implement semantic search and RAG based on the content's plot?