Documentation Index
Fetch the complete documentation index at: https://docs.cyborg.co/llms.txt
Use this file to discover all available pages before exploring further.
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
| 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 | (Optional) Configuration specifying the index type and parameters. When not provided, uses IndexIVFFlat() defaults. |
max_cache_size | int | (Optional) Maximum size of local cache to keep for encrypted index (megabytes). Defaults to 0. |
embedding_model | str | (Optional) Name of the SentenceTransformer model to use for automatic text embeddings. |
metric | str | (Optional) Distance metric to use: “euclidean”, “cosine”, or “squared_euclidean”. Overrides the metric in index_config. Defaults to “euclidean”. |
logger | Logger | (Optional) Logger instance for capturing operation logs. Defaults to None. |
Returns
EncryptedIndex: An instance of the newly created encrypted index.
Exceptions
- Throws if the index name is not unique.
- Throws if the index configuration is invalid.
- Throws if the index could not be created.
Example Usage
Automatic Setup
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(
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
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
)