CreateIndex()

Creates an index on the specified vector field of a collection.

pub async fn create_index(&self, request: CreateIndexRequest) -> Result<()>

Request Syntax

let request = CreateIndexRequest::builder()
    .collection_name("books")
    .index_params(vec![
        IndexParam::new()
            .field_name("embedding")
            .index_name("embedding_idx")
            .index_type(IndexType::AutoIndex)
            .metric_type(MetricType::Cosine),
    ])
    .build()?;

REQUEST FIELDS:

  • database_name: Option<String>

    Name of the target database; uses the default database when empty.

  • collection_name: String

    Name of the collection to index. Required.

  • index_params: Vec<IndexParam>

    Index configurations, one per vector field to index. Each IndexParam names the field, the index implementation, the metric type, and optional extra parameters. At least one is required. See IndexParam.

  • sync: bool

    Whether to wait for the index build to finish before returning. Defaults to false.

  • timeout_ms: i64

    Timeout in milliseconds applied to the operation. Zero means the client default is used.

RETURN TYPE:

Result<()>

RETURNS:

Returns Ok(()) on success, or an Error on failure.

Example

let request = CreateIndexRequest::builder()
    .collection_name("books")
    .index_params(vec![
        IndexParam::new()
            .field_name("embedding")
            .index_name("embedding_idx")
            .index_type(IndexType::AutoIndex)
            .metric_type(MetricType::Cosine),
    ])
    .build()?;
client.create_index(request).await?;

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?