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

# Client

The `cyborg::Client` class manages storage configurations and acts as a factory for creating or loading encrypted indexes.

## Constructor

```cpp theme={null}
cyborg::Client(const std::string& api_key,
               const DBConfig& index_location,
               const DBConfig& config_location,
               const DBConfig& contents_location,
               const int cpu_threads,
               const GPUConfig gpu_config);
```

Initializes a new instance of `Client`.

### Parameters

| Parameter           | Type                              | Description                                                                                                                                                                                                                      |
| ------------------- | --------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `api_key`           | `std::string`                     | API key for your CyborgDB account.                                                                                                                                                                                               |
| `index_location`    | [`DBConfig`](../types#DBConfig)   | Configuration for index storage location.                                                                                                                                                                                        |
| `config_location`   | [`DBConfig`](../types#DBConfig)   | Configuration for index metadata storage.                                                                                                                                                                                        |
| `contents_location` | [`DBConfig`](../types#DBConfig)   | Configuration for encrypted item contents storage. Used by upsert and get operations.                                                                                                                                            |
| `cpu_threads`       | `int`                             | Number of CPU threads to use (e.g., `0` to use all available cores).                                                                                                                                                             |
| `gpu_config`        | [`GPUConfig`](../types#gpuconfig) | GPU operations configuration (requires CUDA). Use bitflags: `kNone` (no GPU), `kUpsert` (GPU for upsert), `kTrain` (GPU for training), `kQuery` (GPU for query), or `kAll` (GPU for all operations). Combine with `\|` operator. |

### Exceptions

<AccordionGroup>
  <Accordion title="std::invalid_argument">
    * Throws if the `cpu_threads` parameter is less than `0`.
    * Throws if any [`DBConfig`](../types#DBConfig) is invalid.
    * Throws if the GPU is not available when `gpu_accelerate` is `true`.
  </Accordion>

  <Accordion title="std::runtime_error">
    * Throws if the backing store is not available.
    * Throws if the Client could not be initialized.
  </Accordion>
</AccordionGroup>

### Example Usage

```cpp theme={null}
#include "cyborgdb_core/client.hpp"

std::string api_key = "your_api_key_here";
cyborg::DBConfig index_location(Location::kThreadSafeMemory);
cyborg::DBConfig config_location(Location::kRedis, "index_metadata", "redis://localhost");
cyborg::DBConfig contents_location(Location::kRocksDB); // Where encrypted item contents are stored
int cpu_threads = 4;

// Example 1: Enable GPU for all operations
cyborg::GPUConfig gpu_config_all = cyborg::kAll;
cyborg::Client client1(api_key, index_location, config_location, contents_location, cpu_threads, gpu_config_all);

// Example 2: Enable GPU for specific operations (upsert, train, and query)
cyborg::GPUConfig gpu_config_selective = cyborg::kUpsert | cyborg::kTrain | cyborg::kQuery;
cyborg::Client client2(api_key, index_location, config_location, contents_location, cpu_threads, gpu_config_selective);

// Example 3: Enable GPU only for training and query
cyborg::GPUConfig gpu_config_train_query = cyborg::kTrain | cyborg::kQuery;
cyborg::Client client3(api_key, index_location, config_location, contents_location, cpu_threads, gpu_config_train_query);

// Example 4: Disable GPU completely
cyborg::GPUConfig gpu_config_none = cyborg::kNone;
cyborg::Client client4(api_key, index_location, config_location, contents_location, cpu_threads, gpu_config_none);
```

***

## Methods

### `cpu_threads()`

```cpp theme={null}
int cpu_threads() const;
```

Returns the number of CPU threads configured for this client.

**Returns:** `int` - The number of CPU threads.

**Example:**

```cpp theme={null}
int threads = client.cpu_threads();
std::cout << "Using " << threads << " CPU threads" << std::endl;
```

***

### `gpu_accelerate()`

```cpp theme={null}
bool gpu_accelerate() const;
```

Checks if GPU acceleration is enabled for any operations.

**Returns:** `bool` - `true` if GPU is enabled for any operation, `false` otherwise.

**Example:**

```cpp theme={null}
if (client.gpu_accelerate()) {
    std::cout << "GPU acceleration is enabled" << std::endl;
}
```

***

### `gpu_config()`

```cpp theme={null}
GPUConfig gpu_config() const;
```

Returns the GPU operations configuration for this client.

**Returns:** [`GPUConfig`](../types#gpuconfig) - The GPU operations configuration.

**Example:**

```cpp theme={null}
cyborg::GPUConfig config = client.gpu_config();
if (config & cyborg::kTrain) {
    std::cout << "GPU is enabled for training" << std::endl;
}
```
