Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing bug where mapping accepts both dimension and model-id (#2410) #2469

Merged
merged 1 commit into from
Jan 30, 2025
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* Fixing the bug where setting rescore as false for on_disk knn_vector query is a no-op (#2399)[https://github.com/opensearch-project/k-NN/pull/2399]
* Fixing the bug to prevent index.knn setting from being modified or removed on restore snapshot (#2445)[https://github.com/opensearch-project/k-NN/pull/2445]
* Fix Faiss byte vector efficient filter bug (#2448)[https://github.com/opensearch-project/k-NN/pull/2448]
* Fixing bug where mapping accepts both dimension and model-id (#2410)[https://github.com/opensearch-project/k-NN/pull/2410]
### Infrastructure
* Updated C++ version in JNI from c++11 to c++17 [#2259](https://github.com/opensearch-project/k-NN/pull/2259)
* Upgrade bytebuddy and objenesis version to match OpenSearch core and, update github ci runner for macos [#2279](https://github.com/opensearch-project/k-NN/pull/2279)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,15 @@ public Mapper.Builder<?> parse(String name, Map<String, Object> node, ParserCont
);
}

// Ensure user-defined dimension and model are mutually exclusive for indicies created after 2.19
if (builder.dimension.getValue() != UNSET_MODEL_DIMENSION_IDENTIFIER
&& builder.modelId.get() != null
&& parserContext.indexVersionCreated().onOrAfter(Version.V_2_19_0)) {
throw new IllegalArgumentException(
String.format(Locale.ROOT, "Cannot specify both a modelId and dimension in the mapping: %s", name)
);
}

// Check for flat configuration and validate only if index is created after 2.17
if (isKNNDisabled(parserContext.getSettings()) && parserContext.indexVersionCreated().onOrAfter(Version.V_2_17_0)) {
validateFromFlat(builder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,6 @@ public void testTypeParser_parse_compressionAndModeParameter() {
XContentBuilder xContentBuilder4 = XContentFactory.jsonBuilder()
.startObject()
.field(TYPE_FIELD_NAME, KNN_VECTOR_TYPE)
.field(DIMENSION, 10)
.field(VECTOR_DATA_TYPE_FIELD, VectorDataType.DEFAULT.getValue())
.field(MODEL_ID, "test")
.field(MODE_PARAMETER, Mode.ON_DISK.getName())
Expand Down Expand Up @@ -893,6 +892,27 @@ public void testTypeParser_parse_fromModel() throws IOException {
);

assertEquals(modelId, builder.modelId.get());

// Fails if both model_id and dimension are set after 2.19
XContentBuilder xContentBuilder2 = XContentFactory.jsonBuilder()
.startObject()
.field(TYPE_FIELD_NAME, KNN_VECTOR_TYPE)
.field(DIMENSION_FIELD_NAME, TEST_DIMENSION)
.field(MODEL_ID, modelId)
.endObject();

expectThrows(
IllegalArgumentException.class,
() -> typeParser.parse(fieldName, xContentBuilderToMap(xContentBuilder2), buildParserContext(indexName, settings))
);

// Should not fail if both are set before 2.19
typeParser.parse(
fieldName,
xContentBuilderToMap(xContentBuilder2),
buildLegacyParserContext(indexName, settings, Version.V_2_18_1)
);

}

public void testTypeParser_parse_fromLegacy() throws IOException {
Expand Down
Loading