# KNN Search super slow

**URL:** https://discuss.elastic.co/t/knn-search-super-slow/321631
**Category:** Elasticsearch
**Tags:** docker, vector-search
**Created:** [December 20, 2022, 10:38am UTC](https://discuss.elastic.co/t/knn-search-super-slow/321631 "2022-12-20T10:38:07Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![TopTea1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/toptea1/32/114949_2.png) [@TopTea1](https://discuss.elastic.co/u/TopTea1)
#### Post date: [December 20, 2022, 10:38am UTC](https://discuss.elastic.co/t/knn-search-super-slow/321631/1 "2022-12-20T10:38:07Z")

</div>

Hi, I'm using ES v8.1.3 in a dockerized env with 4 shards. In my database I have around ~90M documents, and for each I have a dense vector with a dim of 768. But when I'm trying to perform a search using ANN (with cosine distance) the query takes more than 20 mins to complete. Have you any clue how to speed up this process ?  
Thanks

---

<div class="post-metadata">

### Author: ![BenTrent](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bentrent/32/33915_2.png) [@BenTrent](https://discuss.elastic.co/u/BenTrent)
#### Post date: [December 20, 2022, 5:56pm UTC](https://discuss.elastic.co/t/knn-search-super-slow/321631/2 "2022-12-20T17:56:12Z")

</div>

Two major things:

- The KNN vectors and connections need to all be in memory.
- If you can, normalize your vectors before ingesting and use dot\_product instead of cosine.

Your vectors & connections will need `90_000_000 * (768 + 32) * 4` bytes for the vectors to sit in memory.

This will definitely require more than one node to adequately service as that is around `268gb` of ram.

Here is our overall tuning guide: [Tune approximate kNN search | Elasticsearch Guide [8.5] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/tune-knn-search.html)

We are actively making storage of vectors much more efficient. Additionally, in 8.6, we will release support for byte-value vectors so that users can quantize their floats before ingesting for HUGE space savings at minimal accuracy loss.

---

<div class="post-metadata">

### Author: ![BenTrent](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bentrent/32/33915_2.png) [@BenTrent](https://discuss.elastic.co/u/BenTrent)
#### Post date: [December 20, 2022, 5:57pm UTC](https://discuss.elastic.co/t/knn-search-super-slow/321631/3 "2022-12-20T17:57:03Z")

</div>

Also, there are multiple bug fixes and improvements in 8.5. I would recommend actively working towards upgrading your elasticsearch cluster version.

---

<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: [January 17, 2023, 5:57pm UTC](https://discuss.elastic.co/t/knn-search-super-slow/321631/4 "2023-01-17T17:57:40Z")

</div>

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