An index is a basic unit for organizing and storing video data consisting of video embeddings and metadata. Indexes facilitate information retrieval and processing. The resources.Index class provides methods to manage your indexes.

Properties

NameTypeDescription
videoresources.VideoUse this property to manage the videos uploaded to this index.

Methods

Create an index

Description: This method creates a new index based on the provided parameters.

Function signature and example:

def create(
    self,
    name: str,
    models: List[types.IndexModel],
    *,
    addons: Optional[List[str]] = None,
    **kwargs
) -> models.Index
models = [
        {
          "name": "marengo2.7",
          "options": ["visual", "audio"]
        },
        {
            "name": "pegasus1.1",
            "options": ["visual", "audio"]
        }
    ]
created_index = client.index.create(
    name="<YOUR_INDEX_NAME>",
    models=models,
    addons=["thumbnail"]
)
print(f"ID: {created_index.id}")
print(f"Name: {created_index.name}")
print("Models:")
for i, model in enumerate(created_index.models, 1):
    print(f"  Model {i}:")
    print(f"    Name: {model.name}")
    print(f"    Options: {model.options}")
print(f"Video count: {created_index.video_count}")
print(f"Total duration: {created_index.total_duration} seconds")
print(f"created At: {created_index.created_at}")
if created_index.updated_at:
    print(f"Updated at: {created_index.updated_at}")

Parameters

NameTypeRequiredDescription
namestrYesThe name of the new index.
optionsList[types.IndexModel]YesA list of IndexModel objects specifying the video understanding models and the model options you want to enable for this index. Each object is a dictionary with two keys: name and options.
addonsOptional[List[str]]NoA list specifying which add-ons should be enabled.
**kwargsdictNoAdditional keyword arguments for the request.

Return value: Returns a models.Index object representing the newly created index.

API Reference: For a description of each field in the request and response, see the Create an index page.

Related guide: Create indexes.

Retrieve an index

Description: This method retrieves details of a specific index.

Function signature and example:

def retrieve(self, id: str, **kwargs) -> models.Index
retrieved_index = client.index.retrieve("<YOUR_INDEX_ID>")
print(f"ID: {retrieved_index.id}")
print(f"Name: {retrieved_index.name}")
print("Models:")
for i, model in enumerate(retrieved_index.models, 1):
    print(f"  Model {i}:")
    print(f"    Name: {model.name}")
    print(f"    Options: {model.options}")
print(f"Video count: {retrieved_index.video_count}")
print(f"Total duration: {retrieved_index.total_duration} seconds")
print(f"Created at: {retrieved_index.created_at}")
if retrieved_index.updated_at:
    print(f"Updated at: {retrieved_index.updated_at}")
if retrieved_index.expires_at:
    print(f"Expires at: {retrieved_index.expires_at}")

Parameters

NameTypeRequiredDescription
idstrYesThe unique identifier of the index to retrieve.
**kwargsdictNoAdditional options for the request. Defaults to {}.

Return value: Returns a models.Index object representing the retrieved index.

API Reference: For a description of each field in the request and response, see the Retrieve an index page.

List indexes with direct pagination

Description: The list method retrieves a paginated list of indexes based on the provided parameters. Choose this method mainly when the total number of items is manageable or you must fetch a single page of results. By default, the platform returns your indexes sorted by creation date, with the newest at the top of the list.

Function signature and example:

def list(
    self,
    *,
    id: Optional[str] = None,
    name: Optional[str] = None,
    model_options: Optional[List[Union[str, Literal["visual", "audio"]]]] = None,
    model_family: Optional[Union[str, Literal["marengo", "pegasus"]]] = None,
    page: Optional[int] = 1,
    page_limit: Optional[int] = 10,
    sort_by: Optional[str] = "created_at",
    sort_option: Optional[str] = "desc",
    created_at: Optional[Union[str, Dict[str, str]]] = None,
    updated_at: Optional[Union[str, Dict[str, str]]] = None,
    **kwargs
) -> RootModelList[models.Index]
indexes = client.index.list(
    id="<YOUR_INDEX_ID>",
    name="<YOUR_INDEX_NAME>",
    page=1,
    page_limit=5,
    model_options=["visual", "audio"],
    model_family="marengo",
    sort_by = "updated_at",
    sort_option="asc",
    created_at="2024-09-17T07:53:46.365Z",
    updated_at="2024-09-17T07:53:46.365Z"
)
for index in indexes:
    print(f"ID: {index.id}")
    print(f"  Name: {index.name}")
    print("  Models:")
    for i, model in enumerate(index.models, 1):
        print(f"    Model {i}:")
        print(f"      Name: {model.name}")
        print(f"      Options: {model.options}")
    print(f"  Video count: {index.video_count}")
    print(f"  Total duration: {index.total_duration} seconds")
    print(f"  Created at: {index.created_at}")
    if index.updated_at:
        print(f"  Updated at: {index.updated_at}")

Parameters

NameTypeRequiredDescription
idOptional[str]NoFilter by the unique identifier of an index.
nameOptional[str]NoFilter by the name of an index.
model_optionsOptional\[Literal["visual", "audio"]] = NoneNoFilter by model options.
model_familyOptional[Literal["marengo", "pegasus"]] = NoneNoFilter by model family.
pageOptional[int]NoPage number for pagination. Defaults to 1.
page_limitOptional[int]NoNumber of items per page. Defaults to 10.
sort_byOptional[str]NoField to sort by ("created_at" or "updated_at"). Defaults to "created_at".
sort_optionOptional[str]NoSort order ("asc" or "desc"). Defaults to "desc".
created_atOptional[Union[str, Dict[str, str]]] = NoneNoFilter by creation date. This parameter can be a string or a dictionary for range queries.
updated_atOptional[Union[str, Dict[str, str]]] = NoneNoFilter by update date. This parameter can be a string or a dictionary for range queries.
**kwargsdictNoAdditional keyword arguments for the request.

Return value: Returns a RootModelList containing models.Index objects, representing the list of indexes that match the specified criteria.

API Reference: For a description of each field in the request and response, see the List indexes page.

Related guides:

List indexes with iterative pagination

Description: This method iterates through a paginated list of indexes based on the provided parameters. Choose this method mainly when your application must retrieve a large number of items. By default, the platform returns your indexes sorted by creation date, with the newest at the top of the list.

Function signature and example:

def list_pagination(
    self,
    *,
    id: Optional[str] = None,
    name: Optional[str] = None,
    model_options: Optional[Literal["visual", "audio"]] = None,
    model_family: Optional[Union[str, Literal["marengo", "pegasus"]]] = None,
    page: Optional[int] = 1,
    page_limit: Optional[int] = 10,
    sort_by: Optional[str] = "created_at",
    sort_option: Optional[str] = "desc",
    created_at: Optional[Union[str, Dict[str, str]]] = None,
    updated_at: Optional[Union[str, Dict[str, str]]] = None,
    **kwargs
) -> models.IndexListWithPagination
def print_page(page):
    for index in page:
      print(f"ID: {index.id}")
      print(f"  Name: {index.name}")
      print("  Models:")
      for i, model in enumerate(index.models, 1):
          print(f"    Model {i}:")
          print(f"      Name: {model.name}")
          print(f"      Options: {model.options}")
      print(f"  Video count: {index.video_count}")
      print(f"  Total duration: {index.total_duration} seconds")
      print(f"  Created at: {index.created_at}")
      if index.updated_at:
          print(f"  Updated at: {index.updated_at}")

# Fetch the initial page of results
index_paginator = client.index.list_pagination(
    id="<YOUR_INDEX_ID>",
    name="<YOUR_INDEX_NAME>",
    page=1,
    page_limit=5,
    model_options=["visual", "audio"],
    model_family="marengo",
    sort_by = "updated_at",
    sort_option="asc",
    created_at="2024-09-17T07:53:46.365Z",
    updated_at="2024-09-17T07:53:46.365Z"
)

# Print the first page of results
print_page(index_paginator.data)

# Iterate through subsequent pages
while True:
    try:
        next_index_page = next(index_paginator)
        print_page(next_index_page)
    except StopIteration:
        break
   

Parameters

NameTypeRequiredDescription
idOptional[str]NoFilter by the unique identifier of an index.
nameOptional[str]NoFilter by the name of an index.
model_optionsOptional[Literal["visual", "audio"]] = NoneNoFilter by model options.
model_familyOptional[Literal["marengo", "pegasus"]] = NoneNoFilter by model family.
pageOptional[int]NoPage number for pagination. Defaults to 1.
page_limitOptional[int]NoNumber of items per page. Defaults to 10.
sort_byOptional[str]NoField to sort by ("created_at" or "uploaded_at"). Defaults to "created_at".
sort_optionOptional[str]NoSort order ("asc" or "desc"). Defaults to "desc".
created_atOptional[Union[str, Dict[str, str]]]NoFilter by creation date. This parameter can be a string or a dictionary for range queries.
updated_atOptional[Union[str, Dict[str, str]]]NoFilter by update date. This parameter can be a string or a dictionary for range queries.
**kwargsdictNoAdditional keyword arguments for the request.

Return value: Returns a models.IndexListWithPagination object, containing the list of indexes that match the specified criteria and pagination information.

📘

Note:

To retrieve subsequent pages of results, use the iterator protocol:

  1. Invoke the next function, passing the IndexListWithPagination object as a parameter.
  2. Repeat this call until a StopIteration exception occurs, indicating no more pages exist.

API Reference: For a description of each field in the request and response, see the List indexes page.

Related guides:

Update an index

Description: This method updates the name of an existing index.

Function signature and example:

def update(self, id: str, name: str, **kwargs) -> None
client.index.update(id="<INDEX_ID>", name="<NEW_INDEX_NAME>")

Parameters:

NameTypeRequiredDescription
idstrYesThe unique identifier of the index to be updated.
namestrYesThe new name of the index.
**kwargsdictNoAdditional keyword arguments for the request.

Return value: None. This method doesn't return any data upon successful completion.

API Reference: Update an index.

Delete an index

Description: This method deletes an existing index.

Function signature and example:

def delete(self, id: str, **kwargs) -> None
client.index.delete(id="<YOUR_INDEX_ID>")

Parameters:

NameTypeRequiredDescription
idstringYesThe unique identifier of the index to delete.
**kwargsdictNoAdditional keyword arguments for the request.

Return value: None. This method doesn't return any data upon successful completion.

API Reference: Update an index