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 on.StringTrue
index_paramsParameters of the index to create.DictTrue
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
)