From ed86d32105f8c3d3895d54d4bf0a17a9bce4bf6d Mon Sep 17 00:00:00 2001 From: jjovalle99 Date: Sun, 24 Mar 2024 13:32:54 -0500 Subject: [PATCH 1/6] Fixing cohere reranker call --- .../retrievers/document_compressors/cohere_rerank.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py index 3374f7906b907..2258e2f1a8fbf 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py +++ b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py @@ -77,10 +77,14 @@ def rerank( model = model or self.model top_n = top_n if (top_n is None or top_n > 0) else self.top_n results = self.client.rerank( - query, docs, model, top_n=top_n, max_chunks_per_doc=max_chunks_per_doc + query=query, + documents=docs, + model=model, + top_n=top_n, + max_chunks_per_doc=max_chunks_per_doc, ) result_dicts = [] - for res in results: + for res in results.results: result_dicts.append( {"index": res.index, "relevance_score": res.relevance_score} ) From 4624df5ae6969989f94c2e2495f15f0662a1fd89 Mon Sep 17 00:00:00 2001 From: jjovalle99 Date: Sun, 24 Mar 2024 13:43:18 -0500 Subject: [PATCH 2/6] Adding relevant unit test --- .../test_cohere_rerank.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/libs/langchain/tests/unit_tests/retrievers/document_compressors/test_cohere_rerank.py b/libs/langchain/tests/unit_tests/retrievers/document_compressors/test_cohere_rerank.py index 51eb0f626f760..87609e4d59857 100644 --- a/libs/langchain/tests/unit_tests/retrievers/document_compressors/test_cohere_rerank.py +++ b/libs/langchain/tests/unit_tests/retrievers/document_compressors/test_cohere_rerank.py @@ -1,8 +1,10 @@ import os import pytest +from pytest_mock import MockerFixture from langchain.retrievers.document_compressors import CohereRerank +from langchain.schema import Document os.environ["COHERE_API_KEY"] = "foo" @@ -14,3 +16,37 @@ def test_init() -> None: CohereRerank( top_n=5, model="rerank-english_v2.0", cohere_api_key="foo", user_agent="bar" ) + + +@pytest.mark.requires("cohere") +def test_rerank(mocker: MockerFixture) -> None: + mock_client = mocker.MagicMock() + mock_result = mocker.MagicMock() + mock_result.results = [ + mocker.MagicMock(index=0, relevance_score=0.8), + mocker.MagicMock(index=1, relevance_score=0.6), + ] + mock_client.rerank.return_value = mock_result + + test_documents = [ + Document(page_content="This is a test document."), + Document(page_content="Another test document."), + ] + test_query = "Test query" + + mocker.patch("cohere.Client", return_value=mock_client) + + reranker = CohereRerank(cohere_api_key="foo") + results = reranker.rerank(test_documents, test_query) + + mock_client.rerank.assert_called_once_with( + query=test_query, + documents=[doc.page_content for doc in test_documents], + model="rerank-english-v2.0", + top_n=3, + max_chunks_per_doc=None, + ) + assert results == [ + {"index": 0, "relevance_score": 0.8}, + {"index": 1, "relevance_score": 0.6}, + ] From 42de343a2caf5e493f9639116933c681822e7ed2 Mon Sep 17 00:00:00 2001 From: jjovalle99 Date: Sun, 24 Mar 2024 13:46:45 -0500 Subject: [PATCH 3/6] Fixing integration test for Cohere Reranker --- .../retrievers/document_compressors/test_cohere_reranker.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/langchain/tests/integration_tests/retrievers/document_compressors/test_cohere_reranker.py b/libs/langchain/tests/integration_tests/retrievers/document_compressors/test_cohere_reranker.py index 667452041b86e..62713319d71a0 100644 --- a/libs/langchain/tests/integration_tests/retrievers/document_compressors/test_cohere_reranker.py +++ b/libs/langchain/tests/integration_tests/retrievers/document_compressors/test_cohere_reranker.py @@ -1,7 +1,10 @@ """Test the cohere reranker.""" +import os from langchain.retrievers.document_compressors.cohere_rerank import CohereRerank +os.environ["COHERE_API_KEY"] = "foo" + def test_cohere_reranker_init() -> None: """Test the cohere reranker initializes correctly.""" From 2edc098ce74be00b9dd6c145eb665cb2129dfe30 Mon Sep 17 00:00:00 2001 From: jjovalle99 Date: Mon, 25 Mar 2024 11:54:50 -0500 Subject: [PATCH 4/6] Updating cohere@^4 to cohere@^5 --- libs/langchain/poetry.lock | 68 +++++------------------------------ libs/langchain/pyproject.toml | 2 +- 2 files changed, 10 insertions(+), 60 deletions(-) diff --git a/libs/langchain/poetry.lock b/libs/langchain/poetry.lock index 927458b59b979..511bc2a45bdf1 100644 --- a/libs/langchain/poetry.lock +++ b/libs/langchain/poetry.lock @@ -1119,22 +1119,19 @@ types = ["chardet (>=5.1.0)", "mypy", "pytest", "pytest-cov", "pytest-dependency [[package]] name = "cohere" -version = "4.54" -description = "Python SDK for the Cohere API" +version = "5.1.2" +description = "" optional = true -python-versions = ">=3.8,<4.0" +python-versions = "<4.0,>=3.8" files = [ - {file = "cohere-4.54-py3-none-any.whl", hash = "sha256:6f83bd2530d461f91dfea828c1a7162b37cf03bdad4d801a218681064821f167"}, - {file = "cohere-4.54.tar.gz", hash = "sha256:c4bd84f0d766575430db91262e3ba0f4b655e40fec8a08fde98652e49a18608d"}, + {file = "cohere-5.1.2-py3-none-any.whl", hash = "sha256:7782e32cba671fc04203c3b56a9ce1b70e9459d7c983e8576b04d394fbe809f5"}, + {file = "cohere-5.1.2.tar.gz", hash = "sha256:21af5ed6edcf939062c41240040316084cd7e753cf3207f661f68abb4bbbe846"}, ] [package.dependencies] -aiohttp = ">=3.0,<4.0" -backoff = ">=2.0,<3.0" -fastavro = ">=1.8,<2.0" -importlib_metadata = ">=6.0,<7.0" -requests = ">=2.25.0,<3.0.0" -urllib3 = ">=1.26,<3" +httpx = ">=0.21.2" +pydantic = ">=1.9.2" +typing_extensions = ">=4.0.0" [[package]] name = "colorama" @@ -1803,52 +1800,6 @@ files = [ [package.dependencies] numpy = "*" -[[package]] -name = "fastavro" -version = "1.9.4" -description = "Fast read/write of AVRO files" -optional = true -python-versions = ">=3.8" -files = [ - {file = "fastavro-1.9.4-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:60cb38f07462a7fb4e4440ed0de67d3d400ae6b3d780f81327bebde9aa55faef"}, - {file = "fastavro-1.9.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:063d01d197fc929c20adc09ca9f0ca86d33ac25ee0963ce0b438244eee8315ae"}, - {file = "fastavro-1.9.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:87a9053fcfbc895f2a16a4303af22077e3a8fdcf1cd5d6ed47ff2ef22cbba2f0"}, - {file = "fastavro-1.9.4-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:02bf1276b7326397314adf41b34a4890f6ffa59cf7e0eb20b9e4ab0a143a1598"}, - {file = "fastavro-1.9.4-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:56bed9eca435389a8861e6e2d631ec7f8f5dda5b23f93517ac710665bd34ca29"}, - {file = "fastavro-1.9.4-cp310-cp310-win_amd64.whl", hash = "sha256:0cd2099c8c672b853e0b20c13e9b62a69d3fbf67ee7c59c7271ba5df1680310d"}, - {file = "fastavro-1.9.4-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:af8c6d8c43a02b5569c093fc5467469541ac408c79c36a5b0900d3dd0b3ba838"}, - {file = "fastavro-1.9.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e4a138710bd61580324d23bc5e3df01f0b82aee0a76404d5dddae73d9e4c723f"}, - {file = "fastavro-1.9.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:903d97418120ca6b6a7f38a731166c1ccc2c4344ee5e0470d09eb1dc3687540a"}, - {file = "fastavro-1.9.4-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:c443eeb99899d062dbf78c525e4614dd77e041a7688fa2710c224f4033f193ae"}, - {file = "fastavro-1.9.4-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:ac26ab0774d1b2b7af6d8f4300ad20bbc4b5469e658a02931ad13ce23635152f"}, - {file = "fastavro-1.9.4-cp311-cp311-win_amd64.whl", hash = "sha256:cf7247874c22be856ba7d1f46a0f6e0379a6025f1a48a7da640444cbac6f570b"}, - {file = "fastavro-1.9.4-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:68912f2020e1b3d70557260b27dd85fb49a4fc6bfab18d384926127452c1da4c"}, - {file = "fastavro-1.9.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6925ce137cdd78e109abdb0bc33aad55de6c9f2d2d3036b65453128f2f5f5b92"}, - {file = "fastavro-1.9.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8b928cd294e36e35516d0deb9e104b45be922ba06940794260a4e5dbed6c192a"}, - {file = "fastavro-1.9.4-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:90c9838bc4c991ffff5dd9d88a0cc0030f938b3fdf038cdf6babde144b920246"}, - {file = "fastavro-1.9.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:eca6e54da571b06a3c5a72dbb7212073f56c92a6fbfbf847b91c347510f8a426"}, - {file = "fastavro-1.9.4-cp312-cp312-win_amd64.whl", hash = "sha256:a4b02839ac261100cefca2e2ad04cdfedc556cb66b5ec735e0db428e74b399de"}, - {file = "fastavro-1.9.4-cp38-cp38-macosx_11_0_x86_64.whl", hash = "sha256:4451ee9a305a73313a1558d471299f3130e4ecc10a88bf5742aa03fb37e042e6"}, - {file = "fastavro-1.9.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a8524fccfb379565568c045d29b2ebf71e1f2c0dd484aeda9fe784ef5febe1a8"}, - {file = "fastavro-1.9.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:33d0a00a6e09baa20f6f038d7a2ddcb7eef0e7a9980e947a018300cb047091b8"}, - {file = "fastavro-1.9.4-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:23d7e5b29c9bf6f26e8be754b2c8b919838e506f78ef724de7d22881696712fc"}, - {file = "fastavro-1.9.4-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:2e6ab3ee53944326460edf1125b2ad5be2fadd80f7211b13c45fa0c503b4cf8d"}, - {file = "fastavro-1.9.4-cp38-cp38-win_amd64.whl", hash = "sha256:64d335ec2004204c501f8697c385d0a8f6b521ac82d5b30696f789ff5bc85f3c"}, - {file = "fastavro-1.9.4-cp39-cp39-macosx_11_0_x86_64.whl", hash = "sha256:7e05f44c493e89e73833bd3ff3790538726906d2856f59adc8103539f4a1b232"}, - {file = "fastavro-1.9.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:253c63993250bff4ee7b11fb46cf3a4622180a783bedc82a24c6fdcd1b10ca2a"}, - {file = "fastavro-1.9.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:24d6942eb1db14640c2581e0ecd1bbe0afc8a83731fcd3064ae7f429d7880cb7"}, - {file = "fastavro-1.9.4-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:d47bb66be6091cd48cfe026adcad11c8b11d7d815a2949a1e4ccf03df981ca65"}, - {file = "fastavro-1.9.4-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:c293897f12f910e58a1024f9c77f565aa8e23b36aafda6ad8e7041accc57a57f"}, - {file = "fastavro-1.9.4-cp39-cp39-win_amd64.whl", hash = "sha256:f05d2afcb10a92e2a9e580a3891f090589b3e567fdc5641f8a46a0b084f120c3"}, - {file = "fastavro-1.9.4.tar.gz", hash = "sha256:56b8363e360a1256c94562393dc7f8611f3baf2b3159f64fb2b9c6b87b14e876"}, -] - -[package.extras] -codecs = ["cramjam", "lz4", "zstandard"] -lz4 = ["lz4"] -snappy = ["cramjam"] -zstandard = ["zstandard"] - [[package]] name = "fastjsonschema" version = "2.19.1" @@ -6577,7 +6528,6 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, @@ -9412,4 +9362,4 @@ text-helpers = ["chardet"] [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<4.0" -content-hash = "a1a03f1605f937a5b9f82b995c589f93edf8f00ca3eb856dc86c3c63931beb8f" +content-hash = "7767e3db522c09c56af14292082179b387f92866ee7e8a4a2970e4abef69562e" diff --git a/libs/langchain/pyproject.toml b/libs/langchain/pyproject.toml index 92a6e66190668..13b889fdc3427 100644 --- a/libs/langchain/pyproject.toml +++ b/libs/langchain/pyproject.toml @@ -36,7 +36,7 @@ jinja2 = {version = "^3", optional = true} tiktoken = {version = ">=0.3.2,<0.6.0", optional = true, python=">=3.9"} qdrant-client = {version = "^1.3.1", optional = true, python = ">=3.8.1,<3.12"} dataclasses-json = ">= 0.5.7, < 0.7" -cohere = {version = "^4", optional = true} +cohere = {version = "^5", optional = true} openai = {version = "<2", optional = true} nlpcloud = {version = "^1", optional = true} huggingface_hub = {version = "^0", optional = true} From 7755c27eaa51d12a685a6cbe7e93b2e9fab39ba9 Mon Sep 17 00:00:00 2001 From: jjovalle99 Date: Wed, 27 Mar 2024 22:37:40 -0500 Subject: [PATCH 5/6] Updating cohere to version = '>=4,<6' --- libs/langchain/poetry.lock | 57 ++++++++++++++++++++++++++++++++--- libs/langchain/pyproject.toml | 2 +- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/libs/langchain/poetry.lock b/libs/langchain/poetry.lock index 511bc2a45bdf1..cd6ae38c919ed 100644 --- a/libs/langchain/poetry.lock +++ b/libs/langchain/poetry.lock @@ -1119,18 +1119,21 @@ types = ["chardet (>=5.1.0)", "mypy", "pytest", "pytest-cov", "pytest-dependency [[package]] name = "cohere" -version = "5.1.2" +version = "5.1.6" description = "" optional = true python-versions = "<4.0,>=3.8" files = [ - {file = "cohere-5.1.2-py3-none-any.whl", hash = "sha256:7782e32cba671fc04203c3b56a9ce1b70e9459d7c983e8576b04d394fbe809f5"}, - {file = "cohere-5.1.2.tar.gz", hash = "sha256:21af5ed6edcf939062c41240040316084cd7e753cf3207f661f68abb4bbbe846"}, + {file = "cohere-5.1.6-py3-none-any.whl", hash = "sha256:6e431ee3e892b97bccd7bf869d62ab8e596dca46839aee048d3d3d60d600b14e"}, + {file = "cohere-5.1.6.tar.gz", hash = "sha256:7f14c99ea07294a769051d0f564493719a09be4c1877f9bf42ca693762e55877"}, ] [package.dependencies] +fastavro = ">=1.9.4,<2.0.0" httpx = ">=0.21.2" pydantic = ">=1.9.2" +requests = ">=2.31.0,<3.0.0" +types-requests = ">=2.31.0.20240311,<3.0.0.0" typing_extensions = ">=4.0.0" [[package]] @@ -1800,6 +1803,52 @@ files = [ [package.dependencies] numpy = "*" +[[package]] +name = "fastavro" +version = "1.9.4" +description = "Fast read/write of AVRO files" +optional = true +python-versions = ">=3.8" +files = [ + {file = "fastavro-1.9.4-cp310-cp310-macosx_11_0_x86_64.whl", hash = "sha256:60cb38f07462a7fb4e4440ed0de67d3d400ae6b3d780f81327bebde9aa55faef"}, + {file = "fastavro-1.9.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:063d01d197fc929c20adc09ca9f0ca86d33ac25ee0963ce0b438244eee8315ae"}, + {file = "fastavro-1.9.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:87a9053fcfbc895f2a16a4303af22077e3a8fdcf1cd5d6ed47ff2ef22cbba2f0"}, + {file = "fastavro-1.9.4-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:02bf1276b7326397314adf41b34a4890f6ffa59cf7e0eb20b9e4ab0a143a1598"}, + {file = "fastavro-1.9.4-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:56bed9eca435389a8861e6e2d631ec7f8f5dda5b23f93517ac710665bd34ca29"}, + {file = "fastavro-1.9.4-cp310-cp310-win_amd64.whl", hash = "sha256:0cd2099c8c672b853e0b20c13e9b62a69d3fbf67ee7c59c7271ba5df1680310d"}, + {file = "fastavro-1.9.4-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:af8c6d8c43a02b5569c093fc5467469541ac408c79c36a5b0900d3dd0b3ba838"}, + {file = "fastavro-1.9.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e4a138710bd61580324d23bc5e3df01f0b82aee0a76404d5dddae73d9e4c723f"}, + {file = "fastavro-1.9.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:903d97418120ca6b6a7f38a731166c1ccc2c4344ee5e0470d09eb1dc3687540a"}, + {file = "fastavro-1.9.4-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:c443eeb99899d062dbf78c525e4614dd77e041a7688fa2710c224f4033f193ae"}, + {file = "fastavro-1.9.4-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:ac26ab0774d1b2b7af6d8f4300ad20bbc4b5469e658a02931ad13ce23635152f"}, + {file = "fastavro-1.9.4-cp311-cp311-win_amd64.whl", hash = "sha256:cf7247874c22be856ba7d1f46a0f6e0379a6025f1a48a7da640444cbac6f570b"}, + {file = "fastavro-1.9.4-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:68912f2020e1b3d70557260b27dd85fb49a4fc6bfab18d384926127452c1da4c"}, + {file = "fastavro-1.9.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:6925ce137cdd78e109abdb0bc33aad55de6c9f2d2d3036b65453128f2f5f5b92"}, + {file = "fastavro-1.9.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8b928cd294e36e35516d0deb9e104b45be922ba06940794260a4e5dbed6c192a"}, + {file = "fastavro-1.9.4-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:90c9838bc4c991ffff5dd9d88a0cc0030f938b3fdf038cdf6babde144b920246"}, + {file = "fastavro-1.9.4-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:eca6e54da571b06a3c5a72dbb7212073f56c92a6fbfbf847b91c347510f8a426"}, + {file = "fastavro-1.9.4-cp312-cp312-win_amd64.whl", hash = "sha256:a4b02839ac261100cefca2e2ad04cdfedc556cb66b5ec735e0db428e74b399de"}, + {file = "fastavro-1.9.4-cp38-cp38-macosx_11_0_x86_64.whl", hash = "sha256:4451ee9a305a73313a1558d471299f3130e4ecc10a88bf5742aa03fb37e042e6"}, + {file = "fastavro-1.9.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a8524fccfb379565568c045d29b2ebf71e1f2c0dd484aeda9fe784ef5febe1a8"}, + {file = "fastavro-1.9.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:33d0a00a6e09baa20f6f038d7a2ddcb7eef0e7a9980e947a018300cb047091b8"}, + {file = "fastavro-1.9.4-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:23d7e5b29c9bf6f26e8be754b2c8b919838e506f78ef724de7d22881696712fc"}, + {file = "fastavro-1.9.4-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:2e6ab3ee53944326460edf1125b2ad5be2fadd80f7211b13c45fa0c503b4cf8d"}, + {file = "fastavro-1.9.4-cp38-cp38-win_amd64.whl", hash = "sha256:64d335ec2004204c501f8697c385d0a8f6b521ac82d5b30696f789ff5bc85f3c"}, + {file = "fastavro-1.9.4-cp39-cp39-macosx_11_0_x86_64.whl", hash = "sha256:7e05f44c493e89e73833bd3ff3790538726906d2856f59adc8103539f4a1b232"}, + {file = "fastavro-1.9.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:253c63993250bff4ee7b11fb46cf3a4622180a783bedc82a24c6fdcd1b10ca2a"}, + {file = "fastavro-1.9.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:24d6942eb1db14640c2581e0ecd1bbe0afc8a83731fcd3064ae7f429d7880cb7"}, + {file = "fastavro-1.9.4-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:d47bb66be6091cd48cfe026adcad11c8b11d7d815a2949a1e4ccf03df981ca65"}, + {file = "fastavro-1.9.4-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:c293897f12f910e58a1024f9c77f565aa8e23b36aafda6ad8e7041accc57a57f"}, + {file = "fastavro-1.9.4-cp39-cp39-win_amd64.whl", hash = "sha256:f05d2afcb10a92e2a9e580a3891f090589b3e567fdc5641f8a46a0b084f120c3"}, + {file = "fastavro-1.9.4.tar.gz", hash = "sha256:56b8363e360a1256c94562393dc7f8611f3baf2b3159f64fb2b9c6b87b14e876"}, +] + +[package.extras] +codecs = ["cramjam", "lz4", "zstandard"] +lz4 = ["lz4"] +snappy = ["cramjam"] +zstandard = ["zstandard"] + [[package]] name = "fastjsonschema" version = "2.19.1" @@ -9362,4 +9411,4 @@ text-helpers = ["chardet"] [metadata] lock-version = "2.0" python-versions = ">=3.8.1,<4.0" -content-hash = "7767e3db522c09c56af14292082179b387f92866ee7e8a4a2970e4abef69562e" +content-hash = "f5523999d9265b7a0855a542d4060fff8fe1cf5454dbc33fad108f99e6c55e24" diff --git a/libs/langchain/pyproject.toml b/libs/langchain/pyproject.toml index 13b889fdc3427..f9bf34bd132e3 100644 --- a/libs/langchain/pyproject.toml +++ b/libs/langchain/pyproject.toml @@ -36,7 +36,7 @@ jinja2 = {version = "^3", optional = true} tiktoken = {version = ">=0.3.2,<0.6.0", optional = true, python=">=3.9"} qdrant-client = {version = "^1.3.1", optional = true, python = ">=3.8.1,<3.12"} dataclasses-json = ">= 0.5.7, < 0.7" -cohere = {version = "^5", optional = true} +cohere = {version = ">=4,<6", optional = true} openai = {version = "<2", optional = true} nlpcloud = {version = "^1", optional = true} huggingface_hub = {version = "^0", optional = true} From fdcc170029cc1c1bec460ec5612318804840e8d3 Mon Sep 17 00:00:00 2001 From: jjovalle99 Date: Wed, 27 Mar 2024 22:38:10 -0500 Subject: [PATCH 6/6] Backward compatibility cohere rerank --- .../retrievers/document_compressors/cohere_rerank.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py index 08e435ba01888..53c2ee423b395 100644 --- a/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py +++ b/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py @@ -87,8 +87,10 @@ def rerank( top_n=top_n, max_chunks_per_doc=max_chunks_per_doc, ) + if hasattr(results, "results"): + results = getattr(results, "results") result_dicts = [] - for res in results.results: + for res in results: result_dicts.append( {"index": res.index, "relevance_score": res.relevance_score} )