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

[BUG] 2.19.0 - KNN cosinesimil scoring no longer adding 1 #2561

Open
tmoitie opened this issue Feb 20, 2025 · 2 comments
Open

[BUG] 2.19.0 - KNN cosinesimil scoring no longer adding 1 #2561

tmoitie opened this issue Feb 20, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@tmoitie
Copy link

tmoitie commented Feb 20, 2025

Describe the bug

The documentation describes cosinesimil space type as so:

Cosine similarity returns a number between -1 and 1, and because OpenSearch relevance scores can’t be below 0, the k-NN plugin adds 1 to get the final score.

In the latest version of Opensearch, this is no longer the case, as the output is scaled down to sit between 0 and 1.

Related component

Plugins

To Reproduce

Index settings:

{
    "mappings": {
        "properties": {
            "embedding": {
                "type": "knn_vector",
                "dimension": 4
            }
        }
    },
    "settings": {
        "index": {
            "knn": true,
            "knn.space_type": "cosinesimil"
        }
    }
}

Document:

{
    "embedding": [
        1.0,
        1.0,
        1.0,
        1.0
    ]
}

Query:

{
    "query": {
        "script_score" : {
            "query": {
                "bool": {
                    "must": []
                }
            },
            "script": {
                "source": "knn_score",
                "lang": "knn",
                "params": {
                    "field": "embedding",
                    "query_value": [
                      1.0,
                      1.0,
                      1.0,
                      1.0
                    ],
                    "space_type": "cosinesimil"
                }
            }
        }
    }
}

Expected behavior

Results.hits.hits.0._score was 2.0 in 2.18.0, it is now 1.0. It appears to now scale between 0.0 and 1.0.

Additional Details

Plugins
KNN

Host/Environment (please complete the following information):

  • OS: Docker running on Orbstack on MacOS 15.3.1
  • 2.19.0
@tmoitie tmoitie added bug Something isn't working untriaged labels Feb 20, 2025
@andrross
Copy link
Member

@opensearch-project/admin Can this be transferred to the https://github.com/opensearch-project/k-NN repository?

@peterzhuamazon peterzhuamazon transferred this issue from opensearch-project/OpenSearch Feb 25, 2025
@jmazanec15
Copy link
Member

Hi @tmoitie, this was added as part of #2357. Basically, we wanted to make consistent across different engines. Did this cauise a problem? Looks like we might need to update docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants