Skip to content

Commit

Permalink
fixing docstring and improving algorithm, keep docs_to_return outside…
Browse files Browse the repository at this point in the history
… of the recursion loop
  • Loading branch information
davidsbatista committed Jan 6, 2025
1 parent ad59a99 commit 136c3c9
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 136c3c9

Please sign in to comment.