mem0ai/mem0 · error · ValueError

`model` must be an instance of Embeddings

Error message

`model` must be an instance of Embeddings

What it means

Raised by LangchainEmbedding.__init__ when config.model is set but is not an instance of Langchain's Embeddings base class. The Langchain provider does not call an API itself; it wraps an already-configured Langchain embeddings object, so a string like 'text-embedding-3-small' is rejected.

Source

Thrown at mem0/embeddings/langchain.py:20

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.

        Args:
            text (str): The text to embed.
            memory_action (optional): The type of embedding to use. Must be one of "add", "search", or "update". Defaults to None.
        Returns:
            list: The embedding vector.
        """

        return self.langchain_model.embed_query(text)

View on GitHub (pinned to 001c235229)

Solutions

  1. Pass an instance of a class deriving from langchain.embeddings.base.Embeddings (e.g. OpenAIEmbeddings(), HuggingFaceEmbeddings())
  2. If the isinstance check fails despite a real embeddings object, align langchain package versions so the Embeddings base class is the one mem0 imported (pip install -U langchain langchain-community)
  3. If you only have a model name, use the native provider (openai, huggingface, ollama) instead of langchain

Example fix

// before
embedder = LangchainEmbedding(BaseEmbedderConfig(model="nomic-embed-text"))  # ValueError

# after
from langchain_community.embeddings import OllamaEmbeddings
embedder = LangchainEmbedding(BaseEmbedderConfig(model=OllamaEmbeddings(model="nomic-embed-text")))
Defensive patterns

Strategy: type-guard

Validate before calling

from langchain.embeddings.base import Embeddings

model = config.get("model")
assert isinstance(model, Embeddings), (
    "langchain embedder model must be an Embeddings instance, "
    f"got {type(model).__name__}")

Type guard

from langchain.embeddings.base import Embeddings

def is_embeddings_instance(obj) -> bool:
    """True when obj can back LangchainEmbedding."""
    return isinstance(obj, Embeddings) and callable(getattr(obj, "embed_documents", None))

Try / catch

try:
    embedder = LangchainEmbedding(config)
except ValueError as e:
    if "must be an instance of Embeddings" in str(e):
        # user passed a string; convert intent into a real Embeddings object
        raise TypeError("Pass e.g. OpenAIEmbeddings(model=name), not the model name") from e
    raise

Prevention

When it happens

Trigger: Passing model="text-embedding-3-small" (a string) to BaseEmbedderConfig when provider is langchain; passing an LLM object or a LangChain vectorstore instead of an Embeddings implementation.

Common situations: Users porting an OpenAI embedder config verbatim to langchain; passing SentenceTransformerEmbeddings from an incompatible langchain major version whose base class moved (langchain vs langchain_core vs langchain_community split), making isinstance fail even for real embeddings classes.

Related errors


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