11package org .apache .lucene .search ;
22
3+ import java .util .ArrayList ;
4+ import java .util .List ;
35import org .apache .lucene .codecs .Codec ;
46import org .apache .lucene .codecs .KnnVectorsFormat ;
57import org .apache .lucene .codecs .lucene99 .Lucene99HnswScalarQuantizedVectorsFormat ;
2123import org .junit .Before ;
2224import org .junit .Test ;
2325
24- import java .util .ArrayList ;
25- import java .util .List ;
26-
2726public 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