*   [](/v0.2/)
*   Versions
*   v0.2

On this page

LangChain v0.2
==============

LangChain v0.2 was released in May 2024. This release includes a number of [breaking changes and deprecations](/v0.2/docs/versions/v0_2/deprecations/). This document contains a guide on upgrading to 0.2.x.

Reference

*   [Breaking Changes & Deprecations](/v0.2/docs/versions/v0_2/deprecations/)
*   [Migrating to Astream Events v2](/v0.2/docs/versions/v0_2/migrating_astream_events/)

Migration
=========

This documentation will help you upgrade your code to LangChain `0.2.x.`. To prepare for migration, we first recommend you take the following steps:

1.  Install the 0.2.x versions of langchain-core, langchain and upgrade to recent versions of other packages that you may be using. (e.g. langgraph, langchain-community, langchain-openai, etc.)
2.  Verify that your code runs properly with the new packages (e.g., unit tests pass).
3.  Install a recent version of `langchain-cli` , and use the tool to replace old imports used by your code with the new imports. (See instructions below.)
4.  Manually resolve any remaining deprecation warnings.
5.  Re-run unit tests.
6.  If you are using `astream_events`, please review how to [migrate to astream events v2](/v0.2/docs/versions/v0_2/migrating_astream_events/).

Upgrade to new imports[​](#upgrade-to-new-imports "Direct link to Upgrade to new imports")
------------------------------------------------------------------------------------------

We created a tool to help migrate your code. This tool is still in **beta** and may not cover all cases, but we hope that it will help you migrate your code more quickly.

The migration script has the following limitations:

1.  It’s limited to helping users move from old imports to new imports. It does not help address other deprecations.
2.  It can’t handle imports that involve `as` .
3.  New imports are always placed in global scope, even if the old import that was replaced was located inside some local scope (e..g, function body).
4.  It will likely miss some deprecated imports.

Here is an example of the import changes that the migration script can help apply automatically:

From Package

To Package

Deprecated Import

New Import

langchain

langchain-community

from langchain.vectorstores import InMemoryVectorStore

from langchain\_community.vectorstores import InMemoryVectorStore

langchain-community

langchain\_openai

from langchain\_community.chat\_models import ChatOpenAI

from langchain\_openai import ChatOpenAI

langchain-community

langchain-core

from langchain\_community.document\_loaders import Blob

from langchain\_core.document\_loaders import Blob

langchain

langchain-core

from langchain.schema.document import Document

from langchain\_core.documents import Document

langchain

langchain-text-splitters

from langchain.text\_splitter import RecursiveCharacterTextSplitter

from langchain\_text\_splitters import RecursiveCharacterTextSplitter

Installation[​](#installation "Direct link to Installation")
------------------------------------------------------------

    pip install langchain-clilangchain-cli --version # <-- Make sure the version is at least 0.0.22

Usage[​](#usage "Direct link to Usage")
---------------------------------------

Given that the migration script is not perfect, you should make sure you have a backup of your code first (e.g., using version control like `git`).

You will need to run the migration script **twice** as it only applies one import replacement per run.

For example, say your code still uses `from langchain.chat_models import ChatOpenAI`:

After the first run, you’ll get: `from langchain_community.chat_models import ChatOpenAI` After the second run, you’ll get: `from langchain_openai import ChatOpenAI`

    # Run a first time# Will replace from langchain.chat_models import ChatOpenAIlangchain-cli migrate --diff [path to code] # Previewlangchain-cli migrate [path to code] # Apply# Run a second time to apply more import replacementslangchain-cli migrate --diff [path to code] # Previewlangchain-cli migrate [path to code] # Apply

### Other options[​](#other-options "Direct link to Other options")

    # See help menulangchain-cli migrate --help# Preview Changes without applyinglangchain-cli migrate --diff [path to code]# Run on code including ipython notebooks# Apply all import updates except for updates from langchain to langchain-corelangchain-cli migrate --disable langchain_to_core --include-ipynb [path to code]

[Edit this page](https://github.com/langchain-ai/langchain/edit/master/docs/docs/versions/v0_2/index.mdx)

* * *

#### Was this page helpful?

  

#### You can also leave detailed feedback [on GitHub](https://github.com/langchain-ai/langchain/issues/new?assignees=&labels=03+-+Documentation&projects=&template=documentation.yml&title=DOC%3A+%3CPlease+write+a+comprehensive+title+after+the+%27DOC%3A+%27+prefix%3E).

[

Previous

Packages

](/v0.2/docs/versions/packages/)[

Next

LangChain v0.2

](/v0.2/docs/versions/v0_2/)

*   [Upgrade to new imports](#upgrade-to-new-imports)
*   [Installation](#installation)
*   [Usage](#usage)
    *   [Other options](#other-options)