Skip to content

hsfs.embedding #

[source] EmbeddingFeature #

Represents an embedding feature.

PARAMETER DESCRIPTION
name

The name of the embedding feature.

TYPE: str DEFAULT: None

dimension

The dimensionality of the embedding feature.

TYPE: int DEFAULT: None

similarity_function_type

The type of similarity function used for the embedding feature. Available functions are L2, COSINE, and DOT_PRODUCT. Defaults to SimilarityFunctionType.L2.

TYPE: SimilarityFunctionType DEFAULT: SimilarityFunctionType.L2

model

hsml.model.Model A Model in hsml.

DEFAULT: None

feature_group

The feature group object that contains the embedding feature.

DEFAULT: None

embedding_index

EmbeddingIndex The index for managing embedding features.

DEFAULT: None

[source] name property #

str: The name of the embedding feature.

[source] dimenstion property #

The dimensionality of the embedding feature.

This one is excluded from the docs as the name is misspelled but kept to avoid breaking the API.

[source] dimension property #

int: The dimensionality of the embedding feature.

[source] similarity_function_type property #

SimilarityFunctionType: The type of similarity function used for the embedding feature.

[source] model property #

hsml.model.Model: The Model in hsml.

[source] feature_group property writable #

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

[source] embedding_index property writable #

EmbeddingIndex: The index for managing embedding features.

[source] 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()

[source] feature_group property writable #

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

[source] index_name property #

str: The name of the embedding index.

[source] col_prefix property #

str: The prefix to be added to column names.

[source] 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

[source] 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.

[source] 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.

[source] 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][hopsworks_common.core.opensearch.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.

[source] SimilarityFunctionType #

Enumeration class representing different types of similarity functions.

PARAMETER DESCRIPTION
L2

Represents L2 norm similarity function.

COSINE

Represents cosine similarity function.

DOT_PRODUCT

Represents dot product similarity function.