From a27e9f56af0432fc087a28a528206032186b768f Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Mon, 9 Dec 2024 11:33:26 -0500 Subject: [PATCH 1/4] bump langchain-tests --- poetry.lock | 71 +++++++++++++++++++++++++++++++++++++++++++------- pyproject.toml | 2 +- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/poetry.lock b/poetry.lock index c070d931..0787e04b 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.5 and should not be changed by hand. [[package]] name = "aiofiles" @@ -1330,13 +1330,13 @@ test = ["hatch", "ipykernel", "openapi-core (>=0.18.0,<0.19.0)", "openapi-spec-v [[package]] name = "langchain-core" -version = "0.3.19" +version = "0.3.22" description = "Building applications with LLMs through composability" optional = false python-versions = "<4.0,>=3.9" files = [ - {file = "langchain_core-0.3.19-py3-none-any.whl", hash = "sha256:562b7cc3c15dfaa9270cb1496990c1f3b3e0b660c4d6a3236d7f693346f2a96c"}, - {file = "langchain_core-0.3.19.tar.gz", hash = "sha256:126d9e8cadb2a5b8d1793a228c0783a3b608e36064d5a2ef1a4d38d07a344523"}, + {file = "langchain_core-0.3.22-py3-none-any.whl", hash = "sha256:b40b036b3bd4abc1dfc820e149f5a3c4abef2fee83eb807c4310a41a064580e0"}, + {file = "langchain_core-0.3.22.tar.gz", hash = "sha256:c61c6d62f137dff2a1ec785473a3225e4fa237e53eac88f5359fda664dc5d91c"}, ] [package.dependencies] @@ -1353,19 +1353,25 @@ typing-extensions = ">=4.7" [[package]] name = "langchain-tests" -version = "0.3.1" +version = "0.3.6" description = "Standard tests for LangChain implementations" optional = false python-versions = "<4.0,>=3.9" files = [ - {file = "langchain_tests-0.3.1-py3-none-any.whl", hash = "sha256:c62fc827247ec0a1ec73303cda8062b84581663d8f9c6e6081b1362ff822f538"}, - {file = "langchain_tests-0.3.1.tar.gz", hash = "sha256:9a221351f4c9de00d0c731e80d2dd3281ef3ba0786193d7a566a70d480cc109f"}, + {file = "langchain_tests-0.3.6-py3-none-any.whl", hash = "sha256:a651e24e8e4d92458a1b9745e26896cb5736cb8f8d64d73ac06859d28a885cfb"}, + {file = "langchain_tests-0.3.6.tar.gz", hash = "sha256:84251d637d55557b99f25e651ac7fea00f66eea1769003516304586938e6d16c"}, ] [package.dependencies] -httpx = ">=0.27.0,<0.28.0" -langchain-core = ">=0.3.15,<0.4.0" +httpx = ">=0.25.0,<1" +langchain-core = ">=0.3.22,<0.4.0" +numpy = [ + {version = ">=1.24.0,<2.0.0", markers = "python_version < \"3.12\""}, + {version = ">=1.26.2,<3", markers = "python_version >= \"3.12\""}, +] pytest = ">=7,<9" +pytest-asyncio = ">=0.20,<1" +pytest-socket = ">=0.6.0,<1" syrupy = ">=4,<5" [[package]] @@ -1743,6 +1749,51 @@ files = [ {file = "numpy-1.24.4.tar.gz", hash = "sha256:80f5e3a4e498641401868df4208b74581206afbee7cf7b8329daae82676d9463"}, ] +[[package]] +name = "numpy" +version = "1.26.4" +description = "Fundamental package for array computing in Python" +optional = false +python-versions = ">=3.9" +files = [ + {file = "numpy-1.26.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:9ff0f4f29c51e2803569d7a51c2304de5554655a60c5d776e35b4a41413830d0"}, + {file = "numpy-1.26.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:2e4ee3380d6de9c9ec04745830fd9e2eccb3e6cf790d39d7b98ffd19b0dd754a"}, + {file = "numpy-1.26.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d209d8969599b27ad20994c8e41936ee0964e6da07478d6c35016bc386b66ad4"}, + {file = "numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ffa75af20b44f8dba823498024771d5ac50620e6915abac414251bd971b4529f"}, + {file = "numpy-1.26.4-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:62b8e4b1e28009ef2846b4c7852046736bab361f7aeadeb6a5b89ebec3c7055a"}, + {file = "numpy-1.26.4-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:a4abb4f9001ad2858e7ac189089c42178fcce737e4169dc61321660f1a96c7d2"}, + {file = "numpy-1.26.4-cp310-cp310-win32.whl", hash = "sha256:bfe25acf8b437eb2a8b2d49d443800a5f18508cd811fea3181723922a8a82b07"}, + {file = "numpy-1.26.4-cp310-cp310-win_amd64.whl", hash = "sha256:b97fe8060236edf3662adfc2c633f56a08ae30560c56310562cb4f95500022d5"}, + {file = "numpy-1.26.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:4c66707fabe114439db9068ee468c26bbdf909cac0fb58686a42a24de1760c71"}, + {file = "numpy-1.26.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:edd8b5fe47dab091176d21bb6de568acdd906d1887a4584a15a9a96a1dca06ef"}, + {file = "numpy-1.26.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7ab55401287bfec946ced39700c053796e7cc0e3acbef09993a9ad2adba6ca6e"}, + {file = "numpy-1.26.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:666dbfb6ec68962c033a450943ded891bed2d54e6755e35e5835d63f4f6931d5"}, + {file = "numpy-1.26.4-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:96ff0b2ad353d8f990b63294c8986f1ec3cb19d749234014f4e7eb0112ceba5a"}, + {file = "numpy-1.26.4-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:60dedbb91afcbfdc9bc0b1f3f402804070deed7392c23eb7a7f07fa857868e8a"}, + {file = "numpy-1.26.4-cp311-cp311-win32.whl", hash = "sha256:1af303d6b2210eb850fcf03064d364652b7120803a0b872f5211f5234b399f20"}, + {file = "numpy-1.26.4-cp311-cp311-win_amd64.whl", hash = "sha256:cd25bcecc4974d09257ffcd1f098ee778f7834c3ad767fe5db785be9a4aa9cb2"}, + {file = "numpy-1.26.4-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:b3ce300f3644fb06443ee2222c2201dd3a89ea6040541412b8fa189341847218"}, + {file = "numpy-1.26.4-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:03a8c78d01d9781b28a6989f6fa1bb2c4f2d51201cf99d3dd875df6fbd96b23b"}, + {file = "numpy-1.26.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9fad7dcb1aac3c7f0584a5a8133e3a43eeb2fe127f47e3632d43d677c66c102b"}, + {file = "numpy-1.26.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:675d61ffbfa78604709862923189bad94014bef562cc35cf61d3a07bba02a7ed"}, + {file = "numpy-1.26.4-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:ab47dbe5cc8210f55aa58e4805fe224dac469cde56b9f731a4c098b91917159a"}, + {file = "numpy-1.26.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:1dda2e7b4ec9dd512f84935c5f126c8bd8b9f2fc001e9f54af255e8c5f16b0e0"}, + {file = "numpy-1.26.4-cp312-cp312-win32.whl", hash = "sha256:50193e430acfc1346175fcbdaa28ffec49947a06918b7b92130744e81e640110"}, + {file = "numpy-1.26.4-cp312-cp312-win_amd64.whl", hash = "sha256:08beddf13648eb95f8d867350f6a018a4be2e5ad54c8d8caed89ebca558b2818"}, + {file = "numpy-1.26.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:7349ab0fa0c429c82442a27a9673fc802ffdb7c7775fad780226cb234965e53c"}, + {file = "numpy-1.26.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:52b8b60467cd7dd1e9ed082188b4e6bb35aa5cdd01777621a1658910745b90be"}, + {file = "numpy-1.26.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d5241e0a80d808d70546c697135da2c613f30e28251ff8307eb72ba696945764"}, + {file = "numpy-1.26.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f870204a840a60da0b12273ef34f7051e98c3b5961b61b0c2c1be6dfd64fbcd3"}, + {file = "numpy-1.26.4-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:679b0076f67ecc0138fd2ede3a8fd196dddc2ad3254069bcb9faf9a79b1cebcd"}, + {file = "numpy-1.26.4-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:47711010ad8555514b434df65f7d7b076bb8261df1ca9bb78f53d3b2db02e95c"}, + {file = "numpy-1.26.4-cp39-cp39-win32.whl", hash = "sha256:a354325ee03388678242a4d7ebcd08b5c727033fcff3b2f536aea978e15ee9e6"}, + {file = "numpy-1.26.4-cp39-cp39-win_amd64.whl", hash = "sha256:3373d5d70a5fe74a2c1bb6d2cfd9609ecf686d47a2d7b1d37a8f3b6bf6003aea"}, + {file = "numpy-1.26.4-pp39-pypy39_pp73-macosx_10_9_x86_64.whl", hash = "sha256:afedb719a9dcfc7eaf2287b839d8198e06dcd4cb5d276a3df279231138e83d30"}, + {file = "numpy-1.26.4-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:95a7476c59002f2f6c590b9b7b998306fba6a5aa646b1e22ddfeaf8f78c3a29c"}, + {file = "numpy-1.26.4-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:7e50d0a0cc3189f9cb0aeb3a6a6af18c16f59f004b866cd2be1c14b36134a4a0"}, + {file = "numpy-1.26.4.tar.gz", hash = "sha256:2a02aba9ed12e4ac4eb3ea9421c420301a0c6460d9830d74a9df87efa4912010"}, +] + [[package]] name = "orjson" version = "3.10.7" @@ -3249,4 +3300,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "d84c0dd0c6d446789d0816e0491ff0ce7519ab50bbd2eab197315ae1ac2d50fc" +content-hash = "5dd8fb0a3969b3fc6231acf7849a3716aff0435cd47ced9e9a203fb3c2b69dac" diff --git a/pyproject.toml b/pyproject.toml index 97ee36b9..53cbb682 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ pytest-asyncio = "^0.23.2" pytest-socket = "^0.7.0" pytest-cov = "^5.0.0" pytest-timeout = "^2.3.1" -langchain-tests = "0.3.1" +langchain-tests = "0.3.6" [tool.poetry.group.codespell] optional = true From 96432a920be63d5b6eeea03fd8ac395fc2397628 Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Mon, 9 Dec 2024 11:38:02 -0500 Subject: [PATCH 2/4] fix tests --- .../test_vectorstore_standard_tests.py | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/tests/unit_tests/test_vectorstore_standard_tests.py b/tests/unit_tests/test_vectorstore_standard_tests.py index 440cab37..5ce1672d 100644 --- a/tests/unit_tests/test_vectorstore_standard_tests.py +++ b/tests/unit_tests/test_vectorstore_standard_tests.py @@ -1,16 +1,13 @@ -from typing import AsyncGenerator, Generator +from typing import Generator import pytest from langchain_core.vectorstores import VectorStore -from langchain_standard_tests.integration_tests.vectorstores import ( - AsyncReadWriteTestSuite, - ReadWriteTestSuite, -) +from langchain_tests.integration_tests import VectorStoreIntegrationTests -from tests.unit_tests.test_vectorstore import aget_vectorstore, get_vectorstore +from tests.unit_tests.test_vectorstore import get_vectorstore -class TestSync(ReadWriteTestSuite): +class TestStandard(VectorStoreIntegrationTests): @pytest.fixture() def vectorstore(self) -> Generator[VectorStore, None, None]: # type: ignore """Get an empty vectorstore for unit tests.""" @@ -19,14 +16,3 @@ def vectorstore(self) -> Generator[VectorStore, None, None]: # type: ignore vstore.create_tables_if_not_exists() vstore.create_collection() yield vstore - - -class TestAsync(AsyncReadWriteTestSuite): - @pytest.fixture() - async def vectorstore(self) -> AsyncGenerator[VectorStore, None]: # type: ignore - """Get an empty vectorstore for unit tests.""" - async with aget_vectorstore(embedding=self.get_embeddings()) as vstore: - await vstore.adrop_tables() - await vstore.acreate_tables_if_not_exists() - await vstore.acreate_collection() - yield vstore From 34adeb01724d323b449df83517274b662a53b71f Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Mon, 9 Dec 2024 16:06:19 -0500 Subject: [PATCH 3/4] update --- poetry.lock | 45 ++----------------- pyproject.toml | 2 +- .../test_vectorstore_standard_tests.py | 25 +++++++++-- 3 files changed, 27 insertions(+), 45 deletions(-) diff --git a/poetry.lock b/poetry.lock index 0787e04b..b71bde3d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1353,13 +1353,13 @@ typing-extensions = ">=4.7" [[package]] name = "langchain-tests" -version = "0.3.6" +version = "0.3.7" description = "Standard tests for LangChain implementations" optional = false python-versions = "<4.0,>=3.9" files = [ - {file = "langchain_tests-0.3.6-py3-none-any.whl", hash = "sha256:a651e24e8e4d92458a1b9745e26896cb5736cb8f8d64d73ac06859d28a885cfb"}, - {file = "langchain_tests-0.3.6.tar.gz", hash = "sha256:84251d637d55557b99f25e651ac7fea00f66eea1769003516304586938e6d16c"}, + {file = "langchain_tests-0.3.7-py3-none-any.whl", hash = "sha256:ebbb15bb4b81a75b15272ecfd8a6b9ff45f015c6edccdcf0a16d1fe461a33c90"}, + {file = "langchain_tests-0.3.7.tar.gz", hash = "sha256:28c1edff887de6f50b399345568f54f38797b7fa25d1d01b05e07172717ff7a0"}, ] [package.dependencies] @@ -1712,43 +1712,6 @@ jupyter-server = ">=1.8,<3" [package.extras] test = ["pytest", "pytest-console-scripts", "pytest-jupyter", "pytest-tornasync"] -[[package]] -name = "numpy" -version = "1.24.4" -description = "Fundamental package for array computing in Python" -optional = false -python-versions = ">=3.8" -files = [ - {file = "numpy-1.24.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:c0bfb52d2169d58c1cdb8cc1f16989101639b34c7d3ce60ed70b19c63eba0b64"}, - {file = "numpy-1.24.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:ed094d4f0c177b1b8e7aa9cba7d6ceed51c0e569a5318ac0ca9a090680a6a1b1"}, - {file = "numpy-1.24.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:79fc682a374c4a8ed08b331bef9c5f582585d1048fa6d80bc6c35bc384eee9b4"}, - {file = "numpy-1.24.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7ffe43c74893dbf38c2b0a1f5428760a1a9c98285553c89e12d70a96a7f3a4d6"}, - {file = "numpy-1.24.4-cp310-cp310-win32.whl", hash = "sha256:4c21decb6ea94057331e111a5bed9a79d335658c27ce2adb580fb4d54f2ad9bc"}, - {file = "numpy-1.24.4-cp310-cp310-win_amd64.whl", hash = "sha256:b4bea75e47d9586d31e892a7401f76e909712a0fd510f58f5337bea9572c571e"}, - {file = "numpy-1.24.4-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:f136bab9c2cfd8da131132c2cf6cc27331dd6fae65f95f69dcd4ae3c3639c810"}, - {file = "numpy-1.24.4-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:e2926dac25b313635e4d6cf4dc4e51c8c0ebfed60b801c799ffc4c32bf3d1254"}, - {file = "numpy-1.24.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:222e40d0e2548690405b0b3c7b21d1169117391c2e82c378467ef9ab4c8f0da7"}, - {file = "numpy-1.24.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7215847ce88a85ce39baf9e89070cb860c98fdddacbaa6c0da3ffb31b3350bd5"}, - {file = "numpy-1.24.4-cp311-cp311-win32.whl", hash = "sha256:4979217d7de511a8d57f4b4b5b2b965f707768440c17cb70fbf254c4b225238d"}, - {file = "numpy-1.24.4-cp311-cp311-win_amd64.whl", hash = "sha256:b7b1fc9864d7d39e28f41d089bfd6353cb5f27ecd9905348c24187a768c79694"}, - {file = "numpy-1.24.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:1452241c290f3e2a312c137a9999cdbf63f78864d63c79039bda65ee86943f61"}, - {file = "numpy-1.24.4-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:04640dab83f7c6c85abf9cd729c5b65f1ebd0ccf9de90b270cd61935eef0197f"}, - {file = "numpy-1.24.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a5425b114831d1e77e4b5d812b69d11d962e104095a5b9c3b641a218abcc050e"}, - {file = "numpy-1.24.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:dd80e219fd4c71fc3699fc1dadac5dcf4fd882bfc6f7ec53d30fa197b8ee22dc"}, - {file = "numpy-1.24.4-cp38-cp38-win32.whl", hash = "sha256:4602244f345453db537be5314d3983dbf5834a9701b7723ec28923e2889e0bb2"}, - {file = "numpy-1.24.4-cp38-cp38-win_amd64.whl", hash = "sha256:692f2e0f55794943c5bfff12b3f56f99af76f902fc47487bdfe97856de51a706"}, - {file = "numpy-1.24.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:2541312fbf09977f3b3ad449c4e5f4bb55d0dbf79226d7724211acc905049400"}, - {file = "numpy-1.24.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:9667575fb6d13c95f1b36aca12c5ee3356bf001b714fc354eb5465ce1609e62f"}, - {file = "numpy-1.24.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f3a86ed21e4f87050382c7bc96571755193c4c1392490744ac73d660e8f564a9"}, - {file = "numpy-1.24.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d11efb4dbecbdf22508d55e48d9c8384db795e1b7b51ea735289ff96613ff74d"}, - {file = "numpy-1.24.4-cp39-cp39-win32.whl", hash = "sha256:6620c0acd41dbcb368610bb2f4d83145674040025e5536954782467100aa8835"}, - {file = "numpy-1.24.4-cp39-cp39-win_amd64.whl", hash = "sha256:befe2bf740fd8373cf56149a5c23a0f601e82869598d41f8e188a0e9869926f8"}, - {file = "numpy-1.24.4-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:31f13e25b4e304632a4619d0e0777662c2ffea99fcae2029556b17d8ff958aef"}, - {file = "numpy-1.24.4-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:95f7ac6540e95bc440ad77f56e520da5bf877f87dca58bd095288dce8940532a"}, - {file = "numpy-1.24.4-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:e98f220aa76ca2a977fe435f5b04d7b3470c0a2e6312907b37ba6068f26787f2"}, - {file = "numpy-1.24.4.tar.gz", hash = "sha256:80f5e3a4e498641401868df4208b74581206afbee7cf7b8329daae82676d9463"}, -] - [[package]] name = "numpy" version = "1.26.4" @@ -3300,4 +3263,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "5dd8fb0a3969b3fc6231acf7849a3716aff0435cd47ced9e9a203fb3c2b69dac" +content-hash = "d9cb071efbb2e562b65a9950ddfa0e05bd460f5db51895de2a6f929453d82021" diff --git a/pyproject.toml b/pyproject.toml index 53cbb682..0164257a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ pytest-asyncio = "^0.23.2" pytest-socket = "^0.7.0" pytest-cov = "^5.0.0" pytest-timeout = "^2.3.1" -langchain-tests = "0.3.6" +langchain-tests = "0.3.7" [tool.poetry.group.codespell] optional = true diff --git a/tests/unit_tests/test_vectorstore_standard_tests.py b/tests/unit_tests/test_vectorstore_standard_tests.py index 5ce1672d..489128ef 100644 --- a/tests/unit_tests/test_vectorstore_standard_tests.py +++ b/tests/unit_tests/test_vectorstore_standard_tests.py @@ -1,13 +1,13 @@ -from typing import Generator +from typing import AsyncGenerator, Generator import pytest from langchain_core.vectorstores import VectorStore from langchain_tests.integration_tests import VectorStoreIntegrationTests -from tests.unit_tests.test_vectorstore import get_vectorstore +from tests.unit_tests.test_vectorstore import aget_vectorstore, get_vectorstore -class TestStandard(VectorStoreIntegrationTests): +class TestSync(VectorStoreIntegrationTests): @pytest.fixture() def vectorstore(self) -> Generator[VectorStore, None, None]: # type: ignore """Get an empty vectorstore for unit tests.""" @@ -16,3 +16,22 @@ def vectorstore(self) -> Generator[VectorStore, None, None]: # type: ignore vstore.create_tables_if_not_exists() vstore.create_collection() yield vstore + + @property + def has_async(self) -> bool: + return False + + +class TestAsync(VectorStoreIntegrationTests): + @pytest.fixture() + async def vectorstore(self) -> AsyncGenerator[VectorStore, None]: # type: ignore + """Get an empty vectorstore for unit tests.""" + async with aget_vectorstore(embedding=self.get_embeddings()) as vstore: + await vstore.adrop_tables() + await vstore.acreate_tables_if_not_exists() + await vstore.acreate_collection() + yield vstore + + @property + def has_sync(self) -> bool: + return False From f3d2aa23c90fe1027d37c69c30cb9118adf0b21e Mon Sep 17 00:00:00 2001 From: Chester Curme Date: Tue, 10 Dec 2024 09:54:00 -0500 Subject: [PATCH 4/4] fix tests --- tests/unit_tests/test_vectorstore.py | 147 +++++++++--------- .../test_vectorstore_standard_tests.py | 4 +- 2 files changed, 78 insertions(+), 73 deletions(-) diff --git a/tests/unit_tests/test_vectorstore.py b/tests/unit_tests/test_vectorstore.py index 9945e516..2383daf3 100644 --- a/tests/unit_tests/test_vectorstore.py +++ b/tests/unit_tests/test_vectorstore.py @@ -1,6 +1,6 @@ """Test PGVector functionality.""" import contextlib -from typing import Any, AsyncGenerator, Dict, Generator, List, Optional +from typing import Any, AsyncGenerator, Dict, Generator, List, Optional, Sequence import pytest from langchain_core.documents import Document @@ -25,9 +25,12 @@ ADA_TOKEN_COUNT = 1536 -class AnyStr(str): - def __eq__(self, other: Any) -> bool: - return isinstance(other, str) +def _compare_documents(left: Sequence[Document], right: Sequence[Document]) -> None: + """Compare lists of documents, irrespective of IDs.""" + assert len(left) == len(right) + for left_doc, right_doc in zip(left, right): + assert left_doc.page_content == right_doc.page_content + assert left_doc.metadata == right_doc.metadata class FakeEmbeddingsWithAdaDimension(FakeEmbeddings): @@ -55,7 +58,7 @@ def test_pgvector() -> None: pre_delete_collection=True, ) output = docsearch.similarity_search("foo", k=1) - assert output == [Document(page_content="foo", id=AnyStr())] + _compare_documents(output, [Document(page_content="foo")]) @pytest.mark.asyncio @@ -70,7 +73,7 @@ async def test_async_pgvector() -> None: pre_delete_collection=True, ) output = await docsearch.asimilarity_search("foo", k=1) - assert output == [Document(page_content="foo", id=AnyStr())] + _compare_documents(output, [Document(page_content="foo")]) def test_pgvector_embeddings() -> None: @@ -86,7 +89,7 @@ def test_pgvector_embeddings() -> None: pre_delete_collection=True, ) output = docsearch.similarity_search("foo", k=1) - assert output == [Document(page_content="foo", id=AnyStr())] + _compare_documents(output, [Document(page_content="foo")]) @pytest.mark.asyncio @@ -103,7 +106,7 @@ async def test_async_pgvector_embeddings() -> None: pre_delete_collection=True, ) output = await docsearch.asimilarity_search("foo", k=1) - assert output == [Document(page_content="foo", id=AnyStr())] + _compare_documents(output, [Document(page_content="foo")]) def test_pgvector_with_metadatas() -> None: @@ -119,7 +122,7 @@ def test_pgvector_with_metadatas() -> None: pre_delete_collection=True, ) output = docsearch.similarity_search("foo", k=1) - assert output == [Document(page_content="foo", metadata={"page": "0"}, id=AnyStr())] + _compare_documents(output, [Document(page_content="foo", metadata={"page": "0"})]) @pytest.mark.asyncio @@ -136,7 +139,7 @@ async def test_async_pgvector_with_metadatas() -> None: pre_delete_collection=True, ) output = await docsearch.asimilarity_search("foo", k=1) - assert output == [Document(page_content="foo", metadata={"page": "0"}, id=AnyStr())] + _compare_documents(output, [Document(page_content="foo", metadata={"page": "0"})]) def test_pgvector_with_metadatas_with_scores() -> None: @@ -152,9 +155,9 @@ def test_pgvector_with_metadatas_with_scores() -> None: pre_delete_collection=True, ) output = docsearch.similarity_search_with_score("foo", k=1) - assert output == [ - (Document(page_content="foo", metadata={"page": "0"}, id=AnyStr()), 0.0) - ] + docs, scores = zip(*output) + _compare_documents(docs, [Document(page_content="foo", metadata={"page": "0"})]) + assert scores == (0.0,) @pytest.mark.asyncio @@ -171,9 +174,9 @@ async def test_async_pgvector_with_metadatas_with_scores() -> None: pre_delete_collection=True, ) output = await docsearch.asimilarity_search_with_score("foo", k=1) - assert output == [ - (Document(page_content="foo", metadata={"page": "0"}, id=AnyStr()), 0.0) - ] + docs, scores = zip(*output) + _compare_documents(docs, [Document(page_content="foo", metadata={"page": "0"})]) + assert scores == (0.0,) def test_pgvector_with_filter_match() -> None: @@ -189,9 +192,9 @@ def test_pgvector_with_filter_match() -> None: pre_delete_collection=True, ) output = docsearch.similarity_search_with_score("foo", k=1, filter={"page": "0"}) - assert output == [ - (Document(page_content="foo", metadata={"page": "0"}, id=AnyStr()), 0.0) - ] + docs, scores = zip(*output) + _compare_documents(docs, [Document(page_content="foo", metadata={"page": "0"})]) + assert scores == (0.0,) @pytest.mark.asyncio @@ -210,9 +213,9 @@ async def test_async_pgvector_with_filter_match() -> None: output = await docsearch.asimilarity_search_with_score( "foo", k=1, filter={"page": "0"} ) - assert output == [ - (Document(page_content="foo", metadata={"page": "0"}, id=AnyStr()), 0.0) - ] + docs, scores = zip(*output) + _compare_documents(docs, [Document(page_content="foo", metadata={"page": "0"})]) + assert scores == (0.0,) def test_pgvector_with_filter_distant_match() -> None: @@ -228,12 +231,9 @@ def test_pgvector_with_filter_distant_match() -> None: pre_delete_collection=True, ) output = docsearch.similarity_search_with_score("foo", k=1, filter={"page": "2"}) - assert output == [ - ( - Document(page_content="baz", metadata={"page": "2"}, id=AnyStr()), - 0.0013003906671379406, - ) - ] + docs, scores = zip(*output) + _compare_documents(docs, [Document(page_content="baz", metadata={"page": "2"})]) + assert scores == (0.0013003906671379406,) @pytest.mark.asyncio @@ -252,12 +252,9 @@ async def test_async_pgvector_with_filter_distant_match() -> None: output = await docsearch.asimilarity_search_with_score( "foo", k=1, filter={"page": "2"} ) - assert output == [ - ( - Document(page_content="baz", metadata={"page": "2"}, id=AnyStr()), - 0.0013003906671379406, - ) - ] + docs, scores = zip(*output) + _compare_documents(docs, [Document(page_content="baz", metadata={"page": "2"})]) + assert scores == (0.0013003906671379406,) def test_pgvector_with_filter_no_match() -> None: @@ -593,17 +590,16 @@ def test_pgvector_relevance_score() -> None: ) output = docsearch.similarity_search_with_relevance_scores("foo", k=3) - assert output == [ - (Document(page_content="foo", metadata={"page": "0"}, id=AnyStr()), 1.0), - ( - Document(page_content="bar", metadata={"page": "1"}, id=AnyStr()), - 0.9996744261675065, - ), - ( - Document(page_content="baz", metadata={"page": "2"}, id=AnyStr()), - 0.9986996093328621, - ), - ] + docs, scores = zip(*output) + _compare_documents( + docs, + [ + Document(page_content="foo", metadata={"page": "0"}), + Document(page_content="bar", metadata={"page": "1"}), + Document(page_content="baz", metadata={"page": "2"}), + ], + ) + assert scores == (1.0, 0.9996744261675065, 0.9986996093328621) @pytest.mark.asyncio @@ -621,17 +617,16 @@ async def test_async_pgvector_relevance_score() -> None: ) output = await docsearch.asimilarity_search_with_relevance_scores("foo", k=3) - assert output == [ - (Document(page_content="foo", metadata={"page": "0"}, id=AnyStr()), 1.0), - ( - Document(page_content="bar", metadata={"page": "1"}, id=AnyStr()), - 0.9996744261675065, - ), - ( - Document(page_content="baz", metadata={"page": "2"}, id=AnyStr()), - 0.9986996093328621, - ), - ] + docs, scores = zip(*output) + _compare_documents( + docs, + [ + Document(page_content="foo", metadata={"page": "0"}), + Document(page_content="bar", metadata={"page": "1"}), + Document(page_content="baz", metadata={"page": "2"}), + ], + ) + assert scores == (1.0, 0.9996744261675065, 0.9986996093328621) def test_pgvector_retriever_search_threshold() -> None: @@ -652,10 +647,13 @@ def test_pgvector_retriever_search_threshold() -> None: search_kwargs={"k": 3, "score_threshold": 0.999}, ) output = retriever.get_relevant_documents("summer") - assert output == [ - Document(page_content="foo", metadata={"page": "0"}, id=AnyStr()), - Document(page_content="bar", metadata={"page": "1"}, id=AnyStr()), - ] + _compare_documents( + output, + [ + Document(page_content="foo", metadata={"page": "0"}), + Document(page_content="bar", metadata={"page": "1"}), + ], + ) @pytest.mark.asyncio @@ -677,10 +675,13 @@ async def test_async_pgvector_retriever_search_threshold() -> None: search_kwargs={"k": 3, "score_threshold": 0.999}, ) output = await retriever.aget_relevant_documents("summer") - assert output == [ - Document(page_content="foo", metadata={"page": "0"}, id=AnyStr()), - Document(page_content="bar", metadata={"page": "1"}, id=AnyStr()), - ] + _compare_documents( + output, + [ + Document(page_content="foo", metadata={"page": "0"}), + Document(page_content="bar", metadata={"page": "1"}), + ], + ) def test_pgvector_retriever_search_threshold_custom_normalization_fn() -> None: @@ -741,7 +742,7 @@ def test_pgvector_max_marginal_relevance_search() -> None: pre_delete_collection=True, ) output = docsearch.max_marginal_relevance_search("foo", k=1, fetch_k=3) - assert output == [Document(page_content="foo", id=AnyStr())] + _compare_documents(output, [Document(page_content="foo")]) @pytest.mark.asyncio @@ -756,7 +757,7 @@ async def test_async_pgvector_max_marginal_relevance_search() -> None: pre_delete_collection=True, ) output = await docsearch.amax_marginal_relevance_search("foo", k=1, fetch_k=3) - assert output == [Document(page_content="foo", id=AnyStr())] + _compare_documents(output, [Document(page_content="foo")]) def test_pgvector_max_marginal_relevance_search_with_score() -> None: @@ -770,7 +771,9 @@ def test_pgvector_max_marginal_relevance_search_with_score() -> None: pre_delete_collection=True, ) output = docsearch.max_marginal_relevance_search_with_score("foo", k=1, fetch_k=3) - assert output == [(Document(page_content="foo", id=AnyStr()), 0.0)] + docs, scores = zip(*output) + _compare_documents(docs, [Document(page_content="foo")]) + assert scores == (0.0,) @pytest.mark.asyncio @@ -787,7 +790,9 @@ async def test_async_pgvector_max_marginal_relevance_search_with_score() -> None output = await docsearch.amax_marginal_relevance_search_with_score( "foo", k=1, fetch_k=3 ) - assert output == [(Document(page_content="foo", id=AnyStr()), 0.0)] + docs, scores = zip(*output) + _compare_documents(docs, [Document(page_content="foo")]) + assert scores == (0.0,) def test_pgvector_with_custom_connection() -> None: @@ -801,7 +806,7 @@ def test_pgvector_with_custom_connection() -> None: pre_delete_collection=True, ) output = docsearch.similarity_search("foo", k=1) - assert output == [Document(page_content="foo", id=AnyStr())] + _compare_documents(output, [Document(page_content="foo")]) @pytest.mark.asyncio @@ -816,7 +821,7 @@ async def test_async_pgvector_with_custom_connection() -> None: pre_delete_collection=True, ) output = await docsearch.asimilarity_search("foo", k=1) - assert output == [Document(page_content="foo", id=AnyStr())] + _compare_documents(output, [Document(page_content="foo")]) def test_pgvector_with_custom_engine_args() -> None: @@ -839,7 +844,7 @@ def test_pgvector_with_custom_engine_args() -> None: engine_args=engine_args, ) output = docsearch.similarity_search("foo", k=1) - assert output == [Document(page_content="foo", id=AnyStr())] + _compare_documents(output, [Document(page_content="foo")]) # We should reuse this test-case across other integrations diff --git a/tests/unit_tests/test_vectorstore_standard_tests.py b/tests/unit_tests/test_vectorstore_standard_tests.py index 489128ef..a8834f7a 100644 --- a/tests/unit_tests/test_vectorstore_standard_tests.py +++ b/tests/unit_tests/test_vectorstore_standard_tests.py @@ -19,7 +19,7 @@ def vectorstore(self) -> Generator[VectorStore, None, None]: # type: ignore @property def has_async(self) -> bool: - return False + return False # Skip async tests for sync vector store class TestAsync(VectorStoreIntegrationTests): @@ -34,4 +34,4 @@ async def vectorstore(self) -> AsyncGenerator[VectorStore, None]: # type: ignor @property def has_sync(self) -> bool: - return False + return False # Skip sync tests for async vector store