-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Adds new formats that use the new scalar formats from lucene #141601
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
Adds new formats that use the new scalar formats from lucene #141601
Conversation
|
Pinging @elastic/es-search-relevance (Team:Search Relevance) |
|
Here is the difference in recall/etc. this PR (1, 2, 4, 7) bits, all using the new format baseline: (1, 4, 7) Obviously, 2, 4 are way better. Single bit might be a little slower. But int7 is significantly slower due to lack of native code support. Recall is better across the board. |
.../simdvec/src/main21/java/org/elasticsearch/simdvec/internal/Int7OSQVectorScorerSupplier.java
Outdated
Show resolved
Hide resolved
.../simdvec/src/main21/java/org/elasticsearch/simdvec/internal/Int7OSQVectorScorerSupplier.java
Outdated
Show resolved
Hide resolved
...simdvec/src/main21/java/org/elasticsearch/simdvec/internal/Int7uOSQVectorScorerSupplier.java
Show resolved
Hide resolved
.../simdvec/src/main21/java/org/elasticsearch/simdvec/internal/Int7OSQVectorScorerSupplier.java
Outdated
Show resolved
Hide resolved
.../simdvec/src/main21/java/org/elasticsearch/simdvec/internal/Int7OSQVectorScorerSupplier.java
Outdated
Show resolved
Hide resolved
libs/simdvec/src/main22/java/org/elasticsearch/simdvec/internal/Int7OSQVectorScorer.java
Outdated
Show resolved
Hide resolved
libs/simdvec/src/main22/java/org/elasticsearch/simdvec/internal/Int7OSQVectorScorer.java
Outdated
Show resolved
Hide resolved
|
We need some tests on the scorer, that the native and lucene implementations produce the same result - see |
|
@thecoop I am gonna close this and rebase & reopen against the new lucene_10_4 branch |
adding tests [CI] Auto commit changes from spotless adding exposure via module iter fixing things [CI] Auto commit changes from spotless iter iter iter [CI] Auto commit changes from spotless Adding random vector scorer code iter iter fixing scorer supplier iter adding more tests
53d421b to
0d5b790
Compare
|
@thecoop sorry for the force push, but rebased on 10_4 and now merging there. |
| } | ||
|
|
||
| @Override | ||
| float applyCorrections(float rawScore, int ord) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the new name, way better than some variant of score.
Can we have a follow up PR that renames all the others (e.g. in BBQ/DiskBBQ)?
I'm also leaning towards using the same names on native functions. Wdyt? CC @thecoop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also like how you separated corrections into the different distance scorers, like we did in native code.
ldematte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just gave a quick look over; looks good, just a couple of minor comments/questions
| public RandomVectorScorerSupplier getRandomVectorScorerSupplier(VectorSimilarityFunction sim, KnnVectorValues values) | ||
| throws IOException { | ||
| if (values instanceof QuantizedByteVectorValues quantizedValues && quantizedValues.getSlice() != null) { | ||
| // TODO: optimize int4, 2, and single bit quantization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting confused with all the formats :)
Maybe we can sync a bit on these?
Are these "striped" (like BBQ/DiskBBQ) or packed? (e.g. 2 Int4 in a byte?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are scalar quantized, so packed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 bits is striped, int4 are packed.
I am not convinced that "striped" is the best option for int4 * int4 operations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lucene just packs with int4 & int4. Stripes int4 * int1 and double stripes int4 * int2 :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not convinced that "striped" is the best option for int4 * int4 operations.
++
I have (SIMD) implementations for both, I just need some time to test and benchmark them.
My gut feeling is that for int4 packed/normal mul (or madd) is going to be faster.
Give me some time and I'll come back with numbers :)
libs/simdvec/src/main21/java/org/elasticsearch/simdvec/internal/Int7OSQVectorScorer.java
Outdated
Show resolved
Hide resolved
.../simdvec/src/main21/java/org/elasticsearch/simdvec/internal/Int7OSQVectorScorerSupplier.java
Outdated
Show resolved
Hide resolved
.../simdvec/src/main21/java/org/elasticsearch/simdvec/internal/Int7OSQVectorScorerSupplier.java
Outdated
Show resolved
Hide resolved
libs/simdvec/src/main22/java/org/elasticsearch/simdvec/internal/Int7OSQVectorScorer.java
Outdated
Show resolved
Hide resolved
libs/simdvec/src/test/java/org/elasticsearch/simdvec/AbstractVectorTestCase.java
Outdated
Show resolved
Hide resolved
...t/java/org/elasticsearch/index/codec/vectors/es94/ES94ScalarQuantizedVectorsFormatTests.java
Show resolved
Hide resolved
tteofili
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. but I think we need a few more benchmarks
632a640
into
elastic:lucene_snapshot_10_4
| float y1 = quantizedComponentSum; | ||
| float score = ax * ay * values.dimension() + ay * lx * x1 + ax * ly * y1 + lx * ly * rawScore; | ||
| score += additionalCorrection + correctiveTerms.additionalCorrection() - values.getCentroidDP(); | ||
| score = Math.clamp(score, -1, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we can reuse the native code implementations here? Or we can expose a new one, but share the same "kernel"? Besides this clamp, I do not see other differences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We likely could reuse native here.
Adds new ES formats that build on the Lucene formats.
This adds scorers & scorer suppliers.