Skip to content

Commit

Permalink
FloatVectorValues have a different interface in this Lucene version
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Dec 11, 2024
1 parent 81837fb commit bb7c260
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit bb7c260

Please sign in to comment.