Skip to content

Commit

Permalink
Add test for knn retriever
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Nov 29, 2024
1 parent 4fbbadd commit 0dab8ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ public void extractToSearchSourceBuilder(SearchSourceBuilder searchSourceBuilder
searchSourceBuilder.knnSearch(knnSearchBuilders);
}

// ---- FOR TESTING XCONTENT PARSING ----
RescoreVectorBuilder rescoreVectorBuilder() {
return rescoreVectorBuilder;
}

// ---- FOR TESTING XCONTENT PARSING ----

@Override
public void doToXContent(XContentBuilder builder, Params params) throws IOException {
Expand All @@ -278,7 +282,9 @@ public void doToXContent(XContentBuilder builder, Params params) throws IOExcept
}

if (rescoreVectorBuilder != null) {
builder.field(RESCORE_FIELD.getPreferredName(), rescoreVectorBuilder);
builder.startObject(RESCORE_FIELD.getPreferredName());
rescoreVectorBuilder.toXContent(builder, params);
builder.endObject();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public void testRewrite() throws IOException {
assertNull(source.query());
assertThat(source.knnSearch().size(), equalTo(1));
assertThat(source.knnSearch().get(0).getFilterQueries().size(), equalTo(knnRetriever.preFilterQueryBuilders.size()));
assertThat(source.knnSearch().get(0).getRescoreVectorBuilder(), equalTo(knnRetriever.rescoreVectorBuilder()));
for (int j = 0; j < knnRetriever.preFilterQueryBuilders.size(); j++) {
assertThat(
source.knnSearch().get(0).getFilterQueries().get(j),
Expand Down

0 comments on commit 0dab8ea

Please sign in to comment.