Skip to content

Conversation

iverase
Copy link
Contributor

@iverase iverase commented Jul 30, 2025

Introduce a bulk scorer for 7-bit quantize vectors in order to leverage the fast implementations existing in Elasticsearch. The idea os to replace the currently use Int4VectorScorer in DiskBBQ with this one as it is much faster and has higher quality. Performance benchmarks shows the performance difference.

for Int4VectorScorer:

Benchmark                                       (dims)   Mode  Cnt   Score   Error   Units
Int4ScorerBenchmark.scoreFromMemorySegment         384  thrpt    5  17.452 ± 0.755  ops/ms
Int4ScorerBenchmark.scoreFromMemorySegment         782  thrpt    5  10.588 ± 0.371  ops/ms
Int4ScorerBenchmark.scoreFromMemorySegment        1024  thrpt    5   9.963 ± 0.332  ops/ms
Int4ScorerBenchmark.scoreFromMemorySegmentBulk     384  thrpt    5  22.658 ± 0.804  ops/ms
Int4ScorerBenchmark.scoreFromMemorySegmentBulk     782  thrpt    5   9.512 ± 0.275  ops/ms
Int4ScorerBenchmark.scoreFromMemorySegmentBulk    1024  thrpt    5  11.402 ± 0.749  ops/ms

for the new Int7VectorScorer:

Benchmark                                       (dims)   Mode  Cnt   Score   Error   Units
Int7ScorerBenchmark.scoreFromMemorySegment         384  thrpt    5  25.053 ± 2.322  ops/ms
Int7ScorerBenchmark.scoreFromMemorySegment         782  thrpt    5  17.673 ± 0.739  ops/ms
Int7ScorerBenchmark.scoreFromMemorySegment        1024  thrpt    5  17.355 ± 0.713  ops/ms
Int7ScorerBenchmark.scoreFromMemorySegmentBulk     384  thrpt    5  35.215 ± 0.398  ops/ms
Int7ScorerBenchmark.scoreFromMemorySegmentBulk     782  thrpt    5  18.102 ± 0.724  ops/ms
Int7ScorerBenchmark.scoreFromMemorySegmentBulk    1024  thrpt    5  19.854 ± 0.963  ops/ms

As we see, it is almost 2 times faster. There are two caveats for this implementation:

1.- Int7Scorer requires two more bytes per vector than Int4Scorer. This is because the component sum needs to be stores as an integer instead of a short.

2.- For java 21 and preferred bit size of 128, Int7Scorer is slower than Int4Scorer. I think this is an odd combination and clearly not recommended so we shouldn't be optimizing for it.

@elasticsearchmachine elasticsearchmachine added the Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch label Jul 30, 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.

lgtm to right off

@iverase iverase merged commit ff06e46 into elastic:main Jul 31, 2025
33 checks passed
@iverase iverase deleted the Int7VectorsScorer branch July 31, 2025 10:53
smalyshev pushed a commit to smalyshev/elasticsearch that referenced this pull request Jul 31, 2025
…stic#132154)

This scorer gives a better tradeoff on scoring precision and speed and only requiring two additional bytes
per vector comparing to int4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :Search Relevance/Vectors Vector search Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants