milvus-logo

create_index()

This method creates an index with the specified index parameter.

Invocation

create_index(field_name, index_params, timeout=None, **kwargs)

Parameters

ParameterDescriptionTypeRequired
field_nameName of the field to create index onStringTrue
index_paramsParameters of the index to createDictTrue
index_nameName of the index to create. If not specified, the default value of index_name is "_default_idx_".StringFalse
timeoutAn optional duration of time in seconds to allow for the RPC. If it is set to None, the client keeps waiting until the server responds or error occurs.FloatFalse

Return

The newly created index object.

Raises

  • CollectionNotExistException: error if the collection does not exist.
  • ParamError: error if the parameters are invalid.
  • BaseException: error if the specified field does not exist.
  • BaseException: error if the index has been created.

Example

index_params = {
  "metric_type":"L2",
  "index_type":"IVF_FLAT",
  "params":{"nlist":1024}
}
from pymilvus import Collection
collection = Collection("book")      # Get an existing collection.
collection.create_index(
  field_name="book_intro", 
  index_params=index_params
  index_name="vec_index"
)

Note

  • The index_names of different indexes in the same collection must be different, so there can be at most one index whose name is _default_idx_ in a collection.
  • Using the same field_name, index_params, index_name to create the same index repeatedly will return success directly.
  • Indexes can be built for scalar fields. In this case, index_params can be omitted. Milvus will then build default dictionary tree indexes for fields of type VARCHAR. For integer or floating-point fields, the default index type is sort.