mem0ai/mem0 · error · ImportError

langchain is not installed. Please install it using `pip…

Error message

langchain is not installed. Please install it using `pip install langchain`

What it means

mem0/embeddings/langchain.py imports langchain.embeddings.base.Embeddings inside try/except ImportError and re-raises with a pip hint when LangChain is missing. langchain is an optional dependency; selecting embedder provider='langchain' (or merely importing this module via the registry) without it fails at import time. Note the import path is the legacy langchain package — langchain-core alone may not satisfy it depending on version.

Solutions

  1. pip install langchain
  2. If you deliberately use only split packages, install the meta-package anyway (it re-exports Embeddings) or upgrade mem0ai where the import path may target langchain_core.embeddings
  3. Verify in the runtime interpreter: <python> -c 'from langchain.embeddings.base import Embeddings'

Example fix

# before: ImportError at import time

# after
# shell:
pip install langchain
Defensive patterns

Strategy: validation

Validate before calling

try:
    from langchain.embeddings.base import Embeddings  # noqa: F401
except ImportError:
    raise RuntimeError("langchain embedder requires: pip install langchain")

Type guard

def is_langchain_embeddings(obj: object) -> bool:
    try:
        from langchain.embeddings.base import Embeddings
        return isinstance(obj, Embeddings)
    except ImportError:
        return False

Prevention

When it happens

Trigger: embedder={'provider': 'langchain', 'config': {'model': SomeEmbeddings()}} without langchain installed; having only langchain-core or langchain-community installed; venv mismatch between install and run.

Common situations: Projects that migrated to the split langchain packages (langchain-core/community/openai) and no longer depend on the meta-package; CI caching an old env; poetry group not exported to requirements.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/3f40786f6c543af2. Report an issue: GitHub.

Appendix: source

Thrown at mem0/embeddings/langchain.py:9

from typing import Literal, Optional

from mem0.configs.embeddings.base import BaseEmbedderConfig
from mem0.embeddings.base import EmbeddingBase

try:
    from langchain.embeddings.base import Embeddings
except ImportError:
    raise ImportError("langchain is not installed. Please install it using `pip install langchain`")


class LangchainEmbedding(EmbeddingBase):
    def __init__(self, config: Optional[BaseEmbedderConfig] = None):
        super().__init__(config)

        if self.config.model is None:
            raise ValueError("`model` parameter is required")

        if not isinstance(self.config.model, Embeddings):
            raise ValueError("`model` must be an instance of Embeddings")

        self.langchain_model = self.config.model

    def embed(self, text, memory_action: Optional[Literal["add", "search", "update"]] = None):
        """
        Get the embedding for the given text using Langchain.

View on GitHub (pinned to 001c235229)