cohere-haystack 8.0.1__tar.gz → 9.0.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.
Files changed (37) hide show
  1. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/CHANGELOG.md +18 -0
  2. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/PKG-INFO +2 -1
  3. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/pyproject.toml +16 -3
  4. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/embedders/cohere/document_embedder.py +20 -12
  5. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/embedders/cohere/document_image_embedder.py +11 -1
  6. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/embedders/cohere/embedding_types.py +1 -1
  7. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/embedders/cohere/text_embedder.py +18 -11
  8. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/embedders/cohere/utils.py +4 -2
  9. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/generators/cohere/chat/chat_generator.py +20 -2
  10. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/generators/cohere/generator.py +23 -3
  11. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/rankers/cohere/ranker.py +2 -1
  12. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/test_chat_generator.py +7 -0
  13. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/test_document_embedder.py +13 -6
  14. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/test_document_image_embedder.py +7 -0
  15. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/test_generator.py +7 -0
  16. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/test_text_embedder.py +13 -6
  17. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/.gitignore +0 -0
  18. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/LICENSE.txt +0 -0
  19. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/README.md +0 -0
  20. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/examples/cohere_embedding.py +0 -0
  21. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/examples/cohere_generation.py +0 -0
  22. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/examples/cohere_ranker.py +0 -0
  23. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/pydoc/config_docusaurus.yml +0 -0
  24. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/embedders/cohere/__init__.py +0 -0
  25. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/embedders/py.typed +0 -0
  26. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/generators/cohere/__init__.py +0 -0
  27. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/generators/cohere/chat/__init__.py +0 -0
  28. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/generators/py.typed +0 -0
  29. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/rankers/cohere/__init__.py +0 -0
  30. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/src/haystack_integrations/components/rankers/py.typed +0 -0
  31. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/__init__.py +0 -0
  32. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/conftest.py +0 -0
  33. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/test_chat_generator_async.py +0 -0
  34. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/test_chat_generator_chunks.py +0 -0
  35. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/test_files/apple.jpg +0 -0
  36. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/test_files/sample_pdf_1.pdf +0 -0
  37. {cohere_haystack-8.0.1 → cohere_haystack-9.0.0}/tests/test_ranker.py +0 -0
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [integrations/cohere-v8.1.0] - 2026-03-19
4
+
5
+ ### 🚀 Features
6
+
7
+ - Add list of models supported by Cohere components (#2993)
8
+
9
+ ### 🧹 Chores
10
+
11
+ - Enable ANN ruff ruleset for cohere integration (#2983)
12
+
13
+
14
+ ## [integrations/cohere-v8.0.1] - 2026-03-17
15
+
16
+ ### 🐛 Bug Fixes
17
+
18
+ - Fix the conversion of cohere chunks to Haystack streaming chunks (#2968)
19
+
20
+
3
21
  ## [integrations/cohere-v8.0.0] - 2026-03-11
4
22
 
5
23
  ### 🚀 Features
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cohere-haystack
3
- Version: 8.0.1
3
+ Version: 9.0.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
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
17
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
18
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
19
20
  Requires-Python: >=3.10
@@ -19,6 +19,7 @@ classifiers = [
19
19
  "Programming Language :: Python :: 3.11",
20
20
  "Programming Language :: Python :: 3.12",
21
21
  "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
22
23
  "Programming Language :: Python :: Implementation :: CPython",
23
24
  "Programming Language :: Python :: Implementation :: PyPy",
24
25
  ]
@@ -66,7 +67,8 @@ dependencies = [
66
67
  unit = 'pytest -m "not integration" {args:tests}'
67
68
  integration = 'pytest -m "integration" {args:tests}'
68
69
  all = 'pytest {args:tests}'
69
- cov-retry = 'pytest --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x {args:tests}'
70
+ unit-cov-retry = 'pytest --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x -m "not integration" {args:tests}'
71
+ integration-cov-append-retry = 'pytest --cov=haystack_integrations --cov-append --reruns 3 --reruns-delay 30 -x -m "integration" {args:tests}'
70
72
 
71
73
  types = """mypy -p haystack_integrations.components.embedders.cohere \
72
74
  -p haystack_integrations.components.generators.cohere \
@@ -84,9 +86,17 @@ line-length = 120
84
86
  [tool.ruff.lint]
85
87
  select = [
86
88
  "A",
89
+ "ANN",
87
90
  "ARG",
88
91
  "B",
89
92
  "C",
93
+ "D102", # Missing docstring in public method
94
+ "D103", # Missing docstring in public function
95
+ "D205", # 1 blank line required between summary line and description
96
+ "D209", # Closing triple quotes go to new line
97
+ "D213", # summary lines must be positioned on the second physical line of the docstring
98
+ "D417", # Missing argument descriptions in the docstring
99
+ "D419", # Docstring is empty
90
100
  "DTZ",
91
101
  "E",
92
102
  "EM",
@@ -124,6 +134,8 @@ ignore = [
124
134
  # Misc
125
135
  "B008",
126
136
  "S101",
137
+ # Allow `Any` - used legitimately for dynamic types and SDK boundaries
138
+ "ANN401",
127
139
  ]
128
140
 
129
141
  [tool.ruff.lint.isort]
@@ -133,12 +145,13 @@ known-first-party = ["haystack_integrations"]
133
145
  ban-relative-imports = "parents"
134
146
 
135
147
  [tool.ruff.lint.per-file-ignores]
136
- # Tests can use magic values, assertions, and relative imports
137
- "tests/**/*" = ["PLR2004", "S101", "TID252"]
148
+ # Tests can use magic values, assertions, relative imports, and don't need type annotations
149
+ "tests/**/*" = ["PLR2004", "S101", "TID252", "D", "ANN"]
138
150
 
139
151
  [tool.coverage.run]
140
152
  source = ["haystack_integrations"]
141
153
  branch = true
154
+ relative_files = true
142
155
  parallel = false
143
156
 
144
157
 
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
  from dataclasses import replace
5
- from typing import Any
5
+ from typing import Any, ClassVar
6
6
 
7
7
  from haystack import Document, component, default_from_dict, default_to_dict
8
8
  from haystack.utils import Secret, deserialize_secrets_inplace
@@ -36,10 +36,20 @@ class CohereDocumentEmbedder:
36
36
  ```
37
37
  """
38
38
 
39
+ SUPPORTED_MODELS: ClassVar[list[str]] = [
40
+ "embed-v4.0",
41
+ "embed-english-v3.0",
42
+ "embed-english-light-v3.0",
43
+ "embed-multilingual-v3.0",
44
+ "embed-multilingual-light-v3.0",
45
+ ]
46
+ """A non-exhaustive list of embed models supported by this component.
47
+ See https://docs.cohere.com/docs/models#embed for the full list."""
48
+
39
49
  def __init__(
40
50
  self,
41
51
  api_key: Secret = Secret.from_env_var(["COHERE_API_KEY", "CO_API_KEY"]),
42
- model: str = "embed-english-v2.0",
52
+ model: str = "embed-v4.0",
43
53
  input_type: str = "search_document",
44
54
  api_base_url: str = "https://api.cohere.com",
45
55
  truncate: str = "END",
@@ -49,18 +59,15 @@ class CohereDocumentEmbedder:
49
59
  meta_fields_to_embed: list[str] | None = None,
50
60
  embedding_separator: str = "\n",
51
61
  embedding_type: EmbeddingTypes | None = None,
52
- ):
62
+ ) -> None:
53
63
  """
64
+ Initialize the CohereDocumentEmbedder.
65
+
54
66
  :param api_key: the Cohere API key.
55
- :param model: the name of the model to use. Supported Models are:
56
- `"embed-english-v3.0"`, `"embed-english-light-v3.0"`, `"embed-multilingual-v3.0"`,
57
- `"embed-multilingual-light-v3.0"`, `"embed-english-v2.0"`, `"embed-english-light-v2.0"`,
58
- `"embed-multilingual-v2.0"`. This list of all supported models can be found in the
59
- [model documentation](https://docs.cohere.com/docs/models#representation).
67
+ :param model: the name of the model to use.
68
+ Read [Cohere documentation](https://docs.cohere.com/docs/models#embed) for a list of all supported models.
60
69
  :param input_type: specifies the type of input you're giving to the model. Supported values are
61
- "search_document", "search_query", "classification" and "clustering". Not
62
- required for older versions of the embedding models (meaning anything lower than v3), but is required for
63
- more recent versions (meaning anything bigger than v2).
70
+ "search_document", "search_query", "classification" and "clustering".
64
71
  :param api_base_url: the Cohere API Base url.
65
72
  :param truncate: truncate embeddings that are too long from start or end, ("NONE"|"START"|"END").
66
73
  Passing "START" will discard the start of the input. "END" will discard the end of the input. In both
@@ -169,7 +176,8 @@ class CohereDocumentEmbedder:
169
176
 
170
177
  @component.output_types(documents=list[Document], meta=dict[str, Any])
171
178
  def run(self, documents: list[Document]) -> dict[str, list[Document] | dict[str, Any]]:
172
- """Embed a list of `Documents`.
179
+ """
180
+ Embed a list of `Documents`.
173
181
 
174
182
  :param documents: documents to embed.
175
183
  :returns: A dictionary with the following keys:
@@ -3,7 +3,7 @@
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
5
  from dataclasses import replace
6
- from typing import Any
6
+ from typing import Any, ClassVar
7
7
 
8
8
  from haystack import Document, component, default_from_dict, default_to_dict, logging
9
9
  from haystack.components.converters.image.image_utils import (
@@ -59,6 +59,16 @@ class CohereDocumentImageEmbedder:
59
59
  ```
60
60
  """
61
61
 
62
+ SUPPORTED_MODELS: ClassVar[list[str]] = [
63
+ "embed-v4.0",
64
+ "embed-english-v3.0",
65
+ "embed-english-light-v3.0",
66
+ "embed-multilingual-v3.0",
67
+ "embed-multilingual-light-v3.0",
68
+ ]
69
+ """A non-exhaustive list of embed models supported by this component.
70
+ See https://docs.cohere.com/docs/models#embed for the full list."""
71
+
62
72
  def __init__(
63
73
  self,
64
74
  *,
@@ -21,7 +21,7 @@ class EmbeddingTypes(Enum):
21
21
  BINARY = "binary"
22
22
  UBINARY = "ubinary"
23
23
 
24
- def __str__(self):
24
+ def __str__(self) -> str:
25
25
  return self.value
26
26
 
27
27
  @staticmethod
@@ -1,7 +1,7 @@
1
1
  # SPDX-FileCopyrightText: 2023-present deepset GmbH <info@deepset.ai>
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
- from typing import Any
4
+ from typing import Any, ClassVar
5
5
 
6
6
  from haystack import component, default_from_dict, default_to_dict
7
7
  from haystack.utils import Secret, deserialize_secrets_inplace
@@ -32,27 +32,34 @@ class CohereTextEmbedder:
32
32
  ```
33
33
  """
34
34
 
35
+ SUPPORTED_MODELS: ClassVar[list[str]] = [
36
+ "embed-v4.0",
37
+ "embed-english-v3.0",
38
+ "embed-english-light-v3.0",
39
+ "embed-multilingual-v3.0",
40
+ "embed-multilingual-light-v3.0",
41
+ ]
42
+ """A non-exhaustive list of embed models supported by this component.
43
+ See https://docs.cohere.com/docs/models#embed for the full list."""
44
+
35
45
  def __init__(
36
46
  self,
37
47
  api_key: Secret = Secret.from_env_var(["COHERE_API_KEY", "CO_API_KEY"]),
38
- model: str = "embed-english-v2.0",
48
+ model: str = "embed-v4.0",
39
49
  input_type: str = "search_query",
40
50
  api_base_url: str = "https://api.cohere.com",
41
51
  truncate: str = "END",
42
52
  timeout: float = 120.0,
43
53
  embedding_type: EmbeddingTypes | None = None,
44
- ):
54
+ ) -> None:
45
55
  """
56
+ Initialize the CohereTextEmbedder.
57
+
46
58
  :param api_key: the Cohere API key.
47
- :param model: the name of the model to use. Supported Models are:
48
- `"embed-english-v3.0"`, `"embed-english-light-v3.0"`, `"embed-multilingual-v3.0"`,
49
- `"embed-multilingual-light-v3.0"`, `"embed-english-v2.0"`, `"embed-english-light-v2.0"`,
50
- `"embed-multilingual-v2.0"`. This list of all supported models can be found in the
51
- [model documentation](https://docs.cohere.com/docs/models#representation).
59
+ :param model: the name of the model to use.
60
+ Read [Cohere documentation](https://docs.cohere.com/docs/models#embed) for a list of all supported models.
52
61
  :param input_type: specifies the type of input you're giving to the model. Supported values are
53
- "search_document", "search_query", "classification" and "clustering". Not
54
- required for older versions of the embedding models (meaning anything lower than v3), but is required for
55
- more recent versions (meaning anything bigger than v2).
62
+ "search_document", "search_query", "classification" and "clustering".
56
63
  :param api_base_url: the Cohere API Base url.
57
64
  :param truncate: truncate embeddings that are too long from start or end, ("NONE"|"START"|"END").
58
65
  Passing "START" will discard the start of the input. "END" will discard the end of the input. In both
@@ -18,7 +18,8 @@ async def get_async_response(
18
18
  truncate: str,
19
19
  embedding_type: EmbeddingTypes | None = None,
20
20
  ) -> tuple[list[list[float]], dict[str, Any]]:
21
- """Embeds a list of texts asynchronously using the Cohere API.
21
+ """
22
+ Embeds a list of texts asynchronously using the Cohere API.
22
23
 
23
24
  :param cohere_async_client: the Cohere `AsyncClient`
24
25
  :param texts: the texts to embed
@@ -66,7 +67,8 @@ def get_response(
66
67
  progress_bar: bool = False,
67
68
  embedding_type: EmbeddingTypes | None = None,
68
69
  ) -> tuple[list[list[float]], dict[str, Any]]:
69
- """Embeds a list of texts using the Cohere API.
70
+ """
71
+ Embeds a list of texts using the Cohere API.
70
72
 
71
73
  :param cohere_client: the Cohere `Client`
72
74
  :param texts: the texts to embed
@@ -1,6 +1,6 @@
1
1
  import json
2
2
  from collections.abc import AsyncIterator, Iterator
3
- from typing import Any, Literal, get_args
3
+ from typing import Any, ClassVar, Literal, get_args
4
4
 
5
5
  from haystack import component, default_from_dict, default_to_dict, logging
6
6
  from haystack.components.generators.utils import _convert_streaming_chunks_to_chat_message
@@ -480,6 +480,24 @@ class CohereChatGenerator:
480
480
  ```
481
481
  """
482
482
 
483
+ SUPPORTED_MODELS: ClassVar[list[str]] = [
484
+ "command-a-03-2025",
485
+ "command-r7b-12-2024",
486
+ "command-a-translate-08-2025",
487
+ "command-a-reasoning-08-2025",
488
+ "command-a-vision-07-2025",
489
+ "command-r-08-2024",
490
+ "command-r-plus-08-2024",
491
+ "command-r-03-2024",
492
+ "command-r-plus-04-2024",
493
+ "command-r-plus",
494
+ "command-r",
495
+ "command-light",
496
+ "command",
497
+ ]
498
+ """A non-exhaustive list of chat models supported by this component.
499
+ See https://docs.cohere.com/docs/models#command for the full list."""
500
+
483
501
  def __init__(
484
502
  self,
485
503
  api_key: Secret = Secret.from_env_var(["COHERE_API_KEY", "CO_API_KEY"]),
@@ -491,7 +509,7 @@ class CohereChatGenerator:
491
509
  *,
492
510
  timeout: float | None = None,
493
511
  max_retries: int | None = None,
494
- ):
512
+ ) -> None:
495
513
  """
496
514
  Initialize the CohereChatGenerator instance.
497
515
 
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
  from collections.abc import Callable
5
- from typing import Any
5
+ from typing import Any, ClassVar
6
6
 
7
7
  from haystack import component, logging
8
8
  from haystack.dataclasses import ChatMessage
@@ -15,7 +15,8 @@ logger = logging.getLogger(__name__)
15
15
 
16
16
  @component
17
17
  class CohereGenerator(CohereChatGenerator):
18
- """Generates text using Cohere's models through Cohere's `generate` endpoint.
18
+ """
19
+ Generates text using Cohere's models through Cohere's `generate` endpoint.
19
20
 
20
21
  NOTE: Cohere discontinued the `generate` API, so this generator is a mere wrapper
21
22
  around `CohereChatGenerator` provided for backward compatibility.
@@ -30,6 +31,24 @@ class CohereGenerator(CohereChatGenerator):
30
31
  ```
31
32
  """
32
33
 
34
+ SUPPORTED_MODELS: ClassVar[list[str]] = [
35
+ "command-a-03-2025",
36
+ "command-r7b-12-2024",
37
+ "command-a-translate-08-2025",
38
+ "command-a-reasoning-08-2025",
39
+ "command-a-vision-07-2025",
40
+ "command-r-08-2024",
41
+ "command-r-plus-08-2024",
42
+ "command-r-03-2024",
43
+ "command-r-plus-04-2024",
44
+ "command-r-plus",
45
+ "command-r",
46
+ "command-light",
47
+ "command",
48
+ ]
49
+ """A non-exhaustive list of chat models supported by this component.
50
+ See https://docs.cohere.com/docs/models#command for the full list."""
51
+
33
52
  def __init__(
34
53
  self,
35
54
  api_key: Secret = Secret.from_env_var(["COHERE_API_KEY", "CO_API_KEY"]),
@@ -37,7 +56,7 @@ class CohereGenerator(CohereChatGenerator):
37
56
  streaming_callback: Callable | None = None,
38
57
  api_base_url: str | None = None,
39
58
  **kwargs: Any,
40
- ):
59
+ ) -> None:
41
60
  """
42
61
  Instantiates a `CohereGenerator` component.
43
62
 
@@ -97,6 +116,7 @@ class CohereGenerator(CohereChatGenerator):
97
116
  ) -> dict[str, list[str] | list[dict[str, Any]]]:
98
117
  """
99
118
  Queries the LLM asynchronously with the prompts to produce replies.
119
+
100
120
  :param prompt: the prompt to be sent to the generative model.
101
121
  :returns: A dictionary with the following keys:
102
122
  - `replies`: A list of replies generated by the model.
@@ -41,7 +41,7 @@ class CohereRanker:
41
41
  meta_fields_to_embed: list[str] | None = None,
42
42
  meta_data_separator: str = "\n",
43
43
  max_tokens_per_doc: int = 4096,
44
- ):
44
+ ) -> None:
45
45
  """
46
46
  Creates an instance of the 'CohereRanker'.
47
47
 
@@ -106,6 +106,7 @@ class CohereRanker:
106
106
  def _prepare_cohere_input_docs(self, documents: list[Document]) -> list[str]:
107
107
  """
108
108
  Prepare the input by concatenating the document text with the metadata fields specified.
109
+
109
110
  :param documents: The list of Document objects.
110
111
 
111
112
  :return: A list of strings to be given as input to Cohere model.
@@ -148,6 +148,13 @@ class TestFormatMessage:
148
148
 
149
149
 
150
150
  class TestCohereChatGenerator:
151
+ def test_supported_models(self) -> None:
152
+ """SUPPORTED_MODELS is a non-empty list of strings."""
153
+ models = CohereChatGenerator.SUPPORTED_MODELS
154
+ assert isinstance(models, list)
155
+ assert len(models) > 0
156
+ assert all(isinstance(m, str) for m in models)
157
+
151
158
  def test_init_default(self, monkeypatch):
152
159
  monkeypatch.setenv("COHERE_API_KEY", "test-api-key")
153
160
 
@@ -15,11 +15,18 @@ COHERE_API_URL = "https://api.cohere.com"
15
15
 
16
16
 
17
17
  class TestCohereDocumentEmbedder:
18
+ def test_supported_models(self) -> None:
19
+ """SUPPORTED_MODELS is a non-empty list of strings."""
20
+ models = CohereDocumentEmbedder.SUPPORTED_MODELS
21
+ assert isinstance(models, list)
22
+ assert len(models) > 0
23
+ assert all(isinstance(m, str) for m in models)
24
+
18
25
  def test_init_default(self, monkeypatch):
19
26
  monkeypatch.setenv("COHERE_API_KEY", "test-api-key")
20
27
  embedder = CohereDocumentEmbedder()
21
28
  assert embedder.api_key == Secret.from_env_var(["COHERE_API_KEY", "CO_API_KEY"])
22
- assert embedder.model == "embed-english-v2.0"
29
+ assert embedder.model == "embed-v4.0"
23
30
  assert embedder.input_type == "search_document"
24
31
  assert embedder.api_base_url == COHERE_API_URL
25
32
  assert embedder.truncate == "END"
@@ -63,7 +70,7 @@ class TestCohereDocumentEmbedder:
63
70
  "type": "haystack_integrations.components.embedders.cohere.document_embedder.CohereDocumentEmbedder",
64
71
  "init_parameters": {
65
72
  "api_key": {"env_vars": ["COHERE_API_KEY", "CO_API_KEY"], "strict": True, "type": "env_var"},
66
- "model": "embed-english-v2.0",
73
+ "model": "embed-v4.0",
67
74
  "input_type": "search_document",
68
75
  "api_base_url": COHERE_API_URL,
69
76
  "truncate": "END",
@@ -115,7 +122,7 @@ class TestCohereDocumentEmbedder:
115
122
  "type": "haystack_integrations.components.embedders.cohere.document_embedder.CohereDocumentEmbedder",
116
123
  "init_parameters": {
117
124
  "api_key": {"env_vars": ["COHERE_API_KEY", "CO_API_KEY"], "strict": True, "type": "env_var"},
118
- "model": "embed-english-v2.0",
125
+ "model": "embed-v4.0",
119
126
  "input_type": "search_document",
120
127
  "api_base_url": COHERE_API_URL,
121
128
  "truncate": "END",
@@ -130,7 +137,7 @@ class TestCohereDocumentEmbedder:
130
137
  }
131
138
  embedder = CohereDocumentEmbedder.from_dict(component_dict)
132
139
  assert embedder.api_key == Secret.from_env_var(["COHERE_API_KEY", "CO_API_KEY"])
133
- assert embedder.model == "embed-english-v2.0"
140
+ assert embedder.model == "embed-v4.0"
134
141
  assert embedder.input_type == "search_document"
135
142
  assert embedder.api_base_url == COHERE_API_URL
136
143
  assert embedder.truncate == "END"
@@ -246,7 +253,7 @@ class TestCohereDocumentEmbedder:
246
253
  )
247
254
  @pytest.mark.integration
248
255
  def test_live_run(self):
249
- embedder = CohereDocumentEmbedder(model="embed-english-v2.0", embedding_type=EmbeddingTypes.FLOAT)
256
+ embedder = CohereDocumentEmbedder(model="embed-v4.0", embedding_type=EmbeddingTypes.FLOAT)
250
257
 
251
258
  docs = [
252
259
  Document(content="I love cheese", meta={"topic": "Cuisine"}),
@@ -269,7 +276,7 @@ class TestCohereDocumentEmbedder:
269
276
  )
270
277
  @pytest.mark.integration
271
278
  async def test_live_run_async(self):
272
- embedder = CohereDocumentEmbedder(model="embed-english-v2.0", embedding_type=EmbeddingTypes.FLOAT)
279
+ embedder = CohereDocumentEmbedder(model="embed-v4.0", embedding_type=EmbeddingTypes.FLOAT)
273
280
 
274
281
  docs = [
275
282
  Document(content="I love cheese", meta={"topic": "Cuisine"}),
@@ -20,6 +20,13 @@ IMPORT_PATH = "haystack_integrations.components.embedders.cohere.document_image_
20
20
 
21
21
 
22
22
  class TestCohereDocumentImageEmbedder:
23
+ def test_supported_models(self) -> None:
24
+ """SUPPORTED_MODELS is a non-empty list of strings."""
25
+ models = CohereDocumentImageEmbedder.SUPPORTED_MODELS
26
+ assert isinstance(models, list)
27
+ assert len(models) > 0
28
+ assert all(isinstance(m, str) for m in models)
29
+
23
30
  def test_init_default(self, monkeypatch):
24
31
  monkeypatch.setenv("COHERE_API_KEY", "test-api-key")
25
32
  embedder = CohereDocumentImageEmbedder()
@@ -15,6 +15,13 @@ COHERE_API_URL = "https://api.cohere.com"
15
15
 
16
16
 
17
17
  class TestCohereGenerator:
18
+ def test_supported_models(self) -> None:
19
+ """SUPPORTED_MODELS is a non-empty list of strings."""
20
+ models = CohereGenerator.SUPPORTED_MODELS
21
+ assert isinstance(models, list)
22
+ assert len(models) > 0
23
+ assert all(isinstance(m, str) for m in models)
24
+
18
25
  def test_init_default(self, monkeypatch):
19
26
  monkeypatch.setenv("COHERE_API_KEY", "foo")
20
27
  component = CohereGenerator()
@@ -13,6 +13,13 @@ COHERE_API_URL = "https://api.cohere.com"
13
13
 
14
14
 
15
15
  class TestCohereTextEmbedder:
16
+ def test_supported_models(self) -> None:
17
+ """SUPPORTED_MODELS is a non-empty list of strings."""
18
+ models = CohereTextEmbedder.SUPPORTED_MODELS
19
+ assert isinstance(models, list)
20
+ assert len(models) > 0
21
+ assert all(isinstance(m, str) for m in models)
22
+
16
23
  def test_init_default(self, monkeypatch):
17
24
  """
18
25
  Test default initialization parameters for CohereTextEmbedder.
@@ -21,7 +28,7 @@ class TestCohereTextEmbedder:
21
28
  embedder = CohereTextEmbedder()
22
29
 
23
30
  assert embedder.api_key == Secret.from_env_var(["COHERE_API_KEY", "CO_API_KEY"])
24
- assert embedder.model == "embed-english-v2.0"
31
+ assert embedder.model == "embed-v4.0"
25
32
  assert embedder.input_type == "search_query"
26
33
  assert embedder.api_base_url == COHERE_API_URL
27
34
  assert embedder.truncate == "END"
@@ -58,7 +65,7 @@ class TestCohereTextEmbedder:
58
65
  "type": "haystack_integrations.components.embedders.cohere.text_embedder.CohereTextEmbedder",
59
66
  "init_parameters": {
60
67
  "api_key": {"env_vars": ["COHERE_API_KEY", "CO_API_KEY"], "strict": True, "type": "env_var"},
61
- "model": "embed-english-v2.0",
68
+ "model": "embed-v4.0",
62
69
  "input_type": "search_query",
63
70
  "api_base_url": COHERE_API_URL,
64
71
  "truncate": "END",
@@ -101,7 +108,7 @@ class TestCohereTextEmbedder:
101
108
  "type": "haystack_integrations.components.embedders.cohere.text_embedder.CohereTextEmbedder",
102
109
  "init_parameters": {
103
110
  "api_key": {"env_vars": ["COHERE_API_KEY", "CO_API_KEY"], "strict": True, "type": "env_var"},
104
- "model": "embed-english-v2.0",
111
+ "model": "embed-v4.0",
105
112
  "input_type": "search_query",
106
113
  "api_base_url": COHERE_API_URL,
107
114
  "truncate": "END",
@@ -113,7 +120,7 @@ class TestCohereTextEmbedder:
113
120
 
114
121
  embedder = CohereTextEmbedder.from_dict(component_dict)
115
122
  assert embedder.api_key == Secret.from_env_var(["COHERE_API_KEY", "CO_API_KEY"])
116
- assert embedder.model == "embed-english-v2.0"
123
+ assert embedder.model == "embed-v4.0"
117
124
  assert embedder.input_type == "search_query"
118
125
  assert embedder.api_base_url == COHERE_API_URL
119
126
  assert embedder.truncate == "END"
@@ -141,7 +148,7 @@ class TestCohereTextEmbedder:
141
148
  text = "The food was delicious"
142
149
  result = embedder.run(text=text)
143
150
 
144
- assert len(result["embedding"]) == 4096
151
+ assert len(result["embedding"]) == 1536
145
152
  assert all(isinstance(x, float) for x in result["embedding"])
146
153
 
147
154
  @pytest.mark.asyncio
@@ -155,5 +162,5 @@ class TestCohereTextEmbedder:
155
162
  text = "The food was delicious"
156
163
  result = await embedder.run_async(text=text)
157
164
 
158
- assert len(result["embedding"]) == 4096
165
+ assert len(result["embedding"]) == 1536
159
166
  assert all(isinstance(x, float) for x in result["embedding"])