Home

Awesome

Hopsworks Feature Store

<p align="center"> <a href="https://community.hopsworks.ai"><img src="https://img.shields.io/discourse/users?label=Hopsworks%20Community&server=https%3A%2F%2Fcommunity.hopsworks.ai" alt="Hopsworks Community" /></a> <a href="https://docs.hopsworks.ai"><img src="https://img.shields.io/badge/docs-HSFS-orange" alt="Hopsworks Feature Store Documentation" /></a> <a><img src="https://img.shields.io/badge/python-3.8+-blue" alt="python" /></a> <a href="https://pypi.org/project/hsfs/"><img src="https://img.shields.io/pypi/v/hsfs?color=blue" alt="PyPiStatus" /></a> <a href="https://archiva.hops.works/#artifact/com.logicalclocks/hsfs"><img src="https://img.shields.io/badge/java-HSFS-green" alt="Scala/Java Artifacts" /></a> <a href="https://pepy.tech/project/hsfs/month"><img src="https://pepy.tech/badge/hsfs/month" alt="Downloads" /></a> <a href=https://github.com/astral-sh/ruff><img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff" /></a> <a><img src="https://img.shields.io/pypi/l/hsfs?color=green" alt="License" /></a> </p>

HSFS is the library to interact with the Hopsworks Feature Store. The library makes creating new features, feature groups and training datasets easy.

The library is environment independent and can be used in two modes:

The library automatically configures itself based on the environment it is run. However, to connect from an external environment such as Databricks or AWS Sagemaker, additional connection information, such as host and port, is required. For more information checkout the Hopsworks documentation.

Getting Started On Hopsworks

Get started easily by registering an account on Hopsworks Serverless. Create your project and a new Api key. In a new python environment with Python 3.8 or higher, install the client library using pip:

# Get all Hopsworks SDKs: Feature Store, Model Serving and Platform SDK
pip install hopsworks
# or minimum install with the Feature Store SDK
pip install hsfs[python]
# if using zsh don't forget the quotes
pip install 'hsfs[python]'

You can start a notebook and instantiate a connection and get the project feature store handler.

import hopsworks

project = hopsworks.login() # you will be prompted for your api key
fs = project.get_feature_store()

or using hsfs directly:

import hsfs

connection = hsfs.connection(
    host="c.app.hopsworks.ai", #
    project="your-project",
    api_key_value="your-api-key",
)
fs = connection.get_feature_store()

Create a new feature group to start inserting feature values.

fg = fs.create_feature_group("rain",
                        version=1,
                        description="Rain features",
                        primary_key=['date', 'location_id'],
                        online_enabled=True)

fg.save(dataframe)

Upsert new data in to the feature group with time_travel_format="HUDI"".

fg.insert(upsert_df)

Retrieve commit timeline metdata of the feature group with time_travel_format="HUDI"".

fg.commit_details()

"Reading feature group as of specific point in time".

fg = fs.get_feature_group("rain", 1)
fg.read("2020-10-20 07:34:11").show()

Read updates that occurred between specified points in time.

fg = fs.get_feature_group("rain", 1)
fg.read_changes("2020-10-20 07:31:38", "2020-10-20 07:34:11").show()

Join features together

feature_join = rain_fg.select_all()
                    .join(temperature_fg.select_all(), on=["date", "location_id"])
                    .join(location_fg.select_all())
feature_join.show(5)

join feature groups that correspond to specific point in time

feature_join = rain_fg.select_all()
                    .join(temperature_fg.select_all(), on=["date", "location_id"])
                    .join(location_fg.select_all())
                    .as_of("2020-10-31")
feature_join.show(5)

join feature groups that correspond to different time

rain_fg_q = rain_fg.select_all().as_of("2020-10-20 07:41:43")
temperature_fg_q = temperature_fg.select_all().as_of("2020-10-20 07:32:33")
location_fg_q = location_fg.select_all().as_of("2020-10-20 07:33:08")
joined_features_q = rain_fg_q.join(temperature_fg_q).join(location_fg_q)

Use the query object to create a training dataset:

td = fs.create_training_dataset("rain_dataset",
                                version=1,
                                data_format="tfrecords",
                                description="A test training dataset saved in TfRecords format",
                                splits={'train': 0.7, 'test': 0.2, 'validate': 0.1})

td.save(feature_join)

A short introduction to the Scala API:

import com.logicalclocks.hsfs._
val connection = HopsworksConnection.builder().build()
val fs = connection.getFeatureStore();
val attendances_features_fg = fs.getFeatureGroup("games_features", 1);
attendances_features_fg.show(1)

You can find more examples on how to use the library in our hops-examples repository.

Usage

Usage data is collected for improving quality of the library. It is turned on by default if the backend is "c.app.hopsworks.ai". To turn it off, use one of the following way:

# use environment variable
import os
os.environ["ENABLE_HOPSWORKS_USAGE"] = "false"

# use `disable_usage_logging`
import hsfs
hsfs.disable_usage_logging()

The source code can be found in python/hsfs/usage.py.

Documentation

Documentation is available at Hopsworks Feature Store Documentation.

Issues

For general questions about the usage of Hopsworks and the Feature Store please open a topic on Hopsworks Community.

Please report any issue using Github issue tracking.

Please attach the client environment from the output below in the issue:

import hopsworks
import hsfs
hopsworks.login().get_feature_store()
print(hsfs.get_env())

Contributing

If you would like to contribute to this library, please see the Contribution Guidelines.