Calculate similarity in percentage based on the score from azure search

Viewed 65

I am using Azure Search service with Cosmos DB as a data source to enable the search feature in the nodejs application. There is a use case where I need to show the similarity in percentage(to 100%) for each document that is obtained from azure search API. For Eg:

API : https://name.search.windows.net/indexes/dbname/docs/search?api-version=2016-09-01

Payload: {
        "search" : "This is a test key for search service",
        "searchFields":"title, description",
        "searchMode":"all",
        "count":true               
        
    }

Response :  "@odata.count": 2,
            "value": [
            {
              "@search.score": 4.190574,// convert to ~70%(assumption) similarity
              "title": "search service",
              "description": "The Search Service test key provides extensive capabilities for search engine-like querying"
            ...},
           {"@search.score": 3.9293563,// convert to ~40%(assumption) similarity
              "title": "test key",
              "description": " test measures your ability to enter groups of numbers using the numeric ten-key pad"
            ...}]

Is there any way by which the @search.score could be converted to doc1 - 70% and doc2 -40% based on the similarity with the search key? I read through the documentation on using scoring profiles and using a different algorithm for search API. I understand that the score is based on the indexes and there is no specific range to the score. But still, if any kind of conversion is possible then would be great, or do I need to think of another approach? Help will be appreciated :)

1 Answers

Relevance scores are mostly abstract - in the case of Azure Search, the score is a representation of how often the search terms show up in the documents (with some integrated biases toward rarer words and using a formula that takes into consideration the length of the document). A higher score means "more of the words that are being searched for appear in the document". In your scenario, what would a percentage mean? For example, what would 100% mean? or 50%?

If you just want to show percentages instead of scores while keeping the same ranking, you could just divide all scores by the top score (so that the top document of each request always scores a 100%, with the other documents decreasing in percentage). However, this would still not allow you to compare document scores between different requests.

Related