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

enhance: [2.4] support recalls for milvus_client #2554

Open
wants to merge 1 commit into
base: 2.4
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion pymilvus/client/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,13 @@ def __iter__(self) -> SequenceIterator:
def __str__(self) -> str:
"""Only print at most 10 query results"""
reminder = f" ... and {len(self) - 10} results remaining" if len(self) > 10 else ""
recall_msg = f", recalls: {list(map(str, self.recalls))}" if len(self.recalls) > 0 else ""
recall_msg = (
f", recalls: {list(map(str, self.recalls[:10]))}" if len(self.recalls) > 0 else ""
) + (
f" ... and {len(self.recalls) - 10} recall results remaining"
if len(self.recalls) > 10
else ""
)
cost_msg = f", cost: {self.cost}" if self.cost else ""
return f"data: {list(map(str, self[:10]))}{reminder}{recall_msg}{cost_msg}"

Expand Down
18 changes: 15 additions & 3 deletions pymilvus/client/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,15 +995,27 @@ class ExtraList(list):
ExtraList([1, 2, 3], extra={"total": 3})
"""

def __init__(self, *args, extra: Optional[Dict] = None, **kwargs) -> None:
def __init__(
self, *args, extra: Optional[Dict] = None, recalls: Optional[List[float]] = None, **kwargs
) -> None:
super().__init__(*args, **kwargs)
self.extra = OmitZeroDict(extra or {})
self.recalls = recalls

def __str__(self) -> str:
"""Only print at most 10 query results"""
recall_msg = (
f", recalls: {list(map(str, self.recalls[:10]))}"
if self.recalls is not None and len(self.recalls) > 0
else ""
) + (
f" ... and {len(self.recalls) - 10} recall results remaining"
if self.recalls is not None and len(self.recalls) > 10
else ""
)
if self.extra and self.extra.omit_zero_len() != 0:
return f"data: {list(map(str, self[:10]))} {'...' if len(self) > 10 else ''}, extra_info: {self.extra}"
return f"data: {list(map(str, self[:10]))} {'...' if len(self) > 10 else ''}"
return f"data: {list(map(str, self[:10]))}{' ...' if len(self) > 10 else ''}{recall_msg}, extra_info: {self.extra}"
return f"data: {list(map(str, self[:10]))}{' ...' if len(self) > 10 else ''}{recall_msg}"

__repr__ = __str__

Expand Down
2 changes: 1 addition & 1 deletion pymilvus/milvus_client/async_milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ async def search(
query_result.append(hit.to_dict())
ret.append(query_result)

return ExtraList(ret, extra=construct_cost_extra(res.cost))
return ExtraList(ret, extra=construct_cost_extra(res.cost), recalls=res.recalls)

async def query(
self,
Expand Down
2 changes: 1 addition & 1 deletion pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def search(
query_result.append(hit.to_dict())
ret.append(query_result)

return ExtraList(ret, extra=construct_cost_extra(res.cost))
return ExtraList(ret, extra=construct_cost_extra(res.cost), recalls=res.recalls)

def query(
self,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,4 @@ builtins-ignorelist = [
"dict", # TODO
"filter",
]

builtins-allowed-modules = ["types"]
Loading