How to truncate dense_vector fields with a script

I want to make use of the Matryoshka 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)

{
  "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,
…
          ]
        }
      }
    }
  }
}

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