Skip to content

feast.FeastDataset

kedro_datasets_experimental.feast.FeastDataset

FeastDataset(
    *,
    repo,
    credentials=None,
    load_args=None,
    save_args=None,
    metadata=None
)

Bases: AbstractDataset

Kedro dataset backed by a Feast feature view or feature service.

Load returns a FeastFeatureSource for point-in-time queries against the offline store. Save persists a DataFrame to a feature view's batch source via Feast's write_to_offline_store (which matches the DataFrame to the feature view's schema and appends) and, when write_mode is online_and_offline, also to the online store. Feast infers the write schema from the existing table; set create_table: true to bootstrap a (BigQuery) table from the feature view schema when it does not yet exist.

Examples:

Using the YAML API:

feast_features:
    type: kedro_datasets_experimental.feast.FeastDataset
    repo:  # forwarded to feast.RepoConfig
        registry: gs://bucket/feast
        project: project_name
        provider: gcp # default is local
        offline_store:
            type: bigquery # default is bigquery
            location: EU
        online_store:  # optional; required for online_and_offline writes
            type: sqlite
            path: /tmp/online_store.db
    save_args:
    feature_view_name: features
    write_mode: online_and_offline  # or "offline" (default)
    create_table: true  # bootstrap the BigQuery table from the FV schema
    load_args:
    feature_view_name: features

Parameters:

  • repo (dict[str, Any]) –

    Feast repo configuration, forwarded to feast.RepoConfig (which validates it). Any RepoConfig field is accepted, e.g. registry (a path string or dict), project, provider and offline_store. provider defaults to "local" and offline_store to {"type": "bigquery"} when not set; either can be overridden via repo. online_store defaults to disabled (None); set it in repo to enable online_and_offline writes.

  • credentials (dict[str, Any] | str | None, default: None ) –

    Not supported; Feast authenticates via Application Default Credentials (the ambient environment). Passing anything other than None raises NotImplementedError.

  • load_args (dict[str, Any] | None, default: None ) –

    Must contain either feature_view_name or feature_service_name identifying what load retrieves.

  • save_args (dict[str, Any] | None, default: None ) –

    Must contain feature_view_name — the feature view to write to. Optional write_mode selects where to write: "offline" (default) writes only the offline store; "online_and_offline" also pushes to the online store (requires an online_store in repo). Optional create_table (default False): when True, create the backing table from the feature view schema if it does not exist (BigQuery sources only; raises a DatasetError otherwise).

Source code in kedro_datasets_experimental/feast/feast_dataset.py
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
def __init__(
    self,
    *,
    repo: dict[str, Any],
    credentials: dict[str, Any] | str | None = None,
    load_args: dict[str, Any] | None = None,
    save_args: dict[str, Any] | None = None,
    metadata: dict[str, Any] | None = None,
) -> None:
    """Create a new ``FeastDataset``.

    Args:
        repo: Feast repo configuration, forwarded to ``feast.RepoConfig``
            (which validates it). Any ``RepoConfig`` field is accepted, e.g.
            ``registry`` (a path string or dict), ``project``, ``provider``
            and ``offline_store``. ``provider`` defaults to ``"local"`` and
            ``offline_store`` to ``{"type": "bigquery"}`` when not set;
            either can be overridden via ``repo``. ``online_store`` defaults
            to disabled (``None``); set it in ``repo`` to enable
            ``online_and_offline`` writes.
        credentials: Not supported; Feast authenticates via Application
            Default Credentials (the ambient environment). Passing anything
            other than ``None`` raises ``NotImplementedError``.
        load_args: Must contain either ``feature_view_name`` or
            ``feature_service_name`` identifying what ``load`` retrieves.
        save_args: Must contain ``feature_view_name`` — the feature view to
            write to. Optional ``write_mode`` selects where to write:
            ``"offline"`` (default) writes only the offline store;
            ``"online_and_offline"`` also pushes to the online store
            (requires an ``online_store`` in ``repo``). Optional
            ``create_table`` (default ``False``): when ``True``, create the
            backing table from the feature view schema if it does not exist
            (BigQuery sources only; raises a ``DatasetError`` otherwise).
    """
    if credentials is not None:
        raise NotImplementedError("`FeastDataset` supports only Application Default Credentials")

    repo = repo or {}
    repo_config = RepoConfig(
        **{
            "provider": "local",
            "offline_store": {"type": "bigquery"},
            "online_store": None,
            **repo,
        }
    )

    self._repo = repo
    self._feature_store = FeatureStore(config=repo_config)
    self._load_args = load_args or {}
    self._save_args = save_args or {}
    self.metadata = metadata

metadata instance-attribute

metadata = metadata

load

load()
Source code in kedro_datasets_experimental/feast/feast_dataset.py
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
def load(self) -> FeastFeatureSource:
    if (feature_view_name := self._load_args.get("feature_view_name")) is not None:
        feature_view = self._feature_store.get_feature_view(feature_view_name)
        features = [
            f"{feature_view.name}:{field.name}" for field in feature_view.features
        ]
        return FeastFeatureSource(self._feature_store, features)

    if (
        feature_service_name := self._load_args.get("feature_service_name")
    ) is not None:
        feature_service = self._feature_store.get_feature_service(
            feature_service_name
        )
        return FeastFeatureSource(self._feature_store, feature_service)

    msg = (
        "load_args must contain either a `feature_view_name` or "
        "`feature_service_name`"
    )
    raise DatasetError(msg)

save

save(data)
Source code in kedro_datasets_experimental/feast/feast_dataset.py
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
def save(self, data: pd.DataFrame) -> None:
    feature_view_name = self._save_args.get("feature_view_name")
    if feature_view_name is None:
        msg = "save_args must contain a `feature_view_name`"
        raise DatasetError(msg)

    write_mode = self._save_args.get("write_mode", "offline")
    if write_mode not in self._WRITE_MODES:
        msg = (
            f"save_args['write_mode'] must be one of "
            f"{sorted(self._WRITE_MODES)}, got {write_mode!r}."
        )
        raise DatasetError(msg)

    # Optionally bootstrap the backing table from the feature view schema.
    # Feast's write infers its schema from the *existing* table, so this
    # must happen first. Only BigQuery-backed sources are supported for now.
    if self._save_args.get("create_table", False):
        self._create_bigquery_table(feature_view_name)

    # Persist the DataFrame into the feature view's batch source: Feast
    # matches/reorders columns to the Feast schema and appends. Fails if
    # columns don't match.
    self._feature_store.write_to_offline_store(
        feature_view_name, data, reorder_columns=True
    )

    # Optionally also push to the online store (requires an online_store to
    # be configured in `repo`; it is disabled by default).
    if write_mode == "online_and_offline":
        self._feature_store.write_to_online_store(feature_view_name, data)