{"record":{"id":"d0cfd95f01a1388a","repo":"mem0ai/mem0","slug":"model-parameter-is-required","errorCode":null,"errorMessage":"`model` parameter is required","messagePattern":"`model` parameter is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/embeddings/langchain.py","lineNumber":17,"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\n        Args:\n            text (str): The text to embed.\n            memory_action (optional): The type of embedding to use. Must be one of \"add\", \"search\", or \"update\". Defaults to None.\n        Returns:\n            list: The embedding vector.\n        \"\"\"\n\n        return self.langchain_model.embed_query(text)","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/embeddings/langchain.py#L1-L35","documentation":"Raised by LangchainEmbedding.__init__ when the embedder config has no `model` value. Unlike other Mem0 embedding providers that default to a hosted model name, the Langchain integration has no default: the model IS a Langchain `Embeddings` object the user must supply. The constructor fails fast at instantiation time, before any network call.","triggerScenarios":"Calling LangchainEmbedding() or LangchainEmbedding(BaseEmbedderConfig()) with no `model` field, or building a config dict/YAML for Memory() that names the langchain provider but omits the model key.","commonSituations":"Copy-pasting a config template from another provider (e.g. openai) where model is a string default; migrating from an older mem0 version where the langchain embedder behaved differently; assuming `model` means a model name string.","solutions":["Pass a Langchain Embeddings instance as the model, e.g. LangchainEmbedding(BaseEmbedderConfig(model=OpenAIEmbeddings(openai_api_key=...)))","If configuring via dict/YAML, include the instantiated Embeddings object under the model key (object, not a string name)","If you meant to use a hosted provider instead, switch the embedding provider config to openai/ollama/etc. rather than langchain"],"exampleFix":"// before\nembedder = LangchainEmbedding(BaseEmbedderConfig())  # ValueError: `model` parameter is required\n\n# after\nfrom langchain_openai import OpenAIEmbeddings\nembedder = LangchainEmbedding(BaseEmbedderConfig(model=OpenAIEmbeddings(model=\"text-embedding-3-small\")))","handlingStrategy":"validation","validationCode":"from mem0.configs.embeddings.base import BaseEmbedderConfig\nfrom mem0.embeddings.langchain import LangchainEmbedding\n\ncfg = BaseEmbedderConfig()\nif getattr(cfg, \"model\", None) is None:\n    raise SystemExit(\"langchain embedder requires an Embeddings instance in config.model\")\nembedder = LangchainEmbedding(cfg)","typeGuard":"from langchain.embeddings.base import Embeddings\n\ndef has_langchain_model(cfg) -> bool:\n    return getattr(cfg, \"model\", None) is not None and isinstance(cfg.model, Embeddings)","tryCatchPattern":"try:\n    embedder = LangchainEmbedding(config)\nexcept ValueError as e:\n    # config construction error: report which parameter is wrong and stop\n    raise ConfigurationError(str(e)) from e","preventionTips":["Always construct the Embeddings object first and pass it as model","Treat langchain differently from hosted providers: model is an object, never a string","Add a config smoke test that instantiates every configured provider at startup"],"tags":["python","langchain","embeddings","config","mem0"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}