Send image as base64 encoded

#24
by Zarazas - opened

It would be nice if I could send the image as a base64 encoded string. that would improve the latency to transform an image of a user

Hey @Zarazas ! Have you tried

model.encode_image("data:image/jpeg;base64,BASE64_STREAM")

?

I am currently using the model with your api, like:

export const convertImageToVector = async (url: string) => {
  const data = {
    model: "jina-clip-v2",
    dimensions: 1024,
    normalized: true,
    embedding_type: "float",
    input: [{ image: url }],
  }

  const options = {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization:
        "Bearer  <KEY>",
    },
    body: JSON.stringify(data),
  }

  const res = await fetch("https://api.jina.ai/v1/embeddings", options).then(
    (response) => response.json(),
  )

  if (res.detail) {
    return {
      error: res.detail,
    }
  }

  return res.data[0].embedding
}

From what I could find about the docs of your api (btw I love the API explorer, but a classic api reference would be great too) I can only submit a url. Currently I need to wait for the image to be uplaoded to s3 so that I can then send it to jina, which increases latency by a good amount. I was also looking at the aws sagemaker and I think replicate, but they all only show it using a url

Hey @Zarazas ,
You can find an extensive redoc documentation of our API here.

You can send a base64 image to the embeddings API, by replacing "url" with "bytes" in the input.

Awesome, will give it a try. You should think about a more visible/prominent way of linking those docs on your landing page imo. I was looking around for quite some time and couldnt find it

Zarazas changed discussion status to closed

Sign up or log in to comment