Pulkitg64 commented on code in PR #16473:
URL: https://github.com/apache/lucene/pull/16473#discussion_r3814428562


##########
lucene/core/src/java/org/apache/lucene/codecs/lucene104/Lucene104ScalarQuantizedVectorsWriter.java:
##########
@@ -428,21 +420,40 @@ static float[] getCentroid(KnnVectorsReader 
vectorsReader, String fieldName) {
     return null;
   }
 
+  /**
+   * Returns the reader's floating-point vectors viewed as fp32, inflating 
fp16 on read, or null
+   * when the field is absent from this reader or is byte-encoded.
+   */
+  private static FloatVectorValues floatingPointVectorValues(
+      KnnVectorsReader reader, FieldInfo fieldInfo) throws IOException {
+    return switch (fieldInfo.getVectorEncoding()) {
+      case FLOAT32 -> reader.getFloatVectorValues(fieldInfo.name);
+      case FLOAT16 -> {
+        Float16VectorValues f16 = 
reader.getFloat16VectorValues(fieldInfo.name);
+        yield f16 == null ? null : new Float16AsFloatVectorValues(f16);
+      }
+      case BYTE -> null;
+    };
+  }
+
   static int mergeAndRecalculateCentroids(
       MergeState mergeState, FieldInfo fieldInfo, float[] mergedCentroid) 
throws IOException {
     boolean recalculate = false;
     int totalVectorCount = 0;
     for (int i = 0; i < mergeState.knnVectorsReaders.length; i++) {
       KnnVectorsReader knnVectorsReader = mergeState.knnVectorsReaders[i];
-      if (knnVectorsReader == null
-          || knnVectorsReader.getFloatVectorValues(fieldInfo.name) == null) {
+      if (knnVectorsReader == null) {
         continue;
       }
-      float[] centroid = getCentroid(knnVectorsReader, fieldInfo.name);
-      int vectorCount = 
knnVectorsReader.getFloatVectorValues(fieldInfo.name).size();
+      KnnVectorValues values = floatingPointVectorValues(knnVectorsReader, 
fieldInfo);
+      if (values == null) {
+        continue;
+      }
+      int vectorCount = values.size();
       if (vectorCount == 0) {
         continue;
       }
+      float[] centroid = getCentroid(knnVectorsReader, fieldInfo.name);

Review Comment:
   Sure Mike!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to