Trains the encrypted index to optimize it for efficient similarity search queries. Training is essential for IVF-based indexes to achieve optimal query performance and accuracy.
In CyborgDB Service, training is typically handled automatically by the service. However, you can explicitly trigger training once enough vectors have been added.
index.train(
    n_lists=0,
    batch_size=2048,
    max_iters=100,
    tolerance=1e-6
)

Parameters

ParameterTypeDefaultDescription
n_listsintNone(Optional) Number of inverted lists to use for the index. Defaults to 0 which will auto-select based on the dataset size
batch_sizeint2048(Optional) Number of vectors to process per training batch
max_itersint100(Optional) Maximum number of training iterations
tolerancefloat1e-6(Optional) Convergence tolerance for training completion
Training is a compute-intensive operation that may take several seconds to minutes depending on the index size and configuration.

Returns

None

Exceptions

Example Usage

Basic Index Training

# Train the index after adding the data
index.train()

Custom Training Parameters

# Train with custom parameters for large dataset
index.train(
    n_lists=100,        # Number of inverted lists
    batch_size=4096,    # Larger batches for better performance
    max_iters=200,      # More iterations for better convergence
    tolerance=1e-7      # Stricter convergence criteria
)