# compare them
def calculate_similarity(a, b):
    return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))


print(
    f"For the following sentences:\n1: {phrases[0]}\n2: {phrases[1]}n\3: The similarity score is: {calculate_similarity(soup1, soup2):.2f}\n"
)
print(
    f"For the following sentences:\n1: {phrases[0]}\n2: {phrases[2]}n\3: The similarity score is: {calculate_similarity(soup1, london):.2f}"
)
```

## The `input_type` parameter

Cohere embeddings are optimized for different types of inputs.

* When using embeddings for [semantic search](/docs/semantic-search), the search query should be embedded by setting `input_type="search_query"`
* When using embeddings for semantic search, the text passages that are being searched over should be embedded with `input_type="search_document"`.
* When using embedding for `classification` and `clustering` tasks, you can set `input_type` to either 'classification' or 'clustering' to optimize the embeddings appropriately.
* When `input_type='image'` for `embed-v3.0`, the expected input to be embedded is an image instead of text. If you use `input_type=images` with `embed-v4.0` it will default to `search_document`. We recommend using `search_document` when working with `embed-v4.0`.

## Multilingual Support

`embed-v4.0` is a best-in-class best-in-class multilingual model with support for over 100 languages, including Korean, Japanese, Arabic, Chinese, Spanish, and French.

```python PYTHON
import cohere

co = cohere.ClientV2(api_key="YOUR_API_KEY")

texts = [
    "Hello from Cohere!",
    "مرحبًا من كوهير!",
    "Hallo von Cohere!",
    "Bonjour de Cohere!",
    "¡Hola desde Cohere!",
    "Olá do Cohere!",
    "Ciao da Cohere!",
    "您好，来自 Cohere！",
    "कोहेरे से नमस्ते!",
]

response = co.embed(
    model="embed-v4.0",
    texts=texts,
    input_type="classification",
    output_dimension=1024,
    embedding_types=["float"],
)

embeddings = response.embeddings.float  # All text embeddings
print(embeddings[0][:5])  # Print embeddings for the first text
```

## Image Embeddings

The Cohere Embedding platform supports image embeddings for `embed-v4.0` and the `embed-v3.0` family. There are two ways to access this functionality:

* Pass `image` to the `input_type` parameter. Here are the steps:
  * Pass image to the `input_type` parameter
  * Pass your image URL to the images parameter
* Pass your image URL to the new `images` parameter. Here are the steps:
  * Pass in a input list of `dicts` with the key content
  * content contains a list of `dicts` with the keys `type` and `image`

When using the `images` parameter the following restrictions exist:

* Pass `image` to the `input_type` parameter (as discussed above).
* Pass your image URL to the new `images` parameter.

Be aware that image embedding has the following restrictions:

* If `input_type='image'`, the `texts` field must be empty.
* The original image file type must be in a `png`, `jpeg`, `webp`, or `gif` format and can be up to 5 MB in size.
* The image must be base64 encoded and sent as a Data URL to the `images` parameter.
* Our API currently does not support batch image embeddings for `embed-v3.0` models. For `embed-v4.0`, however, you can submit up to 96 images.

When using the `inputs` parameter the following restrictions exist (note these restrictions apply to `embed-v4.0`):

* The maximum size of payload is 20mb
* All images larger than 2,458,624 pixels will be downsampled to 2,458,624 pixels
* All images smaller than 3,136 (56x56) pixels will be upsampled to 3,136 pixels
* `input_type` must be set to one of the following
  * `search_query`
  * `search_document`
  * `classification`
  * `clustering`

Here's a code sample using the `inputs` parameter:

```python PYTHON
import cohere
from PIL import Image
from io import BytesIO
import base64

co = cohere.ClientV2(api_key="YOUR_API_KEY")