{"record":{"id":"cc16ac74490c77e1","repo":"chroma-core/chroma","slug":"building-a-chromalangchainembeddingfunction-from-c","errorCode":null,"errorMessage":"Building a ChromaLangchainEmbeddingFunction from config is not supported. Please recreate the langchain embedding function and pass it to create_langchain_embedding.","messagePattern":"Building a ChromaLangchainEmbeddingFunction from config is not supported\\. Please recreate the langchain embedding function and pass it to create_langchain_embedding\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/chroma_langchain_embedding_function.py","lineNumber":141,"sourceCode":"        else:\n            # Cast to Sequence[str] to satisfy the type checker\n            embeddings = self.embed_documents(cast(Sequence[str], input))\n\n        # Convert to numpy arrays\n        return [np.array(embedding, dtype=np.float32) for embedding in embeddings]\n\n    @staticmethod\n    def name() -> str:\n        return \"langchain\"\n\n    @staticmethod\n    def build_from_config(\n        config: Dict[str, Any]\n    ) -> \"EmbeddingFunction[Union[Documents, Images]]\":\n        # This is a placeholder implementation since we can't easily serialize and deserialize\n        # langchain embedding functions. Users will need to recreate the langchain embedding function\n        # and pass it to create_langchain_embedding.\n        raise NotImplementedError(\n            \"Building a ChromaLangchainEmbeddingFunction from config is not supported. \"\n            \"Please recreate the langchain embedding function and pass it to create_langchain_embedding.\"\n        )\n\n    def get_config(self) -> Dict[str, Any]:\n        return {\n            \"embedding_function_class\": self._embedding_function_class,\n            \"note\": \"This is a placeholder config. You will need to recreate the langchain embedding function.\",\n        }\n\n    def validate_config_update(\n        self, old_config: Dict[str, Any], new_config: Dict[str, Any]\n    ) -> None:\n        raise NotImplementedError(\n            \"Updating a ChromaLangchainEmbeddingFunction config is not supported. \"\n            \"Please recreate the langchain embedding function and pass it to create_langchain_embedding.\"\n        )\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/chroma_langchain_embedding_function.py#L123-L159","documentation":"build_from_config for the langchain bridge always raises NotImplementedError by design: arbitrary langchain embedding objects cannot be serialized (get_config only stores the class name and a placeholder note). When Chroma tries to rehydrate the EF from persisted config — typically when reopening a collection without supplying the function — this error tells you to reconstruct it manually.","triggerScenarios":"A collection was created with a ChromaLangchainEmbeddingFunction (its persisted name is 'langchain'); later, get_collection is called without embedding_function= (or the system calls build_from_config on the stored config), triggering the unconditional raise.","commonSituations":"Process restart: app creates collection in run 1, then re-opens it in run 2 without re-passing the EF; server-side rehydration of collections whose EF config name is 'langchain'; teammates assuming the wrapper round-trips like native chromadb functions.","solutions":["Recreate the langchain embedding at startup and pass it explicitly when reopening: get_collection(name, embedding_function=create_langchain_embedding(OpenAIEmbeddings(...))).","Cache/construct the wrapped langchain object once at boot and reuse it for every get_collection call.","If you need config-only persistence, switch to a native chromadb embedding function that supports build_from_config."],"exampleFix":"# before (second process run)\ncol = client.get_collection(\"docs\")  # tries build_from_config -> NotImplementedError\n\n# after (every run)\nfrom langchain_openai import OpenAIEmbeddings\nfrom chromadb.utils.embedding_functions import create_langchain_embedding\ncol = client.get_collection(\n    \"docs\",\n    embedding_function=create_langchain_embedding(OpenAIEmbeddings(model=\"text-embedding-3-large\")),\n)","handlingStrategy":"fallback","validationCode":"def get_collection_with_langchain_ef(client, name: str):\n    from langchain_openai import OpenAIEmbeddings\n    return client.get_collection(\n        name,\n        embedding_function=create_langchain_embedding(OpenAIEmbeddings(model=\"text-embedding-3-large\")),\n    )  # always supply the EF: langchain configs cannot be rebuilt","typeGuard":null,"tryCatchPattern":"try:\n    col = client.get_collection(\"docs\")  # no EF supplied\nexcept NotImplementedError as e:\n    if \"not supported\" in str(e):\n        col = client.get_collection(\n            \"docs\",\n            embedding_function=create_langchain_embedding(build_my_langchain_ef()),\n        )\n    else:\n        raise","preventionTips":["Construct the langchain embedding once per process and pass it on every get_collection call.","Never rely on persisted EF config for the langchain bridge — it stores only a class-name placeholder.","If you need fully serializable functions, prefer native chromadb embedding functions."],"tags":["langchain","not-implemented","serialization","embedding-function","deserialization"],"backgroundTag":"deserialization-unsupported","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}