From 257b75d1d7a9fe1e989a011fd26babe9b8c667fa Mon Sep 17 00:00:00 2001 From: carlosdelest Date: Fri, 29 Nov 2024 15:41:22 +0100 Subject: [PATCH] Add tests --- .../search/vectors/RescoreVectorBuilder.java | 2 +- .../search/vectors/KnnSearchBuilderTests.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/search/vectors/RescoreVectorBuilder.java b/server/src/main/java/org/elasticsearch/search/vectors/RescoreVectorBuilder.java index 26c151b5d2f72..2471b29dc1193 100644 --- a/server/src/main/java/org/elasticsearch/search/vectors/RescoreVectorBuilder.java +++ b/server/src/main/java/org/elasticsearch/search/vectors/RescoreVectorBuilder.java @@ -24,7 +24,7 @@ public class RescoreVectorBuilder implements Writeable, ToXContentObject { public static final ParseField OVERSAMPLE_FIELD = new ParseField("oversample"); - public static final int MIN_OVERSAMPLE = 1; + public static final float MIN_OVERSAMPLE = 1.0F; private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( "rescore", args -> new RescoreVectorBuilder((Float) args[0]) diff --git a/server/src/test/java/org/elasticsearch/search/vectors/KnnSearchBuilderTests.java b/server/src/test/java/org/elasticsearch/search/vectors/KnnSearchBuilderTests.java index ec2ddebcfc2ca..1a54d7c8420da 100644 --- a/server/src/test/java/org/elasticsearch/search/vectors/KnnSearchBuilderTests.java +++ b/server/src/test/java/org/elasticsearch/search/vectors/KnnSearchBuilderTests.java @@ -254,6 +254,14 @@ public void testInvalidK() { assertThat(e.getMessage(), containsString("[k] must be greater than 0")); } + public void testInvalidRescoreVectorBuilder() { + IllegalArgumentException e = expectThrows( + IllegalArgumentException.class, + () -> new KnnSearchBuilder("field", randomVector(3), 0, 100, new RescoreVectorBuilder(1.0F), null) + ); + assertThat(e.getMessage(), containsString("[oversample] must be > 1.0")); + } + public void testRewrite() throws Exception { float[] expectedArray = randomVector(randomIntBetween(10, 1024)); RescoreVectorBuilder expectedRescore = new RescoreVectorBuilder(randomFloatBetween(1.0f, 10.0f, false));