Skip to content

avoid collision on aliases in MilvusClient _create_connection #2716

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

Merged
merged 3 commits into from
Apr 25, 2025
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
1 change: 0 additions & 1 deletion examples/hybrid_search.py
Original file line number Diff line number Diff line change
@@ -49,7 +49,6 @@
milvus_client.load_collection(collection_name)

field_names = ["embeddings", "embeddings2"]
field_names = ["embeddings"]

req_list = []
nq = 1
2 changes: 1 addition & 1 deletion examples/hybrid_search/hybrid_search.py
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@
req_list.append(req)

print(fmt.format("rank by WightedRanker"))
hybrid_res = hello_milvus.hybrid_search(req_list, WeightedRanker(*weights), default_limit, output_fields=["random"])
hybrid_res = hello_milvus.hybrid_search(req_list, WeightedRanker(*weights, norm_score=True), default_limit, output_fields=["random"])
for hits in hybrid_res:
for hit in hits:
print(f" hybrid search hit: {hit}")
8 changes: 7 additions & 1 deletion pymilvus/client/abstract.py
Original file line number Diff line number Diff line change
@@ -381,16 +381,22 @@ def dict(self):


class WeightedRanker(BaseRanker):
def __init__(self, *nums):
def __init__(self, *nums, norm_score: bool = True):
self._strategy = RANKER_TYPE_WEIGHTED
weights = []
for num in nums:
# isinstance(True, int) is True, thus we need to check bool first
if isinstance(num, bool) or not isinstance(num, (int, float)):
error_msg = f"Weight must be a number, got {type(num)}"
raise TypeError(error_msg)
weights.append(num)
self._weights = weights
self._norm_score = norm_score

def dict(self):
params = {
"weights": self._weights,
"norm_score": self._norm_score,
}
return {
"strategy": self._strategy,
2 changes: 1 addition & 1 deletion pymilvus/milvus_client/milvus_client.py
Original file line number Diff line number Diff line change
@@ -916,7 +916,7 @@ def _create_connection(
) -> str:
"""Create the connection to the Milvus server."""
# TODO: Implement reuse with new uri style
using = uuid4().hex
using = kwargs.pop("alias", None) or uuid4().hex
try:
connections.connect(using, user, password, db_name, token, uri=uri, **kwargs)
except Exception as ex: