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 | VideoResource | 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:
async create(
{ name, engines, addons }: CreateIndexParams,
options: RequestOptions = {},
): Promise<Models.Index>
const createdIndex = await client.index.create({
name: '<YOUR_INDEX_NAME>',
engines: [
{
name: 'marengo2.6',
options: ['visual', 'conversation', 'text_in_video'],
},
],
addons: ['thumbnail'],
});
console.log(`ID: ${createdIndex.id}`);
console.log(`Name: ${createdIndex.name}`);
console.log("Engines:");
createdIndex.engines.forEach((engine, index) => {
console.log(` Engine ${index + 1}:`);
console.log(` Name: ${engine.name}`);
console.log(` Options: ${JSON.stringify(engine.options)}`);
});
console.log(`Video count: ${createdIndex.videoCount}`);
console.log(`Total turation: ${createdIndex.totalDuration} seconds`);
console.log(`Created at: ${createdIndex.createdAt}`);
if (createdIndex.updatedAt) {
console.log(`Updated at: ${createdIndex.updatedAt}`);
}
Parameters
Name | Type | Required | Description |
---|---|---|---|
params | CreateIndexParams | Yes | Parameters for creating the index. |
options | RequestOptions | No | Additional options for the request. Defaults to {} . |
The CreateIndexParams
interface has the following properties:
Name | Type | Required | Description |
---|---|---|---|
name | string | Yes | The name of the new index. |
engines | Array<{ name: string; options: string[] }> | Yes | A list of 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 | string[] | No | A list specifying which add-ons you want to enable. |
Return value: Returns a Promise
that resolves to a Models.Index
instance 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:
async retrieve(id: string, options: RequestOptions = {}): Promise<Models.Index>
const retrievedIndex = await client.index.retrieve('<YOUR_INDEX_ID>');
console.log(`ID: ${retrievedIndex.id}`);
console.log(`Name: ${retrievedIndex.name}`);
console.log("Engines:");
retrievedIndex.engines.forEach((engine, index) => {
console.log(` Engine ${index + 1}:`);
console.log(` Name: ${engine.name}`);
console.log(` Options: ${JSON.stringify(engine.options)}`);
});
console.log(`Video count: ${retrievedIndex.videoCount}`);
console.log(`Total turation: ${retrievedIndex.totalDuration} seconds`);
console.log(`Created at: ${retrievedIndex.createdAt}`);
if (retrievedIndex.updatedAt) {
console.log(`Updated at: ${retrievedIndex.updatedAt}`);
Parameters
Name | Type | Required | Description |
---|---|---|---|
id | string | Yes | The unique identifier of the index you want to retrieve. |
options | RequestOptions | No | Additional options for the request. Defaults to {} . |
Return value: Returns a Promise
that resolves to a Models.Index
instance.
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:
async list(
{ id, name, createdAt, updatedAt, ...restParams }: ListIndexParams = {},
options: RequestOptions = {},
): Promise<Models.Index[]>
const listParams = {
id: '<YOUR_INDEX_ID>',
name: '<YOUR_INDEX_NAME>',
engineOptions: ['conversation', 'visual'],
engineFamily: 'marengo',
page: 1,
pageLimit: 5,
sortBy: 'updated_at',
sortOption: 'asc'
};
const indexes = await client.index.list(listParams);
indexes.forEach(index => {
console.log(`ID: ${index.id}`);
console.log(` Name: ${index.name}`);
console.log(" Engines:");
index.engines.forEach((engine, index) => {
console.log(` Engine ${index + 1}:`);
console.log(` Name: ${engine.name}`);
console.log(` Options: ${JSON.stringify(engine.options)}`);
});
console.log(` Video count: ${index.videoCount}`);
console.log(` Total duration: ${index.totalDuration} seconds`);
console.log(` Created at: ${index.createdAt}`);
if (index.updatedAt) {
console.log(` Updated at: ${index.updatedAt}`);
}
});
Parameters
Name | Type | Required | Description |
---|---|---|---|
params | ListIndexParams | No | Parameters for retrieving the list of indexes. Defaults to {} . |
options | RequestOptions | No | Additional options for the request. Defaults to {} . |
The ListIndexParams
interface extends the PageOptions
interface and defines the parameters for listing indexes:
Name | Type | Required | Description |
---|---|---|---|
id | string | No | Filter by the unique identifier of an index. |
name | string | No | Filter by the name of an index. |
engineOptions | string[] | No | Filter by engine options. |
engineFamily | 'marengo' | 'pegasus' | No | Filter by the engine family. It must be either 'marengo' or 'pegasus'. |
createdAt | string | Record<string, string> | No | Filter by the creation date. This parameter can be a string or an object with string keys and string values for range queries. |
updatedAt | string | Record<string, string> | No | Filter by the last update date. This parameter can be a string or an object with string keys and string values for range queries. |
The following properties are inherited from PageOptions
:
Name | Type | Required | Description |
---|---|---|---|
page | number | No | Page number for pagination. Defaults to 1. |
pageLimit | number | No | Number of items per page. Defaults to 10. |
sortBy | 'createdAt' | 'updatedAt' | No | Field to sort by ("createdAt" or "updatedAt"). Defaults to "createdAt". |
sortOption | 'asc' | 'desc' | No | Sort order ("asc" or "desc"). Defaults to "desc". |
Return value: Returns a Promise
that resolves to an array of Models.Index
instances.
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:
async listPagination(
{ id, name, createdAt, updatedAt, ...restParams }: ListIndexParams = {},
options: RequestOptions = {},
): Promise<Models.IndexListWithPagination>
function printIndexPage(indexPage) {
indexPage.forEach(index => {
console.log(`ID: ${index.id}`);
console.log(` Name: ${index.name}`);
console.log(" Engines:");
index.engines.forEach((engine, index) => {
console.log(` Engine ${index + 1}:`);
console.log(` Name: ${engine.name}`);
console.log(` Options: ${JSON.stringify(engine.options)}`);
});
console.log(` Video count: ${index.videoCount}`);
console.log(` Total duration: ${index.totalDuration} seconds`);
console.log(` Created at: ${index.createdAt}`);
if (index.updatedAt) {
console.log(` Updated at: ${index.updatedAt}`);
}
});
}
const listParams = {
id: '66e9358a808d95368f6f7a7c',
name: 'sdk-ref-index-create-07',
engineOptions: ['conversation', 'visual'],
engineFamily: 'marengo',
page: 1,
pageLimit: 5,
sortBy: 'updated_at',
sortOption: 'asc'
};
// Fetch the initial page of results
const indexPaginator = await client.index.listPagination(listParams);
// Print the first page of results
printIndexPage(indexPaginator.data);
// Iterate through subsequent pages
while (true) {
const nextIndexPage = await indexPaginator.next();
if (!nextIndexPage) {
console.log('No more pages of index results available');
break;
}
printIndexPage(nextIndexPage);
}
Parameters
Name | Type | Required | Description |
---|---|---|---|
params | ListIndexParams | No | Parameters retrieving the list of indexes. Defaults to {}. |
options | RequestOptions | No | Additional options for the request. Defaults to {} . |
The ListIndexParams
interface extends the PageOptions
interface and defines the parameters for listing indexes:
Name | Type | Required | Description |
---|---|---|---|
id | string | No | Filter by the unique identifier of an index. |
name | string | No | Filter by the name of an index. |
engineOptions | string[] | No | Filter by the engine options. |
engineFamily | 'marengo' | 'pegasus' | No | Filter by the engine family. It must be either 'marengo' or 'pegasus'. |
createdAt | string | Record<string, string> | No | Filter by the creation date. This parameter can be a string or an object with string keys and string values for range queries. |
updatedAt | string | Record<string, string> | No | Filter by the last update date. This parameter can be a string or an object with string keys and string values for range queries. |
The following properties are inherited from PageOptions
:
Name | Type | Required | Description |
---|---|---|---|
page | number | No | Page number for pagination. Defaults to 1. |
pageLimit | number | No | Number of items per page. Defaults to 10. |
sortBy | 'createdAt' | 'updatedAt' | No | Field to sort by ("createdAt" or "updatedAt"). Defaults to "createdAt". |
sortOption | 'asc' | 'desc' | No | Sort order ("asc" or "desc"). Defaults to "desc". |
Return value: Returns a Promise
that resolves to a Models.IndexListWithPagination
instance.
Note:
To retrieve subsequent pages of results, use the async iterator protocol:
- Invoke the
next
method of theIndexListWithPagination
object.- Repeat this call until the method returns a promise that resolves to
null
, 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:
async update(id: string, name: string, options: RequestOptions = {}): Promise<void>
await client.index.update('<YOUR_INDEX_ID>', '<NEW_NAME>');
Parameters:
Name | Type | Required | Description |
---|---|---|---|
id | string | Yes | The unique identifier of the index you want to update. |
name | string | Yes | The new name of the index. |
options | RequestOptions | No | Additional options for the request. Defaults to {} . |
Return value: Returns a Promise
that resolves to void
. 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:
async delete(id: string, options: RequestOptions = {}): Promise<void>
await client.index.delete('YOUR_INDEX_ID>');
Parameters:
Name | Type | Required | Description |
---|---|---|---|
id | string | Yes | The unique identifier of the index to delete. |
options | RequestOptions | No | Additional options for the request. Defaults to {} . |
Return value: Returns a Promise
that resolves to void
. This method doesn't return any data upon successful completion.
API Reference: Update an index