# 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)
public final 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/androidx/appsearch/app/AppSearchSession#search(java.lang.String,androidx.appsearch.app.SearchSpec)` and `https://developer.android.com/reference/androidx/appsearch/app/SearchSpec.Builder#setRankingStrategy(java.lang.String)`.

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

## Summary

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

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

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/appsearch/app/EmbeddingVector#equals(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html o)` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/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/androidx/annotation/Nullable https://developer.android.com/reference/androidx/appsearch/app/EmbeddingVector.QuantizedData` | `@https://developer.android.com/reference/androidx/appsearch/app/ExperimentalAppSearchApi https://developer.android.com/reference/androidx/appsearch/app/EmbeddingVector#getQuantizedData()()` Returns the quantized data of this embedding vector, or null if it only contains standard float values. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull float[]` | `https://developer.android.com/reference/androidx/appsearch/app/EmbeddingVector#getValues()()` Returns the values of this embedding vector. |
| `int` | `https://developer.android.com/reference/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)
public EmbeddingVector(
    @NonNull EmbeddingVector.QuantizedData quantizedData,
    @NonNull String modelSignature
)
```

Creates a new `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/appsearch/app/EmbeddingVector.QuantizedData quantizedData` | The pre-quantized embedding data. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html modelSignature` | 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)

```
public EmbeddingVector(@NonNull float[] values, @NonNull String modelSignature)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull float[] values` | The float values of the embedding vector. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html modelSignature` | 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 methods

### equals

```
public boolean equals(@Nullable Object o)
```

### getModelSignature

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

```
public @NonNull String getModelSignature()
```

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
public @Nullable EmbeddingVector.QuantizedData getQuantizedData()
```

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)

```
public @NonNull float[] getValues()
```

Returns the values of this embedding vector.

### hashCode

```
public int hashCode()
```