You can implement a Hybrid Search RAG Pipeline using FAISS for dense retrieval and BM25 for sparse retrieval by combining their outputs to enhance retrieval quality before passing results to a generator.
Here is the code snippet below:

In the above code we are using the following key points:
-
BM25Okapi for sparse keyword-based retrieval.
-
FAISS with SentenceTransformer embeddings for dense vector search.
-
RAG model to fuse retrieved contexts into answer generation.
Hence, this hybrid search pipeline balances semantic and lexical matching to enhance the overall performance of retrieval-augmented generation.