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

Constructor

cyborg::Client(const std::string& api_key,
               const DBConfig& index_location,
               const DBConfig& config_location,
               const DBConfig& items_location,
               const int cpu_threads,
               const GPUConfig gpu_config);
Initializes a new instance of Client.

Parameters

ParameterTypeDescription
api_keystd::stringAPI key for your CyborgDB account.
index_locationDBConfigConfiguration for index storage location.
config_locationDBConfigConfiguration for index metadata storage.
items_locationDBConfigConfiguration intended to be used in a future release. Pass in a DBConfig with a Location of ‘None’.
cpu_threadsintNumber of CPU threads to use (e.g., 0 to use all available cores).
gpu_configGPUConfigGPU 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

  • Throws if the cpu_threads parameter is less than 0.
  • Throws if any DBConfig is invalid.
  • Throws if the GPU is not available when gpu_accelerate is true.
  • Throws if the backing store is not available.
  • Throws if the Client could not be initialized.

Example Usage

#include "cyborgdb_core/client.hpp"

std::string api_key = "your_api_key_here";
cyborg::DBConfig index_location(Location::kMemory);
cyborg::DBConfig config_location(Location::kRedis, "index_metadata", "redis://localhost");
cyborg::DBConfig items_location(Location::kNone); // No item storage
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, items_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, items_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, items_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, items_location, cpu_threads, gpu_config_none);

Methods

cpu_threads()

int cpu_threads() const;
Returns the number of CPU threads configured for this client. Returns: int - The number of CPU threads. Example:
int threads = client.cpu_threads();
std::cout << "Using " << threads << " CPU threads" << std::endl;

gpu_accelerate()

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:
if (client.gpu_accelerate()) {
    std::cout << "GPU acceleration is enabled" << std::endl;
}

gpu_config()

GPUConfig gpu_config() const;
Returns the GPU operations configuration for this client. Returns: GPUConfig - The GPU operations configuration. Example:
cyborg::GPUConfig config = client.gpu_config();
if (config & cyborg::kTrain) {
    std::cout << "GPU is enabled for training" << std::endl;
}