Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Dec 6, 2023
1 parent 80d52c0 commit 0126d66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 11 additions & 8 deletions libs/langchain/tests/unit_tests/retrievers/test_parent_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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"

0 comments on commit 0126d66

Please sign in to comment.