Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
En plus des schémas système prédéfinis, Vertex ML Metadata fournit un modèle de données extensible via des schémas personnalisés. Les schémas personnalisés sont des MetadataSchema définis par l'utilisateur. Utilisez des schémas personnalisés pour vérifier les types de propriétés des métadonnées et interroger les ressources par schéma (par exemple "répertorier tous les artefacts de type MyCustomModel").
Pour définir un schéma personnalisé, vous devez créer une ressource MetadataSchema dans un magasin de métadonnées spécifique qui décrit le schéma attendu. Le format de schéma est un sous-ensemble de la spécification OpenAPI 3.0{class: external}, avec la restriction que le schéma de premier niveau doit être de type object. Tous les types de données compatibles avec OpenAPI 3.0 (par exemple, entier, nombre, chaîne, booléen, tableau, objet) sont acceptés en tant que propriétés de cet objet de schéma de premier niveau. Une restriction est imposée : chaque champ situé sous la section "properties" ne peut être attribué qu'à un seul type de données. Les types mixtes ne sont pas acceptés. Les exigences de données avancées telles que le format minimal, maximal, multiple et la chaîne ne sont pas compatibles.
Enregistrer vos propres schémas personnalisés
Le processus de création d'un MetadataSchema personnalisé est semblable au processus de création de ressources de métadonnées. Les instructions suivantes montrent comment créer un exemple de MetadataSchema. Les MetadataSchema sont limités à leur MetadataStore associé.
REST
Avant d'utiliser les données de requête ci-dessous, effectuez les remplacements suivants :
METADATA_STORE : ID du magasin de métadonnées dans lequel le MetadataSchema est créé.
Le magasin de métadonnées par défaut s'appelle default. À moins qu'un nouveau MetadataStore ne soit requis, vous pouvez utiliser le magasin par défaut.
METADATA_SCHEMA_ID : (facultatif) ID de l'enregistrement MetadataSchema. Si l'ID n'est pas spécifié, Vertex ML Metadata crée un identifiant unique pour ce MetadataSchema.
METADATA_SCHEMA_TITLE : titre du schéma décrivant le champ de métadonnées. Le titre du schéma doit respecter le format ".". L'espace de noms doit commencer par une lettre minuscule, peut contenir des lettres minuscules et des chiffres, et peut comporter de 2 à 20 caractères. Le nom du schéma doit commencer par une lettre majuscule, peut inclure des lettres et des chiffres, et peut comporter de 2 à 49 caractères.
METADATA_SCHEMA_VERSION : version du schéma décrivant le champ de métadonnées. schema_version doit être une chaîne de trois nombres séparés par des points, par exemple : 1.0.0, 1.0.1. Ce format permet de trier et de comparer les versions.
METADATA_SCHEMA_TYPE : type de ressource de métadonnées auquel le schéma créé s'applique.
Les types sont les suivants : ARTIFACT_TYPE, EXECUTION_TYPE ou CONTEXT_TYPE.
METADATA_SCHEMA : schéma détaillé à créer.
DESCRIPTION : (facultatif) chaîne lisible qui décrit l'objectif de l'exécution à créer.
ARTIFACT_ID : (facultatif) ID de l'enregistrement de l'artefact. Si l'ID d'artefact n'est pas spécifié, Vertex ML Metadata crée un identifiant unique pour cet artefact.
DISPLAY_NAME : (facultatif) nom défini par l'utilisateur pour l'artefact.
Méthode HTTP et URL :
POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/metadataStores/METADATA_STORE/metadataSchemas?metadata_schema_id=METADATA_SCHEMA_ID
Pour envoyer votre requête, développez l'une des options suivantes :
curl (Linux, macOS ou Cloud Shell)
Enregistrez le corps de la requête dans un fichier nommé request.json.
Exécutez la commande suivante dans le terminal pour créer ou écraser ce fichier dans le répertoire actuel :
Enregistrez le corps de la requête dans un fichier nommé request.json.
Exécutez la commande suivante dans le terminal pour créer ou écraser ce fichier dans le répertoire actuel :
Des résultats semblables aux lignes suivantes devraient s'afficher : Vous pouvez utiliser METADATA_SCHEMA_ID avec l'ID de l'enregistrement MetadataSchema.
Les appels suivants pour créer, obtenir ou répertorier les artefacts peuvent ensuite faire référence à ce schéma en spécifiant le nom (demo.Artifact) dans le champ schema_title et la version (0.0.1) dans le champ schema_version de la ressource d'artefact. Pour en savoir plus sur la création, l'obtention ou l'affichage des ressources de métadonnées, consultez la page Effectuer le suivi des ressources Vertex ML Metadata.
Gérer les versions de vos schémas
Toutes les ressources MetadataSchema sont avec versions gérées. Un utilisateur peut créer un schéma qui utilise le même schéma schema_title qu'un autre schéma, mais un schéma schema_version différent.
Pour créer une ressource metadataSchema avec une version différente, un utilisateur peut fournir un numéro de version différent et un contenu de schéma modifié.
L'exemple suivant crée une version 0.0.2 du schéma demo.Artifact :
sample_schema_versioned=aip.MetadataSchema()sample_schema_versioned.schema_type=aip.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPEsample_schema_versioned.schema="title: demo.Artifact\ntype: object\nproperties:\n framework:\n type: string\n description: \"The framework type\"\n model_version:\n type: integer\n description: \"The version of the model\""sample_schema_versioned.schema_version="0.0.2"sample_schema_versioned.description="sample schema 2"store_client.create_metadata_schema(parent=metadata_store.name,metadata_schema=sample_schema_versioned)
Les champs du schéma sont toujours considérés comme facultatifs. Il n'y a donc pas de rétrocompatibilité ni de compatibilité ascendante entre les versions du même schema_title. Les utilisateurs peuvent toujours utiliser le schema_title pour filtrer et regrouper des ressources à des fins d'analyse. Pour en savoir plus sur l'utilisation des fonctions de filtre, consultez la page Analyser les métadonnées de Vertex ML.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/28 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/08/28 (UTC)."],[],[],null,["# Create and use custom schemas\n\nIn addition to the predefined system schemas, Vertex ML Metadata provides\nan extensible data model through custom schemas. Custom schemas are user-defined\nMetadataSchemas. Use custom schemas to type check metadata properties and to\nquery resources by schema, for example,\n\"list all Artifacts of type `MyCustomModel`.\n\nTo define a custom schema, you must create a MetadataSchema resource within a\nspecific MetadataStore that describes the expected schema. The schema format is\na subset of the [OpenAPI 3.0 specification](https://swagger.io/specification/#schema-object){class: external},\nwith the restriction that the top-level schema must be of type `object`. All\nOpenAPI 3.0 supported [data types](https://swagger.io/docs/specification/data-models/data-types/)\n(for example, integer, number, string, boolean, array, object) are supported as\nproperties of this top-level schema object. A restriction is that each field\nunder the properties section can be assigned to only one data type. Mixed types\nare not supported. Advanced data requirements such as Minimum,\nMaximum, Multiples, and string formats are also not supported.\n| **Note:** Fields in the schema are always considered optional when the system performs type checking. When you create new metadata resources, you can still include fields that are not defined in the schema.\n\nHow to register your own custom schemas\n---------------------------------------\n\nThe process to create a custom MetadataSchema is similar to creating new\nmetadata resources. The following instructions show how to create a sample\nMetadataSchema. MetadataSchemas are scoped only to their associated\nMetadataStore. \n\n### REST\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003eLOCATION_ID\u003c/var\u003e: The region of your MetadataStore.\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your [project ID](/resource-manager/docs/creating-managing-projects#identifiers) or number.\n- \u003cvar translate=\"no\"\u003eMETADATA_STORE\u003c/var\u003e: The metadata store ID where the MetadataSchema is created. The default metadata store is named `default`. Unless a new MetadataStore is required, you can use the default store.\n- \u003cvar translate=\"no\"\u003eMETADATA_SCHEMA_ID\u003c/var\u003e: (Optional) The ID of the MetadataSchema record. If the ID is not specified, Vertex ML Metadata creates a unique identifier for this MetadataSchema .\n- \u003cvar translate=\"no\"\u003eMETADATA_SCHEMA_TITLE\u003c/var\u003e: The title of the schema that describes the metadata field. The title of the schema must meet the format \\`.\\`. The namespace must start with a lowercase letter, can contain lowercase characters and numbers, and can be two to twenty characters long. The schema name must start with an uppercase letter, can include letters and numbers, and can be two to fortynice characters long.\n- \u003cvar translate=\"no\"\u003eMETADATA_SCHEMA_VERSION\u003c/var\u003e: (Optional) The version of the schema that describes the metadata field. `schema_version` must be a string of three numbers separated by periods, for example, 1.0.0, 1.0.1. This format helps order and compare versions..\n- \u003cvar translate=\"no\"\u003eMETADATA_SCHEMA_TYPE\u003c/var\u003e: The type of metadata resource to which the created schema applies. Types are: `ARTIFACT_TYPE`, `EXECUTION_TYPE`, or `CONTEXT_TYPE`.\n- \u003cvar translate=\"no\"\u003eMETADATA_SCHEMA\u003c/var\u003e: The detailed schema to create.\n- \u003cvar translate=\"no\"\u003eDESCRIPTION\u003c/var\u003e: (Optional) A human readable string, that describes the purpose of the execution to be created..\n- \u003cvar translate=\"no\"\u003eARTIFACT_ID\u003c/var\u003e: (Optional) The ID of the artifact record. If the artifact ID is not specified, Vertex ML Metadata creates a unique identifier for this artifact..\n- \u003cvar translate=\"no\"\u003eDISPLAY_NAME\u003c/var\u003e: (Optional) The user-defined name of the artifact..\n\n\nHTTP method and URL:\n\n```\nPOST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/metadataStores/METADATA_STORE/metadataSchemas?metadata_schema_id=METADATA_SCHEMA_ID\n```\n\n\nRequest JSON body:\n\n```\n{\n \"schemaVersion\": \"0.0.1\",\n \"schema\": \"title: test.Experiment\\ntype: object\",\n \"schemaType\": \"CONTEXT_TYPE\",\n}\n```\n\nTo send your request, expand one of these options:\n\n#### curl (Linux, macOS, or Cloud Shell)\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`.\nRun the following command in the terminal to create or overwrite\nthis file in the current directory: \n\n```\ncat \u003e request.json \u003c\u003c 'EOF'\n{\n \"schemaVersion\": \"0.0.1\",\n \"schema\": \"title: test.Experiment\\ntype: object\",\n \"schemaType\": \"CONTEXT_TYPE\",\n}\nEOF\n```\n\n\nThen execute the following command to send your REST request:\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/v1/projects/PROJECT_ID/locations/LOCATION_ID/metadataStores/METADATA_STORE/metadataSchemas?metadata_schema_id=METADATA_SCHEMA_ID\"\n```\n\n#### PowerShell (Windows)\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`.\nRun the following command in the terminal to create or overwrite\nthis file in the current directory: \n\n```\n@'\n{\n \"schemaVersion\": \"0.0.1\",\n \"schema\": \"title: test.Experiment\\ntype: object\",\n \"schemaType\": \"CONTEXT_TYPE\",\n}\n'@ | Out-File -FilePath request.json -Encoding utf8\n```\n\n\nThen execute the following command to send your REST request:\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/v1/projects/PROJECT_ID/locations/LOCATION_ID/metadataStores/METADATA_STORE/metadataSchemas?metadata_schema_id=METADATA_SCHEMA_ID\" | Select-Object -Expand Content\n```\n\nYou should see output similar to the following. You can use the\n\u003cvar translate=\"no\"\u003eMETADATA_SCHEMA_ID\u003c/var\u003e is the ID of the MetadataSchema record.\n\n```\n{\n \"name\": \"projects/PROJECT_ID/locations/LOCATION_ID/metadataStores/METADATA_STORE/metadataSchemas/METADATA_SCHEMA_ID\",\n \"schemaVersion\": \"0.0.1\",\n \"schema\": \"title: test.Experiment\\ntype: object\",\n \"schemaType\": \"CONTEXT_TYPE\",\n \"createTime\": \"2021-04-06T05:24:04.575481815Z\"\n}\n\n```\n\nSubsequent calls to create, get, or list Artifacts can then refer to this schema\nby specifying the name (demo.Artifact) in the schema_title field and version\n(0.0.1) in the schema_version of the Artifact resource. For more information about\nhow to create, get, or list metadata resources, see\n[Track Vertex ML Metadata](/vertex-ai/docs/ml-metadata/tracking).\n\nVersion your schemas\n--------------------\n\nAll MetadataSchema resources are versioned. A user can create a schema that\nuses the same schema_title as another schema but a different schema_version.\nTo create a metadataSchema resource with a different version, a user can\nprovide a different version number and modified schema content.\n\nThe following example creates a 0.0.2 version of the demo.Artifact schema: \n\n sample_schema_versioned = aip.MetadataSchema()\n sample_schema_versioned.schema_type = aip.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE\n sample_schema_versioned.schema =\"title: demo.Artifact\\ntype: object\\nproperties:\\n framework:\\n type: string\\n description: \\\"The framework type\\\"\\n model_version:\\n type: integer\\n description: \\\"The version of the model\\\"\"\n sample_schema_versioned.schema_version = \"0.0.2\"\n sample_schema_versioned.description = \"sample schema 2\"\n\n store_client.create_metadata_schema(parent=metadata_store.name, metadata_schema=sample_schema_versioned)\n\nFields in the schema are always considered optional, so there is\nno backward or forward compatibility between versions of the same\nschema_title. Users can still use the schema_title to filter and group\nresources for analysis. For more information about\nhow to use filter functions, see\n[Analyzing Vertex ML Metadata](/vertex-ai/docs/ml-metadata/analyzing).\n\nWhat's next\n-----------\n\n- [Get started tracking your Vertex ML Metadata](/vertex-ai/docs/ml-metadata/tracking)."]]