Skip to content

Introduce a vectorized soarDistance function #129744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2025
Merged

Conversation

iverase
Copy link
Contributor

@iverase iverase commented Jun 20, 2025

We are computing soar distance in a two step process. First we compute the distance between the vector and the centroid using a vectorized function. Then we compute the residual using another vectorized function. Finally we compute the soar distance.

Looking at the distance and residual functions, they are actually executing very similar operations, therefore combining them in the same function should lead to a nice speed up. This commit replaces the method #soarResidual with a method call #soarDistance. Microbenchmarks shows a nice speed up in this operation:

Mac:


Ignacio Vera Sequeiros
  8:27 AM
Benchmark                              (dims)   Mode  Cnt   Score   Error   Units
SoarDistanceBenchmark.soarDistanceNew      96  thrpt    5  58.639 ± 0.401  ops/ms
SoarDistanceBenchmark.soarDistanceNew     768  thrpt    5   9.806 ± 0.338  ops/ms
SoarDistanceBenchmark.soarDistanceNew    1024  thrpt    5   7.414 ± 0.273  ops/ms
SoarDistanceBenchmark.soarDistanceOld      96  thrpt    5  38.164 ± 1.216  ops/ms
SoarDistanceBenchmark.soarDistanceOld     768  thrpt    5   6.223 ± 0.113  ops/ms
SoarDistanceBenchmark.soarDistanceOld    1024  thrpt    5   4.790 ± 0.135  ops/ms

GCP:

Benchmark                              (dims)   Mode  Cnt   Score   Error   Units
SoarDistanceBenchmark.soarDistanceNew      96  thrpt    5  93.833 ± 0.975  ops/ms
SoarDistanceBenchmark.soarDistanceNew     768  thrpt    5  10.478 ± 3.752  ops/ms
SoarDistanceBenchmark.soarDistanceNew    1024  thrpt    5   8.644 ± 0.136  ops/ms
SoarDistanceBenchmark.soarDistanceOld      96  thrpt    5  52.466 ± 2.436  ops/ms
SoarDistanceBenchmark.soarDistanceOld     768  thrpt    5   8.336 ± 0.117  ops/ms
SoarDistanceBenchmark.soarDistanceOld    1024  thrpt    5   5.290 ± 0.071  ops/ms

@iverase iverase added >non-issue :Search Relevance/Search Catch all for Search Relevance v9.1.0 labels Jun 20, 2025
@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Jun 20, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-relevance (Team:Search Relevance)

Copy link
Contributor

@john-wagster john-wagster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! lgtm

@iverase iverase merged commit 4ca96c1 into elastic:main Jun 20, 2025
27 checks passed
@iverase iverase deleted the soarDistance branch June 20, 2025 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>non-issue :Search Relevance/Search Catch all for Search Relevance Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants