langchain.embeddings.cohere.CohereEmbeddings

class langchain.embeddings.cohere.CohereEmbeddings(*, client: Any = None, async_client: Any = None, model: str = 'embed-english-v2.0', truncate: Optional[str] = None, cohere_api_key: Optional[str] = None)[source]

Bases: BaseModel, Embeddings

Cohere embedding models.

To use, you should have the cohere python package installed, and the environment variable COHERE_API_KEY set with your API key or pass it as a named parameter to the constructor.

Example

from langchain.embeddings import CohereEmbeddings
cohere = CohereEmbeddings(
    model="embed-english-light-v2.0", cohere_api_key="my-api-key"
)

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

param async_client: Any = None

Cohere async client.

param client: Any = None

Cohere client.

param cohere_api_key: Optional[str] = None
param model: str = 'embed-english-v2.0'

Model name to use.

param truncate: Optional[str] = None

Truncate embeddings that are too long from start or end (“NONE”|”START”|”END”)

async aembed_documents(texts: List[str]) List[List[float]][source]

Async call out to Cohere’s embedding endpoint.

Parameters

texts – The list of texts to embed.

Returns

List of embeddings, one for each text.

async aembed_query(text: str) List[float][source]

Async call out to Cohere’s embedding endpoint.

Parameters

text – The text to embed.

Returns

Embeddings for the text.

embed_documents(texts: List[str]) List[List[float]][source]

Call out to Cohere’s embedding endpoint.

Parameters

texts – The list of texts to embed.

Returns

List of embeddings, one for each text.

embed_query(text: str) List[float][source]

Call out to Cohere’s embedding endpoint.

Parameters

text – The text to embed.

Returns

Embeddings for the text.

validator validate_environment  »  all fields[source]

Validate that api key and python package exists in environment.

model Config[source]

Bases: object

Configuration for this pydantic object.

extra = 'forbid'

Examples using CohereEmbeddings