Skip to content

Commit

Permalink
Fix test, add coverage for byte element types
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosdelest committed Dec 5, 2024
1 parent 9c9773f commit 7d083b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ protected TopDocs mergeLeafResults(TopDocs[] perLeafResults) {
public void profile(QueryProfiler queryProfiler) {
queryProfiler.addVectorOpsCount(vectorOpsCount);
}

public Integer kParam() {
return kParam;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper.VectorSimilarity;
import org.elasticsearch.search.DocValueFormat;
import org.elasticsearch.search.vectors.DenseVectorQuery;
import org.elasticsearch.search.vectors.ESKnnByteVectorQuery;
import org.elasticsearch.search.vectors.ESKnnFloatVectorQuery;
import org.elasticsearch.search.vectors.RescoreKnnVectorQuery;
import org.elasticsearch.search.vectors.VectorData;
Expand Down Expand Up @@ -409,10 +410,11 @@ public void testByteCreateKnnQuery() {
}

public void testRescoreOversampleUsedWithoutQuantization() {
DenseVectorFieldMapper.ElementType elementType = randomFrom(FLOAT, BYTE);
DenseVectorFieldType nonQuantizedField = new DenseVectorFieldType(
"f",
IndexVersion.current(),
randomFrom(FLOAT, BYTE),
elementType,
3,
true,
VectorSimilarity.COSINE,
Expand All @@ -430,9 +432,15 @@ public void testRescoreOversampleUsedWithoutQuantization() {
null
);

ESKnnFloatVectorQuery esKnnQuery = (ESKnnFloatVectorQuery) knnQuery;
assertThat(esKnnQuery.getK(), is(100));
assertThat(esKnnQuery.kParam(), is(10));
if (elementType == BYTE) {
ESKnnByteVectorQuery esKnnQuery = (ESKnnByteVectorQuery) knnQuery;
assertThat(esKnnQuery.getK(), is(100));
assertThat(esKnnQuery.kParam(), is(10));
} else {
ESKnnFloatVectorQuery esKnnQuery = (ESKnnFloatVectorQuery) knnQuery;
assertThat(esKnnQuery.getK(), is(100));
assertThat(esKnnQuery.kParam(), is(10));
}
}

public void testRescoreOversampleModifiesKnnParams() {
Expand Down

0 comments on commit 7d083b7

Please sign in to comment.