From 4d37ace3d60d02448df86ae5de570c452637b35d Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Wed, 17 Nov 2021 00:50:28 +0530 Subject: [PATCH] Reduce search results for cross-encoder to re-rank to improve search speed Search time on my notes reduced from 14s to 4s. Cross-encoder re-ranking step takes majority time, not the cosine similarity search --- src/search_type/asymmetric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/search_type/asymmetric.py b/src/search_type/asymmetric.py index 93e6a181..5881d05d 100644 --- a/src/search_type/asymmetric.py +++ b/src/search_type/asymmetric.py @@ -24,7 +24,7 @@ def initialize_model(): "Initialize model for assymetric semantic search. That is, where query smaller than results" torch.set_num_threads(4) bi_encoder = SentenceTransformer('sentence-transformers/msmarco-MiniLM-L-6-v3') # The bi-encoder encodes all entries to use for semantic search - top_k = 100 # Number of entries we want to retrieve with the bi-encoder + top_k = 30 # Number of entries we want to retrieve with the bi-encoder cross_encoder = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2') # The cross-encoder re-ranks the results to improve quality return bi_encoder, cross_encoder, top_k