跳到主要内容

describe_index()

此操作描述特定索引。

Notes

此方法仅适用于 Dedicated serving 集群和按需计算。

  • 要在 serving 集群的 Collection 中执行此操作,请使用集群 Endpoint 创建 MilvusClient。

    • Free & Serverless

      https://{cluster-id}.serverless.{region}.vectordb.zillizcloud.com

    • Dedicated

      https://{cluster-id}.{region}.vectordb.zillizcloud.com:19530

  • 要在按需计算的 Collection 中执行此操作,请使用项目 Endpoints 创建 MilvusClient,然后创建一个会话并将其附加到按需集群以执行搜索。

    https://{project-id}.{region}.api.zillizcloud.com

请求语法​

python
describe_index(
collection_name: str,
index_name: str,
timeout: Optional[float] = None
) -> Dict

参数:

  • collection_name (str) -

    [必需]

    现有 Collection 的名称。

    如果将其设置为不存在的 Collection,会导致 MilvusException。

  • index_name (str) -

    [必需]

    要描述的索引名称。

    如果将其设置为不存在的 Collection,会导致 MilvusException。

  • timeout (float | None)

    此操作的超时时长。将其设置为 None 表示当收到任意响应或发生任何错误时,此操作即超时。

返回类型:

Dict

返回值:

包含指定索引详细信息的字典。

python
{
'index_type': 'AUTOINDEX',
'metric_type': 'IP',
'M': 32,
'efConstruction': 360,
'total_rows': 0,
'indexed_rows': 0,
'pending_index_rows': 0,
'state': 'Finished',
'field_name': 'my_vector',
'index_name': 'my_vector'
}

参数:

  • index_type (str) -

    用于构建索引的算法。

    在 Zilliz Cloud 上,该值始终为 AUTOINDEX。详情请参见 AUTOINDEX Explained。

  • metric_type (str) -

    用于衡量向量之间相似度的算法。可能的值包括 IP、L2 和 COSINE。

    仅当指定的字段为向量字段时,此参数可用。

  • total_rows (int) -

    此索引目标字段中的行数。

  • indexed_rows (int) -

    此索引目标字段中已建立索引的行数。

  • pending_index_rows (int) -

    指定字段中待建立索引的行数。

  • state (str) -

    索引构建过程的状态。

  • field_name (str) -

    已创建索引的字段名称。

  • index_name (str) -

    已创建索引的名称。

异常:

  • MilvusException

    当此操作期间发生任何错误时,将引发此异常。

示例​

python
from pymilvus import MilvusClient, DataType

client = MilvusClient(
uri="https://inxx-xxxxxxxxxxxx.api.gcp-us-west1.zillizcloud.com:19530",
token="user:password"
)

# 1. Create schema
schema = MilvusClient.create_schema(
auto_id=False,
enable_dynamic_field=False,
)

# 2. Add fields to schema
schema.add_field(field_name="my_id", datatype=DataType.INT64, is_primary=True)
schema.add_field(field_name="my_vector", datatype=DataType.FLOAT_VECTOR, dim=5)

# 3. Create index parameters
index_params = client.prepare_index_params()

# 4. Add indexes
# - For a scalar field
index_params.add_index(
field_name="my_id",
index_type="STL_SORT"
)

# - For a vector field
index_params.add_index(
field_name="my_vector",
index_type="AUTOINDEX",
metric_type="L2",
params={"nlist": 1024}
)

# 5. Create a collection
client.create_collection(
collection_name="customized_setup",
schema=schema
)

# 6. Create indexes
client.create_index(
collection_name="customized_setup",
index_params=index_params
)

# 6. List indexes
client.list_indexes(collection_name="customized_setup")

# ['my_id', 'my_vector']

# 7. Describe the indexes
client.describe_index(
collection_name="customized_setup",
index_name="my_vector"
)

# {
# 'index_type': 'AUTOINDEX',
# 'metric_type': 'L2',
# 'field_name': 'my_vector',
# 'index_name': 'my_vector'
# }

client.describe_index(
collection_name="customized_setup",
index_name="my_id"
)

# {
# 'index_type': 'STL_SORT',
# 'field_name': 'my_id',
# 'index_name': 'my_id'
# }
最低 SDK 版本v2.3.x