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,
logger: Logger = None)
Parameters
Parameter | Type | Description |
---|
index_name | str | Name of the index to create. Must be unique. |
index_key | bytes | 32-byte encryption key for the index, used to secure the index data. |
index_config | IndexConfig | Configuration dictionary specifying the index type (ivf , ivfpq , or ivfflat ) and relevant parameters such as dimension , n_lists , pq_dim , and pq_bits . |
embedding_model | str | (Optional) Which sentence-transfomers model used to auto-generate embeddings. Defaults to None , no auto-generation. |
max_cache_size | int | (Optional) Maximum size of local cache to keep for encrypted index. Defaults to 0 . |
logger | Logger | (Optional) Logger instance for capturing operation logs. Defaults to None . |
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")
# 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,
logger=logger
)