-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Allow zero for rescore_vector.oversample to indicate by-passing oversample and rescoring #125599
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
Changes from 1 commit
b7fb14f
60846bb
6f7dfc0
9a6806f
2e15157
e73ef1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,7 +50,7 @@ public DenseVectorFieldTypeTests() { | |
| } | ||
|
|
||
| private static DenseVectorFieldMapper.RescoreVector randomRescoreVector() { | ||
| return new DenseVectorFieldMapper.RescoreVector(randomFloatBetween(1.0F, 10.0F, false)); | ||
| return new DenseVectorFieldMapper.RescoreVector(randomBoolean() ? 0 : randomFloatBetween(1.0F, 10.0F, false)); | ||
| } | ||
|
|
||
| private DenseVectorFieldMapper.IndexOptions randomIndexOptionsNonQuantized() { | ||
|
|
@@ -94,24 +94,24 @@ private DenseVectorFieldMapper.IndexOptions randomIndexOptionsAll() { | |
| } | ||
|
|
||
| private DenseVectorFieldMapper.IndexOptions randomIndexOptionsHnswQuantized() { | ||
| return randomIndexOptionsHnswQuantized(randomBoolean() ? null : randomRescoreVector()); | ||
| } | ||
|
|
||
| private DenseVectorFieldMapper.IndexOptions randomIndexOptionsHnswQuantized(DenseVectorFieldMapper.RescoreVector rescoreVector) { | ||
| return randomFrom( | ||
| new DenseVectorFieldMapper.Int8HnswIndexOptions( | ||
| randomIntBetween(1, 100), | ||
| randomIntBetween(1, 10_000), | ||
| randomFrom((Float) null, 0f, (float) randomDoubleBetween(0.9, 1.0, true)), | ||
| randomFrom((DenseVectorFieldMapper.RescoreVector) null, randomRescoreVector()) | ||
| rescoreVector | ||
| ), | ||
| new DenseVectorFieldMapper.Int4HnswIndexOptions( | ||
| randomIntBetween(1, 100), | ||
| randomIntBetween(1, 10_000), | ||
| randomFrom((Float) null, 0f, (float) randomDoubleBetween(0.9, 1.0, true)), | ||
| randomFrom((DenseVectorFieldMapper.RescoreVector) null, randomRescoreVector()) | ||
| rescoreVector | ||
| ), | ||
| new DenseVectorFieldMapper.BBQHnswIndexOptions( | ||
| randomIntBetween(1, 100), | ||
| randomIntBetween(1, 10_000), | ||
| randomFrom((DenseVectorFieldMapper.RescoreVector) null, randomRescoreVector()) | ||
| ) | ||
| new DenseVectorFieldMapper.BBQHnswIndexOptions(randomIntBetween(1, 100), randomIntBetween(1, 10_000), rescoreVector) | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -492,20 +492,34 @@ public void testRescoreOversampleModifiesNumCandidates() { | |
| checkRescoreQueryParameters(fieldType, 1000, 1000, 11.0F, OVERSAMPLE_LIMIT, OVERSAMPLE_LIMIT, 1000); | ||
| } | ||
|
|
||
| public void testRescoreOversampleZeroBypassesRescore() { | ||
| public void testRescoreOversampleQueryOverrides() { | ||
| // verify we can override to `0` | ||
| DenseVectorFieldType fieldType = new DenseVectorFieldType( | ||
| "f", | ||
| IndexVersion.current(), | ||
| FLOAT, | ||
| 3, | ||
| true, | ||
| VectorSimilarity.COSINE, | ||
| randomIndexOptionsHnswQuantized(), | ||
| randomIndexOptionsHnswQuantized(new DenseVectorFieldMapper.RescoreVector(randomFloatBetween(1.1f, 9.9f, false))), | ||
| Collections.emptyMap() | ||
| ); | ||
|
|
||
| Query query = fieldType.createKnnQuery(VectorData.fromFloats(new float[] { 1, 4, 10 }), 10, 100, 0f, null, null, null); | ||
| assertTrue(query instanceof ESKnnFloatVectorQuery); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to check that the query parameters do not include rescoring when 0 is used in the query. Also, we should probably check that we can't set 0 for previous index versions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ++ I will add a test |
||
|
|
||
| // verify we can override a `0` to a positive number | ||
| fieldType = new DenseVectorFieldType( | ||
| "f", | ||
| IndexVersion.current(), | ||
| FLOAT, | ||
| 3, | ||
| true, | ||
| VectorSimilarity.COSINE, | ||
| randomIndexOptionsHnswQuantized(new DenseVectorFieldMapper.RescoreVector(0)), | ||
| Collections.emptyMap() | ||
| ); | ||
| query = fieldType.createKnnQuery(VectorData.fromFloats(new float[] { 1, 4, 10 }), 10, 100, 2f, null, null, null); | ||
| assertTrue(query instanceof RescoreKnnVectorQuery); | ||
benwtrent marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private static void checkRescoreQueryParameters( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.