DS DevShelfHub Projects · AI tools
Tutorials / LangChain / Reference / Classes / CohereEmbeddings
Embeddings langchain-cohere Beginner

CohereEmbeddings: Reference Guide

By DevShelfHub

Use Cohere's embedding models.

What is CohereEmbeddings?

CohereEmbeddings is the LangChain wrapper around Cohere's embedding API, exposed through the langchain-cohere package. It turns text into dense vectors for semantic search, classification, and clustering, and it is best known for strong multilingual quality — the embed-multilingual-v3.0 model covers 100+ languages in a shared vector space, so a query in one language can retrieve documents written in another.

A defining feature of Cohere v3 embeddings is the input_type parameter. You must tell the model whether a given text is a search_document (something you are indexing) or a search_query (something a user is asking), and Cohere optimizes the vector differently for each. The LangChain wrapper sets the right input_type automatically when you call embed_documents versus embed_query, which is exactly why you should use those two methods rather than embedding everything the same way. Other supported input types include classification and clustering for non-retrieval tasks.

Authentication uses the COHERE_API_KEY environment variable or an explicit cohere_api_key argument. embed_documents batches automatically and respects Cohere rate limits. Cohere also ships a separate rerank endpoint (CohereRerank in LangChain) that re-scores an initial vector-search shortlist for higher precision; embeddings and rerank are commonly paired in a two-stage retriever. Pin the model id in production so a default change on Cohere's side never silently alters your vectors.

When to Use

You want Cohere's semantic embeddings. Use for multilingual or semantic-focused projects.

Use Cases

  • Semantic search
  • Multilingual RAG
  • Classification
  • Clustering
  • Reranking
  • NLP tasks

Key Features

  • High-quality embeddings
  • Multilingual
  • Reranking available
  • Cost-effective
  • Fast
  • Good semantic

When NOT to Use

If you need vision embeddings.

Notes

input_type matters — use the right method

Cohere v3 embeddings are optimized per input_type. Call embed_documents for text you index and embed_query for user queries; the LangChain wrapper sets search_document versus search_query automatically. Embedding queries as documents (or vice versa) measurably degrades retrieval quality.

Multilingual model for cross-language search

embed-multilingual-v3.0 places 100+ languages in one shared space, so a query in English can match a document in French. Use it when your corpus or your users are not all in one language; stick with embed-english-v3.0 when everything is English for slightly better in-language quality.

Pair with CohereRerank for precision

Vector search gives recall; Cohere rerank gives precision. A common pattern is to retrieve k=20 with embeddings, then re-score down to top_n=4 with CohereRerank inside a ContextualCompressionRetriever. Rerank is a separate billed endpoint, so cap the shortlist size to control cost.

Pin the model and watch rate limits

Set the model id explicitly so a default change never silently alters your vectors, and re-index if you upgrade models. embed_documents batches automatically but trial keys have low rate limits; LangChain retries on 429, but production workloads need a paid key with adequate quota.

Import

python
from langchain_cohere import CohereEmbeddings

Configuration

Parameter Type Default Purpose
model str embed-english-v3.0 Cohere model ID

Usage Examples

Embed a single query

python
from langchain_cohere import CohereEmbeddings

embeddings = CohereEmbeddings(model='embed-english-v3.0')
vector = embeddings.embed_query('What is retrieval augmented generation?')
print(len(vector))

Multilingual RAG index

python
from langchain_cohere import CohereEmbeddings
from langchain_chroma import Chroma

embeddings = CohereEmbeddings(model='embed-multilingual-v3.0')
store = Chroma.from_documents(docs, embeddings)
hits = store.similarity_search('politique de remboursement', k=4)

Two-stage retrieve then rerank

python
from langchain_cohere import CohereEmbeddings, CohereRerank
from langchain.retrievers import ContextualCompressionRetriever

base = store.as_retriever(search_kwargs={"k": 20})
reranker = CohereRerank(model='rerank-english-v3.0', top_n=4)
retriever = ContextualCompressionRetriever(
    base_compressor=reranker, base_retriever=base,
)
results = retriever.invoke('how do I reset my password')

Common Pitfalls

❌ Forget to set COHERE_API_KEY

✅ export COHERE_API_KEY='...'

Alternative Embedding Models

Model When to Use
OpenAIEmbeddings For established quality benchmarks

Browse the full LangChain API reference index to explore more classes, methods, and decorators, or start with the LangChain introduction tutorial for end-to-end context on building with CohereEmbeddings and the wider framework.

CohereEmbeddings FAQ

What is CohereEmbeddings in LangChain?

Use Cohere's embedding models. CohereEmbeddings is the LangChain wrapper around Cohere's embedding API, exposed through the langchain-cohere package. It turns text into dense vectors for semantic search, classification, and clustering, and it is best known for strong multilingual quality — the embed-multilingual-v3.0 model covers 100+ languages in a shared vector space, so a query in one language can retrieve documents written in another. A defining feature of Cohere v3 embeddings is the input_type parame…

Which package provides CohereEmbeddings?

DevShelfHub documents CohereEmbeddings from the langchain-cohere package. Pin your installed LangChain version and match imports to the snippet on this page.

When should I use CohereEmbeddings?

You want Cohere's semantic embeddings. Use for multilingual or semantic-focused projects.

When should I avoid using CohereEmbeddings?

If you need vision embeddings.

How do I import CohereEmbeddings in Python?

from langchain_cohere import CohereEmbeddings

Where can I explore more LangChain API reference pages?

Open the LangChain API reference index on DevShelfHub to browse classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.