> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/deploy/supported-models/perception-encoder.md).

# Perception Encoder

Perception Encoder is Meta's vision-language embedding model. It maps images and text into a shared embedding space for similarity search, zero-shot classification, and retrieval.

{% hint style="info" %}
Perception Encoder is not available on the Serverless Hosted API. Run it on a [Dedicated Deployment](/deploy/dedicated-deployments.md) or [self-hosted Inference](https://inference.roboflow.com/).
{% endhint %}

We support three Perception Encoder endpoints:

* `/perception_encoder/embed_image` — embed an image
* `/perception_encoder/embed_text` — embed a string
* `/perception_encoder/compare` — compute similarity between an image and a list of text prompts

## Code sample

{% stepper %}
{% step %}

### Get your API Key

Create a Roboflow account, find your key on the [Roboflow API settings page](https://app.roboflow.com/settings/api) and make it available to your shell:

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

### Install the dependencies

These packages fetch the image and call the API:

```bash
pip install requests opencv-python
```

{% endstep %}

{% step %}

### Run the model

The sample below sends an image to `/perception_encoder/embed_image` and prints the embedding shape. Set `URL` to your Dedicated Deployment URL or a local Inference server.

```python
import base64
import os
import cv2
import numpy as np
import requests

URL = "https://your-deployment.roboflow.cloud"

content = requests.get("https://media.roboflow.com/notebooks/examples/dog.jpeg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)

_, buffer = cv2.imencode(".jpg", image)
image_base64 = base64.b64encode(buffer).decode("utf-8")

response = requests.post(
    f"{URL}/perception_encoder/embed_image",
    json={
        "api_key": os.environ["ROBOFLOW_API_KEY"],
        "image": {"type": "base64", "value": image_base64},
    },
)
result = response.json()
embedding = result["embeddings"][0]
print(f"Embedding length: {len(embedding)}")
print(f"First values: {embedding[:5]}")
```

{% endstep %}
{% endstepper %}

The code above prints the embedding shape to the terminal:

```
Embedding length: 1024
First values: [0.0545, -0.0338, -0.0355, -0.0062, 0.0154]
```

## Inference speed

Latency measured with [Roboflow Inference](https://inference.roboflow.com/) on 1x NVIDIA L4, batch size 1, mean after warmup.

<table data-search="false"><thead><tr><th>Model</th><th>Latency (ms)</th></tr></thead><tbody><tr><td><code>perception-encoder</code></td><td>25.2</td></tr></tbody></table>

Measured with `embed_image` on the `PE-Core-L14-336` checkpoint (image embedding only).

{% hint style="info" %}
Set `URL` to match your deployment target:

* `http://localhost:9001` for a local [Inference](https://inference.roboflow.com/) server.
* Your [Dedicated Deployment](/deploy/dedicated-deployments.md) URL for a private endpoint.
  {% endhint %}
