> ## 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 and key. The provided key must match the one used during index creation.

```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`          | 32-byte encryption key used during index creation |

<Warning>
  The encryption key must exactly match the key used during index creation.
</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">
    * Throws if the index doesn't exist on the server
    * Throws if the encryption key is incorrect or invalid
    * Throws if the server returns an HTTP error status.
    * Throws 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)
    }
    
    // Replace with your actual encryption key (must be exactly 32 bytes)
    key := []byte("example-index-key-12345678901234")

    // Load existing 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())
    log.Printf("Index type: %s", index.GetIndexType())

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