如何在指定或自有Vertex MetadataStore中查找所有系统Schema?
在Vertex ML Metadata中查找系统定义Schema的方法
一、在指定Vertex MetadataStore中查找系统Schema
使用Vertex AI Python客户端
- 初始化客户端并连接到目标MetadataStore
from google.cloud import aiplatform # 配置项目、区域和MetadataStore ID(使用默认存储可省略metadata_store_id参数) aiplatform.init( project="你的项目ID", location="你的区域", metadata_store_id="目标MetadataStore ID" ) metadata_client = aiplatform.metadata.client.MetadataClient()
- 过滤并列出所有系统定义Schema
系统Schema的名称均以system.为前缀,通过该特征过滤:
system_schemas = [ schema for schema in metadata_client.list_metadata_schemas() if schema.name.split("/")[-1].startswith("system.") ] # 打印系统Schema信息 for schema in system_schemas: schema_name = schema.name.split("/")[-1] print(f"Schema名称: {schema_name}") print(f"描述: {schema.description}") print(f"版本: {schema.schema_version}") print("---")
使用ml-metadata原生客户端
如果需要更底层的操作,可直接使用ml-metadata库:
from ml_metadata import metadata_store from ml_metadata.proto import metadata_store_pb2 # 配置MetadataStore连接 connection_config = metadata_store_pb2.ConnectionConfig() connection_config.gcp_config.project_id = "你的项目ID" connection_config.gcp_config.region = "你的区域" connection_config.gcp_config.metadata_store_id = "目标MetadataStore ID" store = metadata_store.MetadataStore(connection_config) # 列出并过滤系统Schema for schema in store.get_all_metadata_schemas(): if schema.name.startswith("system."): print(f"Schema名称: {schema.name}") print(f"描述: {schema.description}") print("---")
二、在自有Vertex MetadataStore中查找系统Schema
自有MetadataStore(即你自行创建的非默认存储)的查找方法与上述完全一致,只需在初始化客户端时,将metadata_store_id指定为你创建的存储ID即可。系统定义Schema是Vertex ML Metadata全局提供的公共资源,所有MetadataStore均可访问。
查看特定系统Schema的详细结构
如需查看某一系统Schema的完整结构(如字段定义),可调用获取单个Schema的方法:
# 以system.Dataset为例 dataset_schema = metadata_client.get_metadata_schema( name="projects/你的项目ID/locations/你的区域/metadataStores/你的存储ID/metadataSchemas/system.Dataset" ) print(dataset_schema.schema)
内容的提问来源于stack exchange,提问作者Jialu Zhang
相关产品推荐
相关产品推荐

