Stay organized with collections
Save and categorize content based on your preferences.
If you need to retrieve or serve current as well as historical
feature data, use offline serving to fetch feature values from
BigQuery. For example, you can use offline serving to retrieve
the feature values for specific timestamps to train a model.
All feature data, including historical feature data, is maintained in
BigQuery, which constitutes the offline store for your feature values.
To use offline serving, you must first register your BigQuery
data source by creating feature groups and feature values. Also, in the case of
offline serving, every row containing the same entity ID must have a
different timestamp. For more information about data source
preparation guidelines, see Prepare data source.
Before you begin
Authenticate to
Vertex AI, unless you've done so already.
To use the Python samples on this page in a local
development environment, install and initialize the gcloud CLI, and
then set up Application Default Credentials with your user credentials.
FEATURE_GROUP_NAME: The name of the existing feature group
containing the feature.
FEATURE_NAME_1 and FEATURE_NAME_2: The names of the
registered features from which you want to retrieve the feature values.
ENTITY_ID_COLUMN: The name of the column containing the entity IDs.
You can specify a column name only if it's registered in the feature group.
ENTITY_ID_1 and ENTITY_ID_2: The entity IDs for which
you want to fetch the feature values. If you want to retrieve feature values
for the same entity ID at different timestamps, specify the same entity ID
corresponding to each timestamp.
FEATURE_TIMESTAMP_1 and FEATURE_TIMESTAMP_2: The
timestamps corresponding to the historical feature values you want to retrieve.
FEATURE_TIMESTAMP_1 corresponds to ENTITY_ID_1,
FEATURE_TIMESTAMP_2 corresponds to ENTITY_ID_2, and so on.
Specify the timestamps in the datetime formatโfor example, 2024-05-01T12:00:00.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-29 UTC."],[],[],null,["# Serve historical feature values\n\n| **Preview**\n|\n|\n| This feature is subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section\n| of the [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nIf you need to retrieve or serve current as well as historical\nfeature data, use offline serving to fetch feature values from\nBigQuery. For example, you can use offline serving to retrieve\nthe feature values for specific timestamps to train a model.\n\nAll feature data, including historical feature data, is maintained in\nBigQuery, which constitutes the offline store for your feature values.\nTo use offline serving, you must first register your BigQuery\ndata source by creating feature groups and feature values. Also, in the case of\noffline serving, every row containing the same entity ID must have a\ndifferent timestamp. For more information about data source\npreparation guidelines, see [Prepare data source](/vertex-ai/docs/featurestore/latest/prepare-data-source).\n\nBefore you begin\n----------------\n\n\nto\nVertex AI, unless you've done so already.\n\n\nTo use the Python samples on this page in a local\ndevelopment environment, install and initialize the gcloud CLI, and\nthen set up Application Default Credentials with your user credentials.\n\n1. [Install](/sdk/docs/install) the Google Cloud CLI.\n2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n3. If you're using a local shell, then create local authentication credentials for your user account: \n\n```bash\ngcloud auth application-default login\n```\n4. You don't need to do this if you're using Cloud Shell.\n5. If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have [signed in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n\nFor more information, see\n[Set up authentication for a local development environment](/vertex-ai/docs/authentication#local-development).\n\nFetch historical feature values\n-------------------------------\n\nUse the following sample to fetch historical values from a feature from multiple\nentity IDs and timestamps. \n\n### Python\n\n\nBefore trying this sample, follow the Python setup instructions in the\n[Vertex AI quickstart using\nclient libraries](/vertex-ai/docs/start/client-libraries).\n\n\nFor more information, see the\n[Vertex AI Python API\nreference documentation](/python/docs/reference/aiplatform/latest).\n\n\nTo authenticate to Vertex AI, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n import https://cloud.google.com/python/docs/reference/bigframes/latest/\n import bigframes.pandas\n import pandas as pd\n from google.cloud import https://cloud.google.com/python/docs/reference/bigquery/latest/\n from vertexai.resources.preview.feature_store import (Feature, FeatureGroup, offline_store)\n from vertexai.resources.preview.feature_store import utils as fs_utils\n\n fg = FeatureGroup(\"\u003cvar translate=\"no\"\u003eFEATURE_GROUP_NAME\u003c/var\u003e\")\n f1 = fg.get_feature(\"\u003cvar translate=\"no\"\u003eFEATURE_NAME_1\u003c/var\u003e\")\n f2 = fg.get_feature(\"\u003cvar translate=\"no\"\u003eFEATURE_NAME_2\u003c/var\u003e\")\n\n entity_df = pd.DataFrame(\n data={\n \"\u003cvar translate=\"no\"\u003eENTITY_ID_COLUMN\u003c/var\u003e\": [\n \"\u003cvar translate=\"no\"\u003eENTITY_ID_1\u003c/var\u003e\",\n \"\u003cvar translate=\"no\"\u003eENTITY_ID_2\u003c/var\u003e\",\n ],\n \"timestamp\": [\n pd.Timestamp(\"\u003cvar translate=\"no\"\u003eFEATURE_TIMESTAMP_1\u003c/var\u003e\"),\n pd.Timestamp(\"\u003cvar translate=\"no\"\u003eFEATURE_TIMESTAMP_2\u003c/var\u003e\"),\n ],\n },\n )\n\n offline_store.fetch_historical_feature_values(\n entity_df=entity_df,\n features=[f1,f2],\n )\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eFEATURE_GROUP_NAME\u003c/var\u003e: The name of the existing feature group\n containing the feature.\n\n- \u003cvar translate=\"no\"\u003eFEATURE_NAME_1\u003c/var\u003e and \u003cvar translate=\"no\"\u003eFEATURE_NAME_2\u003c/var\u003e: The names of the\n registered features from which you want to retrieve the feature values.\n\n- \u003cvar translate=\"no\"\u003eENTITY_ID_COLUMN\u003c/var\u003e: The name of the column containing the entity IDs.\n You can specify a column name only if it's registered in the feature group.\n\n- \u003cvar translate=\"no\"\u003eENTITY_ID_1\u003c/var\u003e and \u003cvar translate=\"no\"\u003eENTITY_ID_2\u003c/var\u003e: The entity IDs for which\n you want to fetch the feature values. If you want to retrieve feature values\n for the same entity ID at different timestamps, specify the same entity ID\n corresponding to each timestamp.\n\n- \u003cvar translate=\"no\"\u003eFEATURE_TIMESTAMP_1\u003c/var\u003e and \u003cvar translate=\"no\"\u003eFEATURE_TIMESTAMP_2\u003c/var\u003e: The\n timestamps corresponding to the historical feature values you want to retrieve.\n \u003cvar translate=\"no\"\u003eFEATURE_TIMESTAMP_1\u003c/var\u003e corresponds to \u003cvar translate=\"no\"\u003eENTITY_ID_1\u003c/var\u003e,\n \u003cvar translate=\"no\"\u003eFEATURE_TIMESTAMP_2\u003c/var\u003e corresponds to \u003cvar translate=\"no\"\u003eENTITY_ID_2\u003c/var\u003e, and so on.\n Specify the timestamps in the datetime format---for example, `2024-05-01T12:00:00`.\n\n\n\u003cbr /\u003e"]]