# EmbeddingModel


```
interface EmbeddingModel
```

<br />

*** ** * ** ***

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

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

Typical usage:

```kotlin
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 functions |
|---|---|
| `suspend @https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/FeatureStatus https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingModel#checkStatus()()` Checks the current availability status of the embedding feature. |
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingModel#close()()` Releases resources associated with the underlying embedding engine. |
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/DownloadStatus>` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingModel#download()()` Downloads the required model assets for the embedding feature if they are not already available. |
| `suspend https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingResult` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingModel#generateEmbedding(com.google.mlkit.genai.embedding.EmbeddingRequest)(request: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingRequest)` Performs asynchronous content embedding on the provided input request. |
| `suspend https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingMetadata?` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingModel#getMetadata()()` Returns the `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingMetadata` of the embedding model, or `null` if metadata retrieval fails or is unavailable. |
| `suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingModel#getModelSignature()()` Returns the model signature uniquely identifying the underlying embedding model and version. |
| `suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingModel#getTokenLimit()()` Returns the maximum number of input tokens supported by this model in a single request. |
| `suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingModel#isDeprecated()()` Returns `true` if the model is currently deprecated. |
| `suspend https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developers.google.com/android/reference/kotlin/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/kotlin/com/google/mlkit/genai/embedding/EmbeddingModel#generateEmbedding(com.google.mlkit.genai.embedding.EmbeddingRequest)` call. |

## Public functions

### checkStatus

```
suspend fun checkStatus(): @FeatureStatus Int
```

Checks the current availability status of the embedding feature.

| Returns |
|---|---|
| `@https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/FeatureStatus https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | a `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/FeatureStatus` constant indicating the feature's readiness. |

### close

```
fun close(): Unit
```

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/kotlin/com/google/mlkit/genai/embedding/EmbeddingModel` instances returned by `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingGeneration#getEmbeddingModels(kotlin.String)`.

### download

```
fun download(): Flow<DownloadStatus>
```

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/kotlin/com/google/mlkit/genai/common/DownloadStatus.DownloadFailed` and terminates with the corresponding `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/common/GenAiException`.

| Returns |
|---|---|
| `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developers.google.com/android/reference/kotlin/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/kotlin/com/google/mlkit/genai/common/DownloadStatus` updates for download progress. |

### generateEmbedding

```
suspend fun generateEmbedding(request: EmbeddingRequest): EmbeddingResult
```

Performs asynchronous content embedding on the provided input request.

| Parameters |
|---|---|
| `request: https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingRequest` | the `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingRequest` containing input `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/Content` and optional `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/TaskConfig`. |

| Returns |
|---|---|
| `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingResult` | an `https://developers.google.com/android/reference/kotlin/com/google/mlkit/genai/embedding/EmbeddingResult` containing the generated embedding vector and model signature. |

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

### getMetadata

```
suspend fun getMetadata(): EmbeddingMetadata?
```

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

### getModelSignature

```
suspend fun getModelSignature(): String
```

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://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | the model signature string. |

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

### getTokenLimit

```
suspend fun getTokenLimit(): Int
```

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | 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/kotlin/com/google/mlkit/genai/common/GenAiException` | if retrieving the token limit fails. |

### isDeprecated

```
suspend fun isDeprecated(): Boolean
```

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/kotlin/com/google/mlkit/genai/embedding/EmbeddingMetadata#deprecationDate()`. Returns `false` if model metadata or the deprecation date is unavailable.

### warmup

```
suspend fun warmup(): Unit
```

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/kotlin/com/google/mlkit/genai/embedding/EmbeddingModel#generateEmbedding(com.google.mlkit.genai.embedding.EmbeddingRequest)` call.

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