{"record":{"id":"6103d6ffffbf2678","repo":"chroma-core/chroma","slug":"the-embedding-function-must-implement-the-embeddin","errorCode":null,"errorMessage":"The embedding_function must implement the Embeddings interface from langchain_core.","messagePattern":"The embedding_function must implement the Embeddings interface from langchain_core\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/chroma_langchain_embedding_function.py","lineNumber":51,"sourceCode":"\n    def __init__(self, embedding_function: Any) -> None:\n        \"\"\"\n        Initialize the ChromaLangchainEmbeddingFunction\n\n        Args:\n            embedding_function: The embedding function implementing Embeddings from langchain_core.\n        \"\"\"\n        try:\n            import langchain_core.embeddings\n\n            LangchainEmbeddings = langchain_core.embeddings.Embeddings\n        except ImportError:\n            raise ValueError(\n                \"The langchain_core python package is not installed. Please install it with `pip install langchain-core`\"\n            )\n\n        if not isinstance(embedding_function, LangchainEmbeddings):\n            raise ValueError(\n                \"The embedding_function must implement the Embeddings interface from langchain_core.\"\n            )\n\n        self.embedding_function = embedding_function\n\n        # Store the class name for serialization\n        self._embedding_function_class = embedding_function.__class__.__name__\n\n    def embed_documents(self, documents: Sequence[str]) -> List[List[float]]:\n        \"\"\"\n        Embed documents using the langchain embedding function.\n\n        Args:\n            documents: The documents to embed.\n\n        Returns:\n            The embeddings for the documents.\n        \"\"\"","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/chroma_langchain_embedding_function.py#L33-L69","documentation":"After importing langchain_core, the constructor asserts isinstance(embedding_function, langchain_core.embeddings.Embeddings) and raises ValueError otherwise. The adapter delegates to embed_documents/embed_query, so the wrapped object must be a real Embeddings instance — a bare callable or unrelated object will break every later call.","triggerScenarios":"Passing anything that is not a langchain_core Embeddings subclass: a plain function, an OpenAI/other SDK client object, a chromadb EmbeddingFunction, or a duck-typed object from an incompatible langchain-core version where the ABC identity differs.","commonSituations":"Wrapping the raw OpenAI Python client instead of langchain_openai.OpenAIEmbeddings; passing chromadb's own embedding functions into the langchain bridge; multiple langchain-core versions in one process (conda + pip mix) making isinstance fail despite matching shape.","solutions":["Wrap a genuine langchain embeddings class, e.g. from langchain_openai import OpenAIEmbeddings; create_langchain_embedding(OpenAIEmbeddings(...)).","If you have a custom function, expose it as a class subclassing langchain_core.embeddings.Embeddings implementing embed_documents and embed_query.","For chromadb-native functions, skip the bridge and pass them to the collection directly.","Unify on one langchain-core version to avoid ABC identity mismatches."],"exampleFix":"# before\nfrom openai import OpenAI\nclient = OpenAI()\nef = create_langchain_embedding(client.embeddings)  # ValueError: not an Embeddings instance\n\n# after\nfrom langchain_openai import OpenAIEmbeddings\nef = create_langchain_embedding(OpenAIEmbeddings(model=\"text-embedding-3-large\"))","handlingStrategy":"type-guard","validationCode":"from langchain_core.embeddings import Embeddings\n\nif not isinstance(my_embeddings, Embeddings):\n    raise TypeError(f\"Expected langchain_core Embeddings, got {type(my_embeddings).__name__}\")\nef = create_langchain_embedding(my_embeddings)","typeGuard":"from langchain_core.embeddings import Embeddings\n\ndef is_langchain_embeddings(obj: object) -> bool:\n    \"\"\"True when obj can be wrapped by ChromaLangchainEmbeddingFunction.\"\"\"\n    return isinstance(obj, Embeddings)","tryCatchPattern":"try:\n    ef = create_langchain_embedding(candidate)\nexcept ValueError as e:\n    if \"must implement the Embeddings interface\" in str(e):\n        raise TypeError(f\"Wrap a langchain Embeddings class, not {type(candidate)}\") from e\n    raise","preventionTips":["Always wrap classes from langchain provider packages (langchain_openai, langchain_huggingface), never raw SDK clients.","For custom logic, subclass langchain_core.embeddings.Embeddings with embed_documents and embed_query.","Guard construction sites with an isinstance check against langchain_core's Embeddings."],"tags":["langchain","type-check","embedding-function","isinstance"],"backgroundTag":"interface-not-implemented","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}