You can implement a hybrid retrieval system by combining BM25 scores with dense vector similarity to retrieve and rank relevant documents.
Here is the code snippet below:

In the above code, we are using the following key points:
-
BM25 for sparse keyword matching.
-
Sentence Transformers for semantic dense vector encoding.
-
A simple average fusion of BM25 and dense similarity scores for ranking.
Hence, this hybrid approach enhances retrieval robustness by balancing lexical and semantic relevance.