Todos os produtos
Search
Central de documentação

Intelligent Media Management:Creating a metadata index

Última atualização: Jun 27, 2026

Após criar um dataset, crie um índice de metadados para arquivos em serviços como Object Storage Service (OSS) e Drive and Photo Service (PDS) para gerenciar e recuperar grandes volumes de arquivos de mídia com eficiência.

Pré-requisitos

Você já criou um dataset. Para mais informações, consulte Criar um dataset.

Visão geral

Um índice de metadados permite pesquisar, filtrar e gerenciar grandes coleções de arquivos de mídia por palavras-chave, atributos ou outros identificadores.

Procedimento

Indexe automaticamente todos os arquivos em um bucket do OSS ou indexe manualmente arquivos específicos em um bucket do OSS ou no PDS.

Indexar automaticamente todos os arquivos em um bucket do OSS

Para indexar automaticamente todos os arquivos em um bucket do OSS, vincule um dataset ao bucket chamando uma API ou adicionando uma source de dados no console do IMM. Após a vinculação, o Intelligent Media Management (IMM) varre completamente os dados existentes no bucket, extrai os metadados dos arquivos e os indexa. Em seguida, o IMM monitora o bucket em busca de novos arquivos e executa varreduras incrementais em tempo real para extrair e indexar os metadados correspondentes.

Aviso

Importante: Após a criação bem-sucedida da vinculação, o IMM inicia uma varredura dos arquivos existentes ou novos no bucket do OSS especificado. Quanto mais objetos o bucket contiver, maiores serão os custos de varredura de metadados. Para mais informações, consulte Faturamento do IMM. Se você estiver testando este recurso ou não tiver certeza do resultado, use um bucket do OSS com poucos arquivos e selecione cuidadosamente um modelo de fluxo de trabalho para evitar cobranças inesperadas.

API

O exemplo a seguir indexa todos os arquivos no bucket test-bucket e armazena o índice no dataset test-dataset do projeto test-project.

  1. Chame CreateBinding para vincular o dataset ao bucket do OSS.

    • Exemplo de solicitação

      {
          "ProjectName": "test-project",
          "URI": "oss://test-bucket",
          "DatasetName": "test-dataset"
      }
    • Exemplo de resposta

      {
          "Binding": {
              "Phase": "",
              "ProjectName": "test-project",
              "DatasetName": "test-dataset",
              "State": "Ready",
              "CreateTime": "2022-07-06T07:03:28.054762739+08:00",
              "UpdateTime": "2022-07-06T07:03:28.054762739+08:00",
              "URI": "oss://test-bucket"
          },
          "RequestId": "090D2AC5-8450-0AA8-A1B1-****"
      }
    • Exemplo de código (SDK Python)

      # -*- coding: utf-8 -*-
      import os
      from alibabacloud_imm20200930.client import Client as imm20200930Client
      from alibabacloud_tea_openapi import models as open_api_models
      from alibabacloud_imm20200930 import models as imm_20200930_models
      from alibabacloud_tea_util import models as util_models
      from alibabacloud_tea_util.client import Client as UtilClient
      class Sample:
          def __init__(self):
              pass
          @staticmethod
          def create_client(
              access_key_id: str,
              access_key_secret: str,
          ) -> imm20200930Client:
              """
              Use an AccessKey ID and AccessKey secret to initialize a client.
              @param access_key_id:
              @param access_key_secret:
              @return: Client
              @throws Exception
              """
              config = open_api_models.Config(
                  access_key_id=access_key_id,
                  access_key_secret=access_key_secret
              )
              # Specify the endpoint.
              config.endpoint = f'imm.cn-beijing.aliyuncs.com'
              return imm20200930Client(config)
          @staticmethod
          def main() -> None:
              # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations.
              # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code.
              # This example shows how to read the AccessKey pair from environment variables for authentication. For more information about how to configure environment variables, see https://www.alibabacloud.com/help/document_detail/2361894.html.
              imm_access_key_id = os.getenv("AccessKeyId")
              imm_access_key_secret = os.getenv("AccessKeySecret")
              client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
              create_binding_request = imm_20200930_models.CreateBindingRequest(
                  # Specify the name of the IMM project.
                  project_name='test-project',
                  # Specify the name of the IMM dataset.
                  dataset_name='test-dataset',
                  # Specify the URI of the OSS bucket to bind.
                  uri='oss://test-bucket'
              )
              runtime = util_models.RuntimeOptions()
              try:
                  # Print the API response.
                  response = client.create_binding_with_options(create_binding_request, runtime)
                  print(response.body.to_map())
              except Exception as error:
                  # If an error occurs, print the error message.
                  UtilClient.assert_as_string(error.message)
                  print(error)
      if __name__ == '__main__':
          Sample.main()
  2. Opcional: Chame GetBinding para consultar o status da vinculação.

    • Exemplo de solicitação

      {
          "ProjectName": "test-project",
          "URI": "oss://test-bucket",
          "DatasetName": "test-dataset"
      }
    • Exemplo de resposta

      {
          "Binding": {
              "Phase": "IncrementalScanning",
              "ProjectName": "test-project",
              "DatasetName": "test-dataset",
              "State": "Running",
              "CreateTime": "2022-07-06T07:04:05.105182822+08:00",
              "UpdateTime": "2022-07-06T07:04:13.302084076+08:00",
              "URI": "oss://test-bucket"
          },
          "RequestId": "B5A9F54B-6C54-03C9-B011-****"
      }
      Nota
      • Se o valor do parâmetro Phase for IncrementalScanning, o IMM concluiu a indexação dos dados existentes no bucket do OSS e está executando uma varredura incremental de novos arquivos.

      • Se o valor do parâmetro State for Running, a vinculação está ativa.

    • Exemplo de código (SDK Python 1.27.3)

      # -*- coding: utf-8 -*-
      import os
      from alibabacloud_imm20200930.client import Client as imm20200930Client
      from alibabacloud_tea_openapi import models as open_api_models
      from alibabacloud_imm20200930 import models as imm_20200930_models
      from alibabacloud_tea_util import models as util_models
      from alibabacloud_tea_util.client import Client as UtilClient
      class Sample:
          def __init__(self):
              pass
          @staticmethod
          def create_client(
              access_key_id: str,
              access_key_secret: str,
          ) -> imm20200930Client:
              """
              Use an AccessKey ID and AccessKey secret to initialize a client.
              @param access_key_id:
              @param access_key_id:
              @param access_key_secret:
              @return: Client
              @throws Exception
              """
              config = open_api_models.Config(
                  access_key_id=access_key_id,
                  access_key_secret=access_key_secret
              )
              # Specify the endpoint.
              config.endpoint = f'imm.cn-beijing.aliyuncs.com'
              return imm20200930Client(config)
          @staticmethod
          def main() -> None:
              # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations.
              # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code.
              # This example shows how to read the AccessKey pair from environment variables for authentication. For more information about how to configure environment variables, see https://www.alibabacloud.com/help/document_detail/2361894.html.
              imm_access_key_id = os.getenv("AccessKeyId")
              imm_access_key_secret = os.getenv("AccessKeySecret")
              client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
              get_binding_request = imm_20200930_models.GetBindingRequest(
                  # Specify the name of the IMM project.
                  project_name='test-project',
                  # Specify the name of the IMM dataset.
                  dataset_name='test-dataset',
                  # Specify the URI of the bound OSS bucket.
                  uri='oss://test-bucket'
              )
              runtime = util_models.RuntimeOptions()
              try:
                  # Print the API response.
                  response = client.get_binding_with_options(get_binding_request, runtime)
                  print(response.body.to_map())
              except Exception as error:
                  # If an error occurs, print the error message.
                  UtilClient.assert_as_string(error.message)
                  print(error)
      if __name__ == '__main__':
          Sample.main()

Add data source

  1. No seu projeto, localize o dataset test-dataset.

    No painel de navegação à esquerda, escolha Data Management & Indexing > Datasets. Localize test-dataset na lista.

  1. Clique em dataset test-dataset, selecione a aba Data access e clique em New Data Source.

  2. Selecione o bucket que deseja vincular e clique em OK.

    Nota

    Ao adicionar uma source de dados, o IMM cria primeiro tarefas de extração de metadados para os arquivos existentes no bucket. Depois, o IMM monitora continuamente a source de dados em busca de eventos e cria novas tarefas conforme necessário. Essas tarefas geram cobranças. Para mais informações, consulte Visão geral do faturamento. Recomendamos testar este recurso com um bucket que contenha poucos dados.

Indexar arquivos específicos manualmente

API

Para indexar manualmente arquivos específicos em um bucket do OSS ou no PDS, chame BatchIndexFileMeta ou IndexFileMeta.

  • Chame a operação BatchIndexFileMeta

    O exemplo a seguir indexa os arquivos do OSS oss://test-bucket/test-object1.jpg e oss://test-bucket/test-object2.jpg no dataset test-dataset do projeto test-project.

    • Exemplo de solicitação

      {
        "ProjectName": "test-project",
        "DatasetName": "test-dataset",
        "Files": [
          {
            "URI": "oss://test-bucket/test-object1.jpg",
            "CustomLabels": {
              "category": "People"
            }
          },
          {
            "URI": "oss://test-bucket/test-object2.jpg",
            "CustomLabels": {
              "category": "Pets"
            }
          }
        ],
        "Notification": {
          "MNS": {
            "TopicName": "test-topic"
          }
        }
      }
    • Exemplo de resposta

      {
          "RequestId": "0D4CB096-EB44-02D6-A4E9-****",
          "EventId": "16C-1KoeYbdckkiOObpyzc****"
      }
    • Mensagem do Simple Message Queue (MNS). O resultado é retornado em uma mensagem do MNS. Para mais informações sobre o SDK do MNS, consulte Etapa 4: Receber e excluir mensagens.

      {
          "ProjectName": "test-project",
          "DatasetName": "test-dataset",
          "RequestId": "658FFD57-B495-07C0-B24B-B64CC52993CB",
          "StartTime": "2022-07-06T07:18:18.664770352+08:00",
          "EndTime": "2022-07-06T07:18:20.762465221+08:00",
          "Success": true,
          "Message": "",
          "Files": [
              {
                  "URI": "oss://test-bucket/test-object1.jpg",
                  "CustomLabels": {
                      "category": "People"
                  },
                  "Error": ""
              },
              {
                  "URI": "oss://test-bucket/test-object2.jpg",
                  "CustomLabels": {
                      "category": "Pets"
                  },
                  "Error": ""
              }
          ]
      }
      Nota
      • Se o parâmetro Success for true, a tarefa de indexação de metadados foi concluída com êxito.

      • O array Files retorna a URI e as informações de erro de cada arquivo. Se o campo Error estiver vazio, os metadados do arquivo foram indexados com êxito.

    • Exemplo de código (SDK Python)

      # -*- coding: utf-8 -*-
      # This file is auto-generated, don't edit it. Thanks.
      import sys
      import os
      from typing import List
      from alibabacloud_imm20200930.client import Client as imm20200930Client
      from alibabacloud_tea_openapi import models as open_api_models
      from alibabacloud_imm20200930 import models as imm_20200930_models
      from alibabacloud_tea_util import models as util_models
      from alibabacloud_tea_util.client import Client as UtilClient
      class Sample:
          def __init__(self):
              pass
          @staticmethod
          def create_client(
              access_key_id: str,
              access_key_secret: str,
          ) -> imm20200930Client:
              """
              Use an AccessKey ID and AccessKey secret to initialize a client.
              @param access_key_id:
              @param access_key_secret:
              @return: Client
              @throws Exception
              """
              config = open_api_models.Config(
                  access_key_id=access_key_id,
                  access_key_secret=access_key_secret
              )
              # Specify the endpoint.
              config.endpoint = f'imm.cn-beijing.aliyuncs.com'
              return imm20200930Client(config)
          @staticmethod
          def main(
              args: List[str],
          ) -> None:
              # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations.
              # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code.
              # This example shows how to read the AccessKey pair from environment variables for authentication. For more information about how to configure environment variables, see https://www.alibabacloud.com/help/document_detail/2361894.html.
              imm_access_key_id = os.getenv("AccessKeyId")
              imm_access_key_secret = os.getenv("AccessKeySecret")
              client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
              notification_mns = imm_20200930_models.MNS(
                  topic_name='test-topic'
              )
              notification = imm_20200930_models.Notification(
                  mns=notification_mns
              )
              input_file_0custom_labels = {
                  'category': 'People'
              }
              input_file_0 = imm_20200930_models.InputFile(
                  uri='oss://test-bucket/test-object1.jpg',
                  custom_labels=input_file_0custom_labels
              )
              input_file_1custom_labels = {
                  'category': 'Pets'
              }
              input_file_1 = imm_20200930_models.InputFile(
                  uri='oss://test-bucket/test-object2.jpg',
                  custom_labels=input_file_1custom_labels
              )
              batch_index_file_meta_request = imm_20200930_models.BatchIndexFileMetaRequest(
                  project_name='test-project',
                  dataset_name='test-dataset',
                  files=[
                      input_file_0,
                      input_file_1
                  ],
                  notification=notification
              )
              runtime = util_models.RuntimeOptions()
              try:
                  # Send the request to start the asynchronous indexing task.
                  client.batch_index_file_meta_with_options(batch_index_file_meta_request, runtime)
              except Exception as error:
                  # If an error occurs, print the error message.
                  UtilClient.assert_as_string(error.message)
          @staticmethod
          async def main_async(
              args: List[str],
          ) -> None:
              # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations.
              # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code.
              # This example shows how to read the AccessKey pair from environment variables for authentication. For more information about how to configure environment variables, see https://www.alibabacloud.com/help/document_detail/2361894.html.
              imm_access_key_id = os.getenv("AccessKeyId")
              imm_access_key_secret = os.getenv("AccessKeySecret")
              client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
              notification_mns = imm_20200930_models.MNS(
                  topic_name='test-topic'
              )
              notification = imm_20200930_models.Notification(
                  mns=notification_mns
              )
              input_file_0custom_labels = {
                  'category': 'People'
              }
              input_file_0 = imm_20200930_models.InputFile(
                  uri='oss://test-bucket/test-object1.jpg',
                  custom_labels=input_file_0custom_labels
              )
              input_file_1custom_labels = {
                  'category': 'Pets'
              }
              input_file_1 = imm_20200930_models.InputFile(
                  uri='oss://test-bucket/test-object2.jpg',
                  custom_labels=input_file_1custom_labels
              )
              batch_index_file_meta_request = imm_20200930_models.BatchIndexFileMetaRequest(
                  project_name='test-project',
                  dataset_name='test-dataset',
                  files=[
                      input_file_0,
                      input_file_1
                  ],
                  notification=notification
              )
              runtime = util_models.RuntimeOptions()
              try:
                  # When you run the code, print the API response.
                  await client.batch_index_file_meta_with_options_async(batch_index_file_meta_request, runtime)
              except Exception as error:
                  # If an error occurs, print the error message.
                  UtilClient.assert_as_string(error.message)
      if __name__ == '__main__':
          Sample.main(sys.argv[1:])
  • Chame a operação IndexFileMeta

    O exemplo a seguir indexa o arquivo do OSS oss://test-bucket/test-object1.jpg no dataset test-dataset do projeto test-project.

    • Exemplo de solicitação

      {
        "ProjectName": "test-project",
        "DatasetName": "test-dataset",
        "File": {
          "URI": "oss://test-bucket/test-object1.jpg",
          "CustomLabels": {
            "category": "People"
          }
        },
        "Notification": {
          "MNS": {
            "TopicName": "test-topic"
          }
        }
      }
    • Exemplo de resposta

      {
          "RequestId": "5AA694AD-3D10-0B6A-85B2-****",
          "EventId": "17C-1Kofq1mlJxRYF7vAGF****"
      }
    • Mensagem do Simple Message Queue (MNS). O resultado é retornado em uma mensagem do MNS. Para mais informações sobre o SDK do MNS, consulte Etapa 4: Receber e excluir mensagens.

      {
          "ProjectName": "test-project",
          "DatasetName": "test-dataset",
          "RequestId": "658FFD57-B495-07C0-B24B-B64CC52993CB",
          "StartTime": "2022-07-06T07:18:18.664770352+08:00",
          "EndTime": "2022-07-06T07:18:20.762465221+08:00",
          "Success": true,
          "Message": "",
          "Files": [
              {
                  "URI": "oss://test-bucket/test-object1.jpg",
                  "CustomLabels": {
                      "category": "People"
                  },
                  "Error": ""
              }
          ]
      }
      Nota
      • Se o parâmetro Success for true, a tarefa de indexação de metadados foi concluída com êxito.

      • O array Files retorna a URI e as informações de erro do arquivo. Se o campo Error estiver vazio, os metadados do arquivo foram indexados com êxito.

    • Exemplo de código (SDK Python)

      # -*- coding: utf-8 -*-
      # This file is auto-generated, don't edit it. Thanks.
      import sys
      import os
      from typing import List
      from alibabacloud_imm20200930.client import Client as imm20200930Client
      from alibabacloud_tea_openapi import models as open_api_models
      from alibabacloud_imm20200930 import models as imm_20200930_models
      from alibabacloud_tea_util import models as util_models
      from alibabacloud_tea_util.client import Client as UtilClient
      class Sample:
          def __init__(self):
              pass
          @staticmethod
          def create_client(
              access_key_id: str,
              access_key_secret: str,
          ) -> imm20200930Client:
              """
              Use an AccessKey ID and AccessKey secret to initialize a client.
              @param access_key_id:
              @param access_key_secret:
              @return: Client
              @throws Exception
              """
              config = open_api_models.Config(
                  access_key_id=access_key_id,
                  access_key_secret=access_key_secret
              )
              # Specify the endpoint.
              config.endpoint = f'imm.cn-beijing.aliyuncs.com'
              return imm20200930Client(config)
          @staticmethod
          def main(
              args: List[str],
          ) -> None:
              # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations.
              # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code.
              # This example shows how to read the AccessKey pair from environment variables for authentication. For more information about how to configure environment variables, see https://www.alibabacloud.com/help/document_detail/2361894.html.
              imm_access_key_id = os.getenv("AccessKeyId")
              imm_access_key_secret = os.getenv("AccessKeySecret")
              client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
              notification_mns = imm_20200930_models.MNS(
                  topic_name='test-topic'
              )
              notification = imm_20200930_models.Notification(
                  mns=notification_mns
              )
              input_file_custom_labels = {
                  'category': 'People'
              }
              input_file = imm_20200930_models.InputFile(
                  uri='oss://test-bucket/test-object1.jpg',
                  custom_labels=input_file_custom_labels
              )
              index_file_meta_request = imm_20200930_models.IndexFileMetaRequest(
                  project_name='test-project',
                  dataset_name='test-dataset',
                  file=input_file,
                  notification=notification
              )
              runtime = util_models.RuntimeOptions()
              try:
                  # When you run the code, print the API response.
                  client.index_file_meta_with_options(index_file_meta_request, runtime)
              except Exception as error:
                  # If an error occurs, print the error message.
                  UtilClient.assert_as_string(error.message)
          @staticmethod
          async def main_async(
              args: List[str],
          ) -> None:
              # The AccessKey pair of an Alibaba Cloud account grants full access to all APIs. For better security, we recommend that you use a RAM user for API calls and daily operations.
              # To prevent security risks, do not hard-code your AccessKey ID and AccessKey secret in your project code.
              # This example shows how to read the AccessKey pair from environment variables for authentication. For more information about how to configure environment variables, see https://www.alibabacloud.com/help/document_detail/2361894.html.
              imm_access_key_id = os.getenv("AccessKeyId")
              imm_access_key_secret = os.getenv("AccessKeySecret")
              client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
              notification_mns = imm_20200930_models.MNS(
                  topic_name='test-topic'
              )
              notification = imm_20200930_models.Notification(
                  mns=notification_mns
              )
              input_file_custom_labels = {
                  'category': 'People'
              }
              input_file = imm_20200930_models.InputFile(
                  uri='oss://test-bucket/test-object1.jpg',
                  custom_labels=input_file_custom_labels
              )
              index_file_meta_request = imm_20200930_models.IndexFileMetaRequest(
                  project_name='test-project',
                  dataset_name='test-dataset',
                  file=input_file,
                  notification=notification
              )
              runtime = util_models.RuntimeOptions()
              try:
                  # When you run the code, print the API response.
                  await client.index_file_meta_with_options_async(index_file_meta_request, runtime)
              except Exception as error:
                  # If an error occurs, print the error message.
                  UtilClient.assert_as_string(error.message)
      if __name__ == '__main__':
          Sample.main(sys.argv[1:])

Batch add

Nota

Adicione vários arquivos de um bucket do OSS a um dataset em uma única operação em lote. O IMM executa um fluxo de trabalho assíncrono para extrair e indexar metadados desses novos arquivos. Esse fluxo de trabalho oferece suporte a notificações por mensagem; portanto, ao adicionar os arquivos, especifique um tópico do MNS para receber os resultados da tarefa. Para mais informações, consulte Formato de mensagem de notificação assíncrona.

  1. No seu projeto, localize o dataset test-dataset.

  2. Clique em dataset test-dataset, selecione a aba Data access e clique em Batch Add.

  3. No painel Add File to Dataset, insira o nome do tópico do Simple Message Queue (MNS) para recebimento dos resultados e clique em Select File para adicionar os arquivos que deseja indexar.

    Após adicionar os arquivos, visualize os registros de arquivos do OSS na lista. Clique em Edit Labels para adicionar rótulos personalizados a um arquivo ou em Delete para remover um arquivo.