Skip to content

Commit 2c96c82

Browse files
committed
added trimtosize and fixed a spot where we should be returning KMeansResult
1 parent cf7c6b3 commit 2c96c82

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/DefaultIVFVectorsWriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ CentroidAssignments calculateAndWriteCentroids(
291291
}
292292
}
293293

294+
cluster.trimToSize();
294295
assignmentsByCluster[c] = cluster;
295296
}
296297

server/src/main/java/org/elasticsearch/index/codec/vectors/cluster/HierarchicalKMeans.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public HierarchicalKMeans(int dimension) {
5151
* @return the centroids and the vectors assignments and SOAR (spilled from nearby neighborhoods) assignments
5252
* @throws IOException is thrown if vectors is inaccessible
5353
*/
54-
public KMeansIntermediate cluster(FloatVectorValues vectors, int targetSize) throws IOException {
54+
public KMeansResult cluster(FloatVectorValues vectors, int targetSize) throws IOException {
5555

5656
if (vectors.size() == 0) {
5757
return new KMeansIntermediate();

server/src/test/java/org/elasticsearch/index/codec/vectors/cluster/HierarchicalKMeansTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void testHKmeans() throws IOException {
3030
int targetSize = (int) ((float) nVectors / (float) nClusters);
3131
HierarchicalKMeans hkmeans = new HierarchicalKMeans(dims, maxIterations, sampleSize, clustersPerNeighborhood, soarLambda);
3232

33-
KMeansIntermediate result = hkmeans.cluster(vectors, targetSize);
33+
KMeansResult result = hkmeans.cluster(vectors, targetSize);
3434

3535
float[][] centroids = result.centroids();
3636
int[] assignments = result.assignments();

0 commit comments

Comments
 (0)