From 0126d664d10c1f54607ffb90e00d03f666fa6a69 Mon Sep 17 00:00:00 2001 From: jacoblee93 Date: Wed, 6 Dec 2023 09:55:22 -0800 Subject: [PATCH] Update tests --- .../retrievers/test_multi_vector.py | 2 +- .../retrievers/test_parent_document.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libs/langchain/tests/unit_tests/retrievers/test_multi_vector.py b/libs/langchain/tests/unit_tests/retrievers/test_multi_vector.py index 73e3bd334b2b2..0d5f9a1836807 100644 --- a/libs/langchain/tests/unit_tests/retrievers/test_multi_vector.py +++ b/libs/langchain/tests/unit_tests/retrievers/test_multi_vector.py @@ -17,7 +17,7 @@ def similarity_search( return [res] -def test_multi_vector_retriever() -> None: +def test_multi_vector_retriever_initialization() -> None: vectorstore = InMemoryVectorstoreWithSearch() retriever = MultiVectorRetriever( vectorstore=vectorstore, docstore=InMemoryStore(), doc_id="doc_id" diff --git a/libs/langchain/tests/unit_tests/retrievers/test_parent_document.py b/libs/langchain/tests/unit_tests/retrievers/test_parent_document.py index 8e46074ec5f68..6a35b7cbcd38a 100644 --- a/libs/langchain/tests/unit_tests/retrievers/test_parent_document.py +++ b/libs/langchain/tests/unit_tests/retrievers/test_parent_document.py @@ -4,7 +4,7 @@ from langchain.retrievers import ParentDocumentRetriever from langchain.storage import InMemoryStore -from langchain.text_splitter import RecursiveCharacterTextSplitter +from langchain.text_splitter import CharacterTextSplitter from tests.unit_tests.indexes.test_indexing import InMemoryVectorStore @@ -17,21 +17,24 @@ def similarity_search( return [] return [res] - def add_documents(self, documents: Sequence) -> None: - return super().add_documents(documents, ids=["1"]) + def add_documents(self, documents: Sequence[Document]) -> None: + print(documents) + return super().add_documents( + documents, ids=[f"{i}" for i in range(len(documents))] + ) -def test_parent_document_retriever() -> None: +def test_parent_document_retriever_initialization() -> None: vectorstore = InMemoryVectorstoreWithSearch() store = InMemoryStore() - child_splitter = RecursiveCharacterTextSplitter(chunk_size=400) - documents = [Document(page_content="test document", metadata={"doc_id": "1"})] + child_splitter = CharacterTextSplitter(chunk_size=400) + documents = [Document(page_content="test document")] retriever = ParentDocumentRetriever( vectorstore=vectorstore, docstore=store, child_splitter=child_splitter, ) - retriever.add_documents(documents, ids=["1"]) - results = retriever.invoke("1") + retriever.add_documents(documents) + results = retriever.invoke("0") assert len(results) > 0 assert results[0].page_content == "test document"