Portfolio

Engineering notes

Evaluating RAG retrieval with hit rate and reciprocal rank

A practical explanation of this portfolio's 20-question retrieval check, what hit@1 and MRR measure, and why answer quality needs separate evaluation.

By Vincent Teo · Updated

Define what should be retrieved

The repository includes a retrieval evaluation script with 20 questions about awards, research, education, tools, work experience, and individual projects. Each question has an expected substring in a metadata field, such as a project name or the Research category.

The script uses the same retrieval service as the chatbot and requests the six highest-ranked matches. It then finds the first result whose selected metadata field contains the expected substring. This makes the check reproducible, while keeping the expected answers understandable enough to inspect manually.

Read the three reported metrics

Hit@1 counts questions for which the expected entry appears first. Hit@3 counts those where it appears within the first three results. Mean reciprocal rank averages one divided by the rank of the first expected match; a question without a match contributes zero. For example, an expected entry at rank two contributes 0.5 to that question's reciprocal rank.

These measures answer different practical questions. Hit@1 describes whether the best result is usually useful. Hit@3 describes whether relevant evidence is available near the top. Reciprocal rank distinguishes finding the expected entry immediately from finding it lower in the list.

Know what this check cannot establish

The script inspects retrieval before the chat route's similarity cutoff. It therefore does not measure whether the production route would retain each expected match. A useful follow-up evaluation would report both retrieval rank and the answerable-question rate after the configured cutoff.

A category match can also be generous: a Skills entry may satisfy the label check while omitting the particular skill the question asks about. A stronger test set would identify the supporting fact or exact source, and would include questions that have no supported answer.

Finally, relevant context can still lead to an incomplete or unsupported generated answer. Retrieval scores should be reported alongside a separate review of factual support, citation relevance, appropriate abstention, and the final answer's usefulness. The presence of a source is not a calibrated probability that the response is correct.

Make comparisons reproducible

To compare an embedding or preprocessing change, hold the questions and knowledge-base snapshot constant. Record the embedding model, namespace, retrieval depth, cutoff, and evaluation date. The existing script can compare query name stripping with raw queries, but the indexed document preprocessing must also be documented for that comparison to be interpretable.

A future report should include individual failures and a separate held-out set of paraphrases. Questions about missing experience, ambiguous project references, and multilingual input are useful additions. Latency should be measured independently, with cached and uncached requests identified.

This article explains the evaluation method as it was first built, with 20 questions. The test has grown since then, and it now also checks questions the assistant should decline. The current dated results, the question counts and a real ranking miss are published in the AI evaluation lab.

Analytics cookies

I'd like to use Google Analytics to see which pages are useful. It sets cookies and is off unless you accept. Privacy policy