Skip to main content
Client is the main class exposed by CyborgDB. It exposes the functionality necessary to create, load, list and delete indexes. Operations within encrypted indexes (such as upsert and query) are contained within the EncryptedIndex class returned by create_index and load_index.

Constructor

Client(api_key: str,
       index_location: DBConfig,
       config_location: DBConfig,
       items_location: DBConfig,
       cpu_threads: int = 0,
       gpu_config: GPUConfig | None = None)
Initializes a new CyborgDB Client instance.

Parameters

ParameterTypeDefaultDescription
api_keystr-API key for your CyborgDB account.
index_locationDBConfig-Configuration for index storage location. Use a dictionary with keys location, table_name, and connection_string.
config_locationDBConfig-Configuration for index metadata storage. Uses the same dictionary structure as index_location.
items_locationDBConfigNONE(Optional) Configuration for encrypted item storage. Uses the same dictionary structure as index_location.
cpu_threadsint0(Optional) Number of CPU threads to use for computations (defaults to 0 = all cores).
gpu_configGPUConfig | NoneNone(Optional) GPU operations configuration. Specify which operations use GPU acceleration (defaults to None, no GPU).

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_config is set.
  • Throws if the backing store is not available.
  • Throws if the Client could not be initialized.

Example Usage

import cyborgdb_core as cyborgdb

api_key = "your_api_key_here"
index_location = cyborgdb.DBConfig(location='redis', connection_string="redis://localhost")
config_location = cyborgdb.DBConfig(location='redis', connection_string="redis://localhost")
items_location = cyborgdb.DBConfig(location='postgres', table_name="items", connection_string="host=localhost dbname=postgres")

# Example 1: Enable GPU for specific operations (upsert and train)
gpu_config = cyborgdb.GPUConfig(upsert=True, train=True)
client1 = cyborgdb.Client(
    api_key=api_key,
    index_location=index_location,
    config_location=config_location,
    items_location=items_location,
    cpu_threads=4,
    gpu_config=gpu_config
)

# Example 2: Disable GPU (default)
client2 = cyborgdb.Client(
    api_key=api_key,
    index_location=index_location,
    config_location=config_location,
    items_location=items_location,
    cpu_threads=4
)

# Proceed with further operations

Methods

get_cpu_threads()

Returns the number of CPU threads configured for this client.
def get_cpu_threads(self) -> int

Returns

int: The number of CPU threads.

Example Usage

threads = client.get_cpu_threads()
print(f"Using {threads} CPU threads")

is_gpu_enabled()

Checks if GPU acceleration is enabled for this client.
def is_gpu_enabled(self) -> bool

Returns

bool: True if GPU acceleration is enabled, False otherwise.

Example Usage

gpu_enabled = client.is_gpu_enabled()
print(f"GPU acceleration is {'enabled' if gpu_enabled else 'disabled'}")

get_gpu_config()

Returns the GPU operations configuration for this client.
def get_gpu_config(self) -> GPUConfig

Returns

GPUConfig: The GPU operations configuration.

Example Usage

gpu_config = client.get_gpu_config()
print(f"GPU operations: upsert={gpu_config.upsert}, train={gpu_config.train}, query={gpu_config.query}")