To create an encrypted index, you need to specify an index name (must be unique) and an index key:
import cyborgdb_core as cyborgdbimport secrets# Using `threadsafememory` storage for this exampleindex_location = cyborgdb.DBConfig("threadsafememory") config_location = cyborgdb.DBConfig("threadsafememory")# Get your API keyapi_key = "your_api_key_here" # Replace with your actual API key# Create a clientclient = cyborgdb.Client( api_key=api_key, index_location=index_location, config_location=config_location)# Generate an encryption key for the indexindex_key = secrets.token_bytes(32)# Create an encrypted indexindex = client.create_index( index_name="my_index", index_key=index_key)
#include "cyborgdb_core/client.hpp"#include "cyborgdb_core/encrypted_index.hpp"#include <openssl/rand.h>#include <array>// Using `threadsafememory` storage for this examplecyborg::DBConfig index_location(cyborg::Location::kThreadSafeMemory);cyborg::DBConfig config_location(cyborg::Location::kThreadSafeMemory);cyborg::DBConfig contents_location(cyborg::Location::kThreadSafeMemory);// Get your API keystd::string api_key = "your_api_key_here"; // Replace with your actual API key// Create a clientcyborg::Client client(api_key, index_location, config_location, contents_location, 0, cyborg::kNone);// Generate a 32-byte secure encryption key using OpenSSLstd::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 indexauto index = client.CreateIndex("my_index", index_key);
This creates a new encrypted index with the IVFSQ (16-bit) type by default. For more details on IVFSQ 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.
This feature is only available in Python. To use it, use 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 cyborgdbimport secrets# Using `threadsafememory` storage for this exampleindex_location = cyborgdb.DBConfig("threadsafememory")config_location = cyborgdb.DBConfig("threadsafememory")items_location = cyborgdb.DBConfig("threadsafememory")# Get your API keyapi_key = "your_api_key_here" # Replace with your actual API key# Create a clientclient = cyborgdb.Client( api_key=api_key, index_location=index_location, config_location=config_location, items_location=items_location)# Generate an encryption key for the indexindex_key = secrets.token_bytes(32)# Set embedding model (from HuggingFace)embedding_model = "all-MiniLM-L6-v2"# Create an encrypted index with managed embedding generationindex = client.create_index( index_name="my_index", index_key=index_key, embedding_model=embedding_model)