Skip to content

Commit 3da5bac

Browse files
refactor: converting some DocumentJoiner methods to staticmethod (#8606)
* converting some methods to static, since they change/depend on state of the object * adding release notes * removing tab
1 parent e349a7f commit 3da5bac

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

Diff for: haystack/components/joiners/document_joiner.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ def __init__(
115115
if isinstance(join_mode, str):
116116
join_mode = JoinMode.from_str(join_mode)
117117
join_mode_functions = {
118-
JoinMode.CONCATENATE: self._concatenate,
118+
JoinMode.CONCATENATE: DocumentJoiner._concatenate,
119119
JoinMode.MERGE: self._merge,
120120
JoinMode.RECIPROCAL_RANK_FUSION: self._reciprocal_rank_fusion,
121-
JoinMode.DISTRIBUTION_BASED_RANK_FUSION: self._distribution_based_rank_fusion,
121+
JoinMode.DISTRIBUTION_BASED_RANK_FUSION: DocumentJoiner._distribution_based_rank_fusion,
122122
}
123123
self.join_mode_function = join_mode_functions[join_mode]
124124
self.join_mode = join_mode
@@ -162,7 +162,8 @@ def run(self, documents: Variadic[List[Document]], top_k: Optional[int] = None):
162162

163163
return {"documents": output_documents}
164164

165-
def _concatenate(self, document_lists: List[List[Document]]) -> List[Document]:
165+
@staticmethod
166+
def _concatenate(document_lists: List[List[Document]]) -> List[Document]:
166167
"""
167168
Concatenate multiple lists of Documents and return only the Document with the highest score for duplicates.
168169
"""
@@ -230,7 +231,8 @@ def _reciprocal_rank_fusion(self, document_lists: List[List[Document]]) -> List[
230231

231232
return list(documents_map.values())
232233

233-
def _distribution_based_rank_fusion(self, document_lists: List[List[Document]]) -> List[Document]:
234+
@staticmethod
235+
def _distribution_based_rank_fusion(document_lists: List[List[Document]]) -> List[Document]:
234236
"""
235237
Merge multiple lists of Documents and assign scores based on Distribution-Based Score Fusion.
236238
@@ -256,7 +258,7 @@ def _distribution_based_rank_fusion(self, document_lists: List[List[Document]])
256258
doc.score = (doc.score - min_score) / delta_score if delta_score != 0.0 else 0.0
257259
# if all docs have the same score delta_score is 0, the docs are uninformative for the query
258260

259-
output = self._concatenate(document_lists=document_lists)
261+
output = DocumentJoiner._concatenate(document_lists=document_lists)
260262

261263
return output
262264

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
enhancements:
3+
-|
4+
DocumentJoiner methods `_concatenate()` and `_distribution_based_rank_fusion()` were converted to static methods.

0 commit comments

Comments
 (0)