opensearch-project / k-NN

🆕 Find the k-nearest neighbors (k-NN) for your vector data
https://opensearch.org/docs/latest/search-plugins/knn/index/
Apache License 2.0
152 stars 113 forks source link

[Backport 2.x] Block a vector field to have invalid characters for a physical file n… #1982

Closed 0ctopus13prime closed 1 month ago

0ctopus13prime commented 1 month ago

…ame.

Description

Issue : https://github.com/opensearch-project/k-NN/issues/1859.

Issue

While OpenSearch does allow for a field name to have an empty space within it and it disallows an empty space to be contained in a physical file name, KNNCodecUtil::buildEngineFileName uses the field name directly as a part of a vector file name. As a result, in case where the field name had one of disallowed character for a physical file name, it fails in validation of BlobStoreIndexShardSnapshot. For example, _0_2011_my vector.hnswc (where 'my vector' is the field name). As a result, BlobStoreIndexShardSnapshot throws an exception complaining file name is not valid.

Solution

Add a validation logic to throw an exception in case provided vector field name has any invalid characters.

private void validateFullFieldName(BuilderContext context) {
    final String fullFieldName = buildFullName(context);
    for (char ch : fullFieldName.toCharArray()) {
        if (Strings.INVALID_FILENAME_CHARS.contains(ch)) {
            throw new IllegalArgumentException(...);
        }
    }
}

public abstract class KNNVectorFieldMapper extends ParametrizedFieldMapper {
    ...
    public static class Builder extends ParametrizedFieldMapper.Builder {
        @Override
        public KNNVectorFieldMapper build(BuilderContext context) {
            validateFullFieldName(context);
            ...

Related Issues

Issue : https://github.com/opensearch-project/k-NN/issues/1859.

Check List

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. For more information on following Developer Certificate of Origin and signing off your commits, please check here.

0ctopus13prime commented 1 month ago

Change log already had the bug fix #1936. I did not include it in this PR.

jmazanec15 commented 1 month ago

@0ctopus13prime I think we need to backport change log as well

0ctopus13prime commented 1 month ago

@0ctopus13prime I think we need to backport change log as well

Hi @jmazanec15 Just wondering, does this have the line we need already..?? 🤔 - Link Please let me know if I missed sth.