diff --git a/pymilvus/client/grpc_handler.py b/pymilvus/client/grpc_handler.py index 89046dec2..de207edcf 100644 --- a/pymilvus/client/grpc_handler.py +++ b/pymilvus/client/grpc_handler.py @@ -922,6 +922,23 @@ def _check(): return Status(status.code, status.reason) + @retry_on_rpc_failure() + def alter_index( + self, + collection_name: str, + index_name: str, + extra_params: dict, + timeout: Optional[float] = None, + **kwargs, + ): + check_pass_param(collection_name=collection_name) + request = Prepare.alter_index_request(collection_name, index_name, extra_params) + + rf = self._stub.AlterIndex.future(request, timeout=timeout) + response = rf.result() + status = response.status + check_status(status) + @retry_on_rpc_failure() def list_indexes(self, collection_name: str, timeout: Optional[float] = None, **kwargs): check_pass_param(collection_name=collection_name) diff --git a/pymilvus/client/prepare.py b/pymilvus/client/prepare.py index 138146011..9109dc7c6 100644 --- a/pymilvus/client/prepare.py +++ b/pymilvus/client/prepare.py @@ -726,6 +726,20 @@ def dump(tv: Dict): return index_params + @classmethod + def alter_index_request(cls, collection_name: str, index_name: str, extra_params: dict): + def dump(tv: Dict): + if isinstance(tv, dict): + return ujson.dumps(tv) + return str(tv) + + params = [] + for k, v in extra_params.items(): + params.append(common_types.KeyValuePair(key=str(k), value=dump(v))) + return milvus_types.AlterIndexRequest( + collection_name=collection_name, index_name=index_name, extra_params=params + ) + @classmethod def describe_index_request( cls, collection_name: str, index_name: str, timestamp: Optional[int] = None diff --git a/pymilvus/orm/collection.py b/pymilvus/orm/collection.py index 4c2ddddd1..56f247666 100644 --- a/pymilvus/orm/collection.py +++ b/pymilvus/orm/collection.py @@ -1349,6 +1349,48 @@ def create_index( conn = self._get_connection() return conn.create_index(self._name, field_name, index_params, timeout=timeout, **kwargs) + def alter_index( + self, + index_name: str, + extra_params: dict, + timeout: Optional[float] = None, + ): + """Alter index for a specified field, with a index name. + + Args: + index_name (``str``): The name of the index to alter + extra_params (``dict``): The parameters to index + * *mmap.enabled* (``str``) + "mmap.enabled" as the key, example values: True or False. + + timeout (``float``, optional): An optional duration of time in seconds to allow + for the RPC. When timeout is set to None, client waits until server + response or error occur. + + Raises: + MilvusException: If anything goes wrong. + + Examples: + >>> from pymilvus import Collection, FieldSchema, CollectionSchema, DataType + >>> from pymilvus import IndexType, MetricType + >>> schema = CollectionSchema([ + ... FieldSchema("film_id", DataType.INT64, is_primary=True), + ... FieldSchema("title", DataType.STRING), + ... FieldSchema("films", dtype=DataType.FLOAT_VECTOR, dim=2) + ... ]) + >>> collection = Collection("test_collection_alter_index", schema) + >>> index_params = { + ... "index_type": IndexType.IVF_FLAT, + ... "metric_type": MetricType.L2, + ... "params": {"nlist": 128} + ... } + >>> collection.create_index("films", index_params, index_name="idx") + Status(code=0, message='') + >>> collection.alter_index("idx", {"mmap.enabled": True) + """ + conn = self._get_connection() + return conn.alter_index(self._name, index_name, extra_params, timeout=timeout) + def has_index(self, timeout: Optional[float] = None, **kwargs) -> bool: """Check whether a specified index exists.