使用实体

Note

The Snowflake Feature Store API is available in the Snowpark ML Python package (snowflake-ml-python) v1.5.0 and later.

实体按主题整理特征视图,让用户能够更轻松地找到所需的特征视图。例如,一个视频流媒体服务的特征平台可能会为用户和电影定义实体。特征平台中的每个特征视图都被标记为与电影和/或用户相关,并且您可以检索与这些实体相关的特征视图列表。

除了帮助整理特征视图之外,实体还会存储键列名称,可用于将提取出的特征重新联接回原始数据。

创建实体

To create a new entity and register it in a feature store, use the feature store’s register_entity method. Here, fs is the feature store instance (see Creating or connecting to a feature store).

from snowflake.ml.feature_store import Entity

entity = Entity(
    name="MY_ENTITY",
    join_keys=["UNIQUE_ID"],
    desc="my entity"
)
fs.register_entity(entity)

列出实体

To see the registered entities in your feature store, use the feature store’s list_entities method, which returns a Snowpark DataFrame. (fs is the feature store instance; see Creating or connecting to a feature store.)

fs.list_entities().show()

检索实体

You can retrieve a registered entity using the feature store’s get_entity method; for example, to obtain its join keys.

entity = fs.get_entity(name="MY_ENTITY")
print(entity.join_keys)

修改实体

You can update an entity’s description using the feature store’s update_entity method:

fs.update_entity(
    name="MY_ENTITY",
    desc="NEW DESCRIPTION"
)

实体的其他方面(例如其联接键)不可变。若要更改这些方面,您需要创建一个新实体。

删除实体

You can delete an entity using the feature store’s delete_entity method.

fs.delete_entity(name="MY_ENTITY")

任何特征视图所引用的实体均不可删除。

已知限制