Skip to content

pixano_inference.models.embedding

Embedding model base class.

A single capability that embeds either an image or text into a shared vector space (CLIP-style), so image and text embeddings are directly comparable (text-to-image search). The I/O types live in :mod:pixano_inference_client.embedding and are re-exported here so from pixano_inference.models.embedding import EmbeddingInput keeps working.

EmbeddingModel(config)

Bases: InferenceModel

Base class for image/text embedding models (CLIP-style shared space).

Example
@register_model("my-embedder")
class MyEmbedder(EmbeddingModel):
    def load_model(self):
        self.model = load_weights(self.config.model_params["path"])

    def predict(self, input: EmbeddingInput) -> EmbeddingOutput:
        vectors = self.model.encode(input.image or input.text)
        return EmbeddingOutput(embeddings=NDArrayFloat.from_numpy(vectors), dim=vectors.shape[-1])
Source code in pixano_inference/models/base.py
def __init__(self, config: ModelDeploymentConfig) -> None:
    """Initialize the model with deployment config.

    Args:
        config: Model deployment configuration.
    """
    self._config = config

predict(input) abstractmethod

Compute embeddings for the given image(s) or text(s).

Parameters:

Name Type Description Default
input EmbeddingInput

Embedding input with exactly one of image/text.

required

Returns:

Type Description
EmbeddingOutput

Embedding output with a [num_inputs, dim] vector array.

Source code in pixano_inference/models/embedding.py
@abstractmethod
def predict(self, input: EmbeddingInput) -> EmbeddingOutput:
    """Compute embeddings for the given image(s) or text(s).

    Args:
        input: Embedding input with exactly one of image/text.

    Returns:
        Embedding output with a ``[num_inputs, dim]`` vector array.
    """