diff --git a/docs/changelog/122653.yaml b/docs/changelog/122653.yaml new file mode 100644 index 0000000000000..e36eb8debf10d --- /dev/null +++ b/docs/changelog/122653.yaml @@ -0,0 +1,6 @@ +pr: 122653 +summary: Knn vector rescoring to sort score docs +area: Vector Search +type: bug +issues: + - 119711 diff --git a/muted-tests.yml b/muted-tests.yml index 5868accc1a146..b468807628119 100644 --- a/muted-tests.yml +++ b/muted-tests.yml @@ -338,9 +338,6 @@ tests: - class: org.elasticsearch.xpack.restart.FullClusterRestartIT method: testWatcherWithApiKey {cluster=UPGRADED} issue: https://github.com/elastic/elasticsearch/issues/119396 -- class: org.elasticsearch.search.profile.dfs.DfsProfilerIT - method: testProfileDfs - issue: https://github.com/elastic/elasticsearch/issues/119711 - class: org.elasticsearch.xpack.security.authc.ldap.ADLdapUserSearchSessionFactoryTests issue: https://github.com/elastic/elasticsearch/issues/119882 - class: org.elasticsearch.index.mapper.AbstractShapeGeometryFieldMapperTests diff --git a/server/src/main/java/org/elasticsearch/search/vectors/RescoreKnnVectorQuery.java b/server/src/main/java/org/elasticsearch/search/vectors/RescoreKnnVectorQuery.java index e107db3a5b328..967f310f9352c 100644 --- a/server/src/main/java/org/elasticsearch/search/vectors/RescoreKnnVectorQuery.java +++ b/server/src/main/java/org/elasticsearch/search/vectors/RescoreKnnVectorQuery.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.util.Arrays; +import java.util.Comparator; import java.util.Objects; /** @@ -60,6 +61,7 @@ public Query rewrite(IndexSearcher searcher) throws IOException { TopDocs topDocs = searcher.search(query, k); vectorOperations = topDocs.totalHits.value; ScoreDoc[] scoreDocs = topDocs.scoreDocs; + Arrays.sort(scoreDocs, Comparator.comparingInt(scoreDoc -> scoreDoc.doc)); int[] docIds = new int[scoreDocs.length]; float[] scores = new float[scoreDocs.length]; for (int i = 0; i < scoreDocs.length; i++) {