feast icon indicating copy to clipboard operation
feast copied to clipboard

Unable to register the feature view and on demand feature view together

Open itsmano1993 opened this issue 1 year ago • 6 comments

Code snippet

import pandas as pd
from feast import FeatureStore, FeatureView, Field, FileSource, Entity, FeatureService, OnDemandFeatureView, \
    RequestSource
from feast.on_demand_feature_view import on_demand_feature_view
from feast.transformation.python_transformation import PythonTransformation
from feast.types import Int64, Float32
import datetime

store = FeatureStore(".")

customer_data_source = FileSource(
    path="data/customer_features.parquet",  # Can be a local file, S3, GCS, etc.
    timestamp_field="event_timestamp",  # Required for time-series data
    created_timestamp_column="created_timestamp"
)

customer = Entity(name="customer", join_keys=["customer_id"])

customer_features_view = FeatureView(name="customer_features", source=customer_data_source, entities=[customer],
                                     ttl=datetime.timedelta(days=365),
                                     schema=[
                                         Field(name="age", dtype=Int64),
                                         Field(name="income", dtype=Float32),
                                     ])

input_request = RequestSource(
    name="vals_to_add",
    schema=[
        Field(name="val_to_add", dtype=Int64)
    ],
)


@on_demand_feature_view(
    sources=[customer_features_view, input_request], schema=[
        Field(name="age_income_ratio", dtype=Float32),
    ], mode="pandas", write_to_online_store=True)
def calculate_ondemand_features(df: pd.DataFrame) -> pd.DataFrame:
    df["age_income_ratio"] = df["age"] / df["income"]
    return df


customer_feature_service = FeatureService(name="customer_feature_service", features=[customer_features_view, calculate_ondemand_features])

store.apply([customer, customer_features_view, customer_feature_service, calculate_ondemand_features])

store.materialize(
    start_date=datetime.datetime(2024, 1, 1),  # Historical start date
    end_date=datetime.datetime.now()  # Latest available data
)

Error details

feast.errors.SpecifiedFeaturesNotPresentError: Explicitly specified features [Field(
    name='age_income_ratio',
    dtype=<PrimitiveFeastType.FLOAT32: 6>,
    description='',
    tags={}
    vector_index=False
    vector_search_metric=None
)] not found in inferred list of features [Field(
    name='customer_features__age',
    dtype=<PrimitiveFeastType.INT64: 4>,
    description='',
    tags={}
    vector_index=False
    vector_search_metric=None
), Field(
    name='age',
    dtype=<PrimitiveFeastType.INT64: 4>,
    description='',
    tags={}
    vector_index=False
    vector_search_metric=None
), Field(
    name='customer_features__income',
    dtype=<PrimitiveFeastType.FLOAT64: 5>,
    description='',
    tags={}
    vector_index=False
    vector_search_metric=None
), Field(
    name='income',
    dtype=<PrimitiveFeastType.FLOAT64: 5>,
    description='',
    tags={}
    vector_index=False
    vector_search_metric=None
), Field(
    name='val_to_add',
    dtype=<PrimitiveFeastType.INT64: 4>,
    description='',
    tags={}
    vector_index=False
    vector_search_metric=None
), Field(
    name='age_income_ratio',
    dtype=<PrimitiveFeastType.FLOAT64: 5>,
    description='',
    tags={}
    vector_index=False
    vector_search_metric=None
)] for 'calculate_ondemand_features'

Dataset creation

import pandas as pd
import datetime
import os

# Ensure the data directory exists
# os.makedirs("data", exist_ok=True)

# Create sample data
data = {
    "customer_id": [101, 102, 103, 104, 105],  # Entity IDs
    "age": [25, 34, 45, 29, 40],  # Age feature
    "income": [50000.0, 72000.5, 83000.0, 62000.7, 91000.3],  # Income feature
    "event_timestamp": [
        datetime.datetime(2024, 1, 1, 10, 0),
        datetime.datetime(2024, 1, 2, 12, 0),
        datetime.datetime(2024, 1, 3, 14, 0),
        datetime.datetime(2024, 1, 4, 16, 0),
        datetime.datetime(2024, 1, 5, 18, 0),
    ],
    "created_timestamp": [
        datetime.datetime(2024, 1, 1, 9, 30),
        datetime.datetime(2024, 1, 2, 11, 45),
        datetime.datetime(2024, 1, 3, 13, 15),
        datetime.datetime(2024, 1, 4, 15, 20),
        datetime.datetime(2024, 1, 5, 17, 10),
    ],
}

# Convert to DataFrame
df = pd.DataFrame(data)

# Save as Parquet
df.to_parquet("data/customer_features.parquet", index=False)

print("Parquet file 'customer_features.parquet' generated successfully!")

itsmano1993 avatar Feb 05 '25 17:02 itsmano1993

which version of feast are you using?

franciscojavierarceo avatar Feb 05 '25 17:02 franciscojavierarceo

can you share your feature_store.yaml?

franciscojavierarceo avatar Feb 05 '25 17:02 franciscojavierarceo

which version of feast are you using?

feast==0.43.0

even I installed latest version of feast 0.45.0 and still experiencing the same issue

itsmano1993 avatar Feb 06 '25 04:02 itsmano1993

can you share your feature_store.yaml?

---
project: dev
registry: data/registry.db
provider: local
online_store:
  type: mysql
  host: localhost
  port: 3306
  database: feast
  user: progressfinQA
  password: passwordQA
entity_key_serialization_version: 2
auth:
  type: no_auth

itsmano1993 avatar Feb 06 '25 04:02 itsmano1993

@franciscojavierarceo Did you get a chance to look into this?

itsmano1993 avatar Feb 06 '25 17:02 itsmano1993

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 27 '25 01:06 stale[bot]