MediaPipeTasksRetrieval Framework Reference

UniversalEmbedder

class UniversalEmbedder: NSObject, EmbeddingProvider

Performs multi-modal embedding extraction on text, image, audio, or custom content blocks.

This API wraps the native LiteRT-LM EmbeddingEngine directly, providing real on-device multimodal embeddings.

  • Utility function to compute cosine similarity between two embeddings.

    Declaration

    Swift

    class func cosineSimilarity(embedding1: Embedding, embedding2: Embedding) throws -> NSNumber

    Parameters

    embedding1

    One of the two embeddings between whom cosine similarity is to be computed.

    embedding2

    One of the two embeddings between whom cosine similarity is to be computed.

    error

    An optional error parameter populated when there is an error.

    Return Value

    An NSNumber holding the cosine similarity of type double.

  • Creates a new instance of MPPUniversalEmbedder from an absolute path to a model file stored locally on the device and the default options.

    Declaration

    Swift

    convenience init(modelPath: String) throws

    Parameters

    modelPath

    An absolute path to a model file stored locally on the device.

    error

    An optional error parameter populated when there is an error in initializing the universal embedder.

    Return Value

    A new instance of MPPUniversalEmbedder with the given model path. nil if there is an error.

  • Creates a new instance of MPPUniversalEmbedder from the given MPPUniversalEmbedderOptions.

    Declaration

    Swift

    init(options: UniversalEmbedderOptions) throws

    Parameters

    options

    The options to use for configuring the MPPUniversalEmbedder.

    error

    An optional error parameter populated when there is an error in initializing.

    Return Value

    A new instance of MPPUniversalEmbedder with the given options. nil if there is an error.

  • Performs embedding extraction on the input MPPAudioData.

    Declaration

    Swift

    func embed(audio audioData: AudioData) throws -> EmbeddingResult

    Parameters

    audioData

    The audio data object containing the audio samples.

    error

    An optional error parameter populated when there is an error.

    Return Value

    A MPPEmbeddingResult object that contains the embeddings.

  • Performs embedding extraction on the input audio float samples.

    Declaration

    Swift

    func embed(audioFloatBuffer audioData: MPPFloatBuffer) throws -> EmbeddingResult

    Parameters

    audioData

    The float buffer containing the audio samples.

    error

    An optional error parameter populated when there is an error.

    Return Value

    A MPPEmbeddingResult object that contains the embeddings.

  • Performs embedding extraction on multi-modal parts of a content block.

    Each element in the content array must be one of NSString, MPPImage, MPPAudioData, or MPPTaskPart (like MPPTextPart, MPPImagePart, MPPAudioPart).

    Declaration

    Swift

    func embed(content: [Any]) throws -> EmbeddingResult

    Parameters

    content

    An array of content objects or parts.

    error

    An optional error parameter populated when there is an error.

    Return Value

    A MPPEmbeddingResult object that contains the embeddings.

  • Performs embedding extraction on the input MPPImage (e.g. UIImage).

    Declaration

    Swift

    func embed(image: MPImage) throws -> EmbeddingResult

    Parameters

    image

    The image on which embedding extraction is to be performed.

    error

    An optional error parameter populated when there is an error.

    Return Value

    A MPPEmbeddingResult object that contains the embeddings.

  • Performs embedding extraction on the input image bytes (e.g. JPEG, PNG contents).

    Declaration

    Swift

    func embed(imageBytes: Data) throws -> EmbeddingResult

    Parameters

    imageBytes

    The raw compressed image data.

    error

    An optional error parameter populated when there is an error.

    Return Value

    A MPPEmbeddingResult object that contains the embeddings.

  • Performs embedding extraction on the input text.

    Declaration

    Swift

    func embed(text: String) throws -> EmbeddingResult

    Parameters

    text

    The string on which embedding extraction is to be performed.

    error

    An optional error parameter populated when there is an error.

    Return Value

    A MPPEmbeddingResult object that contains the embeddings.