Creates and returns a new encrypted index based on the provided configuration.
def create_index(self,
                 index_name: str,
                 index_key: bytes,
                 index_config: IndexConfig = None,
                 max_cache_size: int = 0,
                 embedding_model: str = None,
                 metric: str = None,
                 logger: Logger = None)

Parameters

ParameterTypeDescription
index_namestrName of the index to create. Must be unique.
index_keybytes32-byte encryption key for the index, used to secure the index data.
index_configIndexConfig(Optional) Configuration specifying the index type and parameters. When not provided, uses IndexIVFFlat() defaults.
max_cache_sizeint(Optional) Maximum size of local cache to keep for encrypted index (megabytes). Defaults to 0.
embedding_modelstr(Optional) Name of the SentenceTransformer model to use for automatic text embeddings.
metricstr(Optional) Distance metric to use: “euclidean”, “cosine”, or “squared_euclidean”. Overrides the metric in index_config. Defaults to “euclidean”.
loggerLogger(Optional) Logger instance for capturing operation logs. Defaults to None.
For more info on auto-generating embeddings, refer to Auto-Generate Embeddings.

Returns

EncryptedIndex: An instance of the newly created encrypted index.

Exceptions

Example Usage

Automatic Setup

import cyborgdb_core as cyborgdb
# or import cyborgdb_lite as cyborgdb
import secrets

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")

client = cyborgdb.Client(
    api_key=api_key,
    index_location=index_location, 
    config_location=config_location, 
    items_location=items_location
)

index_name = "my_index"
index_key = secrets.token_bytes(32)  # Generate a secure 32-byte encryption key

# Create with automatic IndexIVFFlat defaults (overload 2)
index = client.create_index(
    index_name=index_name, 
    index_key=index_key
)

Explicit Setup

import cyborgdb_core as cyborgdb
# or import cyborgdb_lite as cyborgdb
import secrets

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")

client = cyborgdb.Client(
    api_key=api_key, 
    index_location=index_location, 
    config_location=config_location, 
    items_location=items_location
)

index_name = "my_index"
index_key = secrets.token_bytes(32)  # Generate a secure 32-byte encryption key
index_config = cyborgdb.IndexIVF(
    dimension=128  # n_lists will be set automatically during training
)

# Optional: Set up logging
logger = cyborgdb.Logger.instance()
logger.configure(level="info", to_file=True, file_path="index_creation.log")

index = client.create_index(
    index_name=index_name, 
    index_key=index_key, 
    index_config=index_config,
    max_cache_size=1024,
    metric="cosine",  # Override default metric
    logger=logger
)