Skip to content

Commit 1bb9649

Browse files
committed
Rewrite properly recreates the original KNNQueryBuilder with null k
Signed-off-by: Andrew Klepchick <[email protected]>
1 parent 38008fb commit 1bb9649

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ All notable changes to this project are documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). See the [CONTRIBUTING guide](./CONTRIBUTING.md#Changelog) for instructions on how to add changelog entries.
66

7-
## [Unreleased 3.2](https://github.com/opensearch-project/k-NN/compare/main...HEAD)
7+
## Bug Fixes
8+
9+
* Reverts k back to null in radial search with filter rewrite [#2915](https://github.com/opensearch-project/k-NN/pull/2915)

src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,11 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryShardContext) throws I
740740
if (Objects.nonNull(filter)) {
741741
rewrittenFilter = filter.rewrite(queryShardContext);
742742
if (rewrittenFilter != filter) {
743+
Integer optionalK = this.k == 0 ? null : this.k;
743744
KNNQueryBuilder rewrittenQueryBuilder = KNNQueryBuilder.builder()
744745
.fieldName(this.fieldName)
745746
.vector(this.vector)
746-
.k(this.k)
747+
.k(optionalK)
747748
.maxDistance(this.maxDistance)
748749
.minScore(this.minScore)
749750
.methodParameters(this.methodParameters)

src/test/java/org/opensearch/knn/index/query/KNNQueryBuilderTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ public void testDoToQuery_whenDoRadiusSearch_whenDistanceThreshold_whenFilter_th
540540
org.opensearch.knn.common.KNNConstants.METHOD_HNSW,
541541
ImmutableMap.of()
542542
);
543+
knnQueryBuilder = (KNNQueryBuilder) knnQueryBuilder.doRewrite(mockQueryShardContext);
543544
KNNMethodContext knnMethodContext = new KNNMethodContext(KNNEngine.LUCENE, SpaceType.L2, methodComponentContext);
544545
when(mockKNNVectorField.getKnnMappingConfig()).thenReturn(getMappingConfigForMethodMapping(knnMethodContext, 4));
545546
when(mockQueryShardContext.fieldMapper(anyString())).thenReturn(mockKNNVectorField);

0 commit comments

Comments
 (0)