Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -131,6 +131,7 @@ public static boolean isNotUnitVector(float magnitude) {
// vector
public static final int MAGNITUDE_BYTES = 4;
public static final int OVERSAMPLE_LIMIT = 10_000; // Max oversample allowed
private static final float DEFAULT_OVERSAMPLE = 3.0F; // Default oversample value

private static DenseVectorFieldMapper toType(FieldMapper in) {
return (DenseVectorFieldMapper) in;
Expand Down Expand Up @@ -1462,6 +1463,9 @@ public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOpti
RescoreVector rescoreVector = null;
if (indexVersion.onOrAfter(ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS)) {
rescoreVector = RescoreVector.fromIndexOptions(indexOptionsMap, indexVersion);
if (rescoreVector == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only happen on new indices. Please add a new index version to bar changing this on existing indices.

rescoreVector = new RescoreVector(DEFAULT_OVERSAMPLE);
}
}
MappingParser.checkNoRemainingFields(fieldName, indexOptionsMap);
return new BBQHnswIndexOptions(m, efConstruction, rescoreVector);
Expand All @@ -1483,6 +1487,9 @@ public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOpti
RescoreVector rescoreVector = null;
if (indexVersion.onOrAfter(ADD_RESCORE_PARAMS_TO_QUANTIZED_VECTORS)) {
rescoreVector = RescoreVector.fromIndexOptions(indexOptionsMap, indexVersion);
if (rescoreVector == null) {
rescoreVector = new RescoreVector(DEFAULT_OVERSAMPLE);
}
}
MappingParser.checkNoRemainingFields(fieldName, indexOptionsMap);
return new BBQFlatIndexOptions(rescoreVector);
Expand Down Expand Up @@ -2311,6 +2318,10 @@ int getVectorDimensions() {
ElementType getElementType() {
return elementType;
}

IndexOptions getIndexOptions() {
return indexOptions;
}
}

private final IndexOptions indexOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,60 @@ public void testInvalidRescoreVector() {
}
}

public void testDefaultOversampleValue() throws IOException {
{
DocumentMapper mapperService = createDocumentMapper(fieldMapping(b -> {
b.field("type", "dense_vector");
b.field("dims", 128);
b.field("index", true);
b.field("similarity", "dot_product");
b.startObject("index_options");
b.field("type", "bbq_hnsw");
b.endObject();
}));

DenseVectorFieldMapper denseVectorFieldMapper = (DenseVectorFieldMapper) mapperService.mappers().getMapper("field");
DenseVectorFieldMapper.BBQHnswIndexOptions indexOptions = (DenseVectorFieldMapper.BBQHnswIndexOptions) denseVectorFieldMapper
.fieldType()
.getIndexOptions();
assertEquals(3.0F, indexOptions.rescoreVector.oversample(), 0.0F);
}
{
DocumentMapper mapperService = createDocumentMapper(fieldMapping(b -> {
b.field("type", "dense_vector");
b.field("dims", 128);
b.field("index", true);
b.field("similarity", "dot_product");
b.startObject("index_options");
b.field("type", "bbq_flat");
b.endObject();
}));

DenseVectorFieldMapper denseVectorFieldMapper = (DenseVectorFieldMapper) mapperService.mappers().getMapper("field");
DenseVectorFieldMapper.BBQFlatIndexOptions indexOptions = (DenseVectorFieldMapper.BBQFlatIndexOptions) denseVectorFieldMapper
.fieldType()
.getIndexOptions();
assertEquals(3.0F, indexOptions.rescoreVector.oversample(), 0.0F);
}
{
DocumentMapper mapperService = createDocumentMapper(fieldMapping(b -> {
b.field("type", "dense_vector");
b.field("dims", 128);
b.field("index", true);
b.field("similarity", "dot_product");
b.startObject("index_options");
b.field("type", "int8_hnsw");
b.endObject();
}));

DenseVectorFieldMapper denseVectorFieldMapper = (DenseVectorFieldMapper) mapperService.mappers().getMapper("field");
DenseVectorFieldMapper.Int8HnswIndexOptions indexOptions = (DenseVectorFieldMapper.Int8HnswIndexOptions) denseVectorFieldMapper
.fieldType()
.getIndexOptions();
assertNull(indexOptions.rescoreVector);
}
}

public void testDims() {
{
Exception e = expectThrows(MapperParsingException.class, () -> createMapperService(fieldMapping(b -> {
Expand Down