# Failed to create query: the query vector has a different dimension \[384\] than the index vectors \[768\]

**URL:** <https://discuss.elastic.co/t/failed-to-create-query-the-query-vector-has-a-different-dimension-384-than-the-index-vectors-768/357317>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-machine-learning\
**Created:** [April 12, 2024, 6:21pm UTC](https://discuss.elastic.co/t/failed-to-create-query-the-query-vector-has-a-different-dimension-384-than-the-index-vectors-768/357317 "2024-04-12T18:21:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![wnmills3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wnmills3/32/133048_2.png) [@wnmills3](https://discuss.elastic.co/u/wnmills3)\
**Post date:** [April 12, 2024, 6:21pm UTC](https://discuss.elastic.co/t/failed-to-create-query-the-query-vector-has-a-different-dimension-384-than-the-index-vectors-768/357317/1 "2024-04-12T18:21:44Z")

</div>

How does one set the dimension in the query to avoid this message?

---

<div class="post-metadata">

**Author:** ![anuj99](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anuj99/32/133376_2.png) [@anuj99](https://discuss.elastic.co/u/anuj99)\
**Post date:** [April 12, 2024, 6:29pm UTC](https://discuss.elastic.co/t/failed-to-create-query-the-query-vector-has-a-different-dimension-384-than-the-index-vectors-768/357317/2 "2024-04-12T18:29:23Z")

</div>

while setting up index mapping, you will have a "dims" field along with type: "dense\_vector".

set it to "dims": 768

---

<div class="post-metadata">

**Author:** ![wnmills3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wnmills3/32/133048_2.png) [@wnmills3](https://discuss.elastic.co/u/wnmills3)\
**Post date:** [April 12, 2024, 6:42pm UTC](https://discuss.elastic.co/t/failed-to-create-query-the-query-vector-has-a-different-dimension-384-than-the-index-vectors-768/357317/3 "2024-04-12T18:42:16Z")

</div>

Yes, I have that in the index mappings, but where is the query getting the 384 value -- how would I set that?

```auto
    "path": {
      "type": "text",
      "term_vector": "with_positions_offsets",
      "analyzer": "text_keep_stopwords",
      "search_analyzer": "text_drop_stopwords",
      "index_options": "offsets",
      "store": "true"
    },
    "path_embedding.predicted_value": {
      "type": "dense_vector",
      "dims": 768,
      "index": true,
      "similarity": "cosine"
    },
    "passage": {
      "type": "text",
      "analyzer": "text_keep_stopwords",
      "search_analyzer": "text_drop_stopwords",
      "term_vector": "with_positions_offsets",
      "index_options": "offsets",
      "store": "true"
    },
    "passage_embedding.predicted_value": {
      "type": "dense_vector",
      "dims": 768,
      "index": true,
      "similarity": "cosine"
    },

```

---

<div class="post-metadata">

**Author:** ![anuj99](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anuj99/32/133376_2.png) [@anuj99](https://discuss.elastic.co/u/anuj99)\
**Post date:** [April 12, 2024, 6:47pm UTC](https://discuss.elastic.co/t/failed-to-create-query-the-query-vector-has-a-different-dimension-384-than-the-index-vectors-768/357317/4 "2024-04-12T18:47:31Z")

</div>

Can you share your insert script (only vector key value)

---

<div class="post-metadata">

**Author:** ![wnmills3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wnmills3/32/133048_2.png) [@wnmills3](https://discuss.elastic.co/u/wnmills3)\
**Post date:** [April 12, 2024, 6:56pm UTC](https://discuss.elastic.co/t/failed-to-create-query-the-query-vector-has-a-different-dimension-384-than-the-index-vectors-768/357317/5 "2024-04-12T18:56:00Z")

</div>

I'm using a bulk ingester:

```auto
        BulkIngester<ObjectNode> ingester = BulkIngester
            .of(b -> b.client(_client)
                .maxOperations(100).flushInterval(20L, TimeUnit.SECONDS)
                .listener(ESUtils.getBulkListener(_logger)));

```

With the pipeline defined like:

```auto
        client.ingest().putPipeline(pr -> pr.id("rdp_pipeline")
            .processors(p -> p
                .inference(i -> i.modelId(".multilingual-e5-small_linux-x86_64")
                    .fieldMap("passage", JsonData.of("text_field"))
                    .targetField("passage_embedding")))
            .processors(p -> p
                .inference(i -> i.modelId(".multilingual-e5-small_linux-x86_64")
                    .fieldMap("path", JsonData.of("text_field"))
                    .targetField("path_embedding")))

        );

```

And I build an ObjectNode and send that for ingestion:

```auto
        String path = passage.get("path").asText().replace("~", " ~ ");
        int linenum = passage.get("lineNum").intValue();
        String text = passage.get("text").asText();
        ObjectNode content = s_objectMapper.createObjectNode();
        content.put("passage", text);
        content.put("path", path);
        content.put("url", url);
        content.put("title", title);
        content.put("linenum", linenum);
        content.put("filestem", filestem);
        content.put("id", id);
        content.put("language", langFamily);
        ingester
            .add(op -> op.index(idx -> idx.index(indexName).document(content)));

```

---

<div class="post-metadata">

**Author:** ![anuj99](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anuj99/32/133376_2.png) [@anuj99](https://discuss.elastic.co/u/anuj99)\
**Post date:** [April 12, 2024, 7:24pm UTC](https://discuss.elastic.co/t/failed-to-create-query-the-query-vector-has-a-different-dimension-384-than-the-index-vectors-768/357317/6 "2024-04-12T19:24:32Z")

</div>

I think the model used produces a output embedding of size 384 ([intfloat/multilingual-e5-small](https://huggingface.co/intfloat/multilingual-e5-small)) whereas you have configured 768 in index mapping

---

<div class="post-metadata">

**Author:** ![wnmills3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wnmills3/32/133048_2.png) [@wnmills3](https://discuss.elastic.co/u/wnmills3)\
**Post date:** [April 12, 2024, 8:05pm UTC](https://discuss.elastic.co/t/failed-to-create-query-the-query-vector-has-a-different-dimension-384-than-the-index-vectors-768/357317/7 "2024-04-12T20:05:37Z")

</div>

You are absolutely correct. I didn't realize this limitation. Thank you.
