{"id":4601,"library":"langchain-cohere","title":"Cohere LangChain Integration","description":"langchain-cohere is an integration package that connects Cohere's powerful language AI models (Chat, Embeddings, Rerank) with the LangChain framework. It simplifies the process of building LLM-powered applications using Cohere's capabilities. The library is actively developed, with frequent releases often occurring on a weekly or bi-weekly cadence, and the current version is 0.5.0.","status":"active","version":"0.5.0","language":"en","source_language":"en","source_url":"https://github.com/langchain-ai/langchain-cohere","tags":["AI","LLM","Cohere","LangChain","Generative AI","NLP","RAG","Embeddings","Rerank"],"install":[{"cmd":"pip install langchain-cohere","lang":"bash","label":"Install package"}],"dependencies":[{"reason":"Provides core abstractions and interfaces for the LangChain ecosystem, enabling seamless integration with other LangChain components. Version 1.0 is supported since langchain-cohere v0.5.0.","package":"langchain-core","optional":false},{"reason":"The official Cohere Python SDK, which langchain-cohere uses to interact with Cohere's API. This package manages the Cohere SDK version, supporting v5+.","package":"cohere","optional":false}],"imports":[{"note":"Cohere chat model integrations were moved from `langchain_community` to `langchain_cohere`.","wrong":"from langchain_community.chat_models import ChatCohere","symbol":"ChatCohere","correct":"from langchain_cohere import ChatCohere"},{"note":"Embeddings integrations were moved from `langchain.embeddings` (and `langchain_community`) to `langchain_cohere`.","wrong":"from langchain.embeddings import CohereEmbeddings","symbol":"CohereEmbeddings","correct":"from langchain_cohere import CohereEmbeddings"},{"note":"Rerank integrations were moved from `langchain.retrievers.document_compressors` (and `langchain_community`) to `langchain_cohere`.","wrong":"from langchain.retrievers.document_compressors import CohereRerank","symbol":"CohereRerank","correct":"from langchain_cohere import CohereRerank"},{"note":"`create_cohere_tools_agent` was deprecated in v0.3.3 and has been replaced by `create_cohere_react_agent` with a different import path.","wrong":"from langchain_cohere import create_cohere_tools_agent","symbol":"create_cohere_react_agent","correct":"from langchain_cohere.react_multi_hop.agent import create_cohere_react_agent"}],"quickstart":{"code":"import os\nfrom langchain_cohere import ChatCohere\nfrom langchain_core.messages import HumanMessage\n\n# Ensure your COHERE_API_KEY is set as an environment variable\n# or pass it directly to the ChatCohere constructor.\n# For example: cohere_api_key=\"your_api_key\"\n\nllm = ChatCohere(\n    model=\"command-r-plus\", # or another supported Cohere chat model\n    temperature=0, \n    cohere_api_key=os.environ.get('COHERE_API_KEY', '')\n)\n\nmessages = [HumanMessage(content=\"What is the capital of Canada?\")]\n\ntry:\n    response = llm.invoke(messages)\n    print(response.content)\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n    print(\"Please ensure COHERE_API_KEY is set and the model name is correct.\")","lang":"python","description":"This quickstart demonstrates how to initialize the `ChatCohere` model and perform a simple chat completion. It uses the `COHERE_API_KEY` environment variable for authentication and `command-r-plus` as the model, which can be changed to other supported Cohere models."},"warnings":[{"fix":"Migrate to using `create_csv_agent` from `langchain_experimental.agents.agent_toolkits.csv.base` and manually construct the agent workflow.","message":"The `create_csv_agent` abstraction was deprecated in v0.3.5 and subsequently removed in v0.4.1. Users relying on this function will need to refactor their code.","severity":"breaking","affected_versions":">=0.3.5"},{"fix":"Update import statements to use `from langchain_cohere import ...` for all Cohere components. For example, `from langchain_community.chat_models import ChatCohere` should become `from langchain_cohere import ChatCohere`.","message":"Cohere integrations were moved from `langchain_community` (and other `langchain` paths) to the dedicated `langchain-cohere` package. Direct imports from `langchain_community.chat_models.ChatCohere`, `langchain.embeddings.CohereEmbeddings`, or `langchain.retrievers.document_compressors.CohereRerank` are deprecated and will break in newer `langchain` versions.","severity":"breaking","affected_versions":">=0.0.30 (for langchain-community deprecation)"},{"fix":"Review Cohere API v2 migration guides for `Chat` and `Rerank` to adapt request formats, message structures, and ensure the `model` parameter is always provided. `CohereRerank` now mandates the `model` parameter.","message":"The Cohere Chat and Rerank APIs migrated to v2 starting from v0.4.1. This introduced significant changes to message structure (using a single `messages` parameter with roles), chat history handling, tool definitions (JSON schema), and requires the `model` parameter to be explicitly specified for all calls.","severity":"breaking","affected_versions":">=0.4.1"},{"fix":"Migrate to `create_cohere_react_agent` found at `langchain_cohere.react_multi_hop.agent`. Re-evaluate usage of `connectors` as their functionality may have changed or been replaced by alternative methods within the Cohere API or LangChain.","message":"The `create_cohere_tools_agent` and general `connectors` functionality were deprecated in v0.3.3.","severity":"deprecated","affected_versions":">=0.3.3"},{"fix":"Ensure that your installed `cohere` package is version 5 or higher. `pip install --upgrade cohere` may be necessary. It's recommended to let `langchain-cohere` manage this dependency.","message":"The `langchain-cohere` package now manages the compatible `cohere` Python SDK version (v5+). Using an older or incompatible `cohere` SDK version installed separately may lead to unexpected behavior or errors.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}