Skip to content

featurebyte.Context.create

create(
name: str,
primary_entity: List[str],
description: Optional[str]=None,
treatment_name: Optional[str]=None,
user_provided_columns: Optional[List[UserProvidedColumn]]=None,
forecast_point_schema: Optional[ForecastPointSchema]=None
) -> Context

Description

Create a new Context.

Parameters

  • name: str
    Name of the UseCase.

  • primary_entity: List[str]
    List of entity names.

  • description: Optional[str]
    Description of the Context.

  • treatment_name: Optional[str]
    treatment name if this is a causal modeling context.

  • user_provided_columns: Optional[List[UserProvidedColumn]]
    List of user-provided column definitions.

  • forecast_point_schema: Optional[ForecastPointSchema]
    Schema for forecast point column if this is a forecasting context. Defines the granularity (day, week, etc.) and timezone handling.

Returns

  • Context
    The newly created Context.

Examples

>>> fb.Context.create(
...     name="context_1",
...     primary_entity=primary_entity,
... )
>>> context_1 = catalog.get_context("context_1")
>>> # Example with user-provided columns
>>> fb.Context.create(
...     name="loan_approval_context",
...     primary_entity=["customer"],
...     user_provided_columns=[
...         fb.UserProvidedColumn(
...             name="annual_income",
...             dtype=fb.DBVarType.FLOAT,
...             feature_type=fb.FeatureType.NUMERIC,
...         ),
...         fb.UserProvidedColumn(
...             name="credit_score",
...             dtype=fb.DBVarType.INT,
...             feature_type=fb.FeatureType.NUMERIC,
...         ),
...     ],
... )
>>> # Example with Observational Treatment and Estimated Unit-Level Propensity
>>> observational_treatment = fb.Treatment.create(
...     name="Churn Campaign A/B test",
...     dtype=DBVarType.INT,
...     treatment_type=fb.TreatmentType.BINARY,
...     source="observational",
...     design="business-rule",
...     time="static",
...     time_structure="none",
...     interference="none",
...     treatment_labels=[0, 1],
...     control_label=0,
...     propensity=fb.Propensity(
...         granularity="unit",
...         knowledge="estimated",  # Requires model-based p(T|X)
...     ),
... )
>>> fb.Context.create(
...     name="context_with_observational_treatment",
...     primary_entity=primary_entity,
...     treatment_name=observational_treatment.name,
... )
>>> context_2 = catalog.get_context(
...     "context_with_observational_treatment"
... )
>>> # Example with Forecast Point Schema for daily forecasting
>>> forecast_schema = fb.ForecastPointSchema(
...     granularity=fb.TimeIntervalUnit.DAY,
...     dtype=fb.DBVarType.DATE,
...     timezone="America/New_York",
... )
>>> fb.Context.create(
...     name="daily_forecast_context",
...     primary_entity=primary_entity,
...     forecast_point_schema=forecast_schema,
... )