# Sparse Vectors

**URL:** <https://discuss.elastic.co/t/sparse-vectors/366856>\
**Category:** Elasticsearch\
**Created:** [September 20, 2024, 7:06am UTC](https://discuss.elastic.co/t/sparse-vectors/366856 "2024-09-20T07:06:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harsh\_Sonaiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsh_sonaiya/32/137750_2.png) [@Harsh\_Sonaiya](https://discuss.elastic.co/u/Harsh_Sonaiya)\
**Post date:** [September 20, 2024, 7:06am UTC](https://discuss.elastic.co/t/sparse-vectors/366856/1 "2024-09-20T07:06:37Z")

</div>

Is there a way to create index with sparse vectors and insert sparse vectors

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 20, 2024, 9:15am UTC](https://discuss.elastic.co/t/sparse-vectors/366856/2 "2024-09-20T09:15:55Z")

</div>

From #Elastic Search to #Elasticsearch

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 20, 2024, 9:15am UTC](https://discuss.elastic.co/t/sparse-vectors/366856/3 "2024-09-20T09:15:56Z")

</div>

Removed #docker

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 20, 2024, 9:16am UTC](https://discuss.elastic.co/t/sparse-vectors/366856/4 "2024-09-20T09:16:29Z")

</div>

Welcome!

Yes. See [Sparse vector field type | Elasticsearch Guide [8.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/sparse-vector.html)

---

<div class="post-metadata">

**Author:** ![Harsh\_Sonaiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsh_sonaiya/32/137750_2.png) [@Harsh\_Sonaiya](https://discuss.elastic.co/u/Harsh_Sonaiya)\
**Post date:** [September 20, 2024, 9:34am UTC](https://discuss.elastic.co/t/sparse-vectors/366856/5 "2024-09-20T09:34:14Z")

</div>

I checked the documentation you specified but I am using elastic using docker and I dont want use the ELSER model without that can I index sparse vectors as I tried to mention field type : "sparse\_vectors" then I got the error that sparse\_vectors are not supported

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 20, 2024, 9:41am UTC](https://discuss.elastic.co/t/sparse-vectors/366856/6 "2024-09-20T09:41:20Z")

</div>

Which version of Elasticsearch are you using? Vector search is an area that has been and is moving quickly, so I would recommend you ensure you are on the latest released version.

---

<div class="post-metadata">

**Author:** ![Harsh\_Sonaiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsh_sonaiya/32/137750_2.png) [@Harsh\_Sonaiya](https://discuss.elastic.co/u/Harsh_Sonaiya)\
**Post date:** [September 20, 2024, 9:41am UTC](https://discuss.elastic.co/t/sparse-vectors/366856/7 "2024-09-20T09:41:48Z")

</div>

18.5.1

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [September 20, 2024, 9:51am UTC](https://discuss.elastic.co/t/sparse-vectors/366856/8 "2024-09-20T09:51:26Z")

</div>

Is that 8.5.1 or 8.15.1? If it is 8.5.1 you should upgarde to 8.15.1.

---

<div class="post-metadata">

**Author:** ![Harsh\_Sonaiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsh_sonaiya/32/137750_2.png) [@Harsh\_Sonaiya](https://discuss.elastic.co/u/Harsh_Sonaiya)\
**Post date:** [September 20, 2024, 10:00am UTC](https://discuss.elastic.co/t/sparse-vectors/366856/9 "2024-09-20T10:00:25Z")

</div>

Sorry I wrote it wrong in a hurry it is already 8.15.1

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 20, 2024, 10:18am UTC](https://discuss.elastic.co/t/sparse-vectors/366856/10 "2024-09-20T10:18:36Z")

</div>

Did you try the example?

```auto
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "text": {
        "type": "text",
        "analyzer": "standard"
      },
      "impact": {
        "type": "sparse_vector"
      },
      "positive": {
        "type": "sparse_vector"
      },
      "negative": {
        "type": "sparse_vector"
      }
    }
  }
}

POST my-index-000001/_doc
{
    "text": "I had some terribly delicious carrots.",
    "impact": [{"I": 0.55, "had": 0.4, "some": 0.28, "terribly": 0.01, "delicious": 1.2, "carrots": 0.8},
               {"I": 0.54, "had": 0.4, "some": 0.28, "terribly": 2.01, "delicious": 0.02, "carrots": 0.4}],
    "positive": {"I": 0.55, "had": 0.4, "some": 0.28, "terribly": 0.01, "delicious": 1.2, "carrots": 0.8},
    "negative": {"I": 0.54, "had": 0.4, "some": 0.28, "terribly": 2.01, "delicious": 0.02, "carrots": 0.4}
}

GET my-index-000001/_search
{
  "query": {
    "term": {
      "impact": {
         "value": "delicious"
      }
    }
  }
}

```

There's no ELSER involved here.

---

<div class="post-metadata">

**Author:** ![Harsh\_Sonaiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsh_sonaiya/32/137750_2.png) [@Harsh\_Sonaiya](https://discuss.elastic.co/u/Harsh_Sonaiya)\
**Post date:** [September 20, 2024, 11:14am UTC](https://discuss.elastic.co/t/sparse-vectors/366856/11 "2024-09-20T11:14:13Z")

</div>

I tried it like this :

```auto
mappings = {
        "properties": {
            "title": {
                "type": "sparse_vector",
            },
            "content": {
                "type": "dense_vector",
                "dims": 384
            }
        }
    }

    # Create index with mapping
es_client.indices.create(index=index_name, mappings = mappings)

```

On executing this I got the error that sparse\_vector is not supported

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 20, 2024, 12:01pm UTC](https://discuss.elastic.co/t/sparse-vectors/366856/12 "2024-09-20T12:01:03Z")

</div>

I just tested the following on a new 8.16.0-SNAPSHOT cluster and it's all good:

```auto
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "text": {
        "type": "text",
        "analyzer": "standard"
      },
      "impact": {
        "type": "sparse_vector"
      },
      "positive": {
        "type": "sparse_vector"
      },
      "negative": {
        "type": "sparse_vector"
      }
    }
  }
}

```

So please first, test this in Kibana so we can know where to search.

Thanks

---

<div class="post-metadata">

**Author:** ![Harsh\_Sonaiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsh_sonaiya/32/137750_2.png) [@Harsh\_Sonaiya](https://discuss.elastic.co/u/Harsh_Sonaiya)\
**Post date:** [September 20, 2024, 12:26pm UTC](https://discuss.elastic.co/t/sparse-vectors/366856/13 "2024-09-20T12:26:50Z")

</div>

I will try in Kibana and let you know. I tried implementing it using Elasticsearch Python client like this :

```auto
from elasticsearch import Elasticsearch

index_name = 'temp1'
    # Define mappings for dense and sparse vectors
mappings = {
    "properties": {
      "text": {
        "type": "text",
        "analyzer": "standard"
      },
      "impact": {
        "type": "sparse_vector"
      },
      "positive": {
        "type": "sparse_vector"
      },
      "negative": {
        "type": "sparse_vector"
      }
    }
  }

    # Create index with mapping
es_client.indices.create(index=index_name, mappings = mappings)

```

And it gave the following error :

BadRequestError: BadRequestError(400, 'mapper\_parsing\_exception', 'Failed to parse mapping: The [sparse\_vector] field type is no longer supported.')

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 20, 2024, 1:28pm UTC](https://discuss.elastic.co/t/sparse-vectors/366856/14 "2024-09-20T13:28:11Z")

</div>

What is the version of the Python client?

---

<div class="post-metadata">

**Author:** ![Harsh\_Sonaiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsh_sonaiya/32/137750_2.png) [@Harsh\_Sonaiya](https://discuss.elastic.co/u/Harsh_Sonaiya)\
**Post date:** [September 20, 2024, 1:30pm UTC](https://discuss.elastic.co/t/sparse-vectors/366856/15 "2024-09-20T13:30:06Z")

</div>

Version: 8.15.1

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 20, 2024, 1:37pm UTC](https://discuss.elastic.co/t/sparse-vectors/366856/16 "2024-09-20T13:37:34Z")

</div>

I ran that on my side and got:

```auto
ObjectApiResponse({'acknowledged': True, 'shards_acknowledged': True, 'index': 'temp1'})

```

So I think there's something wrong in your code somewhere... Or may be you don't hit the right endpoint.

What is the output of:

```auto
es_client.info()

```

---

<div class="post-metadata">

**Author:** ![Harsh\_Sonaiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsh_sonaiya/32/137750_2.png) [@Harsh\_Sonaiya](https://discuss.elastic.co/u/Harsh_Sonaiya)\
**Post date:** [September 20, 2024, 2:23pm UTC](https://discuss.elastic.co/t/sparse-vectors/366856/17 "2024-09-20T14:23:53Z")

</div>

```auto
ObjectApiResponse({
    'name': 'bfd82a576095',
    'cluster_name': 'docker-cluster',
    'version': {
        'number': '8.8.0',
        'build_flavor': 'default',
        'build_date': '2023-05-23T17:16:07.179039820Z',
        'lucene_version': '9.6.0',
        'minimum_wire_compatibility_version': '7.17.0',
        'minimum_index_compatibility_version': '7.0.0'
    },
    'tagline': 'You Know, for Search'
})

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 20, 2024, 2:44pm UTC](https://discuss.elastic.co/t/sparse-vectors/366856/18 "2024-09-20T14:44:10Z")

</div>

It's now obvious that you are not using Elasticsearch 8.15.1 but 8.8.0.

---

<div class="post-metadata">

**Author:** ![Harsh\_Sonaiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harsh_sonaiya/32/137750_2.png) [@Harsh\_Sonaiya](https://discuss.elastic.co/u/Harsh_Sonaiya)\
**Post date:** [September 20, 2024, 2:50pm UTC](https://discuss.elastic.co/t/sparse-vectors/366856/19 "2024-09-20T14:50:55Z")

</div>

I checked that 8.8.0 has support for sparse vectors

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [September 20, 2024, 3:04pm UTC](https://discuss.elastic.co/t/sparse-vectors/366856/20 "2024-09-20T15:04:01Z")

</div>

> I checked that 8.8.0 has support for sparse vectors

Where? Because if you read the documentation I linked ([Sparse vector field type | Elasticsearch Guide [8.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.15/sparse-vector.html)), you will read:

> `sparse_vector` fields can not be included in indices that were **created** on Elasticsearch versions between 8.0 and 8.10

`sparse_vector` has been introduced in 8.11 AFAIK.

[Next page](https://discuss.elastic.co/t/sparse-vectors/366856.md?page=2)
