Skip to content

Commit bdff038

Browse files
szabostevejrodewig
andcommitted
[DOCS] Reformats ranking evaluation API (#46974)
* [DOCS] Reformats ranking evaluation API. Co-Authored-By: James Rodewig <[email protected]>
1 parent e84fafb commit bdff038

File tree

1 file changed

+150
-61
lines changed

1 file changed

+150
-61
lines changed

docs/reference/search/rank-eval.asciidoc

+150-61
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,87 @@
33

44
experimental["The ranking evaluation API is experimental and may be changed or removed completely in a future release, as well as change in non-backwards compatible ways on minor versions updates. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features."]
55

6-
The ranking evaluation API allows to evaluate the quality of ranked search
6+
Allows you to evaluate the quality of ranked search results over a set of
7+
typical search queries.
8+
9+
10+
[[search-rank-eval-api-request]]
11+
==== {api-request-title}
12+
13+
`GET /<index>/_rank_eval`
14+
15+
`POST /<index>/_rank_eval`
16+
17+
18+
[[search-rank-eval-api-desc]]
19+
==== {api-description-title}
20+
21+
The ranking evaluation API allows you to evaluate the quality of ranked search
722
results over a set of typical search queries. Given this set of queries and a
823
list of manually rated documents, the `_rank_eval` endpoint calculates and
924
returns typical information retrieval metrics like _mean reciprocal rank_,
1025
_precision_ or _discounted cumulative gain_.
1126

12-
[float]
13-
==== Overview
27+
Search quality evaluation starts with looking at the users of your search
28+
application, and the things that they are searching for. Users have a specific
29+
_information need_, for example they are looking for gift in a web shop or want
30+
to book a flight for their next holiday. They usually enter some search terms
31+
into a search box or some other web form. All of this information, together with
32+
meta information about the user (for example the browser, location, earlier
33+
preferences and so on) then gets translated into a query to the underlying
34+
search system.
1435

15-
Search quality evaluation starts with looking at the users of your search application, and the things that they are searching for.
16-
Users have a specific _information need_, e.g. they are looking for gift in a web shop or want to book a flight for their next holiday.
17-
They usually enter some search terms into a search box or some other web form.
18-
All of this information, together with meta information about the user (e.g. the browser, location, earlier preferences etc...) then gets translated into a query to the underlying search system.
36+
The challenge for search engineers is to tweak this translation process from
37+
user entries to a concrete query in such a way, that the search results contain
38+
the most relevant information with respect to the users information need. This
39+
can only be done if the search result quality is evaluated constantly across a
40+
representative test suite of typical user queries, so that improvements in the
41+
rankings for one particular query doesn't negatively effect the ranking for
42+
other types of queries.
1943

20-
The challenge for search engineers is to tweak this translation process from user entries to a concrete query in such a way, that the search results contain the most relevant information with respect to the users information need.
21-
This can only be done if the search result quality is evaluated constantly across a representative test suite of typical user queries, so that improvements in the rankings for one particular query doesn't negatively effect the ranking for other types of queries.
44+
In order to get started with search quality evaluation, three basic things are
45+
needed:
2246

23-
In order to get started with search quality evaluation, three basic things are needed:
47+
. A collection of documents you want to evaluate your query performance against,
48+
usually one or more indices.
49+
. A collection of typical search requests that users enter into your system.
50+
. A set of document ratings that judge the documents relevance with respect to a
51+
search request.
52+
53+
It is important to note that one set of document ratings is needed per test
54+
query, and that the relevance judgements are based on the information need of
55+
the user that entered the query.
2456

25-
. a collection of documents you want to evaluate your query performance against, usually one or more indices
26-
. a collection of typical search requests that users enter into your system
27-
. a set of document ratings that judge the documents relevance with respect to a search request+
28-
It is important to note that one set of document ratings is needed per test query, and that
29-
the relevance judgements are based on the information need of the user that entered the query.
57+
The ranking evaluation API provides a convenient way to use this information in
58+
a ranking evaluation request to calculate different search evaluation metrics.
59+
This gives a first estimation of your overall search quality and give you a
60+
measurement to optimize against when fine-tuning various aspect of the query
61+
generation in your application.
3062

31-
The ranking evaluation API provides a convenient way to use this information in a ranking evaluation request to calculate different search evaluation metrics. This gives a first estimation of your overall search quality and give you a measurement to optimize against when fine-tuning various aspect of the query generation in your application.
3263

33-
[float]
34-
==== Ranking evaluation request structure
64+
[[search-rank-eval-api-path-params]]
65+
==== {api-path-parms-title}
66+
67+
`<index>`::
68+
(Required, string) Comma-separated list or wildcard expression of index names
69+
used to limit the request.
70+
71+
[[search-rank-eval-api-query-params]]
72+
==== {api-query-parms-title}
73+
74+
include::{docdir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
75+
76+
include::{docdir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
77+
+
78+
--
79+
Defaults to `open`.
80+
--
81+
82+
include::{docdir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]
83+
84+
85+
[[search-rank-eval-api-example]]
86+
==== {api-examples-title}
3587

3688
In its most basic form, a request to the `_rank_eval` endpoint has two sections:
3789

@@ -51,10 +103,13 @@ GET /my_index/_rank_eval
51103
<2> definition of the evaluation metric to calculate
52104
<3> a specific metric and its parameters
53105

54-
The request section contains several search requests typical to your application, along with the document ratings for each particular search request, e.g.
106+
The request section contains several search requests typical to your
107+
application, along with the document ratings for each particular search request.
55108

56109
[source,js]
57110
-----------------------------
111+
GET /my_index/_rank_eval
112+
{
58113
"requests": [
59114
{
60115
"id": "amsterdam_query", <1>
@@ -77,20 +132,30 @@ The request section contains several search requests typical to your application
77132
]
78133
}
79134
]
135+
}
80136
-----------------------------
81137
// NOTCONSOLE
82138

83139
<1> the search requests id, used to group result details later
84140
<2> the query that is being evaluated
85-
<3> a list of document ratings, each entry containing the documents `_index` and `_id` together with
86-
the rating of the documents relevance with regards to this search request
141+
<3> a list of document ratings, each entry containing the documents `_index` and
142+
`_id` together with the rating of the documents relevance with regards to this
143+
search request
87144

88-
A document `rating` can be any integer value that expresses the relevance of the document on a user defined scale. For some of the metrics, just giving a binary rating (e.g. `0` for irrelevant and `1` for relevant) will be sufficient, other metrics can use a more fine grained scale.
145+
A document `rating` can be any integer value that expresses the relevance of the
146+
document on a user defined scale. For some of the metrics, just giving a binary
147+
rating (for example `0` for irrelevant and `1` for relevant) will be sufficient,
148+
other metrics can use a more fine grained scale.
89149

90-
[float]
91-
==== Template based ranking evaluation
92150

93-
As an alternative to having to provide a single query per test request, it is possible to specify query templates in the evaluation request and later refer to them. Queries with similar structure that only differ in their parameters don't have to be repeated all the time in the `requests` section this way. In typical search systems where user inputs usually get filled into a small set of query templates, this helps making the evaluation request more succinct.
151+
===== Template based ranking evaluation
152+
153+
As an alternative to having to provide a single query per test request, it is
154+
possible to specify query templates in the evaluation request and later refer to
155+
them. Queries with similar structure that only differ in their parameters don't
156+
have to be repeated all the time in the `requests` section this way. In typical
157+
search systems where user inputs usually get filled into a small set of query
158+
templates, this helps making the evaluation request more succinct.
94159

95160
[source,js]
96161
--------------------------------
@@ -129,23 +194,30 @@ GET /my_index/_rank_eval
129194
<3> a reference to a previously defined template
130195
<4> the parameters to use to fill the template
131196

132-
[float]
133-
==== Available evaluation metrics
134197

135-
The `metric` section determines which of the available evaluation metrics is going to be used.
136-
Currently, the following metrics are supported:
198+
===== Available evaluation metrics
199+
200+
The `metric` section determines which of the available evaluation metrics is
201+
going to be used. The following metrics are supported:
137202

138203
[float]
139204
[[k-precision]]
140205
===== Precision at K (P@k)
141206

142-
This metric measures the number of relevant results in the top k search results. Its a form of the well known https://en.wikipedia.org/wiki/Information_retrieval#Precision[Precision] metric that only looks at the top k documents. It is the fraction of relevant documents in those first k
143-
search. A precision at 10 (P@10) value of 0.6 then means six out of the 10 top hits are relevant with respect to the users information need.
144-
145-
P@k works well as a simple evaluation metric that has the benefit of being easy to understand and explain.
146-
Documents in the collection need to be rated either as relevant or irrelevant with respect to the current query.
147-
P@k does not take into account where in the top k results the relevant documents occur, so a ranking of ten results that
148-
contains one relevant result in position 10 is equally good as a ranking of ten results that contains one relevant result in position 1.
207+
This metric measures the number of relevant results in the top k search results.
208+
Its a form of the well known
209+
https://en.wikipedia.org/wiki/Information_retrieval#Precision[Precision] metric
210+
that only looks at the top k documents. It is the fraction of relevant documents
211+
in those first k search. A precision at 10 (P@10) value of 0.6 then means six
212+
out of the 10 top hits are relevant with respect to the users information need.
213+
214+
P@k works well as a simple evaluation metric that has the benefit of being easy
215+
to understand and explain. Documents in the collection need to be rated either
216+
as relevant or irrelevant with respect to the current query. P@k does not take
217+
into account where in the top k results the relevant documents occur, so a
218+
ranking of ten results that contains one relevant result in position 10 is
219+
equally good as a ranking of ten results that contains one relevant result in
220+
position 1.
149221

150222
[source,js]
151223
--------------------------------
@@ -182,13 +254,15 @@ in the query. Defaults to 10.
182254
If set to 'true', unlabeled documents are ignored and neither count as relevant or irrelevant. Set to 'false' (the default), they are treated as irrelevant.
183255
|=======================================================================
184256

257+
185258
[float]
186259
===== Mean reciprocal rank
187260

188-
For every query in the test suite, this metric calculates the reciprocal of the rank of the
189-
first relevant document. For example finding the first relevant result
190-
in position 3 means the reciprocal rank is 1/3. The reciprocal rank for each query
191-
is averaged across all queries in the test suite to give the https://en.wikipedia.org/wiki/Mean_reciprocal_rank[mean reciprocal rank].
261+
For every query in the test suite, this metric calculates the reciprocal of the
262+
rank of the first relevant document. For example finding the first relevant
263+
result in position 3 means the reciprocal rank is 1/3. The reciprocal rank for
264+
each query is averaged across all queries in the test suite to give the
265+
https://en.wikipedia.org/wiki/Mean_reciprocal_rank[mean reciprocal rank].
192266

193267
[source,js]
194268
--------------------------------
@@ -222,12 +296,18 @@ in the query. Defaults to 10.
222296
"relevant". Defaults to `1`.
223297
|=======================================================================
224298

299+
225300
[float]
226301
===== Discounted cumulative gain (DCG)
227302

228-
In contrast to the two metrics above, https://en.wikipedia.org/wiki/Discounted_cumulative_gain[discounted cumulative gain] takes both, the rank and the rating of the search results, into account.
303+
In contrast to the two metrics above,
304+
https://en.wikipedia.org/wiki/Discounted_cumulative_gain[discounted cumulative gain]
305+
takes both, the rank and the rating of the search results, into account.
229306

230-
The assumption is that highly relevant documents are more useful for the user when appearing at the top of the result list. Therefore, the DCG formula reduces the contribution that high ratings for documents on lower search ranks have on the overall DCG metric.
307+
The assumption is that highly relevant documents are more useful for the user
308+
when appearing at the top of the result list. Therefore, the DCG formula reduces
309+
the contribution that high ratings for documents on lower search ranks have on
310+
the overall DCG metric.
231311

232312
[source,js]
233313
--------------------------------
@@ -260,23 +340,31 @@ in the query. Defaults to 10.
260340
|`normalize` | If set to `true`, this metric will calculate the https://en.wikipedia.org/wiki/Discounted_cumulative_gain#Normalized_DCG[Normalized DCG].
261341
|=======================================================================
262342

343+
263344
[float]
264345
===== Expected Reciprocal Rank (ERR)
265346

266-
Expected Reciprocal Rank (ERR) is an extension of the classical reciprocal rank for the graded relevance case
267-
(Olivier Chapelle, Donald Metzler, Ya Zhang, and Pierre Grinspan. 2009. http://olivier.chapelle.cc/pub/err.pdf[Expected reciprocal rank for graded relevance].)
268-
269-
It is based on the assumption of a cascade model of search, in which a user scans through ranked search
270-
results in order and stops at the first document that satisfies the information need. For this reason, it
271-
is a good metric for question answering and navigation queries, but less so for survey oriented information
272-
needs where the user is interested in finding many relevant documents in the top k results.
273-
274-
The metric models the expectation of the reciprocal of the position at which a user stops reading through
275-
the result list. This means that relevant document in top ranking positions will contribute much to the
276-
overall score. However, the same document will contribute much less to the score if it appears in a lower rank,
277-
even more so if there are some relevant (but maybe less relevant) documents preceding it.
278-
In this way, the ERR metric discounts documents which are shown after very relevant documents. This introduces
279-
a notion of dependency in the ordering of relevant documents that e.g. Precision or DCG don't account for.
347+
Expected Reciprocal Rank (ERR) is an extension of the classical reciprocal rank
348+
for the graded relevance case (Olivier Chapelle, Donald Metzler, Ya Zhang, and
349+
Pierre Grinspan. 2009.
350+
http://olivier.chapelle.cc/pub/err.pdf[Expected reciprocal rank for graded relevance].)
351+
352+
It is based on the assumption of a cascade model of search, in which a user
353+
scans through ranked search results in order and stops at the first document
354+
that satisfies the information need. For this reason, it is a good metric for
355+
question answering and navigation queries, but less so for survey oriented
356+
information needs where the user is interested in finding many relevant
357+
documents in the top k results.
358+
359+
The metric models the expectation of the reciprocal of the position at which a
360+
user stops reading through the result list. This means that relevant document in
361+
top ranking positions will contribute much to the overall score. However, the
362+
same document will contribute much less to the score if it appears in a lower
363+
rank, even more so if there are some relevant (but maybe less relevant)
364+
documents preceding it. In this way, the ERR metric discounts documents which
365+
are shown after very relevant documents. This introduces a notion of dependency
366+
in the ordering of relevant documents that e.g. Precision or DCG don't account
367+
for.
280368

281369
[source,js]
282370
--------------------------------
@@ -310,12 +398,13 @@ relevance judgments.
310398
in the query. Defaults to 10.
311399
|=======================================================================
312400

313-
[float]
314-
==== Response format
315401

316-
The response of the `_rank_eval` endpoint contains the overall calculated result for the defined quality metric,
317-
a `details` section with a breakdown of results for each query in the test suite and an optional `failures` section
318-
that shows potential errors of individual queries. The response has the following format:
402+
===== Response format
403+
404+
The response of the `_rank_eval` endpoint contains the overall calculated result
405+
for the defined quality metric, a `details` section with a breakdown of results
406+
for each query in the test suite and an optional `failures` section that shows
407+
potential errors of individual queries. The response has the following format:
319408

320409
[source,js]
321410
--------------------------------

0 commit comments

Comments
 (0)