Create and Drop an Index

This article provides Python sample codes for creating or droping indexes.

Create an index

Currently, a collection only supports one index type. When you change the index type of a collection, Milvus automatically deletes the old index file. Before creating other indexes, a collection uses FLAT as the default index type.

create_index() specifies the index type of a collection and synchronously creates indexes for the previously inserted data. When the size of the subsequently inserted data reaches the index_file_size, Milvus automatically creates indexes in the background. For streaming data, it is recommended to create indexes before inserting the vector so that the system can automatically build indexes for the next data. For static data, it is recommended to import all the data at first and then create indexes. See index sample program for details about using index.
  1. Prepare the parameters needed to create indexes (take IVF_FLAT as an example). The index parameters are stored in a JSON string, which is represented by a dictionary in the Python SDK.

    # Prepare index param.
    >>> ivf_param = {'nlist': 16384}
    
    Different index types requires different indexing parameters. They must all have a value.
  2. Create index for the collection:

    # Create an index.
    >>> milvus.create_index('test01', IndexType.IVF_FLAT, ivf_param)
    

Drop an index

After deleting the index, the collection uses the default index type FLAT again.

>>> milvus.drop_index('test01')

FAQ

How to set the value of nlist when I build indexes? It depends on your scenario. See Performance tuning > Index for more information.
Can Milvus create different types of index for different partitions in the same collection? No. A collection can have only one index type at a time.
Does Milvus create new indexes after vectors are inserted? Yes. When the inserted vectors grow to a specified volume, Milvus creates a new segment and starts to create an index file for it at the same time. The building of the new index file does not affect the existing index files.
Edit
© 2019 - 2020 Milvus. All rights reserved.