> ## 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 by name. `indexKey` is optional in v0.17: SDK-supplied indexes (`provider: none`) must pass the exact 32-byte key used at creation, while KMS-backed indexes omit it — the service resolves the KEK via the stored `KMSBlob`.

```go theme={null}
func (c *Client) LoadIndex(ctx context.Context, indexName string, indexKey []byte) (*EncryptedIndex, error)
```

### Parameters

| Parameter   | Type              | Description                                                                                                                                                                                               |
| ----------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ctx`       | `context.Context` | Context for cancellation/timeouts                                                                                                                                                                         |
| `indexName` | `string`          | Name of the existing index to load                                                                                                                                                                        |
| `indexKey`  | `[]byte`          | *(Optional)* 32-byte encryption key used during index creation. Required for indexes created with the SDK-supplied KEK path (`provider: none`); pass `nil` or a zero-length slice for KMS-backed indexes. |

<Note>In v0.17 `indexKey` is optional. KMS-backed indexes (created with `KmsName`) omit it — the server resolves the DEK via the persisted `KMSBlob`. SDK-supplied indexes must re-supply the same 32-byte key here.</Note>

<Warning>
  For SDK-supplied indexes, the encryption key must exactly match the key used during index creation. KMS-backed indexes are tied to their `KmsName` slot in the service YAML — load fails if that slot is missing or unreachable.
</Warning>

### Returns

| Type              | Description                                                 |
| ----------------- | ----------------------------------------------------------- |
| `*EncryptedIndex` | Handle for performing vector operations on the loaded index |
| `error`           | Any error encountered during index loading                  |

### Exceptions

<AccordionGroup>
  <Accordion title="Error">
    * Returns error if the index doesn't exist on the server
    * Returns error if the encryption key is incorrect or invalid
    * Returns error from the server if a KMS-backed index's slot is unavailable
    * Returns error if the server returns an HTTP error status
    * Returns error if authentication fails (invalid API key)
  </Accordion>

  <Accordion title="Service Errors">
    * Throws if the CyborgDB service is unavailable or unreachable.
    * Throws if there are internal server errors on the CyborgDB service.
  </Accordion>
</AccordionGroup>

### Example Usage

```go theme={null}
package main

import (
    "context"
    "encoding/hex"
    "log"
    
    "github.com/cyborginc/cyborgdb-go"
)

func main() {
    // Create client
    client, err := cyborgdb.NewClient("http://localhost:8000", "your-api-key")
    if err != nil {
        log.Fatal(err)
    }
    
    // 32-byte encryption key encoded as 64 hex chars
    indexKeyHex := "your-64-character-hex-key-here"
    key, err := hex.DecodeString(indexKeyHex)
    if err != nil {
        log.Fatal(err)
    }

    // Load existing SDK-supplied index
    ctx := context.Background()
    index, err := client.LoadIndex(ctx, "my-documents", key)
    if err != nil {
        log.Fatal("Failed to load index:", err)
    }

    log.Printf("Loaded index: %s", index.GetIndexName())

    dim, _ := index.Dimension(ctx)
    log.Printf("Dimension: %d", dim)

    trained, err := index.IsTrained(ctx)
    if err != nil {
        log.Fatal("Failed to check training status:", err)
    }
    log.Printf("Is trained: %t", trained)

    // Load a KMS-backed index — no key required
    kmsIndex, err := client.LoadIndex(ctx, "kms-documents", nil)
    if err != nil {
        log.Fatal("Failed to load KMS index:", err)
    }
    _ = kmsIndex
}
```
