> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lancedb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenCLIP

We support CLIP model embeddings using the open source alternative, [open-clip](https://github.com/mlfoundations/open_clip) which supports various customizations. It is registered as `open-clip` and supports the following customizations:

| Parameter | Type | Default Value | Description |
| - | - | - | - |
| `name` | `str` | `"ViT-B-32"` | The name of the model. |
| `pretrained` | `str` | `"laion2b_s34b_b79k"` | The name of the pretrained model to load. |
| `device` | `str` | `"cpu"` | The device to run the model on. Can be `"cpu"` or `"gpu"`. |
| `batch_size` | `int` | `64` | The number of images to process in a batch. |
| `normalize` | `bool` | `True` | Whether to normalize the input images before feeding them to the model. |

This embedding function supports ingesting images as both bytes and urls. You can query them using both text and other images.

> [!NOTE]
>
> LanceDB supports ingesting images directly from accessible links.

import tempfile
from pathlib import Path

import lancedb
import pandas as pd
import requests
from lancedb.embeddings import get\_registry
from lancedb.pydantic import LanceModel, Vector

db = lancedb.connect(str(Path(tempfile.mkdtemp()) / "openclip-demo"))
func = get\_registry().get("open-clip").create()

class Images(LanceModel):
&#x20;   label: str
&#x20;   image\_uri: str = func.SourceField()
&#x20;   image\_bytes: bytes = func.SourceField()
&#x20;   vector: Vector(func.ndims()) = func.VectorField()
&#x20;   vec\_from\_bytes: Vector(func.ndims()) = func.VectorField()

table = db.create\_table("images", schema=Images)
labels = \["cat", "cat", "dog", "dog", "horse", "horse"]
uris = \[
&#x20;   "http\://farm1.staticflickr.com/53/167798175\_7c7845bbbd\_z.jpg",
&#x20;   "http\://farm1.staticflickr.com/134/332220238\_da527d8140\_z.jpg",
&#x20;   "http\://farm9.staticflickr.com/8387/8602747737\_2e5c2a45d4\_z.jpg",
&#x20;   "http\://farm5.staticflickr.com/4092/5017326486\_1f46057f5f\_z.jpg",
&#x20;   "http\://farm9.staticflickr.com/8216/8434969557\_d37882c42d\_z.jpg",
&#x20;   "http\://farm6.staticflickr.com/5142/5835678453\_4f3a4edb45\_z.jpg",
]
image\_bytes = \[requests.get(uri).content for uri in uris]
table.add(
&#x20;   pd.DataFrame(\{"label": labels, "image\_uri": uris, "image\_bytes": image\_bytes})
)


Now we can search using text from both the default vector column and the custom vector column

actual = table.search("man's best friend").limit(1).to\_pydantic(Images)\[0]
print(actual.label)

frombytes = (
&#x20;   table.search("man's best friend", vector\_column\_name="vec\_from\_bytes")
&#x20;   .limit(1)
&#x20;   .to\_pydantic(Images)\[0]
)
print(frombytes.label)


Because we're using a multimodal embedding function, we can also search using images

import io

from PIL import Image

query\_image\_uri = "http\://farm1.staticflickr.com/200/467715466\_ed4a31801f\_z.jpg"
image\_bytes = requests.get(query\_image\_uri).content
query\_image = Image.open(io.BytesIO(image\_bytes))
actual = table.search(query\_image).limit(1).to\_pydantic(Images)\[0]
print(actual.label == "dog")

other = (
&#x20;   table.search(query\_image, vector\_column\_name="vec\_from\_bytes")
&#x20;   .limit(1)
&#x20;   .to\_pydantic(Images)\[0]
)
print(other.label)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.