From 016ff553af24fa32fdebaf418b6afe23581bab71 Mon Sep 17 00:00:00 2001 From: groot Date: Thu, 14 Nov 2024 18:50:24 +0800 Subject: [PATCH] Remove unnecessary invoke of describe_collection() (#2345) Signed-off-by: yhmo --- pymilvus/milvus_client/milvus_client.py | 26 +++++-------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/pymilvus/milvus_client/milvus_client.py b/pymilvus/milvus_client/milvus_client.py index d5d996029..4f593eef6 100644 --- a/pymilvus/milvus_client/milvus_client.py +++ b/pymilvus/milvus_client/milvus_client.py @@ -453,20 +453,17 @@ def query( ids = [ids] conn = self._get_connection() - try: - schema_dict = conn.describe_collection(collection_name, timeout=timeout, **kwargs) - except Exception as ex: - logger.error("Failed to describe collection: %s", collection_name) - raise ex from ex if ids: + try: + schema_dict = conn.describe_collection(collection_name, timeout=timeout, **kwargs) + except Exception as ex: + logger.error("Failed to describe collection: %s", collection_name) + raise ex from ex filter = self._pack_pks_expr(schema_dict, ids) if not output_fields: output_fields = ["*"] - vec_field_name = self._get_vector_field_name(schema_dict) - if vec_field_name: - output_fields.append(vec_field_name) try: res = conn.query( @@ -524,9 +521,6 @@ def get( if not output_fields: output_fields = ["*"] - vec_field_name = self._get_vector_field_name(schema_dict) - if vec_field_name: - output_fields.append(vec_field_name) expr = self._pack_pks_expr(schema_dict, ids) try: @@ -744,16 +738,6 @@ def _extract_primary_field(self, schema_dict: Dict) -> dict: return {} - def _get_vector_field_name(self, schema_dict: Dict): - fields = schema_dict.get("fields", []) - if not fields: - return {} - - for field_dict in fields: - if field_dict.get("type", None) == DataType.FLOAT_VECTOR: - return field_dict.get("name", "") - return "" - def _pack_pks_expr(self, schema_dict: Dict, pks: List) -> str: primary_field = self._extract_primary_field(schema_dict) pk_field_name = primary_field["name"]