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.
Copy
Ask AI
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!")