Skip to content

Commit 06cc3fb

Browse files
author
Christoph Büscher
committed
Rename ranking evaluation response section (#32166)
Currently the ranking evaluation response contains a 'unknown_docs' section for each search use case in the evaluation set. It contains document ids for results in the search hits that currently don't have a quality rating. This change renames it to `unrated_docs`, which better reflects its purpose.
1 parent 56acf4d commit 06cc3fb

File tree

12 files changed

+29
-36
lines changed

12 files changed

+29
-36
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/RankEvalIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import java.util.stream.Collectors;
4141
import java.util.stream.Stream;
4242

43-
import static org.elasticsearch.index.rankeval.EvaluationMetric.filterUnknownDocuments;
43+
import static org.elasticsearch.index.rankeval.EvaluationMetric.filterUnratedDocuments;
4444

4545
public class RankEvalIT extends ESRestHighLevelClientTestCase {
4646

@@ -85,7 +85,7 @@ public void testRankEvalRequest() throws IOException {
8585
Map<String, EvalQueryQuality> partialResults = response.getPartialResults();
8686
assertEquals(2, partialResults.size());
8787
EvalQueryQuality amsterdamQueryQuality = partialResults.get("amsterdam_query");
88-
assertEquals(2, filterUnknownDocuments(amsterdamQueryQuality.getHitsAndRatings()).size());
88+
assertEquals(2, filterUnratedDocuments(amsterdamQueryQuality.getHitsAndRatings()).size());
8989
List<RatedSearchHit> hitsAndRatings = amsterdamQueryQuality.getHitsAndRatings();
9090
assertEquals(7, hitsAndRatings.size());
9191
for (RatedSearchHit hit : hitsAndRatings) {
@@ -97,7 +97,7 @@ public void testRankEvalRequest() throws IOException {
9797
}
9898
}
9999
EvalQueryQuality berlinQueryQuality = partialResults.get("berlin_query");
100-
assertEquals(6, filterUnknownDocuments(berlinQueryQuality.getHitsAndRatings()).size());
100+
assertEquals(6, filterUnratedDocuments(berlinQueryQuality.getHitsAndRatings()).size());
101101
hitsAndRatings = berlinQueryQuality.getHitsAndRatings();
102102
assertEquals(7, hitsAndRatings.size());
103103
for (RatedSearchHit hit : hitsAndRatings) {

docs/reference/search/rank-eval.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ that shows potential errors of individual queries. The response has the followin
278278
"details": {
279279
"my_query_id1": { <2>
280280
"quality_level": 0.6, <3>
281-
"unknown_docs": [ <4>
281+
"unrated_docs": [ <4>
282282
{
283283
"_index": "my_index",
284284
"_id": "1960795"
@@ -313,7 +313,7 @@ that shows potential errors of individual queries. The response has the followin
313313
<1> the overall evaluation quality calculated by the defined metric
314314
<2> the `details` section contains one entry for every query in the original `requests` section, keyed by the search request id
315315
<3> the `quality_level` in the `details` section shows the contribution of this query to the global quality score
316-
<4> the `unknown_docs` section contains an `_index` and `_id` entry for each document in the search result for this
316+
<4> the `unrated_docs` section contains an `_index` and `_id` entry for each document in the search result for this
317317
query that didn't have a ratings value. This can be used to ask the user to supply ratings for these documents
318318
<5> the `hits` section shows a grouping of the search results with their supplied rating
319319
<6> the `metric_details` give additional information about the calculated quality metric (e.g. how many of the retrieved

modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/EvalQueryQuality.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public List<RatedSearchHit> getHitsAndRatings() {
102102
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
103103
builder.startObject(queryId);
104104
builder.field(QUALITY_LEVEL_FIELD.getPreferredName(), this.evaluationResult);
105-
builder.startArray(UNKNOWN_DOCS_FIELD.getPreferredName());
106-
for (DocumentKey key : EvaluationMetric.filterUnknownDocuments(ratedHits)) {
105+
builder.startArray(UNRATED_DOCS_FIELD.getPreferredName());
106+
for (DocumentKey key : EvaluationMetric.filterUnratedDocuments(ratedHits)) {
107107
builder.startObject();
108108
builder.field(RatedDocument.INDEX_FIELD.getPreferredName(), key.getIndex());
109109
builder.field(RatedDocument.DOC_ID_FIELD.getPreferredName(), key.getDocId());
@@ -123,7 +123,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
123123
}
124124

125125
private static final ParseField QUALITY_LEVEL_FIELD = new ParseField("quality_level");
126-
private static final ParseField UNKNOWN_DOCS_FIELD = new ParseField("unknown_docs");
126+
private static final ParseField UNRATED_DOCS_FIELD = new ParseField("unrated_docs");
127127
private static final ParseField HITS_FIELD = new ParseField("hits");
128128
private static final ParseField METRIC_DETAILS_FIELD = new ParseField("metric_details");
129129
private static final ObjectParser<ParsedEvalQueryQuality, Void> PARSER = new ObjectParser<>("eval_query_quality",

modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/EvaluationMetric.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ static List<RatedSearchHit> joinHitsWithRatings(SearchHit[] hits, List<RatedDocu
7676
/**
7777
* filter @link {@link RatedSearchHit} that don't have a rating
7878
*/
79-
static List<DocumentKey> filterUnknownDocuments(List<RatedSearchHit> ratedHits) {
80-
List<DocumentKey> unknownDocs = ratedHits.stream().filter(hit -> hit.getRating().isPresent() == false)
79+
static List<DocumentKey> filterUnratedDocuments(List<RatedSearchHit> ratedHits) {
80+
return ratedHits.stream().filter(hit -> hit.getRating().isPresent() == false)
8181
.map(hit -> new DocumentKey(hit.getSearchHit().getIndex(), hit.getSearchHit().getId())).collect(Collectors.toList());
82-
return unknownDocs;
8382
}
8483

8584
/**

modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/DiscountedCumulativeGainTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import java.util.Collections;
4141
import java.util.List;
4242

43-
import static org.elasticsearch.index.rankeval.EvaluationMetric.filterUnknownDocuments;
43+
import static org.elasticsearch.index.rankeval.EvaluationMetric.filterUnratedDocuments;
4444
import static org.elasticsearch.test.EqualsHashCodeTestUtils.checkEqualsAndHashCode;
4545
import static org.elasticsearch.test.XContentTestUtils.insertRandomFields;
4646
import static org.hamcrest.CoreMatchers.containsString;
@@ -128,7 +128,7 @@ public void testDCGAtSixMissingRatings() {
128128
DiscountedCumulativeGain dcg = new DiscountedCumulativeGain();
129129
EvalQueryQuality result = dcg.evaluate("id", hits, rated);
130130
assertEquals(12.779642067948913, result.getQualityLevel(), DELTA);
131-
assertEquals(2, filterUnknownDocuments(result.getHitsAndRatings()).size());
131+
assertEquals(2, filterUnratedDocuments(result.getHitsAndRatings()).size());
132132

133133
/**
134134
* Check with normalization: to get the maximal possible dcg, sort documents by
@@ -185,7 +185,7 @@ public void testDCGAtFourMoreRatings() {
185185
DiscountedCumulativeGain dcg = new DiscountedCumulativeGain();
186186
EvalQueryQuality result = dcg.evaluate("id", hits, ratedDocs);
187187
assertEquals(12.392789260714371, result.getQualityLevel(), DELTA);
188-
assertEquals(1, filterUnknownDocuments(result.getHitsAndRatings()).size());
188+
assertEquals(1, filterUnratedDocuments(result.getHitsAndRatings()).size());
189189

190190
/**
191191
* Check with normalization: to get the maximal possible dcg, sort documents by
@@ -224,13 +224,13 @@ public void testNoResults() throws Exception {
224224
DiscountedCumulativeGain dcg = new DiscountedCumulativeGain();
225225
EvalQueryQuality result = dcg.evaluate("id", hits, ratedDocs);
226226
assertEquals(0.0d, result.getQualityLevel(), DELTA);
227-
assertEquals(0, filterUnknownDocuments(result.getHitsAndRatings()).size());
227+
assertEquals(0, filterUnratedDocuments(result.getHitsAndRatings()).size());
228228

229229
// also check normalized
230230
dcg = new DiscountedCumulativeGain(true, null, 10);
231231
result = dcg.evaluate("id", hits, ratedDocs);
232232
assertEquals(0.0d, result.getQualityLevel(), DELTA);
233-
assertEquals(0, filterUnknownDocuments(result.getHitsAndRatings()).size());
233+
assertEquals(0, filterUnratedDocuments(result.getHitsAndRatings()).size());
234234
}
235235

236236
public void testParseFromXContent() throws IOException {

modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/EvalQueryQualityTests.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.elasticsearch.common.xcontent.XContentParser;
2727
import org.elasticsearch.common.xcontent.XContentType;
2828
import org.elasticsearch.index.Index;
29-
import org.elasticsearch.index.rankeval.RatedDocument.DocumentKey;
3029
import org.elasticsearch.search.SearchShardTarget;
3130
import org.elasticsearch.test.ESTestCase;
3231

@@ -52,11 +51,6 @@ protected NamedXContentRegistry xContentRegistry() {
5251
}
5352

5453
public static EvalQueryQuality randomEvalQueryQuality() {
55-
List<DocumentKey> unknownDocs = new ArrayList<>();
56-
int numberOfUnknownDocs = randomInt(5);
57-
for (int i = 0; i < numberOfUnknownDocs; i++) {
58-
unknownDocs.add(new DocumentKey(randomAlphaOfLength(10), randomAlphaOfLength(10)));
59-
}
6054
int numberOfSearchHits = randomInt(5);
6155
List<RatedSearchHit> ratedHits = new ArrayList<>();
6256
for (int i = 0; i < numberOfSearchHits; i++) {

modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RankEvalRequestIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import java.util.Map.Entry;
4141
import java.util.Set;
4242

43-
import static org.elasticsearch.index.rankeval.EvaluationMetric.filterUnknownDocuments;
43+
import static org.elasticsearch.index.rankeval.EvaluationMetric.filterUnratedDocuments;
4444
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
4545
import static org.hamcrest.Matchers.instanceOf;
4646

@@ -120,7 +120,7 @@ public void testPrecisionAtRequest() {
120120
for (Entry<String, EvalQueryQuality> entry : entrySet) {
121121
EvalQueryQuality quality = entry.getValue();
122122
if (entry.getKey() == "amsterdam_query") {
123-
assertEquals(2, filterUnknownDocuments(quality.getHitsAndRatings()).size());
123+
assertEquals(2, filterUnratedDocuments(quality.getHitsAndRatings()).size());
124124
List<RatedSearchHit> hitsAndRatings = quality.getHitsAndRatings();
125125
assertEquals(6, hitsAndRatings.size());
126126
for (RatedSearchHit hit : hitsAndRatings) {
@@ -133,7 +133,7 @@ public void testPrecisionAtRequest() {
133133
}
134134
}
135135
if (entry.getKey() == "berlin_query") {
136-
assertEquals(5, filterUnknownDocuments(quality.getHitsAndRatings()).size());
136+
assertEquals(5, filterUnratedDocuments(quality.getHitsAndRatings()).size());
137137
List<RatedSearchHit> hitsAndRatings = quality.getHitsAndRatings();
138138
assertEquals(6, hitsAndRatings.size());
139139
for (RatedSearchHit hit : hitsAndRatings) {

modules/rank-eval/src/test/java/org/elasticsearch/index/rankeval/RankEvalResponseTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void testToXContent() throws IOException {
158158
" \"details\": {" +
159159
" \"coffee_query\": {" +
160160
" \"quality_level\": 0.1," +
161-
" \"unknown_docs\": [{\"_index\":\"index\",\"_id\":\"456\"}]," +
161+
" \"unrated_docs\": [{\"_index\":\"index\",\"_id\":\"456\"}]," +
162162
" \"hits\":[{\"hit\":{\"_index\":\"index\",\"_type\":\"\",\"_id\":\"123\",\"_score\":1.0}," +
163163
" \"rating\":5}," +
164164
" {\"hit\":{\"_index\":\"index\",\"_type\":\"\",\"_id\":\"456\",\"_score\":1.0}," +

modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/10_basic.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ setup:
7373

7474
- match: { quality_level: 1}
7575
- match: { details.amsterdam_query.quality_level: 1.0}
76-
- match: { details.amsterdam_query.unknown_docs: [ {"_index": "foo", "_id": "doc4"}]}
76+
- match: { details.amsterdam_query.unrated_docs: [ {"_index": "foo", "_id": "doc4"}]}
7777
- match: { details.amsterdam_query.metric_details.precision: {"relevant_docs_retrieved": 2, "docs_retrieved": 2}}
7878

7979
- length: { details.amsterdam_query.hits: 3}
@@ -85,7 +85,7 @@ setup:
8585
- is_false: details.amsterdam_query.hits.2.rating
8686

8787
- match: { details.berlin_query.quality_level: 1.0}
88-
- match: { details.berlin_query.unknown_docs: [ {"_index": "foo", "_id": "doc4"}]}
88+
- match: { details.berlin_query.unrated_docs: [ {"_index": "foo", "_id": "doc4"}]}
8989
- match: { details.berlin_query.metric_details.precision: {"relevant_docs_retrieved": 1, "docs_retrieved": 1}}
9090
- length: { details.berlin_query.hits: 2}
9191
- match: { details.berlin_query.hits.0.hit._id: "doc1" }
@@ -159,9 +159,9 @@ setup:
159159
- gt: {details.amsterdam_query.quality_level: 0.333}
160160
- lt: {details.amsterdam_query.quality_level: 0.334}
161161
- match: {details.amsterdam_query.metric_details.mean_reciprocal_rank: {"first_relevant": 3}}
162-
- match: {details.amsterdam_query.unknown_docs: [ {"_index": "foo", "_id": "doc2"},
162+
- match: {details.amsterdam_query.unrated_docs: [ {"_index": "foo", "_id": "doc2"},
163163
{"_index": "foo", "_id": "doc3"} ]}
164164
- match: {details.berlin_query.quality_level: 0.5}
165165
- match: {details.berlin_query.metric_details.mean_reciprocal_rank: {"first_relevant": 2}}
166-
- match: {details.berlin_query.unknown_docs: [ {"_index": "foo", "_id": "doc1"}]}
166+
- match: {details.berlin_query.unrated_docs: [ {"_index": "foo", "_id": "doc1"}]}
167167

modules/rank-eval/src/test/resources/rest-api-spec/test/rank_eval/20_dcg.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
- lt: {quality_level: 13.848264 }
7474
- gt: {details.dcg_query.quality_level: 13.848263}
7575
- lt: {details.dcg_query.quality_level: 13.848264}
76-
- match: {details.dcg_query.unknown_docs: [ ]}
76+
- match: {details.dcg_query.unrated_docs: [ ]}
7777

7878
# reverse the order in which the results are returned (less relevant docs first)
7979

@@ -100,7 +100,7 @@
100100
- lt: {quality_level: 10.299675}
101101
- gt: {details.dcg_query_reverse.quality_level: 10.299674}
102102
- lt: {details.dcg_query_reverse.quality_level: 10.299675}
103-
- match: {details.dcg_query_reverse.unknown_docs: [ ]}
103+
- match: {details.dcg_query_reverse.unrated_docs: [ ]}
104104

105105
# if we mix both, we should get the average
106106

@@ -138,7 +138,7 @@
138138
- lt: {quality_level: 12.073970}
139139
- gt: {details.dcg_query.quality_level: 13.848263}
140140
- lt: {details.dcg_query.quality_level: 13.848264}
141-
- match: {details.dcg_query.unknown_docs: [ ]}
141+
- match: {details.dcg_query.unrated_docs: [ ]}
142142
- gt: {details.dcg_query_reverse.quality_level: 10.299674}
143143
- lt: {details.dcg_query_reverse.quality_level: 10.299675}
144-
- match: {details.dcg_query_reverse.unknown_docs: [ ]}
144+
- match: {details.dcg_query_reverse.unrated_docs: [ ]}

0 commit comments

Comments
 (0)