> ## 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.

# Create Index

Creates and returns a new encrypted index based on the provided configuration.

```python theme={null}
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`](../types#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`](./logger)                  | *(Optional)* Logger instance for capturing operation logs. Defaults to `None`.                                                                                     |

<Note>For more info on auto-generating embeddings, refer to [Auto-Generate Embeddings](../../guides/data-operations/add-items#automatic-embedding-generation).</Note>

### Returns

`EncryptedIndex`: An instance of the newly created encrypted index.

### Exceptions

<AccordionGroup>
  <Accordion title="ValueError">
    * Throws if the index name is not unique.
    * Throws if the index configuration is invalid.
  </Accordion>

  <Accordion title="RuntimeError">
    * Throws if the index could not be created.
  </Accordion>
</AccordionGroup>

### Example Usage

```python theme={null}
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
)
```
