Tasks

Tasks handle the uploading and processing of videos. Because these operations take some time, video uploading and processing are asynchronous.

The platform utilizes two primary types of tasks:

  • Video indexing tasks: These tasks upload and index videos, making their content accesible to the Search and Analyze APIs.
  • Video embedding tasks: These tasks upload videos and process videos, making their content accessible to the Embed API.

Video indexing tasks

A video indexing task transitions through the following stages, each representing a phase in the platform’s processing:

  • validating: Ensures the video meets requirements.
  • pending: Assigns a server to process the video.
  • queued: Prepares the video for indexing.
  • indexing: Converts the video into embeddings.
  • ready: Completes the process, making the video usable.
  • failed: Indicates an error occurred.

The example code below shows how you can track the progress of a task, checking its status until it’s completed:

1task = client.tasks.create(
2 index_id="<YOUR_INDEX_ID>", video_url="<YOUR_VIDEO_URL>")
3print(f"Created task: id={task.id}")
4
5def on_task_update(task: TasksRetrieveResponse):
6 print(f" Status={task.status}")
7
8task = client.tasks.wait_for_done(task_id=task.id, callback=on_task_update)
9if task.status != "ready":
10 raise RuntimeError(f"Indexing failed with status {task.status}")
11print(
12 f"Upload complete. The unique identifier of your video is {task.video_id}.")

Video embedding tasks

A video embedding task progresses through the following stages:

  • processing: The platform is creating the embeddings.
  • ready: Processing is complete. You can now retrieve the embeddings.
  • failed: The task could not be completed, and the embeddings haven’t been created.

The example code below shows how you can track the progress of a video embedding task, checking its status until it’s completed:

1task = client.embed.tasks.create(
2 model_name="Marengo-retrieval-2.7",
3 video_url="<YOUR_VIDEO_URL>",
4 video_embedding_scope=["clip", "video"]
5)
6print(f"Created video embedding task: id={task.id}")
7
8def on_task_update(task: TasksStatusResponse):
9 print(f" Status={task.status}")
10
11status = client.embed.tasks.wait_for_done(task.id, callback=on_task_update)
12print(f"Embedding done: {status.status}")