Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsbatista committed Nov 27, 2024
1 parent bcf5949 commit 0e13644
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/components/retrievers/test_sentence_window_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,39 @@ def test_constructor_parameter_does_not_change(self):
retriever.run(retrieved_documents=[Document.from_dict(doc)], window_size=1)
assert retriever.window_size == 5

def test_context_documents_returned_are_ordered_by_split_idx_start(self):
docs = []
accumulated_length = 0
for sent in range(10):
content = f"Sentence {sent}."
docs.append(
Document(
content=content,
meta={
"id": f"doc_{sent}",
"split_idx_start": accumulated_length,
"source_id": "source1",
"split_id": sent,
},
)
)
accumulated_length += len(content)

import random

random.shuffle(docs)

doc_store = InMemoryDocumentStore()
doc_store.write_documents(docs)
retriever = SentenceWindowRetriever(document_store=doc_store, window_size=3)

# run the retriever with a document whose content = "Sentence 4."
result = retriever.run(retrieved_documents=[doc for doc in docs if doc.content == "Sentence 4."])

# assert that the context documents are in the correct order
assert len(result["context_documents"]) == 7
assert [doc.meta["split_idx_start"] for doc in result["context_documents"]] == [11, 22, 33, 44, 55, 66, 77]

@pytest.mark.integration
def test_run_with_pipeline(self):
splitter = DocumentSplitter(split_length=1, split_overlap=0, split_by="sentence")
Expand Down

0 comments on commit 0e13644

Please sign in to comment.