Skip to content

Commit

Permalink
converting some methods to static, since they change/depend on state …
Browse files Browse the repository at this point in the history
…of the object
  • Loading branch information
davidsbatista committed Dec 5, 2024
1 parent 2282c26 commit fa19f25
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions haystack/components/joiners/document_joiner.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ def __init__(
if isinstance(join_mode, str):
join_mode = JoinMode.from_str(join_mode)
join_mode_functions = {
JoinMode.CONCATENATE: self._concatenate,
JoinMode.CONCATENATE: DocumentJoiner._concatenate,
JoinMode.MERGE: self._merge,
JoinMode.RECIPROCAL_RANK_FUSION: self._reciprocal_rank_fusion,
JoinMode.DISTRIBUTION_BASED_RANK_FUSION: self._distribution_based_rank_fusion,
JoinMode.DISTRIBUTION_BASED_RANK_FUSION: DocumentJoiner._distribution_based_rank_fusion,
}
self.join_mode_function = join_mode_functions[join_mode]
self.join_mode = join_mode
Expand Down Expand Up @@ -149,7 +149,8 @@ def run(self, documents: Variadic[List[Document]], top_k: Optional[int] = None):

return {"documents": output_documents}

def _concatenate(self, document_lists: List[List[Document]]) -> List[Document]:
@staticmethod
def _concatenate(document_lists: List[List[Document]]) -> List[Document]:
"""
Concatenate multiple lists of Documents and return only the Document with the highest score for duplicates.
"""
Expand Down Expand Up @@ -217,7 +218,8 @@ def _reciprocal_rank_fusion(self, document_lists: List[List[Document]]) -> List[

return list(documents_map.values())

def _distribution_based_rank_fusion(self, document_lists: List[List[Document]]) -> List[Document]:
@staticmethod
def _distribution_based_rank_fusion(document_lists: List[List[Document]]) -> List[Document]:
"""
Merge multiple lists of Documents and assign scores based on Distribution-Based Score Fusion.
Expand All @@ -243,7 +245,7 @@ def _distribution_based_rank_fusion(self, document_lists: List[List[Document]])
doc.score = (doc.score - min_score) / delta_score if delta_score != 0.0 else 0.0
# if all docs have the same score delta_score is 0, the docs are uninformative for the query

output = self._concatenate(document_lists=document_lists)
output = DocumentJoiner._concatenate(document_lists=document_lists)

return output

Expand Down

0 comments on commit fa19f25

Please sign in to comment.