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,
                 embedding_model: str = None,
                 max_cache_size: int = 0)

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_configIndexConfigConfiguration dictionary specifying the index type (ivf, ivfpq, or ivfflat) and relevant parameters such as dimension, n_lists, pq_dim, and pq_bits.
embedding_modelstr(Optional) Which sentence-transfomers model used to auto-generate embeddings. Defaults to None, no auto-generation.
max_cache_sizeint(Optional) Maximum size of local cache to keep for encrypted index. Defaults to 0.
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

import cyborgdb_core 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(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=1024, metric="euclidean")

client.create_index(index_name=index_name, index_key=index_key, index_config=index_config)