Couchbase Lite C++
Couchbase Lite C++ API
Loading...
Searching...
No Matches
cbl::VectorIndexConfiguration Class Reference

Configuration for creating a vector index, which enables searching documents by vector similarity. More...

#include <cbl++/VectorIndex.hh>

Public Member Functions

 VectorIndexConfiguration (CBLQueryLanguage expressionLanguage, std::string_view expression, unsigned dimensions, unsigned centroids)
 Creates the VectorIndexConfiguration.
QueryLanguage expressionLanguage () const
 The language used in the expressions.
slice expression () const
 The expression.
unsigned dimensions () const
 The number of vector dimensions.
unsigned centroids () const
 The number of centroids.

Public Attributes

bool isLazy = false
 The boolean flag indicating that index is lazy or not.
VectorEncoding encoding = VectorEncoding::scalarQuantizer(kCBLSQ8)
 Vector encoding type.
DistanceMetric metric = kCBLDistanceMetricEuclideanSquared
 Distance Metric type.
unsigned minTrainingSize = 0
 The minimum number of vectors for training the index.
unsigned maxTrainingSize = 0
 The maximum number of vectors used for training the index.
unsigned numProbes = 0
 The number of centroids that will be scanned during a query.

Protected Attributes

friend Collection

Detailed Description

Configuration for creating a vector index, which enables searching documents by vector similarity.

Note
ENTERPRISE EDITION ONLY

Constructor & Destructor Documentation

◆ VectorIndexConfiguration()

cbl::VectorIndexConfiguration::VectorIndexConfiguration ( CBLQueryLanguage expressionLanguage,
std::string_view expression,
unsigned dimensions,
unsigned centroids )
inline

Creates the VectorIndexConfiguration.

Parameters
expressionLanguageThe language used in the expressions.
expressionThe expression could be specified in a JSON Array or in N1QL syntax depending on the expressionLanguage.
  • For non-lazy indexes, an expression returning either a vector, which is an array of 32-bit floating-point numbers, or a Base64 string representing an array of 32-bit floating-point numbers in little-endian order.
  • For lazy indexex, an expression returning a value for computing a vector lazily when using IndexUpdater to add or update the vector into the index.
dimensionsThe number of vector dimensions.
Note
The maximum number of vector dimensions supported is 4096.
Parameters
centroidsThe number of centroids which is the number buckets to partition the vectors in the index.
Note
The recommended number of centroids is the square root of the number of vectors to be indexed, and the maximum number of centroids supported is 64,000.

Member Function Documentation

◆ centroids()

unsigned cbl::VectorIndexConfiguration::centroids ( ) const
inline

The number of centroids.

◆ dimensions()

unsigned cbl::VectorIndexConfiguration::dimensions ( ) const
inline

The number of vector dimensions.

◆ expression()

slice cbl::VectorIndexConfiguration::expression ( ) const
inline

The expression.

◆ expressionLanguage()

QueryLanguage cbl::VectorIndexConfiguration::expressionLanguage ( ) const
inline

The language used in the expressions.

Member Data Documentation

◆ Collection

friend cbl::VectorIndexConfiguration::Collection
protected

◆ encoding

VectorEncoding cbl::VectorIndexConfiguration::encoding = VectorEncoding::scalarQuantizer(kCBLSQ8)

Vector encoding type.

The default value is 8-bits Scalar Quantizer.

◆ isLazy

bool cbl::VectorIndexConfiguration::isLazy = false

The boolean flag indicating that index is lazy or not.

The default value is false.

If the index is lazy, it will not be automatically updated when the documents in the collection are changed, except when the documents are deleted or purged.

When configuring the index to be lazy, the expression set to the config is the expression that returns a value used for computing the vector.

To update the lazy index, use a CBLIndexUpdater object, which can be obtained from a QueryIndex object. To get a QueryIndex object, call Collection::getIndex.

◆ maxTrainingSize

unsigned cbl::VectorIndexConfiguration::maxTrainingSize = 0

The maximum number of vectors used for training the index.

The default value is zero, meaning that the maxTrainingSize will be determined based on the number of centroids, encoding types, and encoding parameters.

◆ metric

DistanceMetric cbl::VectorIndexConfiguration::metric = kCBLDistanceMetricEuclideanSquared

Distance Metric type.

The default value is squared euclidean distance.

◆ minTrainingSize

unsigned cbl::VectorIndexConfiguration::minTrainingSize = 0

The minimum number of vectors for training the index.

The default value is zero, meaning that minTrainingSize will be determined based on the number of centroids, encoding types, and the encoding parameters.

Note
The training will occur at or before the APPROX_VECTOR_DISANCE query is executed, provided there is enough data at that time, and consequently, if training is triggered during a query, the query may take longer to return results.
If a query is executed against the index before it is trained, a full scan of the vectors will be performed. If there are insufficient vectors in the database for training, a warning message will be logged, indicating the required number of vectors.

◆ numProbes

unsigned cbl::VectorIndexConfiguration::numProbes = 0

The number of centroids that will be scanned during a query.

The default value is zero, meaning that the numProbes will be determined based on the number of centroids.


The documentation for this class was generated from the following file: