fix(python): support Cohere embed-v4.0 in CohereEmbeddingFunction (#4805)

`CohereEmbeddingFunction(name="embed-v4.0")` raised `ValueError: Model
embed-v4.0 not supported`.

**Cause.** `ndims()` uses a closed list of v2/v3 model names and raises
for everything else, so Cohere's current embedding model was rejected.

**Fix.** Add `embed-v4.0` to `ndims()`, returning its default output
dimension (1536).

**Test.** `test_cohere_embed_v4_is_supported` creates the function with
`name="embed-v4.0"` and checks `ndims() == 1536`. It fails before the
change with the `ValueError` and passes after; the existing Cohere
default-model test still passes.

This change was prepared with the help of an AI assistant (Claude Code),
and the author is responsible for the change.


---------
This commit is contained in:
Alex Castillo González
2026-11-30 19:06:26 +08:00
committed by GitHub
parent f1320b8ef9
commit 9564431b57
3 changed files with 12 additions and 1 deletions
+2 -1
View File
@@ -20,6 +20,7 @@ Supported models are:
- embed-multilingual-v3.0
- embed-english-light-v3.0
- embed-multilingual-light-v3.0
- embed-v4.0 (1536-dimensional by default)
The v2.0 models (`embed-english-v2.0`, `embed-english-light-v2.0` and `embed-multilingual-v2.0`) were retired by Cohere on April 4, 2026.
@@ -33,7 +34,7 @@ Supported parameters (to be passed in `create` method) are:
| Parameter | Type | Default Value | Description |
|---|---|--------|---------|
| `name` | `str` | `"embed-multilingual-v3.0"` | The model ID of the cohere model to use. Supported base models for Text Embeddings: embed-english-v3.0, embed-multilingual-v3.0, embed-english-light-v3.0, embed-multilingual-light-v3.0 |
| `name` | `str` | `"embed-multilingual-v3.0"` | The model ID of the cohere model to use. Supported base models for Text Embeddings: embed-english-v3.0, embed-multilingual-v3.0, embed-english-light-v3.0, embed-multilingual-light-v3.0, embed-v4.0 (1536-dimensional by default) |
| `source_input_type` | `str` | `"search_document"` | The type of input data to be used for the source column. |
| `query_input_type` | `str` | `"search_query"` | The type of input data to be used for the query. |
@@ -50,6 +50,7 @@ class CohereEmbeddingFunction(TextEmbeddingFunction):
* embed-multilingual-v3.0
* embed-english-light-v3.0
* embed-multilingual-light-v3.0
* embed-v4.0 (1536-dimensional by default)
The v2.0 models (embed-english-v2.0, embed-english-light-v2.0 and
embed-multilingual-v2.0) were retired by Cohere on April 4, 2026.
@@ -198,6 +199,9 @@ class CohereEmbeddingFunction(TextEmbeddingFunction):
return 1024
elif self.name in ["embed-english-light-v3.0", "embed-multilingual-light-v3.0"]:
return 384
elif self.name == "embed-v4.0":
# Default output dimension of embed-v4.0
return 1536
elif self.name == "embed-english-v2.0":
return 4096
elif self.name == "embed-multilingual-v2.0":
+6
View File
@@ -1283,3 +1283,9 @@ def test_cohere_default_model_is_not_a_retired_v2_model():
assert cohere.name == "embed-multilingual-v3.0"
assert "v2.0" not in cohere.name
assert cohere.ndims() == 1024
def test_cohere_embed_v4_is_supported():
cohere = get_registry().get("cohere").create(name="embed-v4.0")
assert cohere.ndims() == 1536