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

Add spaceType as a top level parameter while creating vector field. #2044

Closed navneet1v closed 3 weeks ago

navneet1v commented 3 weeks ago

Description

Add spaceType as a top level parameter while creating vector field. With this change a user can change the spaceType for the vector field without defining the method parameter in the mapping. With this change Disk based vector search OOB experience is improved.

Things to be added:

Tests will be added in followup PRs

How testing is done:

I have performed manual testing by running following create index request.

Success

{
    "settings": {
        "index": {
            "number_of_shards": 1,
            "number_of_replicas": 0,
            "refresh_interval": "1s",
            "knn": true
        }
    },
    "mappings": {
        "properties": {
            "my_vector2": {
                "type": "knn_vector",
                "dimension": 4,
                "mode": "on_disk",
                "compression_level": "32x",
                "space_type": "innerproduct"
            }
        }
    }
}

Success and hits the legacy method and use the innerproduct space type

{
    "settings": {
        "index": {
            "number_of_shards": 1,
            "number_of_replicas": 0,
            "refresh_interval": "1s",
            "knn": true
        }
    },
    "mappings": {
        "properties": {
            "my_vector2": {
                "type": "knn_vector",
                "dimension": 4,
                "space_type": "innerproduct"
            }
        }
    }
}

Related Issues

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

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.