Skip to content

Commit

Permalink
Fixing centroid merge
Browse files Browse the repository at this point in the history
  • Loading branch information
benwtrent committed Sep 17, 2024
1 parent 48a8bd0 commit 3acf852
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ public void mergeOneField(FieldInfo fieldInfo, MergeState mergeState) throws IOE
final float[][] centroids;
final float[] mergedCentroid = new float[fieldInfo.getVectorDimension()];
int vectorCount = mergeAndRecalculateCentroids(mergeState, fieldInfo, mergedCentroid);
if (fieldInfo.getVectorSimilarityFunction() == COSINE) {
VectorUtil.l2normalize(mergedCentroid);
}
// If we have more vectors than allowed for a single cluster, we will use KMeans to cluster
// we do an early check here to avoid the overhead of `mergeOneFieldToIndex` which might
// not be as efficient as mergeOneField
Expand Down Expand Up @@ -884,7 +887,7 @@ static int mergeAndRecalculateCentroids(
return calculateCentroid(mergeState, fieldInfo, mergedCentroid);
} else {
for (int j = 0; j < mergedCentroid.length; j++) {
mergedCentroid[j] += mergedCentroid[j] / totalVectorCount;
mergedCentroid[j] = mergedCentroid[j] / totalVectorCount;
}
if (fieldInfo.getVectorSimilarityFunction() == COSINE) {
VectorUtil.l2normalize(mergedCentroid);
Expand Down

0 comments on commit 3acf852

Please sign in to comment.