Class VectorIndexConfiguration

java.lang.Object
com.couchbase.lite.IndexConfiguration
com.couchbase.lite.VectorIndexConfiguration

public final class VectorIndexConfiguration extends IndexConfiguration
  • Constructor Details

    • VectorIndexConfiguration

      public VectorIndexConfiguration(@NonNull String expression, long dimensions, long centroids)
      VectorIndexConfiguration Constructor.

      The number of centroids will be based on the expected number of vectors or documents containing the vectors to be indexed and the application may need to make some experiments to see find an optimal value to use; one simple rule which could be a starting point is to use the square root value of the number of vectors.

      Parameters:
      expression - The SQL++ expression returning a vector which is an array of numbers.
      dimensions - The number of dimensions of the vectors to be indexed. Vectors that do not have the specified dimensions will not be indexed. Max dimensions must be between 2 and 2048, inclusive.
      centroids - The number of centroids is the number buckets into which to partition the vectors in the index. The number of centroids will be based on the expected number of vectors to be indexed. A suggested rule is that it be the square root of the number of vectors. Max centroids must be between 1 and 64000, inclusive.
  • Method Details

    • getExpression

      @NonNull public String getExpression()
      Get the index expression.

      Returns:
      the index expression.
    • getDimensions

      public long getDimensions()
      The number of vector dimensions.

      Returns:
      the number of dimensions
    • getCentroids

      public long getCentroids()
      The number of centroids: the number buckets into which to partition the vectors in the index.

      Returns:
      the number of centroids
    • getEncoding

      @NonNull public VectorEncoding getEncoding()
      Vector encoding type.

      The default value is an 8-bit Scalar Quantizer.

    • setEncoding

      @NonNull public VectorIndexConfiguration setEncoding(@NonNull VectorEncoding encoding)
    • getMetric

      @NonNull public VectorIndexConfiguration.DistanceMetric getMetric()
      Method used to measure distance between vectors.

      The default value is euclidean.

    • setMetric

      @NonNull public VectorIndexConfiguration setMetric(@NonNull VectorIndexConfiguration.DistanceMetric metric)
    • getMinTrainingSize

      public long getMinTrainingSize()
      The minimum number of vectors for training the index.

      The default value is 25 times number of centroids. The number must be more than zero and not greater than maxTrainingSize. An invalid argument exception will be thrown when creating the index if an invalid value is used.

      Note: The training process is performed only once on the first query executed against the index when the number of vectors is at least minTrainingSize. When the training process is triggered the query might take longer than usual to return the result.

      If a query is executed against the index before the index is trained, a full scan on the vectors will be performed for the query.

      Returns:
      the min number of vectors used in training the index
    • setMinTrainingSize

      @NonNull public VectorIndexConfiguration setMinTrainingSize(long minTrainingSize)
    • getMaxTrainingSize

      public long getMaxTrainingSize()
      The max number of vectors used when training the index. The default value is 256 times number of centroids. The number must be more than zero and not less than minTrainingSize. An invalid argument exception will be thrown when creating the index if an invalid value is used.
      Returns:
      the max number of vectors used in training the index
    • setMaxTrainingSize

      @NonNull public VectorIndexConfiguration setMaxTrainingSize(long maxTrainingSize)