mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
`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. ---------
83 lines
3.8 KiB
Plaintext
83 lines
3.8 KiB
Plaintext
---
|
|
title: Cohere
|
|
sidebarTitle: Cohere
|
|
---
|
|
|
|
import { PyEmbeddingCohereFoundry, PyEmbeddingCohereUsage } from '/snippets/integrations.mdx';
|
|
|
|
Using cohere API requires cohere package, which can be installed using `pip install cohere`. Cohere embeddings are used to generate embeddings for text data. The embeddings can be used for various tasks like semantic search, clustering, and classification.
|
|
You also need to set the `COHERE_API_KEY` environment variable to use the Cohere API.
|
|
|
|
<CodeGroup>
|
|
```bash Bash icon="terminal"
|
|
export COHERE_API_KEY="your-api-key"
|
|
```
|
|
</CodeGroup>
|
|
|
|
Supported models are:
|
|
|
|
- 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)
|
|
|
|
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.
|
|
|
|
The previous default, `embed-multilingual-v2.0`, produced 768-dimensional vectors.
|
|
The new default, `embed-multilingual-v3.0`, produces 1024-dimensional vectors.
|
|
Existing tables containing vectors from a v2.0 model must be re-embedded with an
|
|
active model into a table whose vector column has the matching dimension.
|
|
|
|
|
|
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, 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. |
|
|
|
|
Cohere supports following input types:
|
|
|
|
| Input type | Description |
|
|
| --- | --- |
|
|
| `search_document` | Used for embeddings stored in a vector database for search use cases. |
|
|
| `search_query` | Used for embeddings of search queries run against a vector database. |
|
|
| `semantic_similarity` | Specifies that the text will be used for semantic textual similarity (STS). |
|
|
| `classification` | Used for embeddings passed through a text classifier. |
|
|
| `clustering` | Used for embeddings run through a clustering algorithm. |
|
|
|
|
Usage Example:
|
|
|
|
<CodeGroup>
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyEmbeddingCohereUsage}
|
|
</CodeBlock>
|
|
</CodeGroup>
|
|
|
|
## Cohere Embed on Azure AI Foundry {#cohere-embed-on-azure-ai-foundry}
|
|
|
|
For text retrieval with a Cohere Embed v4 deployment in Azure AI Foundry, install
|
|
`cohere>=5.15.0` and use the deployment's native Cohere endpoint and API key.
|
|
Set `base_url` to `https://<resource>.services.ai.azure.com/providers/cohere`.
|
|
The SDK appends `/v2/embed`. Set `name` to the model name configured for your
|
|
deployment, and set `output_dimension` to a dimension the model supports. LanceDB
|
|
uses that value for both the API request and the vector column.
|
|
|
|
<CodeGroup>
|
|
<CodeBlock filename="Python" language="Python" icon="python">
|
|
{PyEmbeddingCohereFoundry}
|
|
</CodeBlock>
|
|
</CodeGroup>
|
|
|
|
Create a table with `schema=Document` and add rows with a `text` field. LanceDB
|
|
embeds documents with `search_document` during `table.add()` and embeds the
|
|
query with `search_query` during `table.search("your question")`. Both requests
|
|
use float embeddings. Table metadata stores the key's `$var:` reference. In a new
|
|
process, call `registry.set_var` again and call `registry.allow_endpoint(endpoint)`
|
|
before reopening the table for embedding or text search.
|
|
|
|
See [Cohere's Foundry example](https://github.com/cohere-ai/cohere-azure-workshops/tree/ca1c4cb162e2/lab-1-embed)
|
|
and the [Cohere Embed v2 API reference](https://docs.cohere.com/v2/reference/embed).
|