Skip to content

Commit

Permalink
adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsbatista committed Jan 3, 2025
1 parent c1f1c55 commit 9c4baa5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,13 @@ def try_merge_level(documents: List[Document]) -> List[Document]:
return []

docs_to_return = []
# group the documents by their parent documents
parent_documents: Dict[str, List[Document]] = defaultdict(list)
parent_documents: Dict[str, List[Document]] = defaultdict(list) # to group the documents by their parent

for doc in documents:
if doc.meta.get("__parent_id"): # Only group docs that have parents
if doc.meta.get("__parent_id"): # only docs that have parents
parent_documents[doc.meta["__parent_id"]].append(doc)
else:
docs_to_return.append(doc) # Keep docs that have no parents
docs_to_return.append(doc) # keep docs that have no parents

# If no documents have parents, we're done
if not parent_documents:
Expand Down
4 changes: 4 additions & 0 deletions test/components/retrievers/test_auto_merging_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def test_run_mixed_valid_and_invalid_documents(self):
with pytest.raises(ValueError, match="The matched leaf documents do not have the required meta field '__parent_id'"):
retriever.run(matched_leaf_documents=docs)

def test_run_empty_documents(self):
retriever = AutoMergingRetriever(InMemoryDocumentStore())
assert retriever.run([]) == {"documents": []}

def test_to_dict(self):
retriever = AutoMergingRetriever(InMemoryDocumentStore(), threshold=0.7)
expected = retriever.to_dict()
Expand Down

0 comments on commit 9c4baa5

Please sign in to comment.