diff --git a/server/src/main/java/org/elasticsearch/index/mapper/vectors/VectorSimilarityFloatValueSource.java b/server/src/main/java/org/elasticsearch/index/mapper/vectors/VectorSimilarityFloatValueSource.java index 74a7dbe168e6b..dc79b0d6aca8e 100644 --- a/server/src/main/java/org/elasticsearch/index/mapper/vectors/VectorSimilarityFloatValueSource.java +++ b/server/src/main/java/org/elasticsearch/index/mapper/vectors/VectorSimilarityFloatValueSource.java @@ -10,7 +10,6 @@ package org.elasticsearch.index.mapper.vectors; import org.apache.lucene.index.FloatVectorValues; -import org.apache.lucene.index.KnnVectorValues; import org.apache.lucene.index.LeafReader; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.VectorSimilarityFunction; @@ -47,18 +46,19 @@ public DoubleValues getValues(LeafReaderContext ctx, DoubleValues scores) throws final LeafReader reader = ctx.reader(); FloatVectorValues vectorValues = reader.getFloatVectorValues(field); - final KnnVectorValues.DocIndexIterator iterator = vectorValues.iterator(); return new DoubleValues() { @Override public double doubleValue() throws IOException { vectorOpsCount++; - return vectorSimilarityFunction.compare(target, vectorValues.vectorValue(iterator.index())); + return vectorSimilarityFunction.compare(target, vectorValues.vectorValue()); } @Override public boolean advanceExact(int doc) throws IOException { - return doc >= iterator.docID() && iterator.docID() != DocIdSetIterator.NO_MORE_DOCS && iterator.advance(doc) == doc; + return doc >= vectorValues.docID() + && vectorValues.docID() != DocIdSetIterator.NO_MORE_DOCS + && vectorValues.advance(doc) == doc; } }; } diff --git a/server/src/test/java/org/elasticsearch/search/vectors/RescoreKnnVectorQueryTests.java b/server/src/test/java/org/elasticsearch/search/vectors/RescoreKnnVectorQueryTests.java index 7bbe7dcc155c5..740c529661959 100644 --- a/server/src/test/java/org/elasticsearch/search/vectors/RescoreKnnVectorQueryTests.java +++ b/server/src/test/java/org/elasticsearch/search/vectors/RescoreKnnVectorQueryTests.java @@ -17,7 +17,6 @@ import org.apache.lucene.index.FloatVectorValues; import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.KnnVectorValues; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.VectorSimilarityFunction; import org.apache.lucene.search.IndexSearcher; @@ -95,12 +94,11 @@ public void testRescoreDocs() throws Exception { for (LeafReaderContext leafReaderContext : reader.leaves()) { FloatVectorValues vectorValues = leafReaderContext.reader().getFloatVectorValues(FIELD_NAME); - KnnVectorValues.DocIndexIterator iterator = vectorValues.iterator(); - while (iterator.nextDoc() != NO_MORE_DOCS) { - float[] vectorData = vectorValues.vectorValue(iterator.docID()); + while (vectorValues.nextDoc() != NO_MORE_DOCS) { + float[] vectorData = vectorValues.vectorValue(); float score = VectorSimilarityFunction.COSINE.compare(queryVector, vectorData); topK.add(score); - int docId = iterator.docID(); + int docId = vectorValues.docID(); // If the doc has been retrieved from the RescoreKnnVectorQuery, check the score is the same and remove it // to ensure we found them all if (rescoredDocs.containsKey(docId)) {