Skip to content

本页尚未翻译

本页内容仍为英文原文,源自官方文档 integrations/embedding/cohere。中文翻译正在分批进行中。

Cohere ​

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.

bash
export COHERE_API_KEY="your-api-key"

Supported models are:

  • embed-english-v3.0
  • embed-multilingual-v3.0
  • embed-english-light-v3.0
  • embed-multilingual-light-v3.0

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:

ParameterTypeDefault ValueDescription
namestr"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
source_input_typestr"search_document"The type of input data to be used for the source column.
query_input_typestr"search_query"The type of input data to be used for the query.

Cohere supports following input types:

Input typeDescription
search_documentUsed for embeddings stored in a vector database for search use cases.
search_queryUsed for embeddings of search queries run against a vector database.
semantic_similaritySpecifies that the text will be used for semantic textual similarity (STS).
classificationUsed for embeddings passed through a text classifier.
clusteringUsed for embeddings run through a clustering algorithm.

Usage Example:

python
import tempfile
from pathlib import Path

import lancedb
from lancedb.embeddings import EmbeddingFunctionRegistry
from lancedb.pydantic import LanceModel, Vector

cohere = (
    EmbeddingFunctionRegistry.get_instance()
    .get("cohere")
    .create(name="embed-multilingual-v3.0")
)

class TextModel(LanceModel):
    text: str = cohere.SourceField()
    vector: Vector(cohere.ndims()) = cohere.VectorField()

data = [{"text": "hello world"}, {"text": "goodbye world"}]

db = lancedb.connect(str(Path(tempfile.mkdtemp()) / "cohere-demo"))
tbl = db.create_table("test", schema=TextModel, mode="overwrite")
tbl.add(data)