Vertex AI Feature Store 不会根据直接写入特征视图实例的特征数据来更新 BigQuery 中的特征数据源。在数据同步期间,Vertex AI Feature Store 会使用具有最新时间戳的特征值更新特征视图。例如,如果您直接在特征视图中更新某个特征值,随后又在 BigQuery 源中更新同一特征,那么在下一次数据同步期间,Vertex AI Feature Store 会使用 BigQuery 中最近更新的特征值来更新特征视图。
如果您想为多个特征视图中使用的特征列添加或更新特征值,则必须分别对每个特征视图进行相同的更新。
如果在线存储区实例配置为优化在线传送,您就无法直接将特征写入该在线存储区中的特征视图。
请注意,此功能不允许您在特征视图中添加或移除特征列。此外,您无法删除现有特征值或实体 ID。
准备工作
向 Vertex AI 进行身份验证,除非您已完成此操作。
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭证。
安装 Google Cloud CLI。 安装完成后,运行以下命令来初始化 Google Cloud CLI:
POST https://LOCATION_ID-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME:directWrite
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Update features in a feature view\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 your online store uses Bigtable online serving, you can directly update\nfeature values in a feature view without updating the feature data source\nin real-time. You can either update the feature values for an existing ID, or\nadd a new entity ID along with the corresponding feature values. Use this\ncapability in the following scenarios:\n\n- You want to write features to an online store faster than batch sync, while\n maintaining data freshness at 100ms or less.\n\n- You want to retrieve the timestamp when the\n feature is written to the online store.\n\nVertex AI Feature Store doesn't update the feature data source in BigQuery\nbased on the feature data that written directly to a feature view instance.\nDuring data sync, Vertex AI Feature Store updates the feature view\nwith the feature value having the most recent timestamp. For example, if you update\na feature value directly in a feature view, and subsequently update the same\nfeature in the BigQuery source, then\nVertex AI Feature Store updates the feature view with the most\nrecently updated feature value from BigQuery during the next\ndata sync.\n\nIf you want to add or update feature values for a feature column that's used in\nmultiple feature views, then you must make the same updates to each feature view\nseparately.\n\nIf an online store instance is configured for Optimized online serving,\nyou can't write features directly to a feature view within that online store.\n\nNote that this capability doesn't let you add or remove feature columns in a\nfeature view. Also, you can't delete existing feature values or entity IDs.\n\nBefore you begin\n----------------\n\n\nto\nVertex AI, unless you've done so already.\n\n\nTo use the REST API samples on this page in a local development environment, you use the\ncredentials you provide to the gcloud CLI.\n\n1. [Install](/sdk/docs/install) the Google Cloud CLI. After installation, [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command: \n\n```bash\ngcloud init\n```\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).\n\n\nFor more information, see\n[Authenticate for using REST](/docs/authentication/rest)\nin the Google Cloud authentication documentation.\n\nUpdate features directly in a feature view\n------------------------------------------\n\nUse the following sample to write features to an entity within a feature view. \n\n### REST\n\n\nTo write features values directly to a\n[`FeatureView`](/vertex-ai/docs/reference/rest/v1/projects.locations.featureOnlineStores.featureViews#resource:-featureView)\ninstance, send a `POST` request by using the\n[`featureViews.directWrite`](/vertex-ai/docs/reference/rest/v1/projects.locations.featureOnlineStores.featureViews/directWrite)\nmethod.\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003eLOCATION_ID\u003c/var\u003e: Region for the feature view where you want to write the features, such as `us-central1`.\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your project ID.\n- \u003cvar translate=\"no\"\u003eFEATUREONLINESTORE_NAME\u003c/var\u003e: The name of the online store instance containing the feature view.\n- \u003cvar translate=\"no\"\u003eFEATUREVIEW_NAME\u003c/var\u003e: The name of the new feature view instance where you want to write the features.\n- \u003cvar translate=\"no\"\u003eENTITY_ID\u003c/var\u003e: The entity ID for which you want to add feature values.\n- \u003cvar translate=\"no\"\u003eFEATURE_1\u003c/var\u003e and \u003cvar translate=\"no\"\u003eFEATURE_2\u003c/var\u003e: The features you want to add.\n- \u003cvar translate=\"no\"\u003eFEATURE_1_VALUE\u003c/var\u003e and \u003cvar translate=\"no\"\u003eFEATURE_2_VALUE\u003c/var\u003e: The feature values for \u003cvar translate=\"no\"\u003eFEATURE_1\u003c/var\u003e and \u003cvar translate=\"no\"\u003eFEATURE_2\u003c/var\u003e, respectively.\n\n\nHTTP method and URL:\n\n```\nPOST https://LOCATION_ID-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME:directWrite\n```\n\n\nRequest JSON body:\n\n```\n[\n {\n \"feature_view\": \"LOCATION_ID-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME\",\n \"data_key_and_feature_values\": {\n \"data_key\": {\n \"key\": \"ENTITY_ID\"\n },\n \"features\": [{\n \"name\": \"FEATURE_1\",\n \"value_and_timestamp\": {\n \"value\": {\n \"string_value\": \"FEATURE_1_VALUE\"\n }\n }\n },\n {\n \"name\": \"FEATURE_2\",\n \"value_and_timestamp\": {\n \"value\": {\n \"string_value\": \"FEATURE_2_VALUE\"\n }\n }\n }\n ]\n }\n }\n]\n\n```\n\nTo send your request, choose one of these options: \n\n#### curl\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nSave the request body in a file named `request.json`,\nand execute the following command:\n\n```\ncurl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n -d @request.json \\\n \"https://LOCATION_ID-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME:directWrite\"\n```\n\n#### PowerShell\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nSave the request body in a file named `request.json`,\nand execute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\" }\n\nInvoke-WebRequest `\n -Method POST `\n -Headers $headers `\n -ContentType: \"application/json; charset=utf-8\" `\n -InFile request.json `\n -Uri \"https://LOCATION_ID-aiplatform.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME:directWrite\" | Select-Object -Expand Content\n```\n\nYou should receive a JSON response similar to the following:\n\n```\n{\n \"status\": {},\n \"writeResponses\": [\n {\n \"dataKey\": {\n \"key\": \"ENTITY_ID\"\n },\n \"onlineStoreWriteTime\": \"2025-04-01T01:30:09.525061Z\"\n }\n ]\n}\n```\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\n- Learn how to [manually start a data sync](/vertex-ai/docs/featurestore/latest/sync-data).\n\n- Learn how to [update a feature view](/vertex-ai/docs/featurestore/latest/update-featureview)."]]