# Vector Embeddings for Images

**URL:** <https://forum.weaviate.io/t/vector-embeddings-for-images/2948>\
**Category:** Showcase\
**Created:** [July 5, 2024, 9:17am UTC](https://forum.weaviate.io/t/vector-embeddings-for-images/2948 "2024-07-05T09:17:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Balachandar\_Ganesan](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/balachandar_ganesan/32/1652_2.png) [@Balachandar\_Ganesan](https://forum.weaviate.io/u/Balachandar_Ganesan)\
**Post date:** [July 5, 2024, 9:17am UTC](https://forum.weaviate.io/t/vector-embeddings-for-images/2948/1 "2024-07-05T09:17:17Z")

</div>

> **[imgbeddings](https://pypi.org/project/imgbeddings/)**
>
> A Python package to generate image embeddings with CLIP without PyTorch/TensorFlow

imgbeddings helps to generate vectors for a given image. Used the following code for generating vector for an image given an URL . Works well.

```auto
def VectorOfImage(strURL):
    import requests
    from PIL import Image
    url = strURL
    image = Image.open(requests.get(url, stream=True).raw)
    from imgbeddings import imgbeddings
    ibed = imgbeddings()
    embedding = ibed.to_embeddings(image)
    #query_vector=list(embedding.flatten())
    vector = embedding.flatten().tolist()
    return vector

```

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [July 5, 2024, 2:09pm UTC](https://forum.weaviate.io/t/vector-embeddings-for-images/2948/2 "2024-07-05T14:09:36Z")

</div>

Hi @Balachandar_Ganesan !!

THanks! I have edited your post and formatted the code 🙂

---

<div class="post-metadata">

**Author:** ![Balachandar\_Ganesan](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/balachandar_ganesan/32/1652_2.png) [@Balachandar\_Ganesan](https://forum.weaviate.io/u/Balachandar_Ganesan)\
**Post date:** [July 5, 2024, 2:52pm UTC](https://forum.weaviate.io/t/vector-embeddings-for-images/2948/3 "2024-07-05T14:52:54Z")

</div>

Apparently list(embedding.flatten()) method worked for inserting the vectors into weaviate but when I called the query method it did not. There is some inconsistency between insert and query. A similar problem I faced when I did embedding with NLP,FastText as well. Deep down I guess there is some inconsistency in processing the vectors even if they are generated by same function between insert and query  
Invalid input provided: The number of target vectors must be equal to the number of vectors… Can one from your team look into this?.

---

<div class="post-metadata">

**Author:** ![DudaNogueira](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/dudanogueira/32/7846_2.png) [@DudaNogueira](https://forum.weaviate.io/u/DudaNogueira)\
**Post date:** [July 5, 2024, 5:01pm UTC](https://forum.weaviate.io/t/vector-embeddings-for-images/2948/4 "2024-07-05T17:01:55Z")

</div>

Sure!

Do you have a code where I could reproduce it end to end?

---

<div class="post-metadata">

**Author:** ![Balachandar\_Ganesan](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.weaviate.io/balachandar_ganesan/32/1652_2.png) [@Balachandar\_Ganesan](https://forum.weaviate.io/u/Balachandar_Ganesan)\
**Post date:** [July 6, 2024, 8:09am UTC](https://forum.weaviate.io/t/vector-embeddings-for-images/2948/5 "2024-07-06T08:09:02Z")

</div>

> <https://github.com/Balachandar-Ganesan/weaviate/blob/main/006-ReverseImageSearch.ipynb>

You can see the full code here I have used the cloud version.Code contains steps needed for creating, generating vector embedding and querying.  
query\_vector=list(embedding.flatten()) works for inserting but not for querying  
vector = embedding.flatten().tolist() works both the ways. Similar problem experienced for NLP text vector embedding as well.

Also if you can show me how I can change the code for leveraging async support for new client, it would be great (I already have new python client installed)
