Skip to content

Commit

Permalink
use reranker ignoring usage of bge m3 (#2031)
Browse files Browse the repository at this point in the history
Signed-off-by: Buqian Zheng <zhengbuqian@gmail.com>
zhengbuqian authored Apr 11, 2024
1 parent 9957fbc commit b6906e1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions examples/hello_hybrid_sparse_dense.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# A demo showing hybrid semantic search with dense and sparse vectors using Milvus.
#
# You can optionally choose to use the BGE-M3 model to embed the text as dense
# and sparse vectors, or simply use random generated vectors as an example.
#
# You can also use the BGE CrossEncoder model to rerank the search results.
#
# Note that the sparse vector search feature is only available in Milvus 2.4.0 or
# higher version. Make sure you follow https://milvus.io/docs/install_standalone-docker.md
# to set up the latest version of Milvus in your local environment.

# To connect to Milvus server, you need the python client library called pymilvus.
# To use BGE-M3 model, you need to install the optional `model` module in pymilvus.
# You can get them by simply running the following commands:
#
# pip install pymilvus
# pip install pymilvus[model]

# If true, use BGE-M3 model to generate dense and sparse vectors.
# If false, use random numbers to compose dense and sparse vectors.
use_bge_m3 = True
# If both use_bge_m3 and use_reranker are true, the search result will be reranked
# using BGE CrossEncoder model.
# If true, the search result will be reranked using BGE CrossEncoder model.
use_reranker = True

# The overall steps are as follows:
@@ -118,7 +122,7 @@ def random_embedding(texts):
# hybrid search queries in the same call.
res = res[0]

if use_bge_m3 and use_reranker:
if use_reranker:
result_texts = [hit.fields["text"] for hit in res]
from pymilvus.model.reranker import BGERerankFunction
bge_rf = BGERerankFunction(device='cpu')

0 comments on commit b6906e1

Please sign in to comment.