> ## 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 a New Encrypted Index

To create an encrypted index, you need to specify an index name (must be unique) and an index key:

<CodeGroup>
  ```python Python icon="python" theme={null}
  import cyborgdb_core as cyborgdb
  import secrets

  # Get your API key
  api_key = "your_api_key_here"  # Replace with your CyborgDB API key

  # Create a client (in-memory backing store for this example)
  client = cyborgdb.Client(api_key, cyborgdb.StorageConfig.memory())

  # Generate an encryption key for the index
  index_key = secrets.token_bytes(32)

  # Create an encrypted index
  index = client.create_index("my_index", index_key)
  ```

  ```cpp C++ icon="brackets-curly" theme={null}
  #include "cyborgdb_core/client.hpp"
  #include "cyborgdb_core/encrypted_index.hpp"
  #include <openssl/rand.h>
  #include <array>

  // Get your API key
  std::string api_key = "your_api_key_here";  // Replace with your CyborgDB API key

  // Create a client (in-memory backing store for this example)
  cyborg::Client client(api_key, cyborg::StorageConfig::Memory(), 0, cyborg::kNone);

  // Generate a 32-byte secure encryption key using OpenSSL
  std::array<uint8_t, 32> index_key;
  if (RAND_bytes(index_key.data(), index_key.size()) != 1) {
      throw std::runtime_error("Failed to generate secure random key");
  }

  // Create an encrypted index (returns std::unique_ptr<cyborg::EncryptedIndex>)
  auto index = client.CreateIndex("my_index", index_key);
  ```
</CodeGroup>

This creates a new DiskIVF encrypted index. The vector dimension is auto-detected from the first upsert (or derived from an `embedding_model`); you can also set it explicitly with the keyword-only `dimension` parameter. Other optional parameters include `metric` (`"euclidean"` default, `"cosine"`, or `"squared_euclidean"`) and `storage_precision` (`float32` default, or `float16` to halve the on-disk rerank-vector footprint).

<Warning>The example above creates a random 32 byte (256-bit) index key.
This is fine for evaluation purposes, but for production use, we recommend that you use an HSM or KMS solution.
For more details, see [Managing Encryption Keys](../advanced/managing-keys).</Warning>

## Automatic Embedding Generation

<Tip>This feature is only available in Python. To use it, use `pip install cyborgdb-core[embeddings]`</Tip>

In the Python version of CyborgDB, you can enable automatic embedding generation for the encrypted index by setting `embedding_model` in `create_index()`:

```python Python icon="python" theme={null}
import cyborgdb_core as cyborgdb
import secrets

# Get your API key
api_key = "your_api_key_here"  # Replace with your CyborgDB API key

# Create a client (in-memory backing store for this example)
client = cyborgdb.Client(api_key, cyborgdb.StorageConfig.memory())

# Generate an encryption key for the index
index_key = secrets.token_bytes(32)

# Create an encrypted index with managed embedding generation (model from HuggingFace)
index = client.create_index(
    "my_index",
    index_key,
    embedding_model="all-MiniLM-L6-v2"
)
```

## API Reference

For more information on creating encrypted indexes, refer to the API reference:

<CardGroup cols={2}>
  <Card title="Python API Reference" href="../../python/client/create-index" icon="python">
    API reference for `create_index()` in Python
  </Card>

  <Card title="C++ API Reference" href="../../cpp/client/create-index" icon="brackets-curly">
    API reference for `CreateIndex()` in C++
  </Card>
</CardGroup>
