Skip to content

Commit f1e2972

Browse files
committed
Remove request size as it is already provided from the query using k
1 parent 17979d5 commit f1e2972

File tree

4 files changed

+15
-57
lines changed

4 files changed

+15
-57
lines changed

server/src/main/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapper.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,6 @@ public Query createKnnQuery(
20212021
VectorData queryVector,
20222022
int k,
20232023
int numCands,
2024-
int requestSize,
20252024
Float numCandsFactor,
20262025
Query filter,
20272026
Float similarityThreshold,
@@ -2038,7 +2037,6 @@ public Query createKnnQuery(
20382037
queryVector.asFloatVector(),
20392038
k,
20402039
numCands,
2041-
requestSize,
20422040
numCandsFactor,
20432041
filter,
20442042
similarityThreshold,
@@ -2105,7 +2103,6 @@ private Query createKnnFloatQuery(
21052103
float[] queryVector,
21062104
int k,
21072105
int numCands,
2108-
int requestSize,
21092106
Float numCandsFactor,
21102107
Query filter,
21112108
Float similarityThreshold,
@@ -2143,7 +2140,7 @@ && isNotUnitVector(squaredMagnitude)) {
21432140
name(),
21442141
queryVector,
21452142
similarity.vectorSimilarityFunction(indexVersionCreated, ElementType.FLOAT),
2146-
k == null ? requestSize : k,
2143+
k,
21472144
knnQuery
21482145
);
21492146
}

server/src/main/java/org/elasticsearch/search/vectors/KnnVectorQueryBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,6 @@ protected Query doToQuery(SearchExecutionContext context) throws IOException {
560560
queryVector,
561561
k,
562562
adjustedNumCands,
563-
requestSize,
564563
numCandidatesFactor,
565564
filterQuery,
566565
vectorSimilarity,

server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapperTests.java

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,7 +1674,7 @@ public void testByteVectorQueryBoundaries() throws IOException {
16741674

16751675
Exception e = expectThrows(
16761676
IllegalArgumentException.class,
1677-
() -> denseVectorFieldType.createKnnQuery(VectorData.fromFloats(new float[] { 128, 0, 0 }), 3, 3, 3, null, null, null, null)
1677+
() -> denseVectorFieldType.createKnnQuery(VectorData.fromFloats(new float[] { 128, 0, 0 }), 3, 3, null, null, null, null)
16781678
);
16791679
assertThat(
16801680
e.getMessage(),
@@ -1687,7 +1687,6 @@ public void testByteVectorQueryBoundaries() throws IOException {
16871687
VectorData.fromFloats(new float[] { 0.0f, 0f, -129.0f }),
16881688
3,
16891689
3,
1690-
3,
16911690
null,
16921691
null,
16931692
null,
@@ -1701,16 +1700,7 @@ public void testByteVectorQueryBoundaries() throws IOException {
17011700

17021701
e = expectThrows(
17031702
IllegalArgumentException.class,
1704-
() -> denseVectorFieldType.createKnnQuery(
1705-
VectorData.fromFloats(new float[] { 0.0f, 0.5f, 0.0f }),
1706-
3,
1707-
3,
1708-
3,
1709-
null,
1710-
null,
1711-
null,
1712-
null
1713-
)
1703+
() -> denseVectorFieldType.createKnnQuery(VectorData.fromFloats(new float[] { 0.0f, 0.5f, 0.0f }), 3, 3, null, null, null, null)
17141704
);
17151705
assertThat(
17161706
e.getMessage(),
@@ -1719,16 +1709,7 @@ public void testByteVectorQueryBoundaries() throws IOException {
17191709

17201710
e = expectThrows(
17211711
IllegalArgumentException.class,
1722-
() -> denseVectorFieldType.createKnnQuery(
1723-
VectorData.fromFloats(new float[] { 0, 0.0f, -0.25f }),
1724-
3,
1725-
3,
1726-
3,
1727-
null,
1728-
null,
1729-
null,
1730-
null
1731-
)
1712+
() -> denseVectorFieldType.createKnnQuery(VectorData.fromFloats(new float[] { 0, 0.0f, -0.25f }), 3, 3, null, null, null, null)
17321713
);
17331714
assertThat(
17341715
e.getMessage(),
@@ -1741,7 +1722,6 @@ public void testByteVectorQueryBoundaries() throws IOException {
17411722
VectorData.fromFloats(new float[] { Float.NaN, 0f, 0.0f }),
17421723
3,
17431724
3,
1744-
3,
17451725
null,
17461726
null,
17471727
null,
@@ -1756,7 +1736,6 @@ public void testByteVectorQueryBoundaries() throws IOException {
17561736
VectorData.fromFloats(new float[] { Float.POSITIVE_INFINITY, 0f, 0.0f }),
17571737
3,
17581738
3,
1759-
3,
17601739
null,
17611740
null,
17621741
null,
@@ -1774,7 +1753,6 @@ public void testByteVectorQueryBoundaries() throws IOException {
17741753
VectorData.fromFloats(new float[] { 0, Float.NEGATIVE_INFINITY, 0.0f }),
17751754
3,
17761755
3,
1777-
3,
17781756
null,
17791757
null,
17801758
null,
@@ -1809,7 +1787,6 @@ public void testFloatVectorQueryBoundaries() throws IOException {
18091787
VectorData.fromFloats(new float[] { Float.NaN, 0f, 0.0f }),
18101788
3,
18111789
3,
1812-
3,
18131790
null,
18141791
null,
18151792
null,
@@ -1824,7 +1801,6 @@ public void testFloatVectorQueryBoundaries() throws IOException {
18241801
VectorData.fromFloats(new float[] { Float.POSITIVE_INFINITY, 0f, 0.0f }),
18251802
3,
18261803
3,
1827-
3,
18281804
null,
18291805
null,
18301806
null,
@@ -1842,7 +1818,6 @@ public void testFloatVectorQueryBoundaries() throws IOException {
18421818
VectorData.fromFloats(new float[] { 0, Float.NEGATIVE_INFINITY, 0.0f }),
18431819
3,
18441820
3,
1845-
3,
18461821
null,
18471822
null,
18481823
null,

server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldTypeTests.java

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void testCreateNestedKnnQuery() {
193193
for (int i = 0; i < dims; i++) {
194194
queryVector[i] = randomFloat();
195195
}
196-
Query query = field.createKnnQuery(VectorData.fromFloats(queryVector), 10, 10, 10, null, null, null, producer);
196+
Query query = field.createKnnQuery(VectorData.fromFloats(queryVector), 10, 10, null, null, null, producer);
197197
assertThat(query, instanceOf(DiversifyingChildrenFloatKnnVectorQuery.class));
198198
}
199199
{
@@ -214,11 +214,11 @@ public void testCreateNestedKnnQuery() {
214214
floatQueryVector[i] = queryVector[i];
215215
}
216216
VectorData vectorData = new VectorData(null, queryVector);
217-
Query query = field.createKnnQuery(vectorData, 10, 10, 10, null, null, null, producer);
217+
Query query = field.createKnnQuery(vectorData, 10, 10, null, null, null, producer);
218218
assertThat(query, instanceOf(DiversifyingChildrenByteKnnVectorQuery.class));
219219

220220
vectorData = new VectorData(floatQueryVector, null);
221-
query = field.createKnnQuery(vectorData, 10, 10, 10, null, null, null, producer);
221+
query = field.createKnnQuery(vectorData, 10, 10, null, null, null, producer);
222222
assertThat(query, instanceOf(DiversifyingChildrenByteKnnVectorQuery.class));
223223
}
224224
}
@@ -283,7 +283,6 @@ public void testFloatCreateKnnQuery() {
283283
VectorData.fromFloats(new float[] { 0.3f, 0.1f, 1.0f, 0.0f }),
284284
10,
285285
10,
286-
10,
287286
null,
288287
null,
289288
null,
@@ -308,7 +307,7 @@ public void testFloatCreateKnnQuery() {
308307
}
309308
e = expectThrows(
310309
IllegalArgumentException.class,
311-
() -> dotProductField.createKnnQuery(VectorData.fromFloats(queryVector), 10, 10, 10, null, null, null, null)
310+
() -> dotProductField.createKnnQuery(VectorData.fromFloats(queryVector), 10, 10, null, null, null, null)
312311
);
313312
assertThat(e.getMessage(), containsString("The [dot_product] similarity can only be used with unit-length vectors."));
314313

@@ -324,7 +323,7 @@ public void testFloatCreateKnnQuery() {
324323
);
325324
e = expectThrows(
326325
IllegalArgumentException.class,
327-
() -> cosineField.createKnnQuery(VectorData.fromFloats(new float[BBQ_MIN_DIMS]), 10, 10, 10, null, null, null, null)
326+
() -> cosineField.createKnnQuery(VectorData.fromFloats(new float[BBQ_MIN_DIMS]), 10, 10, null, null, null, null)
328327
);
329328
assertThat(e.getMessage(), containsString("The [cosine] similarity does not support vectors with zero magnitude."));
330329
}
@@ -345,7 +344,7 @@ public void testCreateKnnQueryMaxDims() {
345344
for (int i = 0; i < 4096; i++) {
346345
queryVector[i] = randomFloat();
347346
}
348-
Query query = fieldWith4096dims.createKnnQuery(VectorData.fromFloats(queryVector), 10, 10, 10, null, null, null, null);
347+
Query query = fieldWith4096dims.createKnnQuery(VectorData.fromFloats(queryVector), 10, 10, null, null, null, null);
349348
assertThat(query, instanceOf(KnnFloatVectorQuery.class));
350349
}
351350

@@ -365,7 +364,7 @@ public void testCreateKnnQueryMaxDims() {
365364
queryVector[i] = randomByte();
366365
}
367366
VectorData vectorData = new VectorData(null, queryVector);
368-
Query query = fieldWith4096dims.createKnnQuery(vectorData, 10, 10, 10, null, null, null, null);
367+
Query query = fieldWith4096dims.createKnnQuery(vectorData, 10, 10, null, null, null, null);
369368
assertThat(query, instanceOf(KnnByteVectorQuery.class));
370369
}
371370
}
@@ -383,7 +382,7 @@ public void testByteCreateKnnQuery() {
383382
);
384383
IllegalArgumentException e = expectThrows(
385384
IllegalArgumentException.class,
386-
() -> unindexedField.createKnnQuery(VectorData.fromFloats(new float[] { 0.3f, 0.1f, 1.0f }), 10, 10, 10, null, null, null, null)
385+
() -> unindexedField.createKnnQuery(VectorData.fromFloats(new float[] { 0.3f, 0.1f, 1.0f }), 10, 10, null, null, null, null)
387386
);
388387
assertThat(e.getMessage(), containsString("to perform knn search on field [f], its mapping must have [index] set to [true]"));
389388

@@ -399,13 +398,13 @@ public void testByteCreateKnnQuery() {
399398
);
400399
e = expectThrows(
401400
IllegalArgumentException.class,
402-
() -> cosineField.createKnnQuery(VectorData.fromFloats(new float[] { 0.0f, 0.0f, 0.0f }), 10, 10, 10, null, null, null, null)
401+
() -> cosineField.createKnnQuery(VectorData.fromFloats(new float[] { 0.0f, 0.0f, 0.0f }), 10, 10, null, null, null, null)
403402
);
404403
assertThat(e.getMessage(), containsString("The [cosine] similarity does not support vectors with zero magnitude."));
405404

406405
e = expectThrows(
407406
IllegalArgumentException.class,
408-
() -> cosineField.createKnnQuery(new VectorData(null, new byte[] { 0, 0, 0 }), 10, 10, 10, null, null, null, null)
407+
() -> cosineField.createKnnQuery(new VectorData(null, new byte[] { 0, 0, 0 }), 10, 10, null, null, null, null)
409408
);
410409
assertThat(e.getMessage(), containsString("The [cosine] similarity does not support vectors with zero magnitude."));
411410
}
@@ -427,7 +426,6 @@ public void testRescoreOversampleUsedWithoutQuantization() {
427426
new VectorData(null, new byte[] { 1, 4, 10 }),
428427
10,
429428
100,
430-
10,
431429
randomFloatBetween(1.0F, 10.0F, false),
432430
null,
433431
null,
@@ -464,21 +462,11 @@ public void testRescoreOversampleModifiesNumCandidates() {
464462
// Oversampling limits for num candidates
465463
checkRescoreQueryParameters(fieldType, 1000, 1000, randomInt(), 11.0F, null, 10000, 1000);
466464
checkRescoreQueryParameters(fieldType, 5000, 7500, randomInt(), 2.5F, null, 10000, 5000);
467-
468-
// Check the same as the above, for null k - take request size
469-
// Total results is k, internal k is multiplied by oversample
470-
checkRescoreQueryParameters(fieldType, null, 200, 25, 2.5F, null, 500, 25);
471-
// If numCands < k, update numCands to k
472-
checkRescoreQueryParameters(fieldType, null, 20, 25, 2.5F, null, 50, 25);
473-
// Oversampling limits for num candidates
474-
checkRescoreQueryParameters(fieldType, null, 1000, 25, 11.0F, null, 10000, 25);
475-
checkRescoreQueryParameters(fieldType, null, 7500, 25, 2.5F, null, 10000, 25);
476-
477465
}
478466

479467
private static void checkRescoreQueryParameters(
480468
DenseVectorFieldType fieldType,
481-
Integer k,
469+
int k,
482470
int candidates,
483471
int requestSize,
484472
float numCandsFactor,
@@ -490,7 +478,6 @@ private static void checkRescoreQueryParameters(
490478
VectorData.fromFloats(new float[] { 1, 4, 10 }),
491479
k,
492480
candidates,
493-
requestSize,
494481
numCandsFactor,
495482
null,
496483
null,

0 commit comments

Comments
 (0)