Skip to content

Commit

Permalink
fix: add BM25 to supported metric type of search iterator (#2301)
Browse files Browse the repository at this point in the history
issue: milvus-io/milvus#36966

Signed-off-by: Buqian Zheng <[email protected]>
  • Loading branch information
zhengbuqian authored Oct 18, 2024
1 parent 2040ac6 commit 0a31f3b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/hello_hybrid_bm25.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def random_embedding(texts):

# We need to create indices for the vector fields. The indices will be loaded
# into memory for efficient search.
sparse_index = {"index_type": "SPARSE_INVERTED_INDEX", "metric_type": "IP"}
sparse_index = {"index_type": "SPARSE_INVERTED_INDEX", "metric_type": "BM25"}
col.create_index("sparse_vector", sparse_index)
dense_index = {"index_type": "FLAT", "metric_type": "IP"}
col.create_index("dense_vector", dense_index)
Expand Down
1 change: 1 addition & 0 deletions pymilvus/orm/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
CALC_DIST_METRIC = "metric"
CALC_DIST_L2 = "L2"
CALC_DIST_IP = "IP"
CALC_DIST_BM25 = "BM25"
CALC_DIST_HAMMING = "HAMMING"
CALC_DIST_TANIMOTO = "TANIMOTO"
CALC_DIST_JACCARD = "JACCARD"
Expand Down
3 changes: 2 additions & 1 deletion pymilvus/orm/iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .connections import Connections
from .constants import (
BATCH_SIZE,
CALC_DIST_BM25,
CALC_DIST_COSINE,
CALC_DIST_HAMMING,
CALC_DIST_IP,
Expand Down Expand Up @@ -321,7 +322,7 @@ def close(self) -> None:
def metrics_positive_related(metrics: str) -> bool:
if metrics in [CALC_DIST_L2, CALC_DIST_JACCARD, CALC_DIST_HAMMING, CALC_DIST_TANIMOTO]:
return True
if metrics in [CALC_DIST_IP, CALC_DIST_COSINE]:
if metrics in [CALC_DIST_IP, CALC_DIST_COSINE, CALC_DIST_BM25]:
return False
raise MilvusException(message=f"unsupported metrics type for search iteration: {metrics}")

Expand Down

0 comments on commit 0a31f3b

Please sign in to comment.