Skip to content

API Reference parrot.embeddings.multimodal.base

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.embeddings.multimodal.base

View source

Multimodal Embedding Base ABC & Supporting Types.

Defines the abstract interface for multimodal embedding providers, supporting both text and image inputs in a shared vector space.

Class EmbeddingBackend

Runtime backend for multimodal inference.

Attributes:

Attribute Type Description
TORCH PyTorch backend (full precision, dev/GPU usage).
ONNX ONNX Runtime backend (lightweight, Knative serving).

Alias EmbeddingModel

Re-exported from parrot.embeddings.base.EmbeddingModel.

Class EmbeddingResult

Return type for all embed_* methods.

Parameter Type Default Description
embeddings np.ndarray
dimension int
quantization QuantizationMode
modality str

Fields:

Field Type Default Description
embeddings np.ndarray Embedding matrix of shape (N, dim).
dimension int Post-Matryoshka output dimension.
quantization QuantizationMode The quantization mode applied.
modality str Source modality: "text", "image", or "mixed".

Attribute ImageInput

Class MultimodalEmbedding

Modality-aware embedding provider ABC.

Extends :class:EmbeddingModel with image support and shared-space guarantees. Concrete providers (e.g. UFormEmbedding) inherit from this class and implement :meth:embed_text, :meth:embed_images, :meth:_create_embedding, and :meth:encode.

All outputs are L2-normalized so cosine similarity equals dot product. Text and image embeddings share the same dimension for a given model, enabling cross-modal retrieval in PgVector.

Parameter Type Default Description
model_name str Provider model identifier.
output_dim Optional[int] None Matryoshka truncation dimension. None = full model dim.
quantization QuantizationMode QuantizationMode.F32 Post-processing quantization mode (default F32).
**kwargs {} Extra arguments forwarded to :class:EmbeddingModel.

Method MultimodalEmbedding.embed_text

Embed a batch of text strings.

embed_text(texts: List[str]) -> EmbeddingResult

Parameter Type Default Description
texts List[str] List of text strings to embed.

Returns: EmbeddingResult — EmbeddingResult with modality="text".

Method MultimodalEmbedding.embed_images

Embed a batch of images.

Images are resolved via :func:resolve_image before encoding.

embed_images(images: List[ImageInput]) -> EmbeddingResult

Parameter Type Default Description
images List[ImageInput] List of image inputs (PIL.Image, bytes, or file paths).

Returns: EmbeddingResult — EmbeddingResult with modality="image".

Method MultimodalEmbedding.embed_documents

Route documents by modality to embed_text or embed_images.

Routing rules:

  • A document is treated as an image document if its metadata contains image_bytes, image_path, or image_url keys.
  • Otherwise it is treated as a text document (embedded via page_content).
  • Mixed batches (text + image) are handled by embedding each group separately and concatenating the results.

embed_documents(docs: List, batch_size: Optional[int] = None) -> EmbeddingResult

Parameter Type Default Description
docs List List of Document instances (parrot.stores.models.Document).
batch_size Optional[int] None Unused — present for signature compatibility with :meth:EmbeddingModel.embed_documents.

Returns: EmbeddingResult — EmbeddingResult with modality="text", "image", or "mixed".

Class QuantizationMode

Post-processing quantization mode for vector storage.

Attributes:

Attribute Type Description
F32 32-bit float (no quantization, passthrough).
F16 16-bit float (half precision).
I8 8-bit integer (maps embeddings to [-127, 127]).
B1 1-bit binary (sign quantization via packbits).

Function resolve_image

Resolve an ImageInput to a PIL.Image.Image.

Resolves the three accepted input types:

  • PIL.Image.Image: passthrough (returned as-is).
  • bytes: decoded via Image.open(BytesIO(data)).
  • str: treated as a local file path and loaded via Image.open(path). HTTP/HTTPS URLs are not supported; raise NotImplementedError.

resolve_image(input: ImageInput) -> 'PILImage.Image'

Parameter Type Default Description
input ImageInput One of PIL.Image.Image, bytes, or a local file path string.

Returns: 'PILImage.Image' — A PIL.Image.Image instance.

Raises:

  • FileNotFoundError — If a file path string points to a missing file.
  • NotImplementedError — If a string starting with http:// or https:// is provided. Pass a local path or use image_bytes instead.
  • OSError — If bytes cannot be decoded as an image.
  • TypeError — If the input type is not supported.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally