2424import org .apache .lucene .index .FloatVectorValues ;
2525import org .apache .lucene .index .KnnVectorValues ;
2626import org .apache .lucene .index .LeafReaderContext ;
27+ import org .apache .lucene .index .VectorEncoding ;
2728import org .apache .lucene .index .VectorSimilarityFunction ;
2829
2930/**
3233 */
3334class FloatVectorSimilarityValuesSource extends VectorSimilarityValuesSource {
3435
36+ public static DoubleValues fullPrecisionScores (
37+ LeafReaderContext ctx , float [] queryVector , String vectorField ) throws IOException {
38+ return new FloatVectorSimilarityValuesSource (queryVector , vectorField , true ).getValues (ctx , null );
39+ }
40+
3541 private final float [] queryVector ;
3642 private final boolean useFullPrecision ;
3743
@@ -69,8 +75,15 @@ public VectorScorer getScorer(LeafReaderContext ctx) throws IOException {
6975 FloatVectorValues .checkField (ctx .reader (), fieldName );
7076 return null ;
7177 }
78+
7279 final FieldInfo fi = ctx .reader ().getFieldInfos ().fieldInfo (fieldName );
73- final VectorSimilarityFunction vectorSimilarityFunction = fi .getVectorSimilarityFunction ();
80+ if (fi .getVectorEncoding () != VectorEncoding .FLOAT32 ) {
81+ throw new IllegalArgumentException (
82+ "Field "
83+ + fieldName
84+ + " does not have the expected vector encoding: "
85+ + VectorEncoding .FLOAT32 );
86+ }
7487 if (fi .getVectorDimension () != queryVector .length ) {
7588 throw new IllegalArgumentException (
7689 "Query vector dimension does not match field dimension: "
@@ -79,12 +92,12 @@ public VectorScorer getScorer(LeafReaderContext ctx) throws IOException {
7992 + fi .getVectorDimension ());
8093 }
8194
95+ // default vector scorer
8296 if (useFullPrecision == false ) {
83- // use default VectorScorer for configured reader
8497 return vectorValues .scorer (queryVector );
8598 }
8699
87- // return a full precision vector scorer
100+ final VectorSimilarityFunction vectorSimilarityFunction = fi . getVectorSimilarityFunction ();
88101 return new VectorScorer () {
89102 final KnnVectorValues .DocIndexIterator iterator = vectorValues .iterator ();
90103
0 commit comments