Skip to content

Commit f339ad6

Browse files
XuanYang-cnjiangyinzuojinjuan zhouzhuwenxingjunjiejiangjjj
authored
enhance: Multi-cp from master to 2.5.x (#2668)
- fix: type annotation in Hits and docs in Collection (#2387) - enhance: update float16/bfloat16 examples (#2388) - fix: sparse slice bug in hello_model.py(#2414) (#2417) - fix: pkg_resources api deprecated warning (#2438) - enhance: Use new model pkg (#2595) See also: milvus-io/milvus#37448 Signed-off-by: yangxuan <[email protected]> Co-authored-by: Yinzuo Jiang <[email protected]> Co-authored-by: Yinzuo Jiang <[email protected]> Co-authored-by: jinjuan zhou <[email protected]> Co-authored-by: zhuwenxing <[email protected]> Co-authored-by: junjie.jiang <[email protected]>
1 parent 8ddcce8 commit f339ad6

File tree

8 files changed

+26
-57
lines changed

8 files changed

+26
-57
lines changed

examples/datatypes/bfloat16_example.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import random
33
import numpy as np
44
import tensorflow as tf
5+
import torch
56
from pymilvus import (
67
connections,
78
utility,
@@ -20,6 +21,11 @@ def gen_bf16_vectors(num, dim):
2021
for _ in range(num):
2122
raw_vector = [random.random() for _ in range(dim)]
2223
raw_vectors.append(raw_vector)
24+
# Numpy itself does not support bfloat16, use TensorFlow extension instead.
25+
# PyTorch does not support converting bfloat16 vector to numpy array.
26+
# See:
27+
# - https://github.com/numpy/numpy/issues/19808
28+
# - https://github.com/pytorch/pytorch/issues/90574
2329
bf16_vector = tf.cast(raw_vector, dtype=tf.bfloat16).numpy()
2430
bf16_vectors.append(bf16_vector)
2531
return raw_vectors, bf16_vectors
@@ -57,8 +63,10 @@ def bf16_vector_search():
5763
index_params={"index_type": index_type, "params": index_params, "metric_type": "L2"})
5864
hello_milvus.load()
5965
print("index_type = ", index_type)
60-
res = hello_milvus.search(vectors[0:10], vector_field_name, {"metric_type": "L2"}, limit=1)
61-
print(res)
66+
res = hello_milvus.search(vectors[0:10], vector_field_name, {"metric_type": "L2"}, limit=1, output_fields=["bfloat16_vector"])
67+
print("raw bytes: ", res[0][0].get("bfloat16_vector"))
68+
print("tensorflow Tensor: ", tf.io.decode_raw(res[0][0].get("bfloat16_vector"), tf.bfloat16, little_endian=True))
69+
print("pytorch Tensor: ", torch.frombuffer(res[0][0].get("bfloat16_vector"), dtype=torch.bfloat16))
6270
hello_milvus.release()
6371
hello_milvus.drop_index()
6472

examples/datatypes/float16_example.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313

1414
default_fp16_index_params = [{"nlist": 128}]
1515

16+
# float16, little endian
17+
fp16_little = np.dtype('e').newbyteorder('<')
18+
1619
def gen_fp16_vectors(num, dim):
1720
raw_vectors = []
1821
fp16_vectors = []
1922
for _ in range(num):
2023
raw_vector = [random.random() for _ in range(dim)]
2124
raw_vectors.append(raw_vector)
22-
fp16_vector = np.array(raw_vector, dtype=np.float16)
25+
fp16_vector = np.array(raw_vector, dtype=fp16_little)
2326
fp16_vectors.append(fp16_vector)
2427
return raw_vectors, fp16_vectors
2528

@@ -57,8 +60,9 @@ def fp16_vector_search():
5760
index_params={"index_type": index_type, "params": index_params, "metric_type": "L2"})
5861
hello_milvus.load()
5962
print("index_type = ", index_type)
60-
res = hello_milvus.search(vectors[0:10], vector_field_name, {"metric_type": "L2"}, limit=1)
61-
print(res)
63+
res = hello_milvus.search(vectors[0:10], vector_field_name, {"metric_type": "L2"}, limit=1, output_fields=["float16_vector"])
64+
print("raw bytes: ", res[0][0].get("float16_vector"))
65+
print("numpy ndarray: ", np.frombuffer(res[0][0].get("float16_vector"), dtype=fp16_little))
6266
hello_milvus.release()
6367
hello_milvus.drop_index()
6468

examples/milvus_model/hello_model.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,16 @@ def log(msg):
5252
# BM25EmbeddingFunction usage
5353
log(fmt.format("BM25EmbeddingFunction Usage"))
5454
ef_bm25 = BM25EmbeddingFunction()
55-
docs_bm25 = [
56-
"Artificial intelligence was founded as an academic discipline in 1956.",
57-
"Alan Turing was the first person to conduct substantial research in AI.",
58-
"Born in Maida Vale, London, Turing was raised in southern England.",
59-
]
6055
ef_bm25.load()
6156
embs_bm25 = ef_bm25.encode_documents(docs)
62-
log(f"Embedding Shape: {embs_bm25[0].shape} Dimension: {ef_bm25.dim}")
57+
log(f"Embedding Shape: {embs_bm25[:, [0]].shape} Dimension: {ef_bm25.dim}")
6358

6459
# -----------------------------------------------------------------------------
6560
# SpladeEmbeddingFunction usage
6661
log(fmt.format("SpladeEmbeddingFunction Usage"))
6762
ef_splade = SpladeEmbeddingFunction(device="cpu")
6863
embs_splade = ef_splade(["Hello world", "Hello world2"])
69-
log(f"Embedding Shape: {embs_splade[0].shape} Dimension: {ef_splade.dim}")
64+
log(f"Embedding Shape: {embs_splade[:, [0]].shape} Dimension: {ef_splade.dim}")
7065

7166
# -----------------------------------------------------------------------------
7267
log(fmt.format("Demonstrations Finished"))

pymilvus/client/__init__.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
import re
33
import subprocess
44
from contextlib import suppress
5-
6-
from pkg_resources import DistributionNotFound, get_distribution
5+
from importlib.metadata import PackageNotFoundError, version
76

87
log = logging.getLogger(__name__)
98

109

1110
__version__ = "0.0.0.dev"
1211

1312

14-
with suppress(DistributionNotFound):
15-
__version__ = get_distribution("pymilvus").version
13+
with suppress(PackageNotFoundError):
14+
__version__ = version("pymilvus")
1615

1716

1817
def get_commit(version: str = "", short: bool = True) -> str:

pymilvus/client/abstract.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ class Hits(list):
679679
def __init__(
680680
self,
681681
topk: int,
682-
pks: Union[int, str],
682+
pks: List[Union[int, str]],
683683
distances: List[float],
684684
fields: Dict[str, Tuple[List[Any], schema_pb2.FieldData]],
685685
output_fields: List[str],

pymilvus/model/__init__.py

-37
This file was deleted.

pymilvus/orm/collection.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ def search(
698698
699699
partition_names (``List[str]``, optional): The names of partitions to search on.
700700
output_fields (``List[str]``, optional):
701-
The name of fields to return in the search result. Can only get scalar fields.
701+
The name of fields to return in the search result.
702702
round_decimal (``int``, optional):
703703
The specified number of decimal places of returned distance.
704704
Defaults to -1 means no round to returned distance.
@@ -833,7 +833,7 @@ def hybrid_search(
833833
834834
partition_names (``List[str]``, optional): The names of partitions to search on.
835835
output_fields (``List[str]``, optional):
836-
The name of fields to return in the search result. Can only get scalar fields.
836+
The name of fields to return in the search result.
837837
round_decimal (``int``, optional):
838838
The specified number of decimal places of returned distance.
839839
Defaults to -1 means no round to returned distance.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bulk_writer = [
5252
]
5353

5454
model = [
55-
"milvus-model>=0.1.0",
55+
"pymilvus.model>=0.3.0",
5656
]
5757

5858
dev = [

0 commit comments

Comments
 (0)