# Difference between KNN similarity and document score

**URL:** <https://discuss.elastic.co/t/difference-between-knn-similarity-and-document-score/354182>\
**Category:** Elastic Search\
**Tags:** elastic-app-search\
**Created:** [February 27, 2024, 7:24am UTC](https://discuss.elastic.co/t/difference-between-knn-similarity-and-document-score/354182 "2024-02-27T07:24:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maorethians](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maorethians/32/122370_2.png) [@maorethians](https://discuss.elastic.co/u/maorethians)\
**Post date:** [February 27, 2024, 7:24am UTC](https://discuss.elastic.co/t/difference-between-knn-similarity-and-document-score/354182/1 "2024-02-27T07:24:08Z")

</div>

Assume we have some documents with a VECTOR field storing normalized vectors in it. this is the mapping we use for this field:

```auto
{
  type: 'dense_vector',
  similarity: 'dot_product',
  index: true,
}

```

Now, we perform KNN on this field:

```auto
{
      field: `FIELD`,
      k,
      num_candidates,
      query_vector,
      similarity: minimumSimilarity,
      filter: {
        bool: {
          must: elasticMust,
          must_not: itemId ? [termTranslator('itemId', itemId)] : [],
        },
      },
    }

```

The problem is that the returned documents does not have any indicator of the similarity. they have score but when we set the minimumSimilarity as 0.3, we don't get documents with the score of 0.6.

I used the profile feature and found that there is a relation between similarity and document score:

```auto
VectorSimilarityQuery[similarity=0.3, docScore=0.65, innerKnnQuery=DocAndScore[10000]]

VectorSimilarityQuery[similarity=0.4, docScore=0.7, innerKnnQuery=DocAndScore[10000]]

VectorSimilarityQuery[similarity=0.812, docScore=0.906, innerKnnQuery=DocAndScore[10000]]

```

We want to give user the similarity to let them set minimumSimilarity based on it.

---

<div class="post-metadata">

**Author:** ![Kathleen\_DeRusso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kathleen_derusso/32/132039_2.png) [@Kathleen\_DeRusso](https://discuss.elastic.co/u/Kathleen_DeRusso)\
**Post date:** [February 28, 2024, 1:40pm UTC](https://discuss.elastic.co/t/difference-between-knn-similarity-and-document-score/354182/2 "2024-02-28T13:40:20Z")

</div>

You're correct that similarity is used to calculate the final score, but it's not accessible in the way you're looking for. We do have some [information on how scores are calculated](https://www.elastic.co/guide/en/elasticsearch/reference/current/dense-vector.html#dense-vector-similarity) if that's of interest - but I don't think you really want to go down the route of filtering on this type of metric.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 27, 2024, 1:40pm UTC](https://discuss.elastic.co/t/difference-between-knn-similarity-and-document-score/354182/3 "2024-03-27T13:40:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
