EmbeddingInput constructor

EmbeddingInput({
  1. String? text,
  2. List<Uint8List> images = const [],
  3. Uint8List? audio,
})

Several parts in one vector: optional text, any images and an optional audio clip — for example a photo with its caption.

Throws ArgumentError for an input with no part, or for an empty byte array among images or in audio. Empty text is valid, as in EmbeddingInput.text.

The order of the parts within the vector is fixed — text, then the images in order, then the audio — whatever order the arguments are written in. An input with more than one part — several modalities, or several images — is a combined input: a model whose engine embeds one part per vector refuses it with UnsupportedEmbeddingCombinationException, before anything is sent. Which engines combine parts is engine-defined (EmbeddingGemma 2 through flutter_edge_ai_litertlm does, natively and, from 1.13.2, on the web).

Implementation

factory EmbeddingInput({
  String? text,
  List<Uint8List> images = const [],
  Uint8List? audio,
}) {
  if (text == null && images.isEmpty && audio == null) {
    throw ArgumentError('An EmbeddingInput needs at least one part.');
  }
  for (final image in images) {
    _requireBytes(image, 'images');
  }
  if (audio != null) _requireBytes(audio, 'audio');
  return EmbeddingInput._(text: text, images: images, audio: audio);
}