Debug Fix easy · 3 min read

How to fix LangChain deprecated import langchain.embeddings

Quick answer
The import langchain.embeddings is deprecated. Replace it with from langchain_openai import OpenAIEmbeddings to import embeddings correctly. This aligns with LangChain v0.2+ SDK patterns and prevents import errors.
ERROR TYPE code_error
⚡ QUICK FIX
Replace from langchain.embeddings import ... with from langchain_openai import OpenAIEmbeddings in your code.

Why this happens

LangChain reorganized its package structure in v0.2+, deprecating the langchain.embeddings module. Attempting to import embeddings using from langchain.embeddings import OpenAIEmbeddings triggers an ImportError or a deprecation warning. This happens because embeddings were moved to a dedicated package langchain_openai to better modularize the SDK.

Example of broken code:

from langchain.embeddings import OpenAIEmbeddings

embeddings = OpenAIEmbeddings()

This import no longer works and will cause runtime errors.

python
from langchain.embeddings import OpenAIEmbeddings

embeddings = OpenAIEmbeddings()
output
ImportError: cannot import name 'OpenAIEmbeddings' from 'langchain.embeddings'

The fix

Update your imports to use the new modular packages. Replace from langchain.embeddings import OpenAIEmbeddings with from langchain_openai import OpenAIEmbeddings. This matches the current LangChain v0.2+ SDK pattern and ensures compatibility.

Example of fixed code:

python
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings()
print(type(embeddings))
output
<class 'langchain_openai.embeddings.OpenAIEmbeddings'>

Preventing it in production

To avoid similar import issues in production, always pin your LangChain version and review the official changelog for breaking changes. Use automated tests to catch import errors early. Consider adding retry or fallback logic if your app depends on dynamic imports or plugin loading.

Also, use the recommended import paths from the LangChain documentation and avoid deprecated modules.

Key Takeaways

  • Always use from langchain_openai import OpenAIEmbeddings instead of deprecated langchain.embeddings.
  • Pin LangChain versions and monitor changelogs to catch breaking changes early.
  • Use automated tests to detect import errors before deployment.
Verified 2026-04
Verify ↗