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:
Copy
Ask AI
from cyborgdb import Client, IndexIVF, generate_key# Create a clientclient = 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 1024index_config = IndexIVF( type='ivf', dimension=768, n_lists=1024, metric='cosine')# Generate an encryption key for the indexindex_key = generate_key() # Returns 32-byte key as bytes# Create an encrypted indexindex = 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.
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:
Both the Python and JavaScript/TypeScript service SDKs support automatic embedding generation. You can specify an embedding model when creating the index:
Copy
Ask AI
from cyborgdb import Client, IndexIVF, generate_key# Create a clientclient = Client('http://localhost:8000', 'your-api-key')# Example index config with dimensions matching the embedding modelindex_config = IndexIVF( type='ivf', dimension=384, # dimension for all-MiniLM-L6-v2 n_lists=1024, metric='cosine')# Generate an encryption key for the indexindex_key = generate_key()# Set embedding model (from HuggingFace)embedding_model = "sentence-transformers/all-MiniLM-L6-v2"# Create an encrypted index with managed embedding generationindex = client.create_index("my_index", index_key, index_config, embedding_model)