I’m using the multi2vec-clip
Vectorizer.
When calling it manually using this command, I get the following error:
$ curl localhost:8080/vectorize -d '{"texts": ["hello"], "images":[]}'
{"detail":[{"type":"model_attributes_type","loc":["body"],"msg":"Input should be a valid dictionary or object to extract fields from","input":"{\"texts\": [\"hello\"], \"images\":[]}","url":"https://errors.pydantic.dev/2.6/v/model_attributes_type"}]}
I am unsure how to proceed, as this command was taken from the documentation.
Documentation: multi2vec-clip | Weaviate - Vector Database
Hi @Mindaugas !!! Welcome to our community!
Nice catch!
I figured that that service will require the Content Type.
so this will work:
curl localhost:9090/vectorize -d '{"texts": ["hello"], "images":[]}' --header 'Content-Type: application/json'
Note: this is considering the model is exposed in 9090, by adding the port mapping:
multi2vec-clip: # Set the name of the inference container
ports:
- 9090:8080
image: cr.weaviate.io/semitechnologies/multi2vec-clip:sentence-transformers-clip-ViT-B-32-multilingual-v1
environment:
ENABLE_CUDA: 0 # set to 1 to enable
I had changed the docs:
weaviate:main
← weaviate:add-content-type-header-to-multi2vec-clip-curl-example
opened 06:53PM - 14 Jun 24 UTC
<!--
Thank you for contributing to this project! You must fill out the informat… ion below before we can review this pull request. We can triage your pull request to the best possible team for review if you explain why you're making a change (or linking to a pull request) and what changes you've made.
See our [CONTRIBUTING.md](/CONTRIBUTING.md) for information how to contribute.
Thanks again!
-->
### What's being changed:
fixing curl example, from discussion:
https://forum.weaviate.io/t/curl-localhost-8080-vectorize-doesnt-work/2707
### Type of change:
- [x] **Documentation** updates (non-breaking change to fix/update documentation)
- [ ] **Website** updates (non-breaking change to update main page, company pages, pricing, etc)
- [ ] **Content** updates – **blog**, **podcast** (non-breaking change to add/update content)
- [ ] **Bug fix** (non-breaking change to fixes an issue with the site)
- [ ] **Feature** or **enhancements** (non-breaking change to add functionality)
### How Has This Been Tested?
- [ ] **Github action** – automated build completed without errors
- [ ] **Local build** - the site works as expected when running `yarn start`
> note, you can run `yarn verify-links` to test site links locally
Also, a nice place to check for our inference models tests is here:
import unittest
import requests
import time
class SmokeTest(unittest.TestCase):
def setUp(self):
self.url = 'http://localhost:8000'
for i in range(0, 100):
try:
res = requests.get(self.url + '/.well-known/ready')
if res.status_code == 204:
return
else:
raise Exception(
"status code is {}".format(res.status_code))
except Exception as e:
print("Attempt {}: {}".format(i, e))
time.sleep(1)
This file has been truncated. show original
Let me know if this helps
1 Like
Thanks. Providing Content Type solved the issue.
Yeah, I forgot to check the tests
1 Like
On the same note, it looks like Go clients have the same Content-Type issue or similar. I’m getting the same errors when calling with Go Client.
See the source code:
texts, images []string, config ent.VectorizationConfig,
) (*ent.VectorizationResult, error) {
body, err := json.Marshal(vecRequest{
Texts: texts,
Images: images,
})
if err != nil {
return nil, errors.Wrapf(err, "marshal body")
}
req, err := http.NewRequestWithContext(ctx, "POST", v.url("/vectorize", config.InferenceURL),
bytes.NewReader(body))
if err != nil {
return nil, errors.Wrap(err, "create POST request")
}
res, err := v.httpClient.Do(req)
if err != nil {
return nil, errors.Wrap(err, "send POST request")
}
defer res.Body.Close()
I tried with this example commit, but I still see the same issue:
committed 08:07PM - 15 Jun 24 UTC
I added debug logging to the Clip-inference service to log all requests.
@app.post("/vectorize")
async def read_item(payload: ClipInput, response: Response):
try:
+ logger.info(f"Vectorizing data: {payload}")
result = await clip.vectorize(payload)
return {
"textVectors": result.text_vectors,
"imageVectors": result.image_vectors
}
And when doing curl, I see these logs:
INFO: 10.244.2.1:55684 - "GET /.well-known/ready HTTP/1.1" 204 No Content
INFO: Vectorizing data: texts=['hello'] images=[]
INFO: 127.0.0.1:34658 - "POST /vectorize HTTP/1.1" 200 OK
INFO: 10.244.2.1:55686 - "GET /.well-known/ready HTTP/1.1" 204 No Content
But when doing it with a GO client, it doesn’t hit the handler:
INFO: 10.244.2.1:58948 - "GET /.well-known/ready HTTP/1.1" 204 No Content
INFO: 10.244.1.44:59570 - "POST /vectorize HTTP/1.1" 422 Unprocessable Entity
INFO: 10.244.2.1:58962 - "GET /.well-known/ready HTTP/1.1" 204 No Content
More debug data. Using netcat as a listener:
This is what go client sends:
POST /vectorize HTTP/1.1
Host: localhost:444
User-Agent: Go-http-client/1.1
Content-Length: 32
Content-Type: application/json
Accept-Encoding: gzip
{"texts":["test"],"images":null}
And this is what curl client sends:
POST /vectorize HTTP/1.1
Host: localhost:444
User-Agent: curl/8.6.0
Accept: */*
Content-Type: application/json
Content-Length: 33
{"texts": ["hello"], "images":[]}
It looks very similar, so I’m baffled why Go clients don’t work.
Hi @Mindaugas !
You say that you were not able to use the clip with Weaviate?
I have updated our recipe here:
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Image Search with CLIP\n",
"This recipe demonstrates how build image search with `CLIP` model ([multi2vec-clip](https://weaviate.io/developers/weaviate/modules/retriever-vectorizer-modules/multi2vec-clip)).\n",
"\n",
"CLIP allows us to search through text and images."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Weaviate Setup\n",
"\n",
"The CLIP model is only available with local Weaviate deployments with Docker or Kubernetes.\n",
"\n",
This file has been truncated. show original
Can you check it out?
I was able to use it, using all latest versions
print("Server Version", client.get_meta().get("version"))
print("Client Version", weaviate.__version__)
>> Server Version 1.25.4
>> Client Version 4.6.4