# Why my OpenSearch vector search is slow

**URL:** <https://forum.opensearch.org/t/why-my-opensearch-vector-search-is-slow/16166>\
**Category:** OpenSearch\
**Created:** [October 5, 2023, 5:10pm UTC](https://forum.opensearch.org/t/why-my-opensearch-vector-search-is-slow/16166 "2023-10-05T17:10:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Garance](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Garance](https://forum.opensearch.org/u/Garance)\
**Post date:** [October 5, 2023, 5:10pm UTC](https://forum.opensearch.org/t/why-my-opensearch-vector-search-is-slow/16166/1 "2023-10-05T17:10:42Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):  
OpenSearch 1.3 on AWS

**Describe the issue** :  
I have a OpenSearch Service instance on AWS with 2 nodes, I created an index with a knn field. My queries took 10 seconds.  
The index contains more than 2 millions of data with size of 11gb.

How to improve the knn search?

**Configuration** :  
Schema:

```auto
{
  "settings": {
    "index": {
      "number_of_shards": 2,
      "number_of_replicas": 0,
      "knn": true,
      "knn.algo_param.ef_search": 512
    }
  },
  "mappings": {
    "dynamic": "false",
    "properties": {
      "title": {
        "type": "text"
      },
      "text": {
        "type": "text"
      }
      "vector": {
        "type": "knn_vector",
        "dimension": 256,
        "method": {
          "name": "hnsw",
          "space_type": "l2",
          "engine": "nmslib",
          "parameters": {
            "ef_construction": 2000,
            "m": 16
          }
        }
      }
    }
  }
}

```

Query:

```auto
{
  "highlight": {
    "fields": {
      "text": {}
    },
    "fragment_size": 1000,
    "fragmenter": "simple",
    "highlight_query": {
      "match": {
        "text": "Why my OpenSearch vector search is slow?"
      }
    },
    "no_match_size": 1000,
    "number_of_fragments": 5,
    "post_tags": "</em>",
    "pre_tags": "<em>"
  },
  "_source": [
    "title",
    "text"
  ],
  "size": 100,
  "query": {
    "knn": {
      "vector": {
        "k": 100,
        "vector": [0.06414795,-0.033294678,...,-0.06677246]
      }
    }
  }
}

```

**Relevant Logs or Screenshots** :

---

<div class="post-metadata">

**Author:** ![Garance](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Garance](https://forum.opensearch.org/u/Garance)\
**Post date:** [November 8, 2023, 4:00pm UTC](https://forum.opensearch.org/t/why-my-opensearch-vector-search-is-slow/16166/2 "2023-11-08T16:00:40Z")

</div>

I installed OpenSearch **2.9** on a local server, the vector index contains 3.5 millions of data with size of 49gb.

A simple knn search takes 8 seconds, a knn search with highlighting takes 18 seconds. We are disappointed on the search performance, compared to other vector search engines (e.g. Weaviate).  
How to improve the knn search performance?

---

<div class="post-metadata">

**Author:** ![Ktyagi](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@Ktyagi](https://forum.opensearch.org/u/Ktyagi)\
**Post date:** [January 14, 2024, 7:16pm UTC](https://forum.opensearch.org/t/why-my-opensearch-vector-search-is-slow/16166/3 "2024-01-14T19:16:29Z")

</div>

Hi

What are the size of dimensions you are using??

---

<div class="post-metadata">

**Author:** ![Garance](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Garance](https://forum.opensearch.org/u/Garance)\
**Post date:** [January 15, 2024, 8:36pm UTC](https://forum.opensearch.org/t/why-my-opensearch-vector-search-is-slow/16166/4 "2024-01-15T20:36:28Z")

</div>

@Ktyagi 256 dimensions, the schema and the query are in my post.

---

<div class="post-metadata">

**Author:** ![Ktyagi](https://avatars.discourse-cdn.com/v4/letter/k/e9c0ed/32.png) [@Ktyagi](https://forum.opensearch.org/u/Ktyagi)\
**Post date:** [January 16, 2024, 4:50pm UTC](https://forum.opensearch.org/t/why-my-opensearch-vector-search-is-slow/16166/5 "2024-01-16T16:50:02Z")

</div>

Hi

What are the number of shards? Also how many nodes are there in cluster?? Vector search is a memory intensive operation so kindly ensure your data nodes have sufficient ram available for them, once you have enough ram then expect performance improvements in query

Also your ef construction value is very high  
Reduce it to 32 and reindex the data

---

<div class="post-metadata">

**Author:** ![Garance](https://avatars.discourse-cdn.com/v4/letter/g/c2a13f/32.png) [@Garance](https://forum.opensearch.org/u/Garance)\
**Post date:** [January 18, 2024, 10:50pm UTC](https://forum.opensearch.org/t/why-my-opensearch-vector-search-is-slow/16166/6 "2024-01-18T22:50:03Z")

</div>

The index has 2 shards, and 1 node in the cluster. Thank you for the advice, I will reindex vectors.
