To create an encrypted index, you need to specify an index name (must be unique), an index key, and an index configuration. Here’s an example with an IVF index type:
from cyborgdb import Client, IndexIVF, generate_key

# Create a client
client = Client('http://localhost:8000', 'your-api-key')

# Create an IVF index config (can also be IVFFlat/IVFPQ)
# Using an example vector dimension of 768, and number of lists of 1024
index_config = IndexIVF(
    type='ivf',
    dimension=768,
    n_lists=1024,
    metric='cosine'
)

# Generate an encryption key for the index
index_key = generate_key()  # Returns 32-byte key as bytes

# Create an encrypted index
index = client.create_index("my_index", index_key, index_config)
This creates a new encrypted index with the IVFFlat type. 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.

Index Caching

The service-based SDKs handle caching automatically on the server side. Unlike the embedded SDKs, you don’t need to specify cache sizes when creating indexes. The CyborgDB service optimizes query performance through:
  • Automatic index caching based on usage patterns
  • Server-side query optimization
  • Efficient index loading and memory management

Automatic Embedding Generation

Both the Python and JavaScript/TypeScript service SDKs support automatic embedding generation. You can specify an embedding model when creating the index:
from cyborgdb import Client, IndexIVF, generate_key

# Create a client
client = Client('http://localhost:8000', 'your-api-key')

# Example index config with dimensions matching the embedding model
index_config = IndexIVF(
    type='ivf',
    dimension=384,  # dimension for all-MiniLM-L6-v2
    n_lists=1024,
    metric='cosine'
)

# Generate an encryption key for the index
index_key = generate_key()

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

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

API Reference

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