{"record":{"id":"3f40786f6c543af2","repo":"mem0ai/mem0","slug":"langchain-is-not-installed-please-install-it-usin","errorCode":null,"errorMessage":"langchain is not installed. Please install it using `pip install langchain`","messagePattern":"langchain is not installed\\. Please install it using `pip install langchain`","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"mem0/embeddings/langchain.py","lineNumber":9,"sourceCode":"from typing import Literal, Optional\n\nfrom mem0.configs.embeddings.base import BaseEmbedderConfig\nfrom mem0.embeddings.base import EmbeddingBase\n\ntry:\n    from langchain.embeddings.base import Embeddings\nexcept ImportError:\n    raise ImportError(\"langchain is not installed. Please install it using `pip install langchain`\")\n\n\nclass LangchainEmbedding(EmbeddingBase):\n    def __init__(self, config: Optional[BaseEmbedderConfig] = None):\n        super().__init__(config)\n\n        if self.config.model is None:\n            raise ValueError(\"`model` parameter is required\")\n\n        if not isinstance(self.config.model, Embeddings):\n            raise ValueError(\"`model` must be an instance of Embeddings\")\n\n        self.langchain_model = self.config.model\n\n    def embed(self, text, memory_action: Optional[Literal[\"add\", \"search\", \"update\"]] = None):\n        \"\"\"\n        Get the embedding for the given text using Langchain.\n","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/embeddings/langchain.py#L1-L27","documentation":"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.","triggerScenarios":"embedder={'provider': 'langchain', 'config': {'model': SomeEmbeddings()}} without langchain installed; having only langchain-core or langchain-community installed; venv mismatch between install and run.","commonSituations":"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.","solutions":["pip install langchain","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","Verify in the runtime interpreter: <python> -c 'from langchain.embeddings.base import Embeddings'"],"exampleFix":"# before: ImportError at import time\n\n# after\n# shell:\npip install langchain","handlingStrategy":"validation","validationCode":"try:\n    from langchain.embeddings.base import Embeddings  # noqa: F401\nexcept ImportError:\n    raise RuntimeError(\"langchain embedder requires: pip install langchain\")","typeGuard":"def is_langchain_embeddings(obj: object) -> bool:\n    try:\n        from langchain.embeddings.base import Embeddings\n        return isinstance(obj, Embeddings)\n    except ImportError:\n        return False","tryCatchPattern":null,"preventionTips":["Install the langchain meta-package (not just langchain-core) when using this provider","Add an import smoke test for optional providers in CI"],"tags":["import-error","langchain","embeddings","dependencies","optional-dependency"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}