BM25 (Wikipedia) also known as the Okapi BM25, is a ranking function used in information retrieval systems to estimate the relevance of documents to a given search query.BM25Retriever retriever uses the rank_bm25 package.
Copy
Ask AI
%pip install --upgrade --quiet rank_bm25
Copy
Ask AI
from langchain_community.retrievers import BM25Retriever
Pass a custom preprocessing function to the retriever to improve search results. Tokenizing text at the word level can enhance retrieval, especially when using vector stores like Chroma, Pinecone, or Faiss for chunked documents.