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 IVFFlat index type:
import cyborg_vector_search_py as cvsimport secrets# Using `memory` storage for this exampleindex_location = cvs.DBConfig("memory") config_location = cvs.DBConfig("memory")# Create a clientclient = cvs.Client(index_location, config_location)# Create an IVFFlat index config (can also be IVF/IVFPQ)# Using an example vector dimension of 128, and number of lists of 1024index_config = cvs.IndexIVFFlat(dimension=128, n_lists=1024)# Generate an encryption key for the indexindex_key = secrets.token_bytes(32)# Create an encrypted indexindex = client.create_index("my_index", index_key, index_config)
#include "cyborg_vector_search/client.hpp"#include "cyborg_vector_search/encrypted_index.hpp"#include <array>#include <random>// Using `memory` storage for this examplecyborg::LocationConfig index_location(Location::kMemory); cyborg::LocationConfig config_location(Location::kMemory);// Create a clientcyborg::Client client(index_location, config_location);// Create an IVFFlat index config (can also be IVF/IVFPQ)// Using an example vector dimension of 128, and number of lists of 1024cyborg::IndexIVFFlat index_config(dimension=128, n_lists=1024);// Generate a 32-byte random encryption keystd::array<uint8_t, 32> index_key;std::random_device rd;std::generate(index_key.begin(), index_key.end(), [&]() { return rd() % 256; });// Create an encrypted indexcyborg::EncryptedIndex index = client.CreateIndex("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 improved query performance, you can enable encrypted index caching by setting a max_cache_size:
import cyborg_vector_search_py as cvsimport secrets# Using `memory` storage for this exampleindex_location = cvs.DBConfig("memory") config_location = cvs.DBConfig("memory")# Create a clientclient = cvs.Client(index_location, config_location)# Example index configindex_config = cvs.IndexIVFFlat(dimension=128, n_lists=1024)# Generate an encryption key for the indexindex_key = secrets.token_bytes(32)# Set max cache size at 1MBmax_cache_size = 1000000# Create an encrypted indexindex = client.create_index("my_index", index_key, index_config, max_cache_size)
#include "cyborg_vector_search/client.hpp"#include "cyborg_vector_search/encrypted_index.hpp"#include <array>#include <random>// Using `memory` storage for this examplecyborg::LocationConfig index_location(Location::kMemory); cyborg::LocationConfig config_location(Location::kMemory);// Create a clientcyborg::Client client(index_location, config_location);// Example index configcyborg::IndexIVFFlat index_config(dimension=128, n_lists=1024);// Generate a 32-byte random encryption keystd::array<uint8_t, 32> index_key;std::random_device rd;std::generate(index_key.begin(), index_key.end(), [&]() { return rd() % 256; });// Set max cache size at 1MBstd::size_t max_cache_size = 1000000;// Create an encrypted indexcyborg::EncryptedIndex index = client.CreateIndex("my_index", index_key, index_config, max_cache_size);