From 136c3c97dd78242d0c5a846bb1c509e516788cc7 Mon Sep 17 00:00:00 2001 From: "David S. Batista" Date: Mon, 6 Jan 2025 19:14:00 +0100 Subject: [PATCH] fixing docstring and improving algorithm, keep docs_to_return outside of the recursion loop --- .../components/retrievers/auto_merging_retriever.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/haystack_experimental/components/retrievers/auto_merging_retriever.py b/haystack_experimental/components/retrievers/auto_merging_retriever.py index c13a8704..b2fd4b5f 100644 --- a/haystack_experimental/components/retrievers/auto_merging_retriever.py +++ b/haystack_experimental/components/retrievers/auto_merging_retriever.py @@ -39,7 +39,7 @@ class AutoMergingRetriever: from haystack_experimental.components.retrievers.auto_merging_retriever import AutoMergingRetriever from haystack.document_stores.in_memory import InMemoryDocumentStore - # create a hierarchical document structure with 2 levels, where the parent document has 3 children + # create a hierarchical document structure with 3 levels, where the parent document has 3 children text = "The sun rose early in the morning. It cast a warm glow over the trees. Birds began to sing." original_document = Document(content=text) builder = HierarchicalDocumentSplitter(block_sizes=[10, 3], split_overlap=0, split_by="word") @@ -122,7 +122,7 @@ def run(self, matched_leaf_documents: List[Document]): :param matched_leaf_documents: List of leaf documents that were matched by a retriever :returns: - List of documents (could be a mix of different hierarchy levels) based on threshold values + List of documents (could be a mix of different hierarchy levels) """ AutoMergingRetriever._check_valid_documents(matched_leaf_documents) @@ -167,7 +167,7 @@ def try_merge_level(documents: List[Document]) -> List[Document]: return merged_docs # Recursively try to merge the next level - return try_merge_level(merged_docs + docs_to_return) + return docs_to_return + try_merge_level(merged_docs) # start the recursive merging process final_docs = try_merge_level(matched_leaf_documents)