Skip to main content
Creates and returns a new encrypted DiskIVF index. CyborgDB supports a single index type, DiskIVF; the older IndexConfig/IndexIVF* variants have been removed.
// Overload 1: Default configuration (DiskIVF, dimension auto-detected)
std::unique_ptr<cyborg::EncryptedIndex>
    CreateIndex(const std::string index_name,
                const std::array<uint8_t, 32>& index_key,
                const std::optional<DistanceMetric>& metric = std::nullopt,
                cyborg::Logger* logger = nullptr);

// Overload 2: With an explicit IndexDiskIVF configuration
std::unique_ptr<cyborg::EncryptedIndex>
    CreateIndex(const std::string index_name,
                const std::array<uint8_t, 32>& index_key,
                const IndexDiskIVF& index_config,
                const std::optional<DistanceMetric>& metric = std::nullopt,
                cyborg::Logger* logger = nullptr);

Parameters

ParameterTypeDescription
index_namestd::stringName of the index to create (must be unique).
index_keystd::array<uint8_t, 32>32-byte encryption key (KEK) for the index, used to secure index data.
index_configIndexDiskIVF(Overload 2 only) DiskIVF configuration (dimension, storage precision, embedding model). When omitted (overload 1), a default DiskIVF config is used and dimension is auto-detected from the first upsert.
metricstd::optional<DistanceMetric>(Optional) Distance metric to override the one set in index_config (default is std::nullopt).
loggercyborg::Logger*(Optional) Pointer to a logger instance for capturing operation logs (default is nullptr).

Returns

std::unique_ptr<cyborg::EncryptedIndex>: A pointer to the newly created index (EncryptedIndex).

Exceptions

  • Throws if the index name is not unique.
  • Throws if the index configuration is invalid.
  • Throws if the index could not be created.

Example Usage

Automatic Index Config

#include "cyborgdb_core/client.hpp"
#include "cyborgdb_core/encrypted_index.hpp"
#include "cyborgdb_core/logger.hpp"
#include <array>

// ... Initialize the client ...

// Create a secure 32-byte key (example: all zeros)
std::array<uint8_t, 32> index_key = {0};

auto index = client.CreateIndex("my_index", index_key);

Explicit Index Config

#include "cyborgdb_core/client.hpp"
#include "cyborgdb_core/encrypted_index.hpp"
#include "cyborgdb_core/logger.hpp"
#include <array>

// ... Initialize the client ...

// Create a secure 32-byte key (example: all zeros)
std::array<uint8_t, 32> index_key = {0};

// Example vector dimensionality
const size_t vector_dim = 1024;

// Create a DiskIVF index configuration with an explicit dimension
cyborg::IndexDiskIVF index_config(vector_dim);

// Optional: store rerank vectors in half precision to shrink the on-disk footprint
// cyborg::IndexDiskIVF index_config(vector_dim, "", cyborg::StoragePrecision::Float16);

// Optional: Create and configure a logger
cyborg::Logger logger;
logger.Configure(LogLevel::Info, true, "index_creation.log");

auto index = client.CreateIndex("my_index", index_key, index_config, cyborg::DistanceMetric::Euclidean, &logger);