> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.twelvelabs.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.twelvelabs.io/_mcp/server.

# Manage indexes

> Create and manage indexes for organizing video embeddings and metadata.

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 `IndexesWrapper` class provides methods to manage your indexes.

# Methods

## Create an index

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

**Function signature and example**:

**`Function signature`**

```javascript Function signature
create(
    request: TwelvelabsApi.IndexesCreateRequest, requestOptions?: Indexes.RequestOptions): core.HttpResponsePromise<TwelvelabsApi.IndexesCreateResponse>
```

**`Node.js example`**

```javascript Node.js example
import { TwelveLabs } from "twelvelabs-js";

const index = await client.indexes.create({
    indexName: "<YOUR_INDEX_NAME>",
    models: [
        {
            modelName: "marengo3.0",
            modelOptions: ["visual", "audio"],
        },
    ],
});
console.log(`ID: ${index.id}`);
```

### Parameters

| Name             | Type                                 | Required | Description                        |
| :--------------- | :----------------------------------- | :------- | :--------------------------------- |
| `request`        | `TwelvelabsApi.IndexesCreateRequest` | Yes      | Parameters for creating the index. |
| `requestOptions` | `Indexes.RequestOptions`             | No       | Request-specific configuration.    |

The `TwelvelabsApi.IndexesCreateRequest` interface has the following properties:

| Name        | Type                                             | Required | Description                                                                                                                                                                                                                                                                                                                                                                                                                           |
| :---------- | :----------------------------------------------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `indexName` | `string`                                         | Yes      | The name of the new index. Use a succinct and descriptive name.                                                                                                                                                                                                                                                                                                                                                                       |
| `models`    | `TwelvelabsApi.IndexesCreateRequestModelsItem[]` | Yes      | A list of 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:  - `modelName`: The name of the model to enable. Value: `marengo3.0`. - `modelOptions`: Specifies which modalities the platform analyzes. Values: `visual`, `audio`. For more details, see the [model options](/v1.3/docs/concepts/modalities#model-options) section. |
| `addons`    | `string[]`                                       | No       | A list of add-ons to enable, such as `"thumbnail"`. If omitted, no add-ons are enabled.                                                                                                                                                                                                                                                                                                                                               |

> **Note**
>
> You cannot change the model configuration after creating the index.

### Return value

Returns an `HttpResponsePromise` that resolves to a `TwelvelabsApi.IndexesCreateResponse` instance containing a field named `id` representing the unique identifier of the newly created index.

### API Reference

[Create an index](/v1.3/api-reference/indexes/create).

### Related guide

[Indexes](/v1.3/docs/concepts/indexes).

## Retrieve an index

**Description**: This method retrieves details of a specific index.

**Function signature and example**:

**`Function signature`**

```javascript Function signature
retrieve(indexId: string, requestOptions?: Indexes.RequestOptions): core.HttpResponsePromise<TwelvelabsApi.IndexSchema>
```

**`Node.js example`**

```javascript Node.js example
import { TwelveLabs } from "twelvelabs-js";

const retrievedIndex = await client.indexes.retrieve("<YOUR_INDEX_ID>");
console.log(`ID: ${retrievedIndex.id}`);
console.log(`Name: ${retrievedIndex.indexName}`);
console.log("Models:");
retrievedIndex.models!.forEach((model, index) => {
console.log(`  Model ${index + 1}:`);
console.log(`    Name: ${model.modelName}`);
console.log(`    Options: ${JSON.stringify(model.modelOptions!)}`);
});
console.log(`Video count: ${retrievedIndex.videoCount}`);
console.log(`Total duration: ${retrievedIndex.totalDuration} seconds`);
console.log(`Created at: ${retrievedIndex.createdAt}`);
if (retrievedIndex.updatedAt) {
    console.log(`Updated at: ${retrievedIndex.updatedAt}`);
}
if (retrievedIndex.expiresAt) {
    console.log(`Expires at: ${retrievedIndex.expiresAt}`);
}
if (retrievedIndex.addons && retrievedIndex.addons.length > 0) {
    console.log(`Add-ons: ${retrievedIndex.addons.join(', ')}`);
}
```

### Parameters

| Name             | Type                     | Required | Description                                              |
| :--------------- | :----------------------- | :------- | :------------------------------------------------------- |
| `indexId`        | `string`                 | Yes      | The unique identifier of the index you want to retrieve. |
| `requestOptions` | `Indexes.RequestOptions` | No       | Request-specific configuration.                          |

### Return value

Returns an `HttpResponsePromise` that resolves to a `TwelvelabsApi.IndexSchema` object representing the retrieved index.

The `TwelvelabsApi.IndexSchema` interface contains the following properties:

| Name            | Type                              | Description                                                                                                                                                                                                                                                 |
| --------------- | --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`            | `string`                          | The unique identifier of the index. It is assigned by the platform when an index is created.                                                                                                                                                                |
| `createdAt`     | `string`                          | The date and time, in the RFC 3339 format, that the index was created.                                                                                                                                                                                      |
| `updatedAt`     | `string`                          | The date and time, in the RFC 3339 format, that the index has been updated.                                                                                                                                                                                 |
| `expiresAt`     | `string`                          | The date and time, in the RFC 3339 format, when your index will expire. If you're on the Free plan, the platform retains your index data for 90 days from creation. If you're on the Developer plan, this field is set to `null`, indicating no expiration. |
| `indexName`     | `string`                          | The name of the index.                                                                                                                                                                                                                                      |
| `totalDuration` | `number`                          | The total duration, in seconds, of the videos in the index.                                                                                                                                                                                                 |
| `videoCount`    | `number`                          | The number of videos uploaded to this index.                                                                                                                                                                                                                |
| `models`        | `TwelvelabsApi.IndexModelsItem[]` | An array containing the list of the video understanding models enabled for this index.                                                                                                                                                                      |
| `addons`        | `string[]`                        | The list of the add-ons that are enabled for this index.                                                                                                                                                                                                    |

The `TwelvelabsApi.IndexModelsItem` interface contains the following properties:

| Name           | Type       | Description                                                                 |
| -------------- | ---------- | --------------------------------------------------------------------------- |
| `modelName`    | `string`   | The name of the model.                                                      |
| `modelOptions` | `string[]` | An array of strings that contains the model options enabled for this index. |

### API Reference

[Retrieve an index](/v1.3/api-reference/indexes/retrieve).

## List indexes

**Description**: This method retrieves a paginated list of indexes based on the provided parameters. By default, the platform returns your indexes sorted by creation date, with the newest at the top of the list.

**Function signature and example**:

**`Function signature`**

```javascript Function signature
  list(
    request?: TwelvelabsApi.IndexesListRequest,
    requestOptions?: Indexes.RequestOptions
  ): Promise<core.Page<TwelvelabsApi.IndexSchema>>
```

**`Node.js example`**

```javascript Node.js example
import { TwelveLabs } from "twelvelabs-js";

const indexesPager = await client.indexes.list({
    page: 1,
    pageLimit: 10,
    sortBy: "created_at",
    sortOption: "desc",
    indexName: "<YOUR_INDEX_NAME>",
    modelOptions: "visual,audio",
    modelFamily: "marengo",
    createdAt: "2024-08-16T16:53:59Z",
    updatedAt: "2024-08-16T16:55:59Z"
});

for await (const index of indexesPager) {
    console.log(`ID: ${index.id}`);
    console.log(`  Name: ${index.indexName}`);
    console.log("  Models:");
    index.models!.forEach((model, index) => {
        console.log(`    Model ${index + 1}:`);
        console.log(`      Name: ${model.modelName}`);
        console.log(`      Options: ${JSON.stringify(model.modelOptions)}`);
    });
    console.log(`  Video count: ${index.videoCount}`);
    console.log(`  Total duration: ${index.totalDuration} seconds`);
    console.log(`  Created at: ${index.createdAt}`);
    console.log(`  Updated at: ${index.updatedAt}`);
}
```

### Parameters

| Name             | Type                               | Required | Description                                                   |
| :--------------- | :--------------------------------- | :------- | :------------------------------------------------------------ |
| `request`        | `TwelvelabsApi.IndexesListRequest` | No       | Parameters for retrieving the list of indexes. Default: `{}`. |
| `requestOptions` | `Indexes.RequestOptions`           | No       | Request-specific configuration. Default:`{}`.                 |

The `IndexesListRequest` interface defines the parameters for listing indexes:

| Name           | Type     | Required | Description                                                                                                                                                                                                   |
| -------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `page`         | `number` | No       | The page number to retrieve. Default: 1.                                                                                                                                                                      |
| `pageLimit`    | `number` | No       | The number of items to return on each page. Default: 10. Max: 50.                                                                                                                                             |
| `sortBy`       | `string` | No       | The field to sort on. The following options are available: "updated\_at" - Sorts by the time when the item was updated, "created\_at" - Sorts by the time when the item was created. Default:  "created\_at". |
| `sortOption`   | `string` | No       | The sorting direction. The following options are available: "asc", "desc". Default: "desc".                                                                                                                   |
| `indexName`    | `string` | No       | Filter by the name of an index.                                                                                                                                                                               |
| `modelOptions` | `string` | No       | Filter by the model options. When filtering by multiple model options, the values must be comma-separated. Example: `"visual,audio"`).                                                                        |
| `modelFamily`  | `string` | No       | Filter by the model family. This parameter can take one of the following values: "marengo" or "pegasus". You can specify a single value.                                                                      |
| `createdAt`    | `string` | No       | Filter indexes by the creation date and time, in the RFC 3339 format ("YYYY-MM-DDTHH:mm:ssZ"). The platform returns the indexes that were created on the specified date at or after the given time.           |
| `updatedAt`    | `string` | No       | Filter indexes by the last update date and time, in the RFC 3339 format ("YYYY-MM-DDTHH:mm:ssZ"). The platform returns the indexes that were last updated on the specified date at or after the given time.   |

### Return value

Returns a `Promise` that resolves to a `core.Page<TwelvelabsApi.IndexSchema>` instance, representing the indexes that match the specified criteria. See the [Retrieve an index](#retrieve-an-index) section above for complete property details.

The `Page` class contains the following properties and methods:

| Name                   | Type               | Description                                                                  |
| ---------------------- | ------------------ | ---------------------------------------------------------------------------- |
| `data`                 | `T[]`              | An array containing the current page of items.                               |
| `getNextPage()`        | `Promise<this>`    | Retrieves the next page and returns the updated `Page` object.               |
| `hasNextPage()`        | `boolean`          | Returns whether there is a next page to load.                                |
| `Symbol.asyncIterator` | `AsyncIterator<T>` | Allows iteration through all items across all pages using `for await` loops. |

### API Reference

[List indexes](/v1.3/api-reference/indexes/list).

## Update an index

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

**Function signature and example**:

**`Function signature`**

```javascript Function signature
update(indexId: string, request: TwelvelabsApi.IndexesUpdateRequest, requestOptions?: Indexes.RequestOptions): core.HttpResponsePromise<void>
```

**`Node.js example`**

```javascript Node.js example
import { TwelveLabs } from "twelvelabs-js";

await client.indexes.update("<YOUR_INDEX_ID>", {
  indexName: "<NEW_INDEX_NAME>"
});
```

### Parameters

| Name                | Type                                 | Required | Description                                          |
| :------------------ | :----------------------------------- | :------- | :--------------------------------------------------- |
| `indexId`           | `string`                             | Yes      | The unique identifier of the index to update.        |
| `request`           | `TwelvelabsApi.IndexesUpdateRequest` | Yes      | The request object containing the update parameters. |
| `request.indexName` | `string`                             | Yes      | The new name of the index.                           |
| `requestOptions`    | `Indexes.RequestOptions`             | No       | Request-specific configuration options.              |

The `TwelvelabsApi.IndexesUpdateRequest` interface contains the following properties:

| Name        | Type     | Description                |
| ----------- | -------- | -------------------------- |
| `indexName` | `string` | The new name of the index. |

### Return value

Returns an `HttpResponsePromise` that resolves to `void`. This method doesn't return any data upon successful completion.

### API Reference

[Update an index](/v1.3/api-reference/indexes/update).

## Delete an index

**Description**: This method deletes an existing index.

**Function signature and example**:

**`Function signature`**

```javascript Function signature
delete(indexId: string, requestOptions?: Indexes.RequestOptions): core.HttpResponsePromise<void>
```

**`Node.js example`**

```javascript Node.js example
import { TwelveLabs } from "twelvelabs-js";

await client.indexes.delete("<YOUR_INDEX_ID>");
```

### Parameters

| Name             | Type                     | Required | Description                                   |
| :--------------- | :----------------------- | :------- | :-------------------------------------------- |
| `indexId`        | `string`                 | Yes      | The unique identifier of the index to delete. |
| `requestOptions` | `Indexes.RequestOptions` | No       | Request-specific configuration.               |

### Return value

Returns an `HttpResponsePromise` that resolves to void. This method doesn't return any data upon successful completion.

### API Reference

[Delete an index](/v1.3/api-reference/indexes/delete).

# Error codes

This section lists the most common error messages you may encounter while managing indexes.

* `index_option_cannot_be_changed`
  * Index option cannot be changed. Please remove index\_options parameter and try again. If you want to change index option, please create new index.
* `index_engine_cannot_be_changed`
  * Index engine cannot be changed. Please remove engine\_id parameter and try again. If you want to change engine, please create new index.
* `index_name_already_exists`
  * Index name `{index_name}` already exists. Please use another unique name and try again.

For a list of general errors that apply to all endpoints, see the [Error codes](/v1.3/api-reference/error-codes) page.