1414import java .util .List ;
1515import java .util .Map ;
1616
17- import static org .elasticsearch .xpack .vectors .mapper .VectorEncoderDecoder .sortSparseDimsDoubleValues ;
17+ import static org .elasticsearch .xpack .vectors .mapper .VectorEncoderDecoder .sortSparseDimsFloatValues ;
1818
1919public class ScoreScriptUtils {
2020
@@ -37,7 +37,7 @@ public static double l1norm(List<Number> queryVector, VectorScriptDocValues.Dens
3737 Iterator <Number > queryVectorIter = queryVector .iterator ();
3838 double l1norm = 0 ;
3939 for (int dim = 0 ; dim < docVector .length ; dim ++){
40- l1norm += Math .abs (queryVectorIter .next ().doubleValue () - docVector [dim ]);
40+ l1norm += Math .abs (queryVectorIter .next ().floatValue () - docVector [dim ]);
4141 }
4242 return l1norm ;
4343 }
@@ -59,7 +59,7 @@ public static double l2norm(List<Number> queryVector, VectorScriptDocValues.Dens
5959 Iterator <Number > queryVectorIter = queryVector .iterator ();
6060 double l2norm = 0 ;
6161 for (int dim = 0 ; dim < docVector .length ; dim ++){
62- double diff = queryVectorIter .next ().doubleValue () - docVector [dim ];
62+ double diff = queryVectorIter .next ().floatValue () - docVector [dim ];
6363 l2norm += diff * diff ;
6464 }
6565 return Math .sqrt (l2norm );
@@ -97,11 +97,11 @@ public static final class CosineSimilarity {
9797 // calculate queryVectorMagnitude once per query execution
9898 public CosineSimilarity (List <Number > queryVector ) {
9999 this .queryVector = queryVector ;
100- double doubleValue ;
100+
101101 double dotProduct = 0 ;
102102 for (Number value : queryVector ) {
103- doubleValue = value .doubleValue ();
104- dotProduct += doubleValue * doubleValue ;
103+ float floatValue = value .floatValue ();
104+ dotProduct += floatValue * floatValue ;
105105 }
106106 this .queryVectorMagnitude = Math .sqrt (dotProduct );
107107 }
@@ -130,7 +130,7 @@ private static double intDotProduct(List<Number> v1, float[] v2){
130130 double v1v2DotProduct = 0 ;
131131 Iterator <Number > v1Iter = v1 .iterator ();
132132 for (int dim = 0 ; dim < v2 .length ; dim ++) {
133- v1v2DotProduct += v1Iter .next ().doubleValue () * v2 [dim ];
133+ v1v2DotProduct += v1Iter .next ().floatValue () * v2 [dim ];
134134 }
135135 return v1v2DotProduct ;
136136 }
@@ -139,15 +139,15 @@ private static double intDotProduct(List<Number> v1, float[] v2){
139139 //**************FUNCTIONS FOR SPARSE VECTORS
140140
141141 public static class VectorSparseFunctions {
142- final double [] queryValues ;
142+ final float [] queryValues ;
143143 final int [] queryDims ;
144144
145145 // prepare queryVector once per script execution
146146 // queryVector represents a map of dimensions to values
147147 public VectorSparseFunctions (Map <String , Number > queryVector ) {
148148 //break vector into two arrays dims and values
149149 int n = queryVector .size ();
150- queryValues = new double [n ];
150+ queryValues = new float [n ];
151151 queryDims = new int [n ];
152152 int i = 0 ;
153153 for (Map .Entry <String , Number > dimValue : queryVector .entrySet ()) {
@@ -156,11 +156,11 @@ public VectorSparseFunctions(Map<String, Number> queryVector) {
156156 } catch (final NumberFormatException e ) {
157157 throw new IllegalArgumentException ("Failed to parse a query vector dimension, it must be an integer!" , e );
158158 }
159- queryValues [i ] = dimValue .getValue ().doubleValue ();
159+ queryValues [i ] = dimValue .getValue ().floatValue ();
160160 i ++;
161161 }
162162 // Sort dimensions in the ascending order and sort values in the same order as their corresponding dimensions
163- sortSparseDimsDoubleValues (queryDims , queryValues , n );
163+ sortSparseDimsFloatValues (queryDims , queryValues , n );
164164 }
165165 }
166166
@@ -317,7 +317,7 @@ public double cosineSimilaritySparse(VectorScriptDocValues.SparseVectorScriptDoc
317317 }
318318 }
319319
320- private static double intDotProductSparse (double [] v1Values , int [] v1Dims , float [] v2Values , int [] v2Dims ) {
320+ private static double intDotProductSparse (float [] v1Values , int [] v1Dims , float [] v2Values , int [] v2Dims ) {
321321 double v1v2DotProduct = 0 ;
322322 int v1Index = 0 ;
323323 int v2Index = 0 ;
0 commit comments