Skip to content

Commit 8e87b52

Browse files
committed
tidy
1 parent 928fdca commit 8e87b52

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

lucene/core/src/java/org/apache/lucene/search/DoubleValuesSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public static DoubleValues similarityToQueryVector(
281281
+ " does not have the expected vector encoding: "
282282
+ VectorEncoding.FLOAT32);
283283
}
284-
return new FloatVectorSimilarityValuesSource(queryVector, vectorField, true).getValues(ctx, null);
284+
return new FloatVectorSimilarityValuesSource(queryVector, vectorField).getValues(ctx, null);
285285
}
286286

287287
/**

lucene/core/src/java/org/apache/lucene/search/FloatVectorSimilarityValuesSource.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.IOException;
2121
import java.util.Arrays;
2222
import java.util.Objects;
23-
2423
import org.apache.lucene.index.FieldInfo;
2524
import org.apache.lucene.index.FloatVectorValues;
2625
import org.apache.lucene.index.KnnVectorValues;
@@ -39,6 +38,7 @@ class FloatVectorSimilarityValuesSource extends VectorSimilarityValuesSource {
3938
/**
4039
* Creates a {@link DoubleValuesSource} that returns vector similarity score between provided
4140
* query vector and field for documents. Uses the scorer exposed by configured vectors reader.
41+
*
4242
* @param vector the query vector
4343
* @param fieldName the field name of the {@link org.apache.lucene.document.KnnFloatVectorField}
4444
*/
@@ -52,10 +52,11 @@ public FloatVectorSimilarityValuesSource(float[] vector, String fieldName) {
5252
*
5353
* @param vector the query vector
5454
* @param fieldName the field name of the {@link org.apache.lucene.document.KnnFloatVectorField}
55-
* @param useFullPrecision uses full precision raw vectors for similarity computation if true, otherwise
56-
* the configured vectors reader is used, which may be quantized or full precision.
55+
* @param useFullPrecision uses full precision raw vectors for similarity computation if true,
56+
* otherwise the configured vectors reader is used, which may be quantized or full precision.
5757
*/
58-
public FloatVectorSimilarityValuesSource(float[] vector, String fieldName, boolean useFullPrecision) {
58+
public FloatVectorSimilarityValuesSource(
59+
float[] vector, String fieldName, boolean useFullPrecision) {
5960
super(fieldName);
6061
this.queryVector = vector;
6162
this.useFullPrecision = useFullPrecision;
@@ -89,7 +90,8 @@ public VectorScorer getScorer(LeafReaderContext ctx) throws IOException {
8990

9091
@Override
9192
public float score() throws IOException {
92-
return vectorSimilarityFunction.compare(queryVector, vectorValues.vectorValue(iterator.index()));
93+
return vectorSimilarityFunction.compare(
94+
queryVector, vectorValues.vectorValue(iterator.index()));
9395
}
9496

9597
@Override

lucene/core/src/test/org/apache/lucene/search/TestQuantizedVectorSimilarityValueSource.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.apache.lucene.search;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
35
import org.apache.lucene.codecs.Codec;
46
import org.apache.lucene.codecs.KnnVectorsFormat;
57
import org.apache.lucene.codecs.lucene99.Lucene99HnswScalarQuantizedVectorsFormat;
@@ -21,9 +23,6 @@
2123
import org.junit.Before;
2224
import org.junit.Test;
2325

24-
import java.util.ArrayList;
25-
import java.util.List;
26-
2726
public class TestQuantizedVectorSimilarityValueSource extends LuceneTestCase {
2827

2928
private Codec savedCodec;
@@ -77,13 +76,17 @@ public void testFullPrecisionVectorSimilarityDVS() throws Exception {
7776
int numVectors = atLeast(NUM_VECTORS);
7877
int numSegments = random().nextInt(2, 10);
7978
final VectorSimilarityFunction vectorSimilarityFunction =
80-
VectorSimilarityFunction.values()[random().nextInt(VectorSimilarityFunction.values().length)];
79+
VectorSimilarityFunction.values()[
80+
random().nextInt(VectorSimilarityFunction.values().length)];
8181

8282
try (Directory dir = newDirectory()) {
8383
int id = 0;
8484

8585
// index some 4 bit quantized vectors
86-
try (IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setCodec(TestUtil.alwaysKnnVectorsFormat(getKnnFormat(4))))) {
86+
try (IndexWriter w =
87+
new IndexWriter(
88+
dir,
89+
newIndexWriterConfig().setCodec(TestUtil.alwaysKnnVectorsFormat(getKnnFormat(4))))) {
8790
for (int j = 0; j < numSegments; j++) {
8891
for (int i = 0; i < numVectors; i++) {
8992
Document doc = new Document();
@@ -111,7 +114,10 @@ public void testFullPrecisionVectorSimilarityDVS() throws Exception {
111114
}
112115

113116
// index some 7 bit quantized vectors
114-
try (IndexWriter w = new IndexWriter(dir, newIndexWriterConfig().setCodec(TestUtil.alwaysKnnVectorsFormat(getKnnFormat(7))))) {
117+
try (IndexWriter w =
118+
new IndexWriter(
119+
dir,
120+
newIndexWriterConfig().setCodec(TestUtil.alwaysKnnVectorsFormat(getKnnFormat(7))))) {
115121
for (int j = 0; j < numSegments; j++) {
116122
for (int i = 0; i < numVectors; i++) {
117123
Document doc = new Document();
@@ -139,12 +145,14 @@ public void testFullPrecisionVectorSimilarityDVS() throws Exception {
139145
}
140146

141147
float[] queryVector = TestVectorUtil.randomVector(VECTOR_DIMENSION);
142-
FloatVectorSimilarityValuesSource fpSimValueSource = new FloatVectorSimilarityValuesSource(queryVector, KNN_FIELD, true);
143-
FloatVectorSimilarityValuesSource quantizedSimValueSource = new FloatVectorSimilarityValuesSource(queryVector, KNN_FIELD);
148+
FloatVectorSimilarityValuesSource fpSimValueSource =
149+
new FloatVectorSimilarityValuesSource(queryVector, KNN_FIELD, true);
150+
FloatVectorSimilarityValuesSource quantizedSimValueSource =
151+
new FloatVectorSimilarityValuesSource(queryVector, KNN_FIELD);
144152

145153
try (IndexReader reader = DirectoryReader.open(dir)) {
146154
FieldExistsQuery query = new FieldExistsQuery(KNN_FIELD);
147-
for (LeafReaderContext ctx: reader.leaves()) {
155+
for (LeafReaderContext ctx : reader.leaves()) {
148156
DoubleValues fpSimValues = fpSimValueSource.getValues(ctx, null);
149157
DoubleValues quantizedSimValues = quantizedSimValueSource.getValues(ctx, null);
150158
// validate when segment has no vectors
@@ -154,7 +162,8 @@ public void testFullPrecisionVectorSimilarityDVS() throws Exception {
154162
continue;
155163
}
156164
StoredFields storedFields = ctx.reader().storedFields();
157-
VectorScorer quantizedScorer = ctx.reader().getFloatVectorValues(KNN_FIELD).scorer(queryVector);
165+
VectorScorer quantizedScorer =
166+
ctx.reader().getFloatVectorValues(KNN_FIELD).scorer(queryVector);
158167
DocIdSetIterator disi = quantizedScorer.iterator();
159168
while (disi.nextDoc() != DocIdSetIterator.NO_MORE_DOCS) {
160169
int doc = disi.docID();

0 commit comments

Comments
 (0)