NewIvfFlatIndex()
This function creates an IVF_FLAT index configuration that partitions vectors into clusters for balanced accuracy and speed.
func NewIvfFlatIndex(metricType MetricType, nlist int) Index
PARAMETERS:
metricType (MetricType)
The distance metric type for similarity search (e.g., index.COSINE, index.L2, index.IP).
nlist (int)
The number of cluster units (inverted lists). Higher values speed up search but reduce recall. Typical range: 1-65536.
RETURNS:
Index
An index configuration instance. Pass this to CreateIndex() via the index option.
Example
import (
"github.com/milvus-io/milvus/client/v2/index"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)
// Create index configuration
idx := index.NewIvfFlatIndex(index.COSINE, 128)
// Use with CreateIndex
createIdxOption := milvusclient.NewCreateIndexOption("collection_name", "vector_field", idx)
task, err := client.CreateIndex(ctx, createIdxOption)