Manage Indexes

This topic describes how to manage indexes in Milvus. See Vector Index and Index Selection for more information.

Vector indexes are an organizational unit of metadata used to accelerate vector similarity search. Without index built on vectors, Milvus will perform a brute-force search by default.

  • Current release of Milvus only supports building and dropping an index on vector field. Future releases will support these operations on scalar field.
  • By default, Milvus does not index a segment with less than 1,024 rows. To change this parameter, configure minSegmentSizeToEnableIndex in root_coord.yaml.

Build an index

The following example builds a 1024-cluster IVF_FLAT index with Euclidean distance (L2) as the similarity metrics. You can choose the index and metric that suit your scenario.

Prepare the index parameters.

index_params = {
        "metric_type":"L2",
        "index_type":"IVF_FLAT",
        "params":{"nlist":1024}
    }
const index_params = {
  metric_type: "L2",
  index_type: "IVF_FLAT",
  params: JSON.stringify({ nlist: 1024 }),
};
Parameter Description
metric_type Type of metrics used to measure similarity of vectors. Find more options in Simlarity Metrics.
index_type Type of index used to accelerate the vector search. Find more options in Index Selection.
params Building parameter(s) specific to the index. See Index Selection for more information.

Build the index by specifying the vector field name and index parameters.

from pymilvus import collection
collection = Collection("example_collection")      # Get an existing collection.
collection.create_index(field_name="example_field", index_params=index_params)
Status(code=0, message='')
await milvusClient.indexManager.createIndex({
  collection_name: "example_collection",
  field_name: "example_field",
  extra_params: index_params,
});

View index details

from pymilvus import collection
collection = Collection("example_collection")      # Get an existing collection.
collection.index().params
{'metric_type': 'L2', 'index_type': 'IVF_FLAT', 'params': {'nlist': 1024}}
await milvusClient.indexManager.describeIndex({
  collection_name: "example_collection",
});

Drop an index

Drop the index if you are sure that you do not want to use it anymore.

The drop operation is irreversible. Dropping an index removes all corresponding index files.
from pymilvus import collection
collection = Collection("example_collection")      # Get an existing collection.
collection.drop_index()
await milvusClient.indexManager.dropIndex({
  collection_name: "example_collection",
});

What's next

该页面是否对你有帮助?
评价成功!