> ## 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.

```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 and deadlines. |
| `indexName` | `string` | Name of an existing index. |
| `indexKey` | `[]byte` | The 32-byte key the index was created with. Required for SDK-supplied-key indexes; pass `nil` 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 `*AuthenticationError` (HTTP `401`).</Warning>

### Returns

The `*EncryptedIndex` bound to the loaded index.

### Errors

<AccordionGroup>
  <Accordion title="*ValidationError">
    Wraps `ErrInvalidKeyLength`. `indexKey` is non-empty but not 32 bytes. Returned before any request is sent.
  </Accordion>

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

  <Accordion title="*AuthenticationError">
    `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="*ServiceError">
    The service returns `5xx`.
  </Accordion>

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

See [Errors](../errors).

<Note>A wrong key returns `*AuthenticationError` (HTTP `401`) when the index has vectors and the service already has it cached, and `*NotFoundError` (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

```go theme={null}
package main

import (
    "context"
    "encoding/hex"
    "fmt"
    "log"

    "github.com/cyborginc/cyborgdb-go"
)

func main() {
    client, err := cyborgdb.NewClient("http://localhost:8000", "your-api-key")
    if err != nil {
        log.Fatal(err)
    }

    // The same 32 bytes that were passed to CreateIndex, e.g. stored as hex
    key, err := hex.DecodeString("your-64-character-hex-key")
    if err != nil {
        log.Fatal(err)
    }

    index, err := client.LoadIndex(context.Background(), "my-index", key)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(index.GetIndexName())
    // Output: my-index
}
```

#### KMS-backed index

```go theme={null}
// No key needed: the service unwraps it with the index's KMS provider.
index, err := client.LoadIndex(ctx, "kms-index", nil)
if err != nil {
    log.Fatal(err)
}
_ = index
```


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