Compare Rankers with Retrieval MetricsBeta
Use the built-in retrieval Metrics to measure what a reranker or embedder changes in your pipeline. Run the same Dataset against two versions of the pipeline, and compare recall@k, MRR, and nDCG.
About This Task
By default, the Recall Metric counts the documents of every retriever and ranker in a run together. A reranker only reorders the documents the retriever found, so swapping one never changes that count. To see the effect of a reranker, you need two things: a Metric that reads only the ranker's output, and a Metric that takes the order of the documents into account.
The Retrieval quality category offers three Metrics for this. All of them read the expected documents from the test case in the same way, and none of them uses a model.
- Recall: The share of the expected documents among the documents read. It ignores order. With
Kset, it counts only the firstKdocuments of each turn. - MRR (mean reciprocal rank,
retrieval_mrr): 1 divided by the rank of the first expected document, averaged over the turns. It is 1 when the first document is expected, 0.5 when it is second, and 0 when no expected document is there. - nDCG (normalized discounted cumulative gain,
retrieval_ndcg): How close the ranking comes to the ideal one, from 0 to 1, averaged over the turns. The same documents ranked lower score less.
A Metric is not applicable when no test case stands behind the conversation, when the test case expects no documents, or when no turn is in focus.
Prerequisites
- A Dataset whose test cases have an expected column that lists the documents, for example
document_idsorfile_name. For how to add one, see Add Test Cases from a Table. - Two pipeline versions to compare, one for each ranker or embedder.
Add the Metrics
- Open your pipeline, click Evaluation, and go to Metrics.
- Click Add built-in Metrics, and select Recall, MRR, and nDCG under Retrieval quality. For more details, see Add Built-In Metrics.
- Confirm. The Metrics appear on the Metrics tab.
Choose the Component and Number of Documents
Without settings, MRR and nDCG read documents in the order they were first produced, which is the retriever's order. To compare rerankers, point the Metric at the ranker. Each Metric is an ordinary code Metric, so you set these values in its code.
- Open the Metric and, in the editor, find the settings at the top of the code.
- Set the ones you need:
COMPONENTS: The name of the component whose documents to read, as it appears in your pipeline, for example"ranker". Use a list of names to read several components.Nonereads every retriever and ranker.K: How many of each turn's first documents count, for example5.Nonecounts all of them. In nDCG, this makes it nDCG@k.EXPECTED_IS_RANKING(nDCG only):Falsetreats every expected document as equally relevant. Set it toTruewhen the expected column lists the documents in their ideal order. The first entry then weighs most.
- Click Try on a few sessions and read the rationale to check that the Metric reads the documents you expect. For how to test a Metric, see Write and Test an Evaluation Metric.
- Save the Metric.
For example, to measure recall@5 of a ranker called ranker, set COMPONENTS = "ranker" and K = 5 in Recall.
Set the same COMPONENTS and K in all three Metrics so that they score the same documents.
A Metric you added before these settings existed keeps the code it was created with. To get the settings, add the Metric again.
Compare the Pipeline Versions
- Add the three Metrics to a Metric Group, or select the Metric Group that holds them.
- Run an experiment on the Dataset for each pipeline version. For the steps, see Run an Experiment.
- Compare the experiments. For the steps, see Compare Pipeline Versions.
If the reranker helps, MRR and nDCG go up, because the expected documents move toward the top. Recall at the same
Kgoes up only if the reranker moves expected documents into the firstK.
If a Metric isn't applicable, never finds the expected documents, or scores the reranker the same as the retriever, see Fix Retrieval Metrics That Don't Match Your Documents.
Related Information
Was this page helpful?