EmbeddingVector


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


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 search and setRankingStrategy.

Summary

Nested types

Holds the pre-quantized embedding values along with the quantization parameters.

Public constructors

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

Creates a new EmbeddingVector from pre-quantized embedding data.

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

Creates a new EmbeddingVector containing standard 32-bit float values.

Public methods

boolean
@NonNull String

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

@Nullable EmbeddingVector.QuantizedData

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

@NonNull float[]

Returns the values of this embedding vector.

int

Public constructors

EmbeddingVector

Added in 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 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
@NonNull EmbeddingVector.QuantizedData quantizedData

The pre-quantized embedding data.

@NonNull String modelSignature

An arbitrary string used to distinguish between embedding vectors generated by different models.

Throws
java.lang.IllegalArgumentException

if quantizedData contains empty values.

EmbeddingVector

Added in 1.1.0
public EmbeddingVector(@NonNull float[] values, @NonNull String modelSignature)

Creates a new EmbeddingVector containing standard 32-bit float values.

Parameters
@NonNull float[] values

The float values of the embedding vector.

@NonNull String modelSignature

An arbitrary string used to distinguish between embedding vectors generated by different models.

Throws
java.lang.IllegalArgumentException

if values is empty.

Public methods

equals

public boolean equals(@Nullable Object o)

getModelSignature

Added in 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
@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
public @NonNull float[] getValues()

Returns the values of this embedding vector.

hashCode

public int hashCode()