# Is it possible to index an array of knn\_vectors in a single document?

**URL:** <https://forum.opensearch.org/t/is-it-possible-to-index-an-array-of-knn-vectors-in-a-single-document/9063>\
**Category:** k-NN\
**Tags:** discuss\
**Created:** [March 29, 2022, 12:21am UTC](https://forum.opensearch.org/t/is-it-possible-to-index-an-array-of-knn-vectors-in-a-single-document/9063 "2022-03-29T00:21:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![spullara](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/spullara/32/3090_2.png) [@spullara](https://forum.opensearch.org/u/spullara)\
**Post date:** [March 29, 2022, 12:21am UTC](https://forum.opensearch.org/t/is-it-possible-to-index-an-array-of-knn-vectors-in-a-single-document/9063/1 "2022-03-29T00:21:12Z")

</div>

I would like all the face embeddings that are in the document to be indexed.

---

<div class="post-metadata">

**Author:** ![jmazane](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jmazane](https://forum.opensearch.org/u/jmazane)\
**Post date:** [March 30, 2022, 8:41pm UTC](https://forum.opensearch.org/t/is-it-possible-to-index-an-array-of-knn-vectors-in-a-single-document/9063/2 "2022-03-30T20:41:41Z")

</div>

Hi @spullara

I think [https://forum.opensearch.org/t/getting-0-search-results-for-a-knn-query-and-score-0-results-from-script/9062/1](https://forum.opensearch.org/t/getting-0-search-results-for-a-knn-query-and-score-0-results-from-script/9062/1) got deleted.

Could you repose?

---

<div class="post-metadata">

**Author:** ![spullara](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/spullara/32/3090_2.png) [@spullara](https://forum.opensearch.org/u/spullara)\
**Post date:** [March 31, 2022, 9:09pm UTC](https://forum.opensearch.org/t/is-it-possible-to-index-an-array-of-knn-vectors-in-a-single-document/9063/3 "2022-03-31T21:09:30Z")

</div>

That one I figured out was an error on my part.

---

<div class="post-metadata">

**Author:** ![jmazane](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@jmazane](https://forum.opensearch.org/u/jmazane)\
**Post date:** [April 6, 2022, 5:23pm UTC](https://forum.opensearch.org/t/is-it-possible-to-index-an-array-of-knn-vectors-in-a-single-document/9063/4 "2022-04-06T17:23:39Z")

</div>

It is possible to have multiple knn\_vector fields in a single document, but not an array of knn\_vectors in a single field.

---

<div class="post-metadata">

**Author:** ![yeonghyeonKo](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/yeonghyeonko/32/8202_2.png) [@yeonghyeonKo](https://forum.opensearch.org/u/yeonghyeonKo)\
**Post date:** [November 15, 2024, 5:59am UTC](https://forum.opensearch.org/t/is-it-possible-to-index-an-array-of-knn-vectors-in-a-single-document/9063/5 "2024-11-15T05:59:10Z")

</div>

yes, until now (the latest version 2.18), we cannot ingest knn\_vector type document in multi-fields.

for example, we are able to set index template like the below:

```auto
"TITLE_VECTOR_768": {
      "method": {
        "engine": "faiss",
        "space_type": "l2",
        "name": "hnsw",
        "parameters": {
          "ef_construction": 128,
          "m": 24
        }
      },
      "fields": {
        "compression_32x": {
          "method": {
            "engine": "faiss",
            "space_type": "l2",
            "name": "hnsw",
            "parameters": {
              "ef_construction": 128,
              "m": 24
            }
          },
          "type": "knn_vector",
          "dimension": 768
        }
      },
      "dimension": 768,
      "type": "knn_vector"
    },

```

but in the phase of indexing, it failed:

```auto
"type": "mapper_parsing_exception",
    "reason": "failed to parse field [TITLE_VECTOR_768.compression_32x] of type [knn_vector] in document with id '4416856'. Preview of field's value: 'null'",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "Vector dimension mismatch. Expected: 768, Given: 0"
    }

```

If you use ingest pipeline with **text\_embedding** processors like:

```auto
"processors": [
    {
      "text_embedding": {
        "model_id": "zjQEJJMByqw6QjR9eFPm",
        "field_map": {
          "DETAIL": "DETAIL_VECTOR_768",
          "TITLE": "TITLE_VECTOR_768"
        }
      }
    },
    {
      "text_embedding": {
        "model_id": "zjQEJJMByqw6QjR9eFPm",
        "field_map": {
          "DETAIL": "DETAIL_VECTOR_768.compression_32x",
          "TITLE": "TITLE_VECTOR_768.compression_32x"
        }
      }
    },

```

it also failed:

```auto
"root_cause": [
      {
        "type": "class_cast_exception",
        "reason": "class_cast_exception: class java.lang.Float cannot be cast to class java.util.Map (java.lang.Float and java.util.Map are in module java.base of loader 'bootstrap')"
      }
    ],
    "type": "class_cast_exception",
    "reason": "class_cast_exception: class java.lang.Float cannot be cast to class java.util.Map (java.lang.Float and java.util.Map are in module java.base of loader 'bootstrap')"

```

* * *
  

So if I were you I would have set multiple **text\_embedding** processors and map them to multiple fields , not **“multi-fields”**.

---

<div class="post-metadata">

**Author:** ![yeonghyeonKo](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/yeonghyeonko/32/8202_2.png) [@yeonghyeonKo](https://forum.opensearch.org/u/yeonghyeonKo)\
**Post date:** [November 15, 2024, 8:23am UTC](https://forum.opensearch.org/t/is-it-possible-to-index-an-array-of-knn-vectors-in-a-single-document/9063/6 "2024-11-15T08:23:35Z")

</div>

Still, we can create index.mapping with “nested” type.

> **[k-NN search with nested fields](https://opensearch.org/docs/latest/search-plugins/knn/nested-search-knn/)**
>
> k-NN search with nested fields

---

<div class="post-metadata">

**Author:** ![lucyy300](https://avatars.discourse-cdn.com/v4/letter/l/d26b3c/32.png) [@lucyy300](https://forum.opensearch.org/u/lucyy300)\
**Post date:** [November 16, 2024, 9:27am UTC](https://forum.opensearch.org/t/is-it-possible-to-index-an-array-of-knn-vectors-in-a-single-document/9063/7 "2024-11-16T09:27:29Z")

</div>

> [@jmazane](#):
>
> It is possible to have multiple knn\_vector fields in a single document, but not an array of knn\_vectors in a single field. [tu](https://atelierrebul.hr/shop/category/mirisi-za-dom-mirisne-svijece-24)

Yes, you can have multiple `knn_vector` fields in a single document
