Location
TheLocation
enum contains the supported index backing store locations for CyborgDB. These are:
DBConfig
DBConfig
defines the storage location for various index components.
Constructor
Parameters
Parameter | Type | Description |
---|---|---|
location | Location | Specifies the type of storage location. |
table_name | std::string | (Optional) Name of the table in the database, if applicable. |
db_connection_string | std::string | (Optional) Connection string for database access, if applicable. |
Example Usage
DeviceConfig
DeviceConfig
class holds the configuration details for the device used in vector search operations, such as the number of CPU threads and whether to accelerate computations using a GPU.
Constructor
Parameters
Parameter | Type | Description |
---|---|---|
cpu_threads | int | (Optional) Number of CPU threads to use. Defaults to 0 (use all available cores). |
gpu_accelerate | bool | (Optional) Whether to use GPU acceleration. Defaults to false . |
Methods
Method | Return Type | Description |
---|---|---|
cpu_threads() const | int | Get the number of CPU threads configured. |
gpu_accelerate() const | bool | Check if GPU acceleration is enabled. |
Example Usage
DistanceMetric
TheDistanceMetric
enum contains the supported distance metrics for CyborgDB. These are:
IndexConfig
IndexConfig
is an abstract base class for configuring index types. The three derived classes can be used to configure indexes:
IndexIVF
Ideal for large-scale datasets where fast retrieval is prioritized over high recall:Speed | Recall | Index Size |
---|---|---|
Fastest | Lowest | Smallest |
Constructor
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
dimension | size_t | 0 | (Optional) Dimensionality of vector embeddings. Auto-detected if 0. |
embedding_model | std::optional<std::string> | "" | (Optional) Embedding model name for auto-generation. |
Methods
Method | Return Type | Description |
---|---|---|
dimension() | size_t | Get vector dimensionality. |
metric() | DistanceMetric | Get distance metric. |
set_metric(DistanceMetric) | void | Set distance metric. |
n_lists() | size_t | Get number of inverted lists (initially 1, set during training). |
set_n_lists(size_t) | void | Set number of inverted lists (usually done automatically during training). |
IndexIVFFlat
Suitable for applications requiring high recall with less concern for memory usage:Speed | Recall | Index Size |
---|---|---|
Fast | Highest | Biggest |
Constructor
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
dimension | size_t | 0 | (Optional) Dimensionality of vector embeddings. Auto-detected if 0. |
embedding_model | std::optional<std::string> | "" | (Optional) Embedding model name for auto-generation. |
Methods
Method | Return Type | Description |
---|---|---|
dimension() | size_t | Get vector dimensionality. |
metric() | DistanceMetric | Get distance metric. |
set_metric(DistanceMetric) | void | Set distance metric. |
n_lists() | size_t | Get number of inverted lists (initially 1, set during training). |
set_n_lists(size_t) | void | Set number of inverted lists (usually done automatically during training). |
IndexIVFFlat
is the default index configuration and is suitable for most use cases.IndexIVFPQ
Product Quantization compresses embeddings, making it suitable for balancing memory use and recall:Speed | Recall | Index Size |
---|---|---|
Fast | High | Medium |
Constructor
Parameters
Parameter | Type | Default | Description |
---|---|---|---|
dimension | size_t | 0 | (Optional) Dimensionality of vector embeddings. Auto-detected if 0. |
pq_dim | size_t | 16 | Dimensionality of embeddings after quantization (less than or equal to dimension ). |
pq_bits | size_t | 8 | Number of bits per dimension for PQ embeddings (between 1 and 16). |
embedding_model | std::optional<std::string> | "" | (Optional) Embedding model name for auto-generation. |
Methods
Method | Return Type | Description |
---|---|---|
dimension() | size_t | Get vector dimensionality. |
metric() | DistanceMetric | Get distance metric. |
set_metric(DistanceMetric) | void | Set distance metric. |
n_lists() | size_t | Get number of inverted lists (initially 1, set during training). |
set_n_lists(size_t) | void | Set number of inverted lists (usually done automatically during training). |
pq_dim() | size_t | Get PQ dimensionality. |
pq_bits() | size_t | Get PQ bits per quantizer. |
Array2D
Array2D
class provides a 2D container for data, which can be initialized with a specific number of rows and columns, or from an existing vector.
Constructors
Array2D(size_t rows, size_t cols, const T& initial_value = T())
: Creates an empty 2D array with specified dimensions.Array2D(std::vector<T>&& data, size_t cols)
: Initializes the 2D array from a 1D vector.Array2D(const std::vector<T>& data, size_t cols)
: Initializes the 2D array from a 1D vector (copy).
Access Methods
operator()(size_t row, size_t col) const
: Access an element at the specified row and column (read-only).operator()(size_t row, size_t col)
: Access an element at the specified row and column (read-write).size_t rows() const
: Returns the number of rows.size_t cols() const
: Returns the number of columns.size_t size() const
: Returns the total number of elements.
Example Usage
TrainingConfig
TheTrainingConfig
struct defines parameters for training an index, allowing control over convergence and memory usage.
Constructor
Parameters
Parameter | Type | Description |
---|---|---|
n_lists | uint64_t | (Optional) Number of inverted lists to create. Defaults to 0 , which auto-determines. |
batch_size | size_t | (Optional) Size of each batch for training. Defaults to 0 , which auto-determines. |
max_iters | size_t | (Optional) Maximum iterations for training. Defaults to 0 , which auto-determines. |
tolerance | double | (Optional) Convergence tolerance for training. Defaults to 1e-6 . |
max_memory | size_t | (Optional) Maximum memory (MB) usage during training. Defaults to 0 , no limit. |
QueryParams
TheQueryParams
struct defines parameters for querying the index, controlling the number of results and probing behavior.
Constructor
Parameters
Parameter | Type | Description |
---|---|---|
top_k | size_t | (Optional) Number of nearest neighbors to return. Defaults to 100 . |
n_probes | size_t | (Optional) Number of lists to probe during query. Defaults to 0 which will auto-determine optimal probes. |
filters | std::string | (Optional) A JSON string of filters to apply to vector metadata, limiting search scope to these vectors. |
include | std::vector<ResultFields> | (Optional) List of result fields to return. Can include kDistance and kMetadata . Defaults to empty. |
greedy | bool | (Optional) Whether to perform greedy search. Defaults to false . |
filters
use a subset of the MongoDB Query and Projection Operators.
For instance: filters: { "$and": [ { "label": "cat" }, { "confidence": { "$gte": 0.9 } } ] }
means that only vectors where label == "cat"
and confidence >= 0.9
will be considered for encrypted vector search.
For more info on metadata, see Metadata Filtering.QueryResults
QueryResults
class holds the results from a Query
operation, including IDs and distances for the nearest neighbors of each query.
Access Methods
Method | Return Type | Description |
---|---|---|
Result operator[](size_t query_idx) | Result | Returns read-write access to IDs and distances for a specific query. |
const std::vector<std::vector<std::string>>& ids() const | std::vector<std::vector<std::string>>& | Get read-only access to all IDs. |
const Array2D<float>& distances() const | const Array2D<float>& | Get read-only access to all distances. |
const std::vector<float>& vectors() const | const std::vectorfloat>& | Get read-only access to all vectors. |
const std::vector<std::vector<std::string>>& metadatas() const | const std::vector<std::vector<std::string>>& | Get read-only access to all metadatas. |
size_t num_queries() const | size_t | Returns the number of queries. |
size_t top_k() const | size_t | Returns the number of top-k items per query. |
bool empty() const | bool | Checks if the results are empty. |
Example Usage
ItemID
ItemID
is a type alias for unique identifiers used throughout CyborgDB.
ItemID
is used to uniquely identify vectors and items within an encrypted index. Currently implemented as std::string
for flexibility and human-readable identifiers.
IndexType
TheIndexType
enum defines the supported index types in CyborgDB:
In Lite mode (
#ifdef LITE
), only IVFFLAT
is available. The full version supports all three index types:IVF
: Fastest retrieval, lowest recall, smallest index sizeIVFPQ
: Balanced memory usage and recall with product quantizationIVFFLAT
: Highest recall, largest index size, no compression
Item
Item
struct holds the individual results from a Get
operation, including the requested fields.
ResultFields
ResultFields
enum specifies which fields to include in query results.
ItemFields
ItemFields
enum defines the fields that can be requested for an Item
object.
ids
are always included in the returned items.