# How to truncate dense\_vector fields with a script

**URL:** <https://discuss.elastic.co/t/how-to-truncate-dense-vector-fields-with-a-script/354569>\
**Category:** Elasticsearch\
**Tags:** vector-search\
**Created:** [March 2, 2024, 2:22pm UTC](https://discuss.elastic.co/t/how-to-truncate-dense-vector-fields-with-a-script/354569 "2024-03-02T14:22:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valentin\_Pletzer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/valentin_pletzer/32/105548_2.png) [@Valentin\_Pletzer](https://discuss.elastic.co/u/Valentin_Pletzer)\
**Post date:** [March 2, 2024, 2:22pm UTC](https://discuss.elastic.co/t/how-to-truncate-dense-vector-fields-with-a-script/354569/1 "2024-03-02T14:22:50Z")

</div>

I want to make use of the [Matryoshka](https://arxiv.org/abs/2205.13147) feature of openAIs new text-embeddings. For that I want only to compare the first 256 fields of the dense\_vector field. Is that possible and if so how? This script doesn't seem to work. (I'm using v8.12)

```auto
{
  "query": {
    "script_score": {
      "query": {
        "bool": {
          "filter": [
            {
              "exists": {
                "field": "text-embedding-3-small"
              }
            }
          ]
        }
      },
      "script": {
        "source": "cosineSimilarity(params.query_vector, doc['text-embedding-3-small'].subList(0, 256)) + 1.0",
        "params": {
          "query_vector": [
            0.010352743,
…
          ]
        }
      }
    }
  }
}

```

---

<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 30, 2024, 2:23pm UTC](https://discuss.elastic.co/t/how-to-truncate-dense-vector-fields-with-a-script/354569/2 "2024-03-30T14:23:30Z")

</div>

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