跳到主要内容

has_index()

Near Deprecation

此操作检查当前 Collection 是否已构建索引。

请求语法

python
has_index(timeout: float | None)

参数:

  • timeout (float | None)

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

返回类型:

bool

返回值:

一个布尔值,表示当前 Collection 是否已构建索引。

异常:

  • MilvusException

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

示例

python
from pymilvus import Collection, CollectionSchema, FieldSchema, DataType

schema = CollectionSchema([
FieldSchema("id", DataType.INT64, is_primary=True),
FieldSchema("vector", DataType.FLOAT_VECTOR, dim=5)
])

# Create a collection
collection = Collection(
name="test_collection",
schema=schema
)

# Set the index parameters
index_params = {
"index_type": "AUTOINDEX",
"metric_type": "COSINE",
"params": {
"nprobe": 10
}
}

# Create an index
collection.create_index(
field_name="test_collection",
index_params=index_params,
timeout=None
)

# Check the index
collection.has_index() # True

# Drop the index
collection.drop_index()

# Check the index
collection.has_index() # False

以下操作与 has_index() 相关:

最低 SDK 版本Inherit
Ctrl I