Skip to content

Commit

Permalink
Resolve feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Junqiu Lei <[email protected]>
  • Loading branch information
junqiu-lei committed Apr 3, 2024
1 parent 4fbd3b2 commit d4f70de
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/main/java/org/opensearch/knn/index/SpaceType.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public VectorSimilarityFunction getVectorSimilarityFunction() {

@Override
public float scoreToDistanceTranslation(float score) {
if (score == 0) {
throw new IllegalArgumentException(String.format(Locale.ROOT, "score cannot be 0 when space type is [%s]", getValue()));

Check warning on line 43 in src/main/java/org/opensearch/knn/index/SpaceType.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/knn/index/SpaceType.java#L43

Added line #L43 was not covered by tests
}
return 1 / score - 1;
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public KNNQueryBuilder k(Integer k) {
if (k == null) {
throw new IllegalArgumentException("[" + NAME + "] requires k to be set");

Check warning on line 99 in src/main/java/org/opensearch/knn/index/query/KNNQueryBuilder.java

View check run for this annotation

Codecov / codecov/patch

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

Added line #L99 was not covered by tests
}
validSingleQueryType(k, distance, score);
validateSingleQueryType(k, distance, score);
if (k <= 0 || k > K_MAX) {
throw new IllegalArgumentException("[" + NAME + "] requires 0 < k <= " + K_MAX);
}
Expand All @@ -115,7 +115,7 @@ public KNNQueryBuilder distance(Float distance) {
if (distance == null) {
throw new IllegalArgumentException("[" + NAME + "] requires distance to be set");
}
validSingleQueryType(k, distance, score);
validateSingleQueryType(k, distance, score);
this.distance = distance;
return this;
}
Expand All @@ -129,7 +129,7 @@ public KNNQueryBuilder score(Float score) {
if (score == null) {
throw new IllegalArgumentException("[" + NAME + "] requires score to be set");
}
validSingleQueryType(k, distance, score);
validateSingleQueryType(k, distance, score);
if (score <= 0) {
throw new IllegalArgumentException("[" + NAME + "] requires score greater than 0");
}
Expand Down Expand Up @@ -295,7 +295,7 @@ public static KNNQueryBuilder fromXContent(XContentParser parser) throws IOExcep
}
}

validSingleQueryType(k, distance, score);
validateSingleQueryType(k, distance, score);

KNNQueryBuilder knnQueryBuilder = new KNNQueryBuilder(fieldName, ObjectsToFloats(vector)).filter(filter)
.ignoreUnmapped(ignoreUnmapped)
Expand Down Expand Up @@ -542,7 +542,7 @@ public String getWriteableName() {
return NAME;
}

private static void validSingleQueryType(Integer k, Float distance, Float score) {
private static void validateSingleQueryType(Integer k, Float distance, Float score) {
int countSetFields = 0;

if (k != null && k != 0) {
Expand Down

0 comments on commit d4f70de

Please sign in to comment.