cohere-haystack 9.4.0__tar.gz → 9.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/CHANGELOG.md +10 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/PKG-INFO +1 -1
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/pyproject.toml +1 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/rankers/cohere/ranker.py +8 -2
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/test_ranker.py +32 -19
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/.gitignore +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/LICENSE.txt +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/README.md +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/examples/cohere_embedding.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/examples/cohere_generation.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/examples/cohere_ranker.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/pydoc/config_docusaurus.yml +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/embedders/cohere/__init__.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/embedders/cohere/document_embedder.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/embedders/cohere/document_image_embedder.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/embedders/cohere/embedding_types.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/embedders/cohere/text_embedder.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/embedders/cohere/utils.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/embedders/py.typed +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/generators/cohere/__init__.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/generators/cohere/chat/__init__.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/generators/cohere/chat/chat_generator.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/generators/cohere/generator.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/generators/py.typed +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/rankers/cohere/__init__.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/src/haystack_integrations/components/rankers/py.typed +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/__init__.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/conftest.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/test_chat_generator.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/test_chat_generator_async.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/test_chat_generator_chunks.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/test_document_embedder.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/test_document_image_embedder.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/test_files/apple.jpg +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/test_files/sample_pdf_1.pdf +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/test_generator.py +0 -0
- {cohere_haystack-9.4.0 → cohere_haystack-9.5.0}/tests/test_text_embedder.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cohere-haystack
|
|
3
|
-
Version: 9.
|
|
3
|
+
Version: 9.5.0
|
|
4
4
|
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/cohere#readme
|
|
5
5
|
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
6
6
|
Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/cohere
|
|
@@ -54,7 +54,13 @@ class CohereRanker:
|
|
|
54
54
|
:param meta_data_separator: Separator used to concatenate the meta fields
|
|
55
55
|
to the Document content.
|
|
56
56
|
:param max_tokens_per_doc: The maximum number of tokens to embed for each document defaults to 4096.
|
|
57
|
+
|
|
58
|
+
:raises ValueError: If `top_k` is not > 0.
|
|
57
59
|
"""
|
|
60
|
+
if top_k <= 0:
|
|
61
|
+
msg = f"top_k must be > 0, but got {top_k}"
|
|
62
|
+
raise ValueError(msg)
|
|
63
|
+
|
|
58
64
|
self.model_name = model
|
|
59
65
|
self.api_key = api_key
|
|
60
66
|
self.api_base_url = api_base_url
|
|
@@ -116,10 +122,10 @@ class CohereRanker:
|
|
|
116
122
|
:return: A tuple of (list of strings to be given as input to Cohere model, resolved top_k).
|
|
117
123
|
:raises ValueError: If `top_k` is not > 0.
|
|
118
124
|
"""
|
|
119
|
-
top_k
|
|
120
|
-
if top_k <= 0:
|
|
125
|
+
if top_k is not None and top_k <= 0:
|
|
121
126
|
msg = f"top_k must be > 0, but got {top_k}"
|
|
122
127
|
raise ValueError(msg)
|
|
128
|
+
top_k = self.top_k if top_k is None else top_k
|
|
123
129
|
|
|
124
130
|
concatenated_input_list = []
|
|
125
131
|
for doc in documents:
|
|
@@ -248,36 +248,39 @@ class TestCohereRanker:
|
|
|
248
248
|
assert texts == []
|
|
249
249
|
assert top_k == 10
|
|
250
250
|
|
|
251
|
-
def
|
|
251
|
+
def test_init_negative_topk(self, monkeypatch):
|
|
252
252
|
monkeypatch.setenv("CO_API_KEY", "test-api-key")
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
documents = [Document(content="doc1"), Document(content="doc2"), Document(content="doc3")]
|
|
256
|
-
with pytest.raises(ValueError, match=r"top_k must be > 0, but got *"):
|
|
257
|
-
ranker.run(query, documents)
|
|
253
|
+
with pytest.raises(ValueError, match=r"top_k must be > 0, but got -2"):
|
|
254
|
+
CohereRanker(top_k=-2)
|
|
258
255
|
|
|
259
|
-
def
|
|
256
|
+
def test_init_zero_topk(self, monkeypatch):
|
|
260
257
|
monkeypatch.setenv("CO_API_KEY", "test-api-key")
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
documents = [Document(content="doc1"), Document(content="doc2"), Document(content="doc3")]
|
|
264
|
-
with pytest.raises(ValueError, match=r"top_k must be > 0, but got *"):
|
|
265
|
-
ranker.run(query, documents)
|
|
258
|
+
with pytest.raises(ValueError, match=r"top_k must be > 0, but got 0"):
|
|
259
|
+
CohereRanker(top_k=0)
|
|
266
260
|
|
|
267
261
|
def test_run_negative_topk_in_run(self, monkeypatch):
|
|
268
262
|
monkeypatch.setenv("CO_API_KEY", "test-api-key")
|
|
269
263
|
ranker = CohereRanker()
|
|
270
264
|
query = "test"
|
|
271
265
|
documents = [Document(content="doc1"), Document(content="doc2"), Document(content="doc3")]
|
|
272
|
-
with pytest.raises(ValueError, match=r"top_k must be > 0, but got
|
|
266
|
+
with pytest.raises(ValueError, match=r"top_k must be > 0, but got -3"):
|
|
273
267
|
ranker.run(query, documents, -3)
|
|
274
268
|
|
|
275
|
-
def
|
|
269
|
+
def test_run_zero_topk_in_run(self, monkeypatch):
|
|
270
|
+
monkeypatch.setenv("CO_API_KEY", "test-api-key")
|
|
271
|
+
ranker = CohereRanker()
|
|
272
|
+
query = "test"
|
|
273
|
+
documents = [Document(content="doc1"), Document(content="doc2"), Document(content="doc3")]
|
|
274
|
+
with pytest.raises(ValueError, match=r"top_k must be > 0, but got 0"):
|
|
275
|
+
ranker.run(query, documents, 0)
|
|
276
|
+
|
|
277
|
+
def test_run_zero_topk_does_not_fall_back_to_instance_topk(self, monkeypatch):
|
|
278
|
+
# a runtime top_k=0 must raise, not silently fall back to the instance top_k
|
|
276
279
|
monkeypatch.setenv("CO_API_KEY", "test-api-key")
|
|
277
|
-
ranker = CohereRanker(top_k=
|
|
280
|
+
ranker = CohereRanker(top_k=5)
|
|
278
281
|
query = "test"
|
|
279
282
|
documents = [Document(content="doc1"), Document(content="doc2"), Document(content="doc3")]
|
|
280
|
-
with pytest.raises(ValueError, match=r"top_k must be > 0, but got
|
|
283
|
+
with pytest.raises(ValueError, match=r"top_k must be > 0, but got 0"):
|
|
281
284
|
ranker.run(query, documents, 0)
|
|
282
285
|
|
|
283
286
|
def test_run_documents_provided(self, monkeypatch, mock_ranker_response): # noqa: ARG002
|
|
@@ -360,11 +363,21 @@ class TestCohereRanker:
|
|
|
360
363
|
@pytest.mark.asyncio
|
|
361
364
|
async def test_run_async_negative_topk(self, monkeypatch):
|
|
362
365
|
monkeypatch.setenv("CO_API_KEY", "test-api-key")
|
|
363
|
-
ranker = CohereRanker(
|
|
366
|
+
ranker = CohereRanker()
|
|
367
|
+
query = "test"
|
|
368
|
+
documents = [Document(content="doc1"), Document(content="doc2"), Document(content="doc3")]
|
|
369
|
+
with pytest.raises(ValueError, match=r"top_k must be > 0, but got -3"):
|
|
370
|
+
await ranker.run_async(query, documents, -3)
|
|
371
|
+
|
|
372
|
+
@pytest.mark.asyncio
|
|
373
|
+
async def test_run_async_zero_topk_does_not_fall_back_to_instance_topk(self, monkeypatch):
|
|
374
|
+
# a runtime top_k=0 must raise, not silently fall back to the instance top_k
|
|
375
|
+
monkeypatch.setenv("CO_API_KEY", "test-api-key")
|
|
376
|
+
ranker = CohereRanker(top_k=5)
|
|
364
377
|
query = "test"
|
|
365
378
|
documents = [Document(content="doc1"), Document(content="doc2"), Document(content="doc3")]
|
|
366
|
-
with pytest.raises(ValueError, match=r"top_k must be > 0, but got
|
|
367
|
-
await ranker.run_async(query, documents)
|
|
379
|
+
with pytest.raises(ValueError, match=r"top_k must be > 0, but got 0"):
|
|
380
|
+
await ranker.run_async(query, documents, 0)
|
|
368
381
|
|
|
369
382
|
@pytest.mark.skipif(
|
|
370
383
|
not os.environ.get("COHERE_API_KEY", None) and not os.environ.get("CO_API_KEY", None),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|