Przeglądaj źródła

Fix reranker tests (#126500)

Aurélien FOUCRET 6 miesięcy temu
rodzic
commit
26ae289648

+ 0 - 3
x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java

@@ -52,7 +52,6 @@ import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.INLINESTA
 import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.JOIN_LOOKUP_V12;
 import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.JOIN_PLANNING_V1;
 import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.METADATA_FIELDS_REMOTE_TEST;
-import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.RERANK;
 import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.UNMAPPED_FIELDS;
 import static org.elasticsearch.xpack.esql.qa.rest.EsqlSpecTestCase.Mode.SYNC;
 import static org.mockito.ArgumentMatchers.any;
@@ -131,8 +130,6 @@ public class MultiClusterSpecIT extends EsqlSpecTestCase {
         assumeFalse("LOOKUP JOIN not yet supported in CCS", testCase.requiredCapabilities.contains(JOIN_LOOKUP_V12.capabilityName()));
         // Unmapped fields require a coorect capability response from every cluster, which isn't currently implemented.
         assumeFalse("UNMAPPED FIELDS not yet supported in CCS", testCase.requiredCapabilities.contains(UNMAPPED_FIELDS.capabilityName()));
-        // Need to do additional developmnet to get CSS support for the rerank coammnd
-        assumeFalse("RERANK not yet supported in CCS", testCase.requiredCapabilities.contains(RERANK.capabilityName()));
     }
 
     @Override

+ 10 - 2
x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/EsqlSpecTestCase.java

@@ -51,6 +51,7 @@ import java.util.TreeMap;
 import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 import java.util.stream.LongStream;
+import java.util.stream.Stream;
 
 import static org.apache.lucene.geo.GeoEncodingUtils.decodeLatitude;
 import static org.apache.lucene.geo.GeoEncodingUtils.decodeLongitude;
@@ -74,6 +75,8 @@ import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.deleteRerankInfere
 import static org.elasticsearch.xpack.esql.CsvTestsDataLoader.loadDataSetIntoEs;
 import static org.elasticsearch.xpack.esql.EsqlTestUtils.classpathResources;
 import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.METRICS_COMMAND;
+import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.RERANK;
+import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.SEMANTIC_TEXT_FIELD_CAPS;
 import static org.elasticsearch.xpack.esql.action.EsqlCapabilities.Cap.SOURCE_FIELD_MAPPING;
 
 // This test can run very long in serverless configurations
@@ -177,8 +180,8 @@ public abstract class EsqlSpecTestCase extends ESRestTestCase {
     }
 
     protected void shouldSkipTest(String testName) throws IOException {
-        if (testCase.requiredCapabilities.contains("semantic_text_field_caps") || testCase.requiredCapabilities.contains("rerank")) {
-            assumeTrue("Inference test service needs to be supported for semantic_text", supportsInferenceTestService());
+        if (requiresInferenceEndpoint()) {
+            assumeTrue("Inference test service needs to be supported", supportsInferenceTestService());
         }
         checkCapabilities(adminClient(), testFeatureService, testName, testCase);
         assumeTrue("Test " + testName + " is not enabled", isEnabled(testName, instructions, Version.CURRENT));
@@ -248,6 +251,11 @@ public abstract class EsqlSpecTestCase extends ESRestTestCase {
         return true;
     }
 
+    protected boolean requiresInferenceEndpoint() {
+        return Stream.of(SEMANTIC_TEXT_FIELD_CAPS.capabilityName(), RERANK.capabilityName())
+            .anyMatch(testCase.requiredCapabilities::contains);
+    }
+
     protected boolean supportsIndexModeLookup() throws IOException {
         return true;
     }

+ 31 - 57
x-pack/plugin/esql/qa/testFixtures/src/main/resources/rerank.csv-spec

@@ -10,15 +10,14 @@ required_capability: match_operator_colon
 FROM books METADATA _score
 | WHERE title:"war and peace" AND author:"Tolstoy"
 | RERANK "war and peace" ON title WITH test_reranker
-| KEEP book_no, title, author, _score
-| EVAL _score = ROUND(_score, 5)
+| KEEP book_no, title, author
 ;
 
-book_no:keyword | title:text                                            | author:text                                 | _score:double
-5327            | War and Peace                                         | Leo Tolstoy                                 | 0.03846
-4536            | War and Peace (Signet Classics)                       | [John Hockenberry, Leo Tolstoy, Pat Conroy] | 0.02222
-9032            | War and Peace: A Novel (6 Volumes)                    | Tolstoy Leo                                 | 0.02083
-2776            | The Devil and Other Stories (Oxford World's Classics) | Leo Tolstoy                                 | 0.01515
+book_no:keyword | title:text                                            | author:text
+5327            | War and Peace                                         | Leo Tolstoy
+4536            | War and Peace (Signet Classics)                       | [John Hockenberry, Leo Tolstoy, Pat Conroy]
+9032            | War and Peace: A Novel (6 Volumes)                    | Tolstoy Leo
+2776            | The Devil and Other Stories (Oxford World's Classics) | Leo Tolstoy
 ;
 
 
@@ -29,15 +28,14 @@ required_capability: match_operator_colon
 FROM books METADATA _score
 | WHERE title:"war and peace" AND author:"Tolstoy"
 | RERANK "war and peace" ON title, author WITH test_reranker
-| KEEP book_no, title, author, _score
-| EVAL _score = ROUND(_score, 5)
+| KEEP book_no, title, author
 ;
 
-book_no:keyword | title:text                                            | author:text                                 | _score:double
-5327            | War and Peace                                         | Leo Tolstoy                                 | 0.02083
-9032            | War and Peace: A Novel (6 Volumes)                    | Tolstoy Leo                                 | 0.01429
-2776            | The Devil and Other Stories (Oxford World's Classics) | Leo Tolstoy                                 | 0.01136
-4536            | War and Peace (Signet Classics)                       | [John Hockenberry, Leo Tolstoy, Pat Conroy] | 0.00952
+book_no:keyword | title:text                                            | author:text 
+5327            | War and Peace                                         | Leo Tolstoy 
+9032            | War and Peace: A Novel (6 Volumes)                    | Tolstoy Leo 
+2776            | The Devil and Other Stories (Oxford World's Classics) | Leo Tolstoy 
+4536            | War and Peace (Signet Classics)                       | [John Hockenberry, Leo Tolstoy, Pat Conroy]
 ;
 
 
@@ -50,14 +48,13 @@ FROM books METADATA _score
 | SORT _score DESC
 | LIMIT 3
 | RERANK "war and peace" ON title WITH test_reranker
-| KEEP book_no, title, author, _score
-| EVAL _score = ROUND(_score, 5)
+| KEEP book_no, title, author
 ;
 
-book_no:keyword | title:text                         | author:text                                 | _score:double
-5327            | War and Peace                      | Leo Tolstoy                                 | 0.03846
-4536            | War and Peace (Signet Classics)    | [John Hockenberry, Leo Tolstoy, Pat Conroy] | 0.02222
-9032            | War and Peace: A Novel (6 Volumes) | Tolstoy Leo                                 | 0.02083
+book_no:keyword | title:text                         | author:text
+5327            | War and Peace                      | Leo Tolstoy
+4536            | War and Peace (Signet Classics)    | [John Hockenberry, Leo Tolstoy, Pat Conroy]
+9032            | War and Peace: A Novel (6 Volumes) | Tolstoy Leo
 ;
 
 
@@ -68,35 +65,14 @@ required_capability: match_operator_colon
 FROM books METADATA _score
 | WHERE title:"war and peace" AND author:"Tolstoy"
 | RERANK "war and peace" ON title WITH test_reranker
-| KEEP book_no, title, author, _score
+| KEEP book_no, title, author
 | LIMIT 3
-| EVAL _score = ROUND(_score, 5)
 ;
 
-book_no:keyword | title:text                         | author:text                                 | _score:double
-5327            | War and Peace                      | Leo Tolstoy                                 | 0.03846
-4536            | War and Peace (Signet Classics)    | [John Hockenberry, Leo Tolstoy, Pat Conroy] | 0.02222
-9032            | War and Peace: A Novel (6 Volumes) | Tolstoy Leo                                 | 0.02083
-;
-
-
-reranker add the _score column when missing
-required_capability: rerank
-required_capability: match_operator_colon
-
-FROM books
-| WHERE title:"war and peace" AND author:"Tolstoy"
-| RERANK "war and peace" ON title WITH test_reranker
-| KEEP book_no, title, author, _score
-| EVAL _score = ROUND(_score, 5)
-;
-
-
-book_no:keyword | title:text                                            | author:text                                 | _score:double
-5327            | War and Peace                                         | Leo Tolstoy                                 | 0.03846
-4536            | War and Peace (Signet Classics)                       | [John Hockenberry, Leo Tolstoy, Pat Conroy] | 0.02222
-9032            | War and Peace: A Novel (6 Volumes)                    | Tolstoy Leo                                 | 0.02083
-2776            | The Devil and Other Stories (Oxford World's Classics) | Leo Tolstoy                                 | 0.01515
+book_no:keyword | title:text                         | author:text
+5327            | War and Peace                      | Leo Tolstoy
+4536            | War and Peace (Signet Classics)    | [John Hockenberry, Leo Tolstoy, Pat Conroy]
+9032            | War and Peace: A Novel (6 Volumes) | Tolstoy Leo
 ;
 
 
@@ -107,16 +83,15 @@ required_capability: match_operator_colon
 FROM books
 | WHERE title:"war and peace" AND author:"Tolstoy"
 | RERANK "war and peace" ON title WITH test_reranker
-| KEEP book_no, title, author, _score
+| KEEP book_no, title, author
 | SORT author, title 
 | LIMIT 3
-| EVAL _score = ROUND(_score, 5)
 ;
 
-book_no:keyword | title:text                                            | author:text                                 | _score:double
-4536            | War and Peace (Signet Classics)                       | [John Hockenberry, Leo Tolstoy, Pat Conroy] | 0.02222
-2776            | The Devil and Other Stories (Oxford World's Classics) | Leo Tolstoy                                 | 0.01515
-5327            | War and Peace                                         | Leo Tolstoy                                 | 0.03846
+book_no:keyword | title:text                                            | author:text
+4536            | War and Peace (Signet Classics)                       | [John Hockenberry, Leo Tolstoy, Pat Conroy]
+2776            | The Devil and Other Stories (Oxford World's Classics) | Leo Tolstoy
+5327            | War and Peace                                         | Leo Tolstoy
 ;
 
 
@@ -132,11 +107,10 @@ FROM books METADATA _id, _index, _score
 | RRF
 | RERANK "Tolkien" ON title WITH test_reranker
 | LIMIT 2
-| KEEP book_no, title, author, _score
-| EVAL _score = ROUND(_score, 5)
+| KEEP book_no, title, author
 ;
 
-book_no:keyword | title:keyword                         | author:keyword                                   | _score:double
-5335            | Letters of J R R Tolkien              | J.R.R. Tolkien                                   | 0.02632
-2130            | The J. R. R. Tolkien Audio Collection | [Christopher Tolkien, John Ronald Reuel Tolkien] | 0.01961
+book_no:keyword | title:keyword                         | author:keyword
+5335            | Letters of J R R Tolkien              | J.R.R. Tolkien
+2130            | The J. R. R. Tolkien Audio Collection | [Christopher Tolkien, John Ronald Reuel Tolkien]
 ;