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,
engines: List[types.IndexEngine],
*,
addons: Optional[List[str]] = None,
**kwargs
) -> models.Index
engines = [
{
"name": "marengo2.6",
"options": ["visual", "conversation", "text_in_video", "logo"]
},
{
"name": "pegasus1.1",
"options": ["visual", "conversation"]
}
]
created_index = client.index.create(
name="<YOUR_INDEX_NAME>",
engines=engines,
addons=["thumbnail"]
)
print(f"ID: {created_index.id}")
print(f"Name: {created_index.name}")
print("Engines:")
for i, engine in enumerate(created_index.engines, 1):
print(f" Engine {i}:")
print(f" Name: {engine.name}")
print(f" Options: {engine.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.IndexEngine]` | Yes | A list of IndexEngine objects specifying the video understanding engines and the engine 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.Index
retrieved_index = client.index.retrieve("<YOUR_INDEX_ID>")
print(f"ID: {retrieved_index.id}")
print(f"Name: {retrieved_index.name}")
print("Engines:")
for i, engine in enumerate(retrieved_index.engines, 1):
print(f" Engine {i}:")
print(f" Name: {engine.name}")
print(f" Options: {engine.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,
engine_options: Optional[List[Union[str, Literal["visual", "conversation", "text_in_video", "logo"]]]] = None,
engine_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,
engine_options=["visual", "conversation"],
engine_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(" Engines:")
for i, engine in enumerate(index.engines, 1):
print(f" Engine {i}:")
print(f" Name: {engine.name}")
print(f" Options: {engine.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. |
engine_options | Optional[List[Union[str, Literal["visual", "conversation", "text_in_video", "logo"]]]] | No | Filter by engine options. |
engine_family | Optional[Union[str, Literal["marengo", "pegasus"]]] | No | Filter by engine 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]]] | 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 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,
engine_options: Optional[List[Union[str, Literal["visual", "conversation", "text_in_video", "logo"]]]] = None,
engine_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(" Engines:")
for i, engine in enumerate(index.engines, 1):
print(f" Engine {i}:")
print(f" Name: {engine.name}")
print(f" Options: {engine.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,
engine_options=["visual", "conversation"],
engine_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. |
engine_options | Optional[List[Union\[str, Literal["visual", "conversation", "text_in_video", "logo"]]]] | No | Filter by engine options. |
engine_family | Optional[Union[str, Literal["marengo", "pegasus"]]] | No | Filter by engine 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
next
function, passing theIndexListWithPagination
object as a parameter.- 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:
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) -> None
client.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: Update an index