EmbeddingVector


@RequiresFeature(enforcement = "androidx.appsearch.app.Features#isFeatureSupported", name = Features.SCHEMA_EMBEDDING_PROPERTY_CONFIG)
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(
    quantizedData: EmbeddingVector.QuantizedData,
    modelSignature: String
)

Creates a new EmbeddingVector from pre-quantized embedding data.

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

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

Public functions

Boolean
equals(o: Any?)
String

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

EmbeddingVector.QuantizedData?

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

Array<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)
EmbeddingVector(
    quantizedData: EmbeddingVector.QuantizedData,
    modelSignature: String
)

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
quantizedData: EmbeddingVector.QuantizedData

The pre-quantized embedding data.

modelSignature: String

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
EmbeddingVector(values: FloatArray<Float>, modelSignature: String)

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

Parameters
values: FloatArray<Float>

The float values of the embedding vector.

modelSignature: String

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

Throws
java.lang.IllegalArgumentException

if values is empty.

Public functions

equals

fun equals(o: Any?): Boolean

getModelSignature

Added in 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
@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
fun getValues(): Array<Float>

Returns the values of this embedding vector.

hashCode

fun hashCode(): Int