NewFlatIndex()

This function creates a FLAT (brute-force) index configuration for exact nearest neighbor search on small datasets.

func NewFlatIndex(metricType MetricType) Index

PARAMETERS:

  • metricType (MetricType)

    The distance metric type for similarity search (e.g., index.COSINE, index.L2, index.IP).

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.NewFlatIndex(index.COSINE)

// Use with CreateIndex
createIdxOption := milvusclient.NewCreateIndexOption("collection_name", "vector_field", idx)
task, err := client.CreateIndex(ctx, createIdxOption)

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?