UniversalEmbedder
class UniversalEmbedder: NSObject, EmbeddingProviderPerforms 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
Parameters
embedding1One of the two embeddings between whom cosine similarity is to be computed.
embedding2One of the two embeddings between whom cosine similarity is to be computed.
errorAn optional error parameter populated when there is an error.
Return Value
An
NSNumberholding the cosine similarity of typedouble. -
Creates a new instance of
MPPUniversalEmbedderfrom an absolute path to a model file stored locally on the device and the default options.Declaration
Swift
convenience init(modelPath: String) throwsParameters
modelPathAn absolute path to a model file stored locally on the device.
errorAn optional error parameter populated when there is an error in initializing the universal embedder.
Return Value
A new instance of
MPPUniversalEmbedderwith the given model path.nilif there is an error. -
Creates a new instance of
MPPUniversalEmbedderfrom the givenMPPUniversalEmbedderOptions.Declaration
Swift
init(options: UniversalEmbedderOptions) throwsParameters
optionsThe options to use for configuring the
MPPUniversalEmbedder.errorAn optional error parameter populated when there is an error in initializing.
Return Value
A new instance of
MPPUniversalEmbedderwith the given options.nilif there is an error. -
Performs embedding extraction on the input
MPPAudioData.Declaration
Swift
func embed(audio audioData: AudioData) throws -> EmbeddingResultParameters
audioDataThe audio data object containing the audio samples.
errorAn optional error parameter populated when there is an error.
Return Value
A
MPPEmbeddingResultobject that contains the embeddings. -
Performs embedding extraction on the input audio float samples.
Declaration
Swift
func embed(audioFloatBuffer audioData: MPPFloatBuffer) throws -> EmbeddingResultParameters
audioDataThe float buffer containing the audio samples.
errorAn optional error parameter populated when there is an error.
Return Value
A
MPPEmbeddingResultobject 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, orMPPTaskPart(likeMPPTextPart,MPPImagePart,MPPAudioPart).Declaration
Swift
func embed(content: [Any]) throws -> EmbeddingResultParameters
contentAn array of content objects or parts.
errorAn optional error parameter populated when there is an error.
Return Value
A
MPPEmbeddingResultobject that contains the embeddings. -
Performs embedding extraction on the input
MPPImage(e.g. UIImage).Declaration
Swift
func embed(image: MPImage) throws -> EmbeddingResultParameters
imageThe image on which embedding extraction is to be performed.
errorAn optional error parameter populated when there is an error.
Return Value
A
MPPEmbeddingResultobject that contains the embeddings. -
Performs embedding extraction on the input image bytes (e.g. JPEG, PNG contents).
Declaration
Swift
func embed(imageBytes: Data) throws -> EmbeddingResultParameters
imageBytesThe raw compressed image data.
errorAn optional error parameter populated when there is an error.
Return Value
A
MPPEmbeddingResultobject that contains the embeddings. -
Performs embedding extraction on the input text.
Declaration
Swift
func embed(text: String) throws -> EmbeddingResultParameters
textThe string on which embedding extraction is to be performed.
errorAn optional error parameter populated when there is an error.
Return Value
A
MPPEmbeddingResultobject that contains the embeddings.