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 v0.17, training is auto-triggered server-side once upserts cross the configured RETRAIN_THRESHOLD. The Go SDK’s Upsert response only carries Status and Message — to observe training, call IsTraining. Calling Train explicitly forces immediate clustering and is useful when you want to block until the index is ready (for example, before benchmarking queries). Auto-training can be disabled service-side with the AUTO_TRAIN_DISABLED setting.
func (e *EncryptedIndex) Train(ctx context.Context, params TrainParams) error
// Training with custom parameters for better controlbatchSize := int32(1024) // Smaller batches for limited memorymaxIters := int32(200) // More iterations for better convergencetolerance := 1e-7 // Tighter convergence tolerancemaxMemory := int32(4096) // Limit to 4GB RAMnLists := int32(256) // Specific number of clustersparams := cyborgdb.TrainParams{ BatchSize: &batchSize, MaxIters: &maxIters, Tolerance: &tolerance, MaxMemory: &maxMemory, NLists: &nLists,}// Use longer timeout for training large datasetsctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)defer cancel()fmt.Println("Starting training with custom parameters...")err := index.Train(ctx, params)if err != nil { if ctx.Err() == context.DeadlineExceeded { log.Fatal("Training timed out after 30 minutes") } log.Fatalf("Training failed: %v", err)}fmt.Println("Custom training completed!")