Skip to content

Commit 719ee96

Browse files
committed
Don't build neighborhoods when clustersPerNeighborhood == 0
1 parent ec846f7 commit 719ee96

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

muted-tests.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,6 @@ tests:
557557
- class: org.elasticsearch.compute.aggregation.TopIntAggregatorFunctionTests
558558
method: testManyInitialManyPartialFinalRunnerThrowing
559559
issue: https://github.com/elastic/elasticsearch/issues/130145
560-
- class: org.elasticsearch.index.codec.vectors.cluster.KMeansLocalTests
561-
method: testKMeansNeighbors
562-
issue: https://github.com/elastic/elasticsearch/issues/130258
563560
- class: org.elasticsearch.xpack.test.rest.XPackRestIT
564561
method: test {p0=esql/10_basic/basic with documents_found}
565562
issue: https://github.com/elastic/elasticsearch/issues/130256
@@ -587,9 +584,6 @@ tests:
587584
- class: org.elasticsearch.test.rest.yaml.RcsCcsCommonYamlTestSuiteIT
588585
method: test {p0=msearch/20_typed_keys/Multisearch test with typed_keys parameter for sampler and significant terms}
589586
issue: https://github.com/elastic/elasticsearch/issues/130472
590-
- class: org.elasticsearch.index.codec.vectors.cluster.HierarchicalKMeansTests
591-
method: testHKmeans
592-
issue: https://github.com/elastic/elasticsearch/issues/130497
593587
- class: org.elasticsearch.xpack.esql.action.EsqlActionBreakerIT
594588
method: testProjectWhere
595589
issue: https://github.com/elastic/elasticsearch/issues/130504

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,10 @@ void cluster(FloatVectorValues vectors, KMeansIntermediate kMeansIntermediate) t
265265
*/
266266
void cluster(FloatVectorValues vectors, KMeansIntermediate kMeansIntermediate, boolean neighborAware) throws IOException {
267267
float[][] centroids = kMeansIntermediate.centroids();
268+
boolean computeNeighborhoods = neighborAware && clustersPerNeighborhood > 0;
268269

269270
List<int[]> neighborhoods = null;
270-
if (neighborAware) {
271+
if (computeNeighborhoods) {
271272
int k = centroids.length;
272273
neighborhoods = new ArrayList<>(k);
273274
for (int i = 0; i < k; ++i) {
@@ -276,7 +277,7 @@ void cluster(FloatVectorValues vectors, KMeansIntermediate kMeansIntermediate, b
276277
computeNeighborhoods(centroids, neighborhoods, clustersPerNeighborhood);
277278
}
278279
cluster(vectors, kMeansIntermediate, neighborhoods);
279-
if (neighborAware && clustersPerNeighborhood > 0) {
280+
if (computeNeighborhoods) {
280281
int[] assignments = kMeansIntermediate.assignments();
281282
assert assignments != null;
282283
assert assignments.length == vectors.size();

0 commit comments

Comments
 (0)