> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cyborg.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Load Index

Loads an existing encrypted index and returns an `EncryptedIndex` bound to it.

```typescript theme={null}
async loadIndex({
    indexName: string,
    indexKey?: Uint8Array,
}): Promise<EncryptedIndex>
```

### Parameters

| Parameter | Type | Default | Description |
| - | - | - | - |
| `indexName` | `string` | - | Name of an existing index. |
| `indexKey` | `Uint8Array` | `undefined` | *(Optional)* The 32-byte key the index was created with. Required for SDK-supplied-key indexes; omit it for KMS-backed indexes (created with `kmsName`). |

<Warning>For SDK-supplied-key indexes, `indexKey` must be the exact key passed to `createIndex()`. A KMS-backed index fails to load if its `kmsName` slot is missing from the service YAML or its provider is unreachable, with `CyborgDBAuthenticationError` (HTTP `401`).</Warning>

### Returns

`Promise<EncryptedIndex>` bound to the loaded index.

### Exceptions

<AccordionGroup>
  <Accordion title="CyborgDBValidationError">
    `indexKey` is passed but is not 32 bytes. Thrown before any request is sent.
  </Accordion>

  <Accordion title="CyborgDBNotFoundError">
    No index named `indexName` exists, or `indexKey` doesn't match (HTTP `404`, in most cases).
  </Accordion>

  <Accordion title="CyborgDBAuthenticationError">
    `indexKey` doesn't match an index that has vectors and is already in the service's cache, or the client's `apiKey` is missing or invalid; or, for a KMS-backed index, its KMS slot is missing or the provider call fails (HTTP `401`).
  </Accordion>

  <Accordion title="CyborgDBServiceError">
    The service returns `5xx`.
  </Accordion>

  <Accordion title="CyborgDBTransportError">
    The service can't be reached.
  </Accordion>
</AccordionGroup>

See [Errors](../errors) for the full hierarchy.

<Note>A wrong key returns `CyborgDBAuthenticationError` (HTTP `401`) when the index has vectors and the service already has it cached, and `CyborgDBNotFoundError` (HTTP `404`) otherwise, for example on an empty index or right after the service restarts. Catch both when checking for a bad key.</Note>

### Example Usage

#### SDK-supplied-key index

```typescript theme={null}
import { Client } from 'cyborgdb';

const client = new Client({ baseUrl: 'http://localhost:8000', apiKey: 'your-api-key' });

// The same 32 bytes that were passed to createIndex(), e.g. stored as hex
const indexKey = new Uint8Array(Buffer.from('your-64-character-hex-key', 'hex'));

const index = await client.loadIndex({ indexName: 'my_index', indexKey });
console.log(await index.getIndexName());
// Output: my_index
```

`Buffer` is Node-only; in a browser or Edge runtime, decode the hex string with your own helper.

#### KMS-backed index

```typescript theme={null}
// No key needed: the service unwraps it with the index's KMS provider.
const index = await client.loadIndex({ indexName: 'kms_index' });
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.