Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary invoke of describe_collection() #2346

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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