跳到主要内容

index()

Near Deprecation

此操作获取当前 Collection 的指定索引。

请求语法

python
index(
**kwargs
)

参数:

  • kwargs -

    附加关键字参数。

    • index_name (str) -

      索引名称。如果未指定索引,则使用默认索引名称。

      默认索引名称的格式如下:_default_idx_{field_id}

返回类型:

Index

返回:

当前 Collection 的 Index 对象。

异常:

  • IndexNotExistException

    当指定的索引不存在时,将引发此异常。

  • AmbiguousIndexName

    当存在多个索引但未指定索引名称时,将引发此异常。

示例

python
from pymilvus import Collection

# Get an existing collection
collection = Collection(name="test_collection")

# Create an index on a scalar field
collection.create_index(
field_name="id"
)

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

# Create an index on the vector field
collection.create_index(
field_name="vector",
index_params=index_params,
timeout=None
)

# Check the index
collection.has_index() # True

# list all index names
collection.indexes

# [<pymilvus.orm.index.Index at 0x12045f910>,
# <pymilvus.orm.index.Index at 0x12045d0d0>]

# Get a specific index object
collection.index(index_name="_default_idex_101")

# <pymilvus.orm.index.Index at 0x1205b8690>

以下操作与 index() 相关

最低 SDK 版本Inherit
Ctrl I