-
I have a query engine that gets for example |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
🤖 Hey there @aiwalter! Good to see you back in action here, I hope you're doing well. Let's delve into this new challenge you've got for us! Based on your requirements, you can modify the Here's how you can do it: def _simple_fusion(
self, results: Dict[Tuple[str, int], List[NodeWithScore]]
) -> List[NodeWithScore]:
"""Apply simple fusion."""
# Use a dict to de-duplicate nodes
all_nodes: Dict[str, NodeWithScore] = {}
file_name_counts: Dict[str, int] = {}
for nodes_with_scores in results.values():
for node_with_score in nodes_with_scores:
text = node_with_score.node.get_content()
file_name = node_with_score.node.metadata["file_name"]
if file_name not in file_name_counts:
file_name_counts[file_name] = 0
if file_name_counts[file_name] < 5:
all_nodes[text] = node_with_score
file_name_counts[file_name] += 1
return sorted(all_nodes.values(), key=lambda x: x.score or 0.0, reverse=True)[:20] In this modification, we keep track of the count of each Please note that this modification assumes that the Regarding the structure of the You can find the original I hope this helps! If you have any other questions or need further clarification, feel free to ask. SourcesThis 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. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
🤖
Sure, I can guide you on how to modify the
BaseRetriever
to implement the functionality you described.First, you need to override the
_retrieve
method in your subclass ofBaseRetriever
. This method should return a list ofNodeWithScore
objects. EachNodeWithScore
object contains anode
and ascore
. Thenode
is an instance of theNode
class, which has ametadata
attribute that is a dictionary. Thescore
is a float that represents the relevance of the node to the query.Here is a simplified version of how you can implement this: