Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
builder.field("type", type);
builder.field("m", m);
builder.field("ef_construction", efConstruction);
if (confidenceInterval != null) {
if (hasSerializableConfidenceInterval(confidenceInterval)) {
builder.field("confidence_interval", confidenceInterval);
}
if (onDiskRescore) {
Expand Down Expand Up @@ -2161,7 +2161,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
if (rescoreVector != null) {
rescoreVector.toXContent(builder, params);
}
if (confidenceInterval != null) {
if (hasSerializableConfidenceInterval(confidenceInterval)) {
builder.field("confidence_interval", confidenceInterval);
}
builder.endObject();
Expand Down Expand Up @@ -3555,6 +3555,10 @@ private static Float parseConfidenceInterval(String fieldName, Map<String, ?> in
return confidenceInterval;
}

private static boolean hasSerializableConfidenceInterval(Float confidenceInterval) {
return confidenceInterval != null && Float.compare(confidenceInterval, 0.0f) != 0;
}

/**
* @return the custom kNN vectors format that is configured for this field or
* {@code null} if the default format should be used.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasToString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -2033,6 +2034,41 @@ public void testConfidenceIntervalNoDeprecationBeforeLatestIndexVersion() throws
assertWarnings();
}

public void testConfidenceIntervalZeroNormalizedAndOmittedFromMappingSource() throws IOException {
DocumentMapper mapper = createDocumentMapper(IndexVersions.UPGRADE_TO_LUCENE_10_4_0, fieldMapping(b -> {
b.field("type", "dense_vector");
b.field("dims", 6);
b.field("index", true);
b.field("similarity", "dot_product");
b.startObject("index_options");
b.field("type", "int4_hnsw");
b.field("m", 16);
b.field("ef_construction", 100);
b.field("confidence_interval", 0.0);
b.endObject();
}));
String source = mapper.mappingSource().string();
assertThat(source, containsString("\"type\":\"int4_hnsw\""));
assertThat(source, not(containsString("confidence_interval")));
}

public void testConfidenceIntervalAbsentInt4HnswMappingSourceStable() throws IOException {
DocumentMapper mapper = createDocumentMapper(IndexVersions.UPGRADE_TO_LUCENE_10_4_0, fieldMapping(b -> {
b.field("type", "dense_vector");
b.field("dims", 6);
b.field("index", true);
b.field("similarity", "dot_product");
b.startObject("index_options");
b.field("type", "int4_hnsw");
b.field("m", 16);
b.field("ef_construction", 100);
b.endObject();
}));
String source = mapper.mappingSource().string();
assertThat(source, containsString("\"type\":\"int4_hnsw\""));
assertThat(source, not(containsString("confidence_interval")));
}

public void testKnnQuantizedFlatVectorsFormat() throws IOException {
for (String quantizedFlatFormat : new String[] { "int8_flat", "int4_flat" }) {
MapperService mapperService = createMapperService(
Expand Down
Loading