將特徵值寫入線上商店時,會使用特徵儲存庫的 CPU 資源 (線上儲存節點)。監控 CPU 使用率,確認需求量未超過供應量,以免發生放送錯誤。建議使用率維持在 70% 以下,以免發生這類錯誤。如果經常超過該值,可以更新特徵商店,增加節點數量或使用自動調整功能。詳情請參閱「管理特徵商店」。
串流匯入
將值寫入特定特徵。特徵值必須包含在匯入要求中。您無法直接從資料來源串流資料。
如果您要寫入最近建立的功能,請稍候幾分鐘再執行,因為新功能可能尚未傳播。否則可能會看到 resource not found 錯誤。
每次寫入作業只能匯入一個實體的特徵值。針對任何特定專案和區域,您最多可以同時為十種不同實體類型中的多個實體寫入特徵值。這項限制包括將串流匯入要求傳送至指定專案和區域中的所有特徵商店。如果超過這個限制,Vertex AI 特徵儲存庫 (舊版) 可能無法將所有資料寫入離線儲存空間。如果發生這種情況,Vertex AI 特徵儲存庫 (舊版) 會在 記錄檔總管中記錄錯誤。詳情請參閱「監控串流匯入的離線儲存空間寫入錯誤」。
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID:writeFeatureValues
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-02 (世界標準時間)。"],[],[],null,["# Streaming import\n\n| To learn more,\n| run the \"Example Feature Store workflow with sample data\" notebook in one of the following\n| environments:\n|\n| [Open in Colab](https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store_legacy/sdk-feature-store.ipynb)\n|\n|\n| \\|\n|\n| [Open in Colab Enterprise](https://console.cloud.google.com/vertex-ai/colab/import/https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fofficial%2Ffeature_store_legacy%2Fsdk-feature-store.ipynb)\n|\n|\n| \\|\n|\n| [Open\n| in Vertex AI Workbench](https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fofficial%2Ffeature_store_legacy%2Fsdk-feature-store.ipynb)\n|\n|\n| \\|\n|\n| [View on GitHub](https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/feature_store_legacy/sdk-feature-store.ipynb)\n\nStreaming import lets you make real-time updates to feature values. This\nmethod is useful when having the latest available data for online serving is a\npriority. For example, you can import streaming event data and, within a few\nseconds, Vertex AI Feature Store (Legacy) makes that data available for online\nserving scenarios.\n\nIf you must backfill data or if you compute feature values in batch, use [batch\nimport](/vertex-ai/docs/featurestore/ingesting-batch). Compared to streaming import requests, [batch\nimport](/vertex-ai/docs/featurestore/ingesting-batch) requests can handle larger payloads but\ntake longer to complete.\n\nFor information about the oldest feature value timestamp that you can import,\nsee [Vertex AI Feature Store (Legacy)](/vertex-ai/docs/quotas#featurestore) in [Quotas and limits](/vertex-ai/docs/quotas).\nYou can't import feature values for which the timestamps indicate future dates or times.\n\nExample use case\n----------------\n\nAn online retail organization might provide a personalized shopping experience\nby using the current activity of a user. As users navigate through the website,\nyou can capture their activity into a featurestore and then, soon\nafter, serve all that information for online predictions. This real-time\nimport and serving can help you show useful and relevant recommendations to\ncustomers during their shopping session.\n\nOnline storage node usage\n-------------------------\n\nWriting feature values to an online store uses the featurestore's CPU resources\n(online storage nodes). [Monitor](/vertex-ai/docs/featurestore/monitoring#featurestore) your CPU\nusage to check that demand doesn't exceed supply, which can lead to serving\nerrors. We recommend around a 70% usage rate or lower to avoid these errors. If\nyou regularly exceed that value, you can update your featurestore to increase\nthe number of nodes or use autoscaling. For more information, see [Manage\nfeaturestores](/vertex-ai/docs/featurestore/managing-featurestores).\n\nStreaming import\n----------------\n\nWrite a value to a particular feature. The feature value must be included as\npart of the import request. You can't stream data directly from a data\nsource.\n\nIf you're writing to recently created features, wait a few minutes before you\ndo so because the new features might not have propagated yet. If you don't, you\nmight see a `resource not found` error.\n\nYou can import feature values for only one entity per write. For any specific project and region, you can simultaneously write feature values for multiple entities within a maximum of ten different entity types. This limit includes streaming import requests to all\nfeaturestores in a given project and region. If you exceed this limit,\nVertex AI Feature Store (Legacy) might not write all of your data to the\noffline store. If this occurs, Vertex AI Feature Store (Legacy) logs the error in the **Logs Explorer** . For more information, see [Monitor offline storage write errors for streaming import](/vertex-ai/docs/featurestore/monitoring#monitor_offline_storage_write_errors). \n\n### REST\n\n\nTo import feature values for existing features, send a POST request by using the\n[featurestores.entityTypes.writeFeatureValues](/vertex-ai/docs/reference/rest/v1/projects.locations.featurestores.entityTypes/writeFeatureValues)\nmethod. If the names of the source data columns and the destination feature IDs\nare different, include the `sourceField` parameter. Note that [featurestores.entityTypes.writeFeatureValues](/vertex-ai/docs/reference/rest/v1/projects.locations.featurestores.entityTypes/writeFeatureValues) lets you import feature values for only one entity at a time.\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: Region where the featurestore is created. For example, `us-central1`.\n- \u003cvar translate=\"no\"\u003ePROJECT\u003c/var\u003e: Your [project ID](/resource-manager/docs/creating-managing-projects#identifiers).\n- \u003cvar translate=\"no\"\u003eFEATURESTORE_ID\u003c/var\u003e: ID of the featurestore.\n- \u003cvar translate=\"no\"\u003eENTITY_TYPE_ID\u003c/var\u003e: ID of the entity type.\n- \u003cvar translate=\"no\"\u003eFEATURE_ID\u003c/var\u003e: ID of an existing feature in the featurestore to write values for.\n- \u003cvar translate=\"no\"\u003eVALUE_TYPE\u003c/var\u003e: The [value\n type](/vertex-ai/docs/reference/rest/v1/projects.locations.featurestores.entityTypes.features#ValueType) of the feature.\n- \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e: Value for the feature.\n- \u003cvar translate=\"no\"\u003eTIME_STAMP\u003c/var\u003e (optional): The time at which the feature was generated. The timestamp must be in the RFC3339 UTC format.\n\n\nHTTP method and URL:\n\n```\nPOST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID:writeFeatureValues\n```\n\n\nRequest JSON body:\n\n```\n{\n \"payloads\": [\n {\n \"entityId\": \"ENTITY_ID\",\n \"featureValues\": {\n \"FEATURE_ID\": {\n \"VALUE_TYPE\": VALUE,\n \"metadata\": {\"generate_time\": \"TIME_STAMP\"}\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-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID:writeFeatureValues\"\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-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/featurestores/FEATURESTORE_ID/entityTypes/ENTITY_TYPE_ID:writeFeatureValues\" | Select-Object -Expand Content\n```\n\nYou should receive a successful status code (2xx) and an empty response.\n\n### Python\n\nTo learn how to install or update the Vertex AI SDK for Python, see [Install the Vertex AI SDK for Python](/vertex-ai/docs/start/use-vertex-ai-python-sdk).\n\nFor more information, see the\n[Python API reference documentation](/python/docs/reference/aiplatform/latest).\n\n from google.cloud import aiplatform\n\n\n def write_feature_values_sample(\n project: str, location: str, entity_type_id: str, featurestore_id: str\n ):\n\n aiplatform.init(project=project, location=location)\n\n my_entity_type = aiplatform.featurestore.EntityType(\n entity_type_name=entity_type_id, featurestore_id=featurestore_id\n )\n\n my_data = {\n \"movie_01\": {\n \"title\": \"The Shawshank Redemption\",\n \"average_rating\": 4.7,\n \"genre\": \"Drama\",\n },\n }\n\n my_entity_type.write_feature_values(instances=my_data)\n\n### Additional languages\n\nYou can [install](/vertex-ai/docs/start/client-libraries) and use the\nfollowing Vertex AI client libraries to call the\nVertex AI API. Cloud Client Libraries provide an optimized developer\nexperience by using the natural conventions and\nstyles of each supported language.\n\n- [Java](/java/docs/reference/google-cloud-aiplatform/latest/overview)\n- [Node.js](/nodejs/docs/reference/aiplatform/latest)\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\n- Learn how to [monitor offline storage write errors for streaming import](/vertex-ai/docs/featurestore/monitoring#monitor_offline_storage_write_errors).\n- Learn how to serve features through [online\n serving](/vertex-ai/docs/featurestore/serving-online) or [batch\n serving](/vertex-ai/docs/featurestore/serving-batch).\n- [Troubleshoot](/vertex-ai/docs/general/troubleshooting#feature-store) common Vertex AI Feature Store (Legacy) issues."]]