milvus-logo
LFAI
< Docs
  • Go

CreateIndex()

This method creates an index for the specified vector field.

Invocation

client.CreateIndex(ctx, collName, fieldName, idx, async)

Parameters

ParameterDescriptionType
ctxContext to control API invocation processcontext.Context
collNameName of the collection to build index onString
fieldNameName of the vector field to build index onString
idxIndex type and specific parametersentity.Index
asyncSwitch value to enable async index building.
Note: the deadline of context is not applied in sync creation precess.
Boolean

Return

No return.

Errors

err: error in the process (if any). Possible errors are listed below:

  • ErrClientNotReady, error that the client is not connected.

  • error that the specified field is not valid.

  • error that API invocation failed.

Example

idx, err := entity.NewIndexIvfFlat(
    entity.L2,
    1024,
)
if err != nil {
  log.Fatal("fail to create ivf flat index parameter:", err.Error())
}
err = milvusClient.CreateIndex(
  context.Background(),
  "book",
  "book_intro",
  idx,
  false,
)
if err != nil {
  log.Fatal("fail to create index:", err.Error())
}
Feedback

Was this page helpful?