Files
lancedb/docs/web/integrations/embedding/openclip.mdx
T
TRexy eea95c8778 feat(python): support SigLIP image search with OpenCLIP (#5355)
## Summary

- Use the existing OpenCLIP provider with the SigLIP SO400M checkpoint
to embed image files and search them from Python.
- Accept filesystem path objects for vector queries and preserve Windows
drive letters and special characters in image ingestion paths. String
queries continue to use the text encoder.
- Add sync and async regression tests and a generated, runnable
documentation example.

Refs #4767

## Validation

- Embedding suite with 122 passing tests, CI-pinned Ruff, Linux-targeted
Pyright, and strict MkDocs.
- The real SigLIP checkpoint returned 1,152-dimensional unit-normalized
vectors and ranked the matching image first. The Windows smoke test used
the non-mapped safetensors reader and one shared model instance.
- Five row-address tests also failed with the preview native extension
on the unmodified base. The source-built CI run will cover these tests.
2026-12-02 12:43:07 +00:00

66 lines
2.7 KiB
Plaintext

---
title: OpenCLIP
sidebarTitle: OpenCLIP
---
import {
PyEmbeddingOpenclipSetup,
PyEmbeddingOpenclipTextSearch,
PyEmbeddingOpenclipImageSearch,
PyEmbeddingOpenclipSiglip,
} from '/snippets/integrations.mdx';
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 PyTorch device to run the model on, such as `"cpu"` or `"cuda"`. |
| `batch_size` | `int` | `64` | The number of images to process in a batch. |
| `normalize` | `bool` | `True` | Whether to normalize the output embeddings to unit length. |
This embedding function accepts image files, encoded image bytes, and URLs at ingestion. For vector search, pass text, a PIL image, or a path object such as `Path("frame.jpg")`. A string query is always treated as text.
<Info>
LanceDB supports ingesting images directly from accessible links.
</Info>
<CodeGroup>
<CodeBlock filename="Python" language="Python" icon="python">
{PyEmbeddingOpenclipSetup}
</CodeBlock>
</CodeGroup>
Now we can search using text from both the default vector column and the custom vector column
<CodeGroup>
<CodeBlock filename="Python" language="Python" icon="python">
{PyEmbeddingOpenclipTextSearch}
</CodeBlock>
</CodeGroup>
Because we're using a multimodal embedding function, we can also search using images
<CodeGroup>
<CodeBlock filename="Python" language="Python" icon="python">
{PyEmbeddingOpenclipImageSearch}
</CodeBlock>
</CodeGroup>
## Search video frames with SigLIP {#search-video-frames-with-siglip}
Use the [SigLIP SO400M checkpoint](https://huggingface.co/timm/ViT-SO400M-14-SigLIP-384) to generate 1,152-dimensional vectors for images and text. Install OpenCLIP and the tokenizer dependencies.
```bash
pip install "lancedb[clip]" "transformers[sentencepiece]"
```
The Python example starts with an extracted frame named `frame.jpg`. LanceDB Embedded fills the vector column when you add the frame.
<CodeGroup>
<CodeBlock filename="Python" language="Python" icon="python">
{PyEmbeddingOpenclipSiglip}
</CodeBlock>
</CodeGroup>
With `AsyncTable`, use `await table.search(frame, query_type="vector")` to build the image query. Use the same model and preprocessing for ingestion and search. If you switch from another embedding pipeline, regenerate the stored vectors unless you have verified compatibility.