Skip to content

Embedder

siglip2_toolkit.embedder.Embedder

Embedder(
    model,
    device="auto",
    dtype=None,
    trust_remote_code=False,
    model_id=None,
)

Generates text and image embeddings with a SigLIP 2 model.

model is a local model directory; model_id is the identifier recorded in logs and in the embedding-space manifest (defaults to the path). Load the model from the toolkit cache with siglip2_toolkit.models.resolve_model.

Embeddings are L2-normalised float32 numpy arrays. The instance is safe to share across threads (inference is serialised with an internal lock); it is not safe to share across processes.

device property

device

Device string (e.g. "cuda"/"cpu"), or None if not loaded.

dimensions property

dimensions

Embedding dimension, or None if the model has not been loaded.

load

load()

Load the model and processor from the local directory (idempotent).

embedding_space

embedding_space()

The embedding space manifest for the loaded model.

embed_texts

embed_texts(texts, batch_size=32, max_length=64)

Embed a batch of texts. Returns a (n, dimensions) float32 array.

embed_text

embed_text(text)

Embed a single text. Returns a (dimensions,) float32 array.

embed_images

embed_images(
    images,
    batch_size=32,
    on_error="raise",
    return_indices=False,
)

Embed a batch of images.

images items may be paths, bytes, file-like objects or PIL images. With on_error="skip" unreadable items are logged and skipped; the kept positions are returned alongside the matrix when return_indices=True.

embed_image

embed_image(image)

Embed a single image. Returns a (dimensions,) float32 array.

zero_shot_logits

zero_shot_logits(
    images, labels, template="{}", batch_size=32
)

Raw zero-shot classification logits, shaped (n_images, n_labels).

Scores follow the SigLIP recipe: cosine similarity between normalised embeddings, scaled by the model's learned logit_scale and shifted by logit_bias. template wraps each label ({} is replaced by the label). When the model has no learned scale (non-SigLIP checkpoints), a CLIP-style temperature of 100 is used.

classify

classify(
    images, labels, template="{}", top_k=None, batch_size=32
)

Zero-shot image classification.

Returns, for each image, (label, probability) pairs sorted by decreasing softmax probability over the candidate labels (mutually exclusive assumption). Use zero_shot_logits when you need the raw scores for custom decision rules.