mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
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.
This commit is contained in:
@@ -7,6 +7,7 @@ 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:
|
||||
@@ -15,11 +16,11 @@ We support CLIP model embeddings using the open source alternative, [open-clip](
|
||||
|---|---|---|---|
|
||||
| `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"`. |
|
||||
| `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 input images before feeding them to the model. |
|
||||
| `normalize` | `bool` | `True` | Whether to normalize the output embeddings to unit length. |
|
||||
|
||||
This embedding function supports ingesting images as both bytes and urls. You can query them using both text and other images.
|
||||
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.
|
||||
@@ -44,3 +45,21 @@ Because we're using a multimodal embedding function, we can also search using im
|
||||
{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.
|
||||
|
||||
Reference in New Issue
Block a user