To create an encrypted index, you need to specify an index name (must be unique) and an index key:
import cyborgdb_core as cyborgdb
# or import cyborgdb_lite as cyborgdb
import secrets

# Using `memory` storage for this example
index_location = cyborgdb.DBConfig("memory") 
config_location = cyborgdb.DBConfig("memory")

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

# Create a client
client = cyborgdb.Client(
    api_key=api_key, 
    index_location=index_location, 
    config_location=config_location
)

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

# Create an encrypted index
index = client.create_index(
    index_name="my_index", 
    index_key=index_key
)
This creates a new encrypted index with the IVFFlat type by default. For more details on IVFFlat and other index options, see Configure an Encrypted Index.
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.

Encrypted Index Caching

For improved query performance, you can enable encrypted index caching by setting a max_cache_size:
import cyborgdb_core as cyborgdb
# or import cyborgdb_lite as cyborgdb
import secrets

# Using `memory` storage for this example
index_location = cyborgdb.DBConfig("memory") 
config_location = cyborgdb.DBConfig("memory")

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

# Create a client
client = cyborgdb.Client(
    api_key=api_key, 
    index_location=index_location, 
    config_location=config_location
)

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

# Set max cache size at 1MB
max_cache_size = 1000000

# Create an encrypted index
index = client.create_index(
    index_name="my_index", 
    index_key=index_key, 
    max_cache_size=max_cache_size
)
The maximum cache size is specified in megabytes. When the cache reaches this size, the least recently used entries will be evicted.

Automatic Embedding Generation

This feature is only available in Python. To use it, use pip install cyborgdb-core[embeddings] or pip install cyborgdb-core[embeddings]
In the Python version of CyborgDB, you can enable automatic embedding generation for the encrypted index by setting embedding_model in create_index():
Python
import cyborgdb_core as cyborgdb
# or import cyborgdb_lite as cyborgdb
import secrets

# Using `memory` storage for this example
index_location = cyborgdb.DBConfig("memory")
config_location = cyborgdb.DBConfig("memory")
items_location = cyborgdb.DBConfig("memory")

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

# Create a client
client = cyborgdb.Client(
    api_key=api_key, 
    index_location=index_location, 
    config_location=config_location, 
    items_location=items_location
)

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

# Set embedding model (from HuggingFace)
embedding_model = "all-MiniLM-L6-v2"

# Create an encrypted index with managed embedding generation
index = client.create_index(
    index_name="my_index", 
    index_key=index_key, 
    embedding_model=embedding_model
)

API Reference

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