> ## 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 instance of `EncryptedIndex`.

```cpp theme={null}
std::unique_ptr<cyborg::EncryptedIndex>
    LoadIndex(const std::string index_name,
              const std::array<uint8_t, 32>& index_key,
              cyborg::Logger* logger = nullptr,
              std::optional<std::array<uint8_t, 16>> user_id = std::nullopt);
```

### Parameters

| Parameter    | Type                                     | Description                                                                                                                                                                                                              |
| ------------ | ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `index_name` | `std::string`                            | Name of the index to load.                                                                                                                                                                                               |
| `index_key`  | `std::array<uint8_t, 32>`                | 32-byte encryption key (KEK) for the index. For a root load this is the root index KEK; for an RBAC user-scoped load (see `user_id`) this is that user's KEK.                                                            |
| `logger`     | [`cyborg::Logger*`](./logger)            | *(Optional)* Pointer to a logger instance for capturing operation logs (default is `nullptr`).                                                                                                                           |
| `user_id`    | `std::optional<std::array<uint8_t, 16>>` | *(Optional)* 16-byte RBAC user identifier. When provided, the index is loaded user-scoped: `index_key` is treated as that user's KEK and per-operation permissions are enforced. Defaults to `std::nullopt` (root load). |

### Returns

`std::unique_ptr<cyborg::EncryptedIndex>`: A pointer to the loaded index ([`EncryptedIndex`](../encrypted-index)).

### Exceptions

<AccordionGroup>
  <Accordion title="std::invalid_argument">
    * Throws if the index name does not exist.
  </Accordion>

  <Accordion title="std::runtime_error">
    * Throws if the index could not be loaded or decrypted.
  </Accordion>
</AccordionGroup>

### Example Usage

```cpp theme={null}
#include "cyborgdb_core/client.hpp"
#include "cyborgdb_core/encrypted_index.hpp"
#include "cyborgdb_core/logger.hpp"
#include <array>

// ... Initialize the client ...

// Create a secure 32-byte key (example: all zeros)
std::array<uint8_t, 32> index_key = {0};

// Optional: Create and configure a logger
cyborg::Logger logger;
logger.Configure(LogLevel::Debug, true, "index_loading.log");

auto index = client.LoadIndex("my_index", index_key, &logger);
```
