# 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.
- `
  ### [cosineSimilarity(embedding1:embedding2:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/UniversalEmbedder.md.txt#/c:objc(cs)MPPUniversalEmbedder(cm)cosineSimilarityBetweenEmbedding1:andEmbedding2:error:)

  ` 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. |

  #### Return Value

  An `NSNumber` holding the cosine similarity of type `double`.
- `
  ### [init(modelPath:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/UniversalEmbedder.md.txt#/c:objc(cs)MPPUniversalEmbedder(im)initWithModelPath:error:)

  ` 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. |

  #### Return Value

  A new instance of `MPPUniversalEmbedder` with the given model path. `nil` if there is an error.
- `
  ### [init(options:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/UniversalEmbedder.md.txt#/c:objc(cs)MPPUniversalEmbedder(im)initWithOptions: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`. |

  #### Return Value

  A new instance of `MPPUniversalEmbedder` with the given options. `nil` if there is an error.
- `
  ### [embed(audio:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/UniversalEmbedder.md.txt#/c:objc(cs)MPPUniversalEmbedder(im)embedAudio: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. |

  #### Return Value

  A `MPPEmbeddingResult` object that contains the embeddings.
- `
  ### [embed(audioFloatBuffer:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/UniversalEmbedder.md.txt#/c:objc(cs)MPPUniversalEmbedder(im)embedAudioFloatBuffer:error:)

  ` 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. |

  #### Return Value

  A `MPPEmbeddingResult` object that contains the embeddings.
- `
  ### [embed(content:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/UniversalEmbedder.md.txt#/c:objc(cs)MPPUniversalEmbedder(im)embedContent:error:)

  ` 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. |

  #### Return Value

  A `MPPEmbeddingResult` object that contains the embeddings.
- `
  ### [embed(image:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/UniversalEmbedder.md.txt#/c:objc(cs)MPPUniversalEmbedder(im)embedImage:error:)

  ` 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. |

  #### Return Value

  A `MPPEmbeddingResult` object that contains the embeddings.
- `
  ### [embed(imageBytes:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/UniversalEmbedder.md.txt#/c:objc(cs)MPPUniversalEmbedder(im)embedImageBytes:error:)

  ` 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. |

  #### Return Value

  A `MPPEmbeddingResult` object that contains the embeddings.
- `
  ### [embed(text:)](https://developers.google.com/edge/api/mediapipe/swift/retrieval/Classes/UniversalEmbedder.md.txt#/c:objc(cs)MPPUniversalEmbedder(im)embedText:error:)

  ` 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. |

  #### Return Value

  A `MPPEmbeddingResult` object that contains the embeddings.