Skip to content

EmbeddingIndex#

EmbeddingIndex #

Represents an index for managing embedding features.

PARAMETER DESCRIPTION
index_name

The name of the embedding index. The name of the project index is used if not provided.

TYPE: str | None DEFAULT: None

features

A list of EmbeddingFeature objects for the features that contain embeddings that should be indexed for similarity search.

TYPE: list[EmbeddingFeature] | None DEFAULT: None

col_prefix

The prefix to be added to column names when using project index. It is managed by Hopsworks and should not be provided.

TYPE: str | None DEFAULT: None

Example
embedding_index = EmbeddingIndex()
embedding_index.add_embedding(name="user_vector", dimension=256)
embeddings = embedding_index.get_embeddings()

col_prefix property #

col_prefix

str: The prefix to be added to column names.

feature_group property writable #

feature_group

FeatureGroup: The feature group object that contains the embedding feature.

index_name property #

index_name

str: The name of the embedding index.

add_embedding #

add_embedding(
    name: str,
    dimension: int,
    similarity_function_type: SimilarityFunctionType
    | None = SimilarityFunctionType.L2,
    model=None,
)

Adds a new embedding feature to the index.

Example
embedding_index = EmbeddingIndex()
embedding_index.add_embedding(name="user_vector", dimension=256)

# Attach a hsml model to the embedding feature
embedding_index = EmbeddingIndex()
embedding_index.add_embedding(name="user_vector", dimension=256, model=hsml_model)
PARAMETER DESCRIPTION
name

The name of the embedding feature.

TYPE: str

dimension

The dimensionality of the embedding feature.

TYPE: int

similarity_function_type

The type of similarity function to be used.

TYPE: SimilarityFunctionType | None DEFAULT: SimilarityFunctionType.L2

model

hsml.model.Model | None The hsml model used to generate the embedding.

DEFAULT: None

count #

count(options: map = None) -> int

Count the number of records in the feature group.

PARAMETER DESCRIPTION
options

The options used for the request to the vector database. The keys are attribute values of OpensearchRequestOption.

TYPE: map DEFAULT: None

RETURNS DESCRIPTION
int

The number of records in the feature group.

RAISES DESCRIPTION
ValueError

If the feature group is not initialized.

hopsworks.client.exceptions.FeatureStoreException

If an error occurs during the count operation.

get_embedding #

get_embedding(name: str) -> EmbeddingFeature

Get EmbeddingFeature associated with the feature name.

PARAMETER DESCRIPTION
name

The name of the embedding feature.

TYPE: str

RETURNS DESCRIPTION
EmbeddingFeature

The EmbeddingFeature associated with the name.

get_embeddings #

get_embeddings() -> list[EmbeddingFeature]

Returns the list of EmbeddingFeature objects associated with the index.

RETURNS DESCRIPTION
list[EmbeddingFeature]

All embedding features in the index.

json #

json()

Serialize the EmbeddingIndex object to a JSON string.

to_dict #

to_dict() -> dict

Convert the EmbeddingIndex object to a dictionary.

RETURNS DESCRIPTION
dict

A dictionary representation of the EmbeddingIndex object.