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
| Name | Type | Description |
|---|---|---|
video | resources.Video | Use 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.Indexmodels = [
{
"name": "marengo2.7",
"options": ["visual", "audio"]
},
{
"name": "pegasus1.2",
"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
| Name | Type | Required | Description |
|---|---|---|---|
name | str | Yes | The name of the new index. |
options | List[types.IndexModel] | Yes | A 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. |
addons | Optional[List[str]] | No | A list specifying which add-ons should be enabled. |
**kwargs | dict | No | Additional 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.Indexretrieved_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
| Name | Type | Required | Description |
|---|---|---|---|
id | str | Yes | The unique identifier of the index to retrieve. |
**kwargs | dict | No | Additional 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
| Name | Type | Required | Description |
|---|---|---|---|
id | Optional[str] | No | Filter by the unique identifier of an index. |
name | Optional[str] | No | Filter by the name of an index. |
model_options | Optional\[Literal["visual", "audio"]] = None | No | Filter by model options. |
model_family | Optional[Literal["marengo", "pegasus"]] = None | No | Filter by model family. |
page | Optional[int] | No | Page number for pagination. Defaults to 1. |
page_limit | Optional[int] | No | Number of items per page. Defaults to 10. |
sort_by | Optional[str] | No | Field to sort by ("created_at" or "updated_at"). Defaults to "created_at". |
sort_option | Optional[str] | No | Sort order ("asc" or "desc"). Defaults to "desc". |
created_at | Optional[Union[str, Dict[str, str]]] = None | No | Filter by creation date. This parameter can be a string or a dictionary for range queries. |
updated_at | Optional[Union[str, Dict[str, str]]] = None | No | Filter by update date. This parameter can be a string or a dictionary for range queries. |
**kwargs | dict | No | Additional 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.IndexListWithPaginationdef 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
| Name | Type | Required | Description |
|---|---|---|---|
id | Optional[str] | No | Filter by the unique identifier of an index. |
name | Optional[str] | No | Filter by the name of an index. |
model_options | Optional[Literal["visual", "audio"]] = None | No | Filter by model options. |
model_family | Optional[Literal["marengo", "pegasus"]] = None | No | Filter by model family. |
page | Optional[int] | No | Page number for pagination. Defaults to 1. |
page_limit | Optional[int] | No | Number of items per page. Defaults to 10. |
sort_by | Optional[str] | No | Field to sort by ("created_at" or "uploaded_at"). Defaults to "created_at". |
sort_option | Optional[str] | No | Sort order ("asc" or "desc"). Defaults to "desc". |
created_at | Optional[Union[str, Dict[str, str]]] | No | Filter by creation date. This parameter can be a string or a dictionary for range queries. |
updated_at | Optional[Union[str, Dict[str, str]]] | No | Filter by update date. This parameter can be a string or a dictionary for range queries. |
**kwargs | dict | No | Additional 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:
- Invoke the
nextfunction, passing theIndexListWithPaginationobject as a parameter.- Repeat this call until a
StopIterationexception 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) -> Noneclient.index.update(id="<INDEX_ID>", name="<NEW_INDEX_NAME>")Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
id | str | Yes | The unique identifier of the index to be updated. |
name | str | Yes | The new name of the index. |
**kwargs | dict | No | Additional 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) -> Noneclient.index.delete(id="<YOUR_INDEX_ID>")Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The unique identifier of the index to delete. |
**kwargs | dict | No | Additional keyword arguments for the request. |
Return value: None. This method doesn't return any data upon successful completion.
API Reference: Delete an index