Manage indexes

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
videoVideoResourceUse 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

NameTypeRequiredDescription
paramsCreateIndexParamsYesParameters for creating the index.
optionsRequestOptionsNoAdditional options for the request. Defaults to {}.

The CreateIndexParams interface has the following properties:

NameTypeRequiredDescription
namestringYesThe name of the new index.
enginesArray<{ name: string; options: string[] }>YesA 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.
addonsstring[]NoA 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

NameTypeRequiredDescription
idstringYesThe unique identifier of the index you want to retrieve.
optionsRequestOptionsNoAdditional 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

NameTypeRequiredDescription
paramsListIndexParamsNoParameters for retrieving the list of indexes. Defaults to {}.
optionsRequestOptionsNoAdditional options for the request. Defaults to {}.

The ListIndexParams interface extends the PageOptions interface and defines the parameters for listing indexes:

NameTypeRequiredDescription
idstringNoFilter by the unique identifier of an index.
namestringNoFilter by the name of an index.
engineOptionsstring[]NoFilter by engine options.
engineFamily'marengo' | 'pegasus'NoFilter by the engine family. It must be either 'marengo' or 'pegasus'.
createdAtstring | Record<string, string>NoFilter by the creation date. This parameter can be a string or an object with string keys and string values for range queries.
updatedAtstring | Record<string, string>NoFilter 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:

NameTypeRequiredDescription
pagenumberNoPage number for pagination. Defaults to 1.
pageLimitnumberNoNumber of items per page. Defaults to 10.
sortBy'createdAt' | 'updatedAt'NoField to sort by ("createdAt" or "updatedAt"). Defaults to "createdAt".
sortOption'asc' | 'desc'NoSort 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

NameTypeRequiredDescription
paramsListIndexParamsNoParameters retrieving the list of indexes. Defaults to {}.
optionsRequestOptionsNoAdditional options for the request. Defaults to {}.

The ListIndexParams interface extends the PageOptions interface and defines the parameters for listing indexes:

NameTypeRequiredDescription
idstringNoFilter by the unique identifier of an index.
namestringNoFilter by the name of an index.
engineOptionsstring[]NoFilter by the engine options.
engineFamily'marengo' | 'pegasus'NoFilter by the engine family. It must be either 'marengo' or 'pegasus'.
createdAtstring | Record<string, string>NoFilter by the creation date. This parameter can be a string or an object with string keys and string values for range queries.
updatedAtstring | Record<string, string>NoFilter 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:

NameTypeRequiredDescription
pagenumberNoPage number for pagination. Defaults to 1.
pageLimitnumberNoNumber of items per page. Defaults to 10.
sortBy'createdAt' | 'updatedAt'NoField to sort by ("createdAt" or "updatedAt"). Defaults to "createdAt".
sortOption'asc' | 'desc'NoSort 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:

  1. Invoke theย nextmethod of the IndexListWithPagination object.
  2. Repeat this call until the method returns a promise that resolves tonull, 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:

NameTypeRequiredDescription
idstringYesThe unique identifier of the index you want to update.
namestringYesThe new name of the index.
optionsRequestOptionsNoAdditional 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:

NameTypeRequiredDescription
idstringYesThe unique identifier of the index to delete.
optionsRequestOptionsNoAdditional 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