You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In BM25 retriever the corpus is built from nodes using the default argument to get_content() as shown below.
self._corpus = [self._tokenizer(node.get_content()) for node in self._nodes]
But, if the nodes have a specific metadata to include/exclude while searching then we cannot enable it. When we build hybrid retriever (using vector index and bm25 retrievers) the content that gets passed to vector retriever will be different than bm25 retriever. Since it is expected for retrieval we should use MetadataMode.EMBED then the same has to be passed for bm25 corpus generation as well (below).
self._corpus = [self._tokenizer(node.get_content(metadata_mode=MetadataMode.EMBED)) for node in self._nodes]
Version
v0.10.35
Steps to Reproduce
Use this notebook and add metadata fields to the nodes. Set excluded_embed_metadata_keys in the nodes to []. Embedded search will use different content than bm25 search.
gopalgk
changed the title
[Bug]: Corpus uses default MetadataMode while reading content from nodes instead of MetadataMode.EMBED or user provided option
[Bug]: BM25 Retriever - Corpus uses default MetadataMode while reading content from nodes instead of MetadataMode.EMBED or user provided option
May 8, 2024
To address the issue where the BM25 Retriever does not utilize MetadataMode.EMBED or a user-provided option for metadata handling, you can extend the BM25Retriever class to support metadata. This involves modifying the retriever to include an additional parameter for metadata handling and ensuring that both the BM25 and vector index retrievers handle metadata consistently.
Here's a concise approach to modify the BM25Retriever:
Extend BM25Retriever: Add a use_metadata boolean flag to indicate whether to use metadata.
Uniform Metadata Handling: Ensure the vector index retriever also supports metadata in a similar manner.
Metadata Preprocessing: Implement a step to combine text with metadata before indexing and retrieval.
Query Expansion: Incorporate metadata into queries for consistent retrieval.
Custom Retrieval Logic: Adjust the retrieval methods to consider metadata in scoring.
Hybrid Model Integration: Ensure metadata handling is consistent across both retrievers.
This approach ensures that metadata is consistently handled across both the BM25 and vector index retrievers, improving the accuracy and relevance of search results in a hybrid retrieval model.
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
Bug Description
In BM25 retriever the corpus is built from nodes using the default argument to get_content() as shown below.
self._corpus = [self._tokenizer(node.get_content()) for node in self._nodes]
But, if the nodes have a specific metadata to include/exclude while searching then we cannot enable it. When we build hybrid retriever (using vector index and bm25 retrievers) the content that gets passed to vector retriever will be different than bm25 retriever. Since it is expected for retrieval we should use MetadataMode.EMBED then the same has to be passed for bm25 corpus generation as well (below).
self._corpus = [self._tokenizer(node.get_content(metadata_mode=MetadataMode.EMBED)) for node in self._nodes]
Version
v0.10.35
Steps to Reproduce
Use this notebook and add metadata fields to the nodes. Set
excluded_embed_metadata_keys
in the nodes to []. Embedded search will use different content than bm25 search.https://colab.research.google.com/github/jerryjliu/llama_index/blob/main/docs/docs/examples/retrievers/bm25_retriever.ipynb
Relevant Logs/Tracbacks
No response
The text was updated successfully, but these errors were encountered: