Cohere supports various integrations with LangChain, a large language model (LLM) framework which allows you to quickly create applications based on Cohere's models. This doc will guide you through how to leverage different Cohere embeddings with LangChain.

## Prerequisites

Running Cohere embeddings with LangChain doesn't require many prerequisites, consult the [top-level document](/guides/integrations-cohere-and-langchain) for more information.

## Cohere Embeddings with LangChain

To use [Cohere's Embeddings](/guides/embeddings-vectors-search-retrieval-v2-text-embeddings-embeddings) with LangChain, create a [CohereEmbedding](https://github.com/langchain-ai/langchain-community/blob/main/libs/community/langchain_community/embeddings/cohere.py) object as follows (the available cohere embedding models [are listed here](/api)):

```python PYTHON
from langchain_cohere import CohereEmbeddings

# Define the Cohere embedding model
embeddings = CohereEmbeddings(
    cohere_api_key="COHERE_API_KEY", model="embed-v4.0"
)

# Embed a document
text = "This is a test document."
query_result = embeddings.embed_query(text)
print(query_result[:5], "...")
doc_result = embeddings.embed_documents([text])
print(doc_result[0][:5], "...")
```

To use these embeddings with Cohere's RAG functionality, you will need to use one of the vector DBs [from this list](https://python.langchain.com/docs/integrations/vectorstores). In this example we use chroma, so in order to run it you will need to install chroma using `pip install chromadb`. We retrieve the most relevant chunks from the vector store and pass them to `ChatCohere` through its `documents` argument to get a grounded answer with citations.

```python PYTHON
from langchain_cohere import ChatCohere, CohereEmbeddings
from langchain_text_splitters import CharacterTextSplitter
from langchain_community.vectorstores import Chroma
from langchain_community.document_loaders import WebBaseLoader

user_query = "what is Cohere Toolkit?"

llm = ChatCohere(
    cohere_api_key="COHERE_API_KEY",
    model="command-a-03-2025",
    temperature=0,
)

embeddings = CohereEmbeddings(
    cohere_api_key="COHERE_API_KEY", model="embed-v4.0"
)

# Load text and split into chunks, you can also use data gathered elsewhere in your application
raw_documents = WebBaseLoader(
    "https://docs.cohere.com/docs/cohere-toolkit"
).load()

text_splitter = CharacterTextSplitter(chunk_size=500, chunk_overlap=0)
documents = text_splitter.split_documents(raw_documents)

# Create a vector store from the documents and retrieve the most relevant chunks
db = Chroma.from_documents(documents, embeddings)
input_docs = db.as_retriever().invoke(user_query)

# Ground the answer in the retrieved documents
response = llm.invoke(user_query, documents=input_docs)

# Print the answer
print("Answer:")
print(response.content)
# Print the citations that ground the answer in the documents
print("Citations:")
print(response.additional_kwargs.get("citations"))
```

## Cohere with LangChain and Bedrock

### Prerequisite

In addition to the prerequisites above, integrating Cohere with LangChain on Amazon Bedrock also requires:

- The LangChain AWS package. To install it, run `pip install langchain-aws`.
- AWS Python SDK. To install it, run `pip install boto3`. You can find [more details here](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#install-boto3).
- Configured authentication credentials for AWS. For more details, [see this document](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration).

### Cohere Embeddings with LangChain and Amazon Bedrock

In this example, we create embeddings for a query using Bedrock and LangChain:

```python PYTHON
from langchain_aws import BedrockEmbeddings

# Replace the profile name with the one created in the setup.
embeddings = BedrockEmbeddings(
    credentials_profile_name="{PROFILE-NAME}",
    region_name="us-east-1",
    model_id="cohere.embed-english-v3",
)

embeddings.embed_query("This is a content of the document")
```

## Using LangChain on Private Deployments

You can use LangChain with privately deployed Cohere models. To use it, specify your model deployment URL in the `base_url` parameter.

```python PYTHON
llm = CohereEmbeddings(
    base_url="<YOUR_DEPLOYMENT_URL>",
    cohere_api_key="COHERE_API_KEY",
    model="MODEL_NAME",
)
```

## Related pages

- [Cohere Chat on LangChain (Integration Guide)](./integrations-cohere-and-langchain-chat-on-langchain.md)
- [Cohere Rerank on LangChain (Integration Guide)](./integrations-cohere-and-langchain-rerank-on-langchain.md)
- [Cohere Tools on LangChain (Integration Guide)](./integrations-cohere-and-langchain-tools-on-langchain.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
