# EmbeddingVector

Artifact: [androidx.appsearch:appsearch](https://developer.android.com/jetpack/androidx/releases/appsearch) [View Source](https://cs.android.com/search?q=file:androidx/appsearch/app/EmbeddingVector.java+class:androidx.appsearch.app.EmbeddingVector) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

*** ** * ** ***


```
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_EMBEDDING_PROPERTY_CONFIG)
class EmbeddingVector
```

<br />

*** ** * ** ***

Embeddings are vector representations of data, such as text, images, and audio, which can be generated by machine learning models and used for semantic search. This class represents an embedding vector, which wraps a float array for the values of the embedding vector and a model signature that can be any string to distinguish between embedding vectors generated by different models.

For more details on how embedding search works, check `https://developer.android.com/reference/kotlin/androidx/appsearch/app/AppSearchSession#search(java.lang.String,androidx.appsearch.app.SearchSpec)` and `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec.Builder#setRankingStrategy(java.lang.String)`.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/SearchSpec.Builder#addEmbeddingParameters(androidx.appsearch.app.EmbeddingVector...)` |   |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/GenericDocument.Builder#setPropertyEmbedding(java.lang.String,androidx.appsearch.app.EmbeddingVector...)` |   |

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi class https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector.QuantizedData` Holds the pre-quantized embedding values along with the quantization parameters. |

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi @https://developer.android.com/reference/kotlin/androidx/annotation/RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = https://developer.android.com/reference/kotlin/androidx/appsearch/app/Features.SCHEMA_EMBEDDING_PRE_QUANTIZED_DATA) https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector#EmbeddingVector(androidx.appsearch.app.EmbeddingVector.QuantizedData,java.lang.String)( quantizedData: https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector.QuantizedData, modelSignature: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html )` Creates a new `https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector` from pre-quantized embedding data. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector#EmbeddingVector(float[],java.lang.String)(values: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>, modelSignature: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Creates a new `https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector` containing standard 32-bit float values. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector#equals(java.lang.Object)(o: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector#getModelSignature()()` Returns the model signature of this embedding vector, which is an arbitrary string to distinguish between embedding vectors generated by different models. |
| `https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector.QuantizedData?` | `@https://developer.android.com/reference/kotlin/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector#getQuantizedData()()` Returns the quantized data of this embedding vector, or null if it only contains standard float values. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector#getValues()()` Returns the values of this embedding vector. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector#hashCode()()` |

## Public constructors

### EmbeddingVector

Added in [1.2.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

```
@ExperimentalAppSearchApi
@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_EMBEDDING_PRE_QUANTIZED_DATA)
EmbeddingVector(
    quantizedData: EmbeddingVector.QuantizedData,
    modelSignature: String
)
```

Creates a new `https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector` from pre-quantized embedding data.

Storing 8-bit quantized values directly helps reduce memory and disk space usage by approximately 75% compared to storing full 32-bit floats.

| Parameters |
|---|---|
| `quantizedData: https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector.QuantizedData` | The pre-quantized embedding data. |
| `modelSignature: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | An arbitrary string used to distinguish between embedding vectors generated by different models. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `quantizedData` contains empty values. |

### EmbeddingVector

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
EmbeddingVector(values: FloatArray<Float>, modelSignature: String)
```

Creates a new `https://developer.android.com/reference/kotlin/androidx/appsearch/app/EmbeddingVector` containing standard 32-bit float values.

| Parameters |
|---|---|
| `values: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | The float values of the embedding vector. |
| `modelSignature: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | An arbitrary string used to distinguish between embedding vectors generated by different models. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if `values` is empty. |

## Public functions

### equals

```
fun equals(o: Any?): Boolean
```

### getModelSignature

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

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

Returns the model signature of this embedding vector, which is an arbitrary string to distinguish between embedding vectors generated by different models.

### getQuantizedData

Added in [1.2.0-alpha02](https://developer.android.com/jetpack/androidx/releases/appsearch#1.2.0-alpha02)

```
@ExperimentalAppSearchApi
fun getQuantizedData(): EmbeddingVector.QuantizedData?
```

Returns the quantized data of this embedding vector, or null if it only contains standard float values.

### getValues

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/appsearch#1.1.0)

```
fun getValues(): Array<Float>
```

Returns the values of this embedding vector.

### hashCode

```
fun hashCode(): Int
```