Skip to content

Commit

Permalink
Remove unnecessary invoke of describe_collection() (milvus-io#2346)
Browse files Browse the repository at this point in the history
Signed-off-by: yhmo <yihua.mo@zilliz.com>
  • Loading branch information
yhmo authored Nov 14, 2024
1 parent 2c9c55b commit 0be8e7f
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 0be8e7f

Please sign in to comment.