# ALgorithm in ElasticSearch for similarity distances between 2 floating vectors

**URL:** <https://discuss.elastic.co/t/algorithm-in-elasticsearch-for-similarity-distances-between-2-floating-vectors/259859>\
**Category:** Elasticsearch\
**Created:** [December 30, 2020, 8:01am UTC](https://discuss.elastic.co/t/algorithm-in-elasticsearch-for-similarity-distances-between-2-floating-vectors/259859 "2020-12-30T08:01:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![deshwal.mahesh](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@deshwal.mahesh](https://discuss.elastic.co/u/deshwal.mahesh)\
**Post date:** [December 30, 2020, 8:01am UTC](https://discuss.elastic.co/t/algorithm-in-elasticsearch-for-similarity-distances-between-2-floating-vectors/259859/1 "2020-12-30T08:01:58Z")

</div>

Before I start, I seriously have no idea what Elastic is and How it works. I am ML Engineer and has recently been assigned the task for Image - Image similarity. I developed a model which will compare the distances between the vectors provided by the model such as `Manhattan, Euclidean, cosine etc.` I could do it easily but the problem is that I have this huge data around 20M images and I can not store all the vectors in memory for starters and even if I do, it is practically impossible for me to compare with each and every unit as it'll be `O(12M)` comparisons.

So I want to know that are there any algorithms for Vectors searching just there is text search algo like `Okapi BM25`.

My vectors look like:  
`[0.2,0.1,0.04,......]` etc. They can be any dimensional depending on the use case. But is there any algorithm which can get me `top-k` search results.

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [January 15, 2021, 11:52pm UTC](https://discuss.elastic.co/t/algorithm-in-elasticsearch-for-similarity-distances-between-2-floating-vectors/259859/2 "2021-01-15T23:52:10Z")

</div>

Elasticsearch provides [dense\_vector](https://www.elastic.co/guide/en/elasticsearch/reference/current/dense-vector.html) type for storing vectors, and [vector functions](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-score-query.html#_dense_vector_functions) to find the most similar vectors.

But be aware that the current search goes sequentially through all documents, and can be slow depending on the size of your collection and the number of vector dimensions.

---

<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:** [February 12, 2021, 11:52pm UTC](https://discuss.elastic.co/t/algorithm-in-elasticsearch-for-similarity-distances-between-2-floating-vectors/259859/3 "2021-02-12T23:52:12Z")

</div>

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