# EmbeddingModel


```
public interface EmbeddingModel
```

<br />

*** ** * ** ***

Provides an interface for generating embeddings for text and multimodal `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/Content`.

Obtain instances via `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingGeneration#getEmbeddingModels(kotlin.String)`, and call `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#close()` when the model is no longer needed to release underlying resources.

Typical usage:

```
val models = EmbeddingGeneration.getEmbeddingModels()
val model = models.firstOrNull() ?: return
models.drop(1).forEach { it.close() }
try {
  if (model.checkStatus() == FeatureStatus.DOWNLOADABLE) {
    model.download().collect()
  }
  val request = EmbeddingRequest(
    Content(listOf(TextPart("What is machine learning?"))),
    TaskConfig.RetrievalQuery(),
  )
  val result = model.generateEmbedding(request)
  val vector = result.embedding.vector
} finally {
  model.close()
}
```

## Summary

| ### Public methods |
|---|---|
| `abstract @https://developers.google.com/android/reference/com/google/mlkit/genai/common/FeatureStatus int` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#checkStatus()()` Checks the current availability status of the embedding feature. |
| `abstract void` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#close()()` Releases resources associated with the underlying embedding engine. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/common/DownloadStatus>` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#download()()` Downloads the required model assets for the embedding feature if they are not already available. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingResult` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#generateEmbedding(com.google.mlkit.genai.embedding.EmbeddingRequest)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingRequest request)` Performs asynchronous content embedding on the provided input request. |
| `abstract https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingMetadata` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#getMetadata()()` Returns the `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingMetadata` of the embedding model, or `null` if metadata retrieval fails or is unavailable. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#getModelSignature()()` Returns the model signature uniquely identifying the underlying embedding model and version. |
| `abstract int` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#getTokenLimit()()` Returns the maximum number of input tokens supported by this model in a single request. |
| `abstract boolean` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#isDeprecated()()` Returns `true` if the model is currently deprecated. |
| `abstract void` | `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#warmup()()` Warms up the inference engine for use by loading necessary models and initializing runtime components, reducing latency for the first `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#generateEmbedding(com.google.mlkit.genai.embedding.EmbeddingRequest)` call. |

## Public methods

### checkStatus

```
abstract @FeatureStatus int checkStatus()
```

Checks the current availability status of the embedding feature.

| Returns |
|---|---|
| `@https://developers.google.com/android/reference/com/google/mlkit/genai/common/FeatureStatus int` | a `https://developers.google.com/android/reference/com/google/mlkit/genai/common/FeatureStatus` constant indicating the feature's readiness. |

### close

```
abstract void close()
```

Releases resources associated with the underlying embedding engine.

Callers should invoke this method when the model is no longer needed, including on any unused `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel` instances returned by `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingGeneration#getEmbeddingModels(kotlin.String)`.

### download

```
abstract @NonNull Flow<@NonNull DownloadStatus> download()
```

Downloads the required model assets for the embedding feature if they are not already available.

The download starts when the returned cold `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` is collected. If the download fails, the flow emits `https://developers.google.com/android/reference/com/google/mlkit/genai/common/DownloadStatus.DownloadFailed` and terminates with the corresponding `https://developers.google.com/android/reference/com/google/mlkit/genai/common/GenAiException`.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/common/DownloadStatus>` | a cold `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` that emits `https://developers.google.com/android/reference/com/google/mlkit/genai/common/DownloadStatus` updates for download progress. |

### generateEmbedding

```
abstract @NonNull EmbeddingResult generateEmbedding(@NonNull EmbeddingRequest request)
```

Performs asynchronous content embedding on the provided input request.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingRequest request` | the `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingRequest` containing input `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/Content` and optional `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/TaskConfig`. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingResult` | an `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingResult` containing the generated embedding vector and model signature. |

| Throws |
|---|---|
| `https://developers.google.com/android/reference/com/google/mlkit/genai/common/GenAiException` | if embedding generation fails or the request content is invalid. |

### getMetadata

```
abstract EmbeddingMetadata getMetadata()
```

Returns the `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingMetadata` of the embedding model, or `null` if metadata retrieval fails or is unavailable.

### getModelSignature

```
abstract @NonNull String getModelSignature()
```

Returns the model signature uniquely identifying the underlying embedding model and version.

Embeddings generated by models with different signatures are incompatible and should not be directly compared. Callers that persist embeddings should store this signature alongside the vectors to detect model updates and re-index when the signature changes.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | the model signature string. |

| Throws |
|---|---|
| `https://developers.google.com/android/reference/com/google/mlkit/genai/common/GenAiException` | if retrieving the model signature fails. |

### getTokenLimit

```
abstract int getTokenLimit()
```

Returns the maximum number of input tokens supported by this model in a single request.

| Returns |
|---|---|
| `int` | the maximum input token capacity, `-1` if the token limit is unknown, or `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/-m-a-x_-v-a-l-u-e.html` if there is no token limit restriction. |

| Throws |
|---|---|
| `https://developers.google.com/android/reference/com/google/mlkit/genai/common/GenAiException` | if retrieving the token limit fails. |

### isDeprecated

```
abstract boolean isDeprecated()
```

Returns `true` if the model is currently deprecated.

A model is considered deprecated if the current UTC date is on or after `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingMetadata#deprecationDate()`. Returns `false` if model metadata or the deprecation date is unavailable.

### warmup

```
abstract void warmup()
```

Warms up the inference engine for use by loading necessary models and initializing runtime components, reducing latency for the first `https://developers.google.com/android/reference/com/google/mlkit/genai/embedding/EmbeddingModel#generateEmbedding(com.google.mlkit.genai.embedding.EmbeddingRequest)` call.

| Throws |
|---|---|
| `https://developers.google.com/android/reference/com/google/mlkit/genai/common/GenAiException` | if initializing the inference engine fails. |