[DiskBBQ] Add concurrency to KMeansLocal#139239
Merged
iverase merged 17 commits intoelastic:mainfrom Dec 11, 2025
Merged
Conversation
Collaborator
|
Pinging @elastic/es-search-relevance (Team:Search Relevance) |
Collaborator
|
Hi @iverase, I've created a changelog YAML for you. |
benwtrent
reviewed
Dec 9, 2025
Member
benwtrent
left a comment
There was a problem hiding this comment.
I also think we can build neighborhoods concurrently. Maybe that isn't that big of a cost right now and we want to only optimize one thing at a time.
server/src/main/java/org/elasticsearch/index/codec/vectors/cluster/HierarchicalKMeans.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/codec/vectors/cluster/HierarchicalKMeans.java
Outdated
Show resolved
Hide resolved
Contributor
Author
I planned to do it in a follow up as it needs a bit of analysis to make sure we make the right decision between brute force and building a graph. |
davidkyle
reviewed
Dec 10, 2025
Member
davidkyle
left a comment
There was a problem hiding this comment.
Nice change, much less complicated than I was expecting
server/src/main/java/org/elasticsearch/index/codec/vectors/cluster/KMeansLocal.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/codec/vectors/cluster/KMeansLocalConcurrent.java
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/index/codec/vectors/cluster/KMeansLocal.java
Show resolved
Hide resolved
...main/java/org/elasticsearch/index/codec/vectors/diskbbq/next/ESNextDiskBBQVectorsWriter.java
Outdated
Show resolved
Hide resolved
benwtrent
approved these changes
Dec 10, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The most expensive methods when running the k-means algorithm are the methods that assign the closest centroid and the soar assignment to each of the vectors. Still those methods can be easily slice and execute using more than one thread.
Therefore this PR refactors the
KmeansLocalclass as an abstract class and implements aKmeansLocalSerialimplementation that just runs on the current thread and aKmeansLocalConcurrentimplementation that uses concurrency for the assignments.It does provide a great speed up for large merges while using almost the same resources. We only need to allocate a extract FixedBitSet per thread with size being the number of centroids.