{"record":{"id":"30cbfdf1eab743e1","repo":"chroma-core/chroma","slug":"an-embedding-function-already-exists-in-the-collec","errorCode":null,"errorMessage":"An embedding function already exists in the collection configuration, and a new one is provided. If this is intentional, please embed documents separately. Embedding function conflict: new: {embedding_function.name()} vs persisted: {persisted_ef_config.get('name')}","messagePattern":"An embedding function already exists in the collection configuration, and a new one is provided\\. If this is intentional, please embed documents separately\\. Embedding function conflict: new: (.+?) vs persisted: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/api/collection_configuration.py","lineNumber":806,"sourceCode":"\n# The reason to use the config on get, rather than build the ef is because\n# if there is an issue with deserializing the config, an error shouldn't be raised\n# at get time. CollectionCommon.py will raise an error at _embed time if there is an issue deserializing.\ndef validate_embedding_function_conflict_on_get(\n    embedding_function: Optional[EmbeddingFunction],  # type: ignore\n    persisted_ef_config: Optional[Dict[str, Any]],\n) -> None:\n    \"\"\"\n    Validates that there are no conflicting embedding functions between function parameter\n    and collection configuration.\n    \"\"\"\n    if persisted_ef_config is not None and embedding_function is not None:\n        if (\n            embedding_function.name() != \"default\"\n            and persisted_ef_config.get(\"name\") is not None\n            and persisted_ef_config.get(\"name\") != embedding_function.name()\n        ):\n            raise ValueError(\n                f\"An embedding function already exists in the collection configuration, and a new one is provided. If this is intentional, please embed documents separately. Embedding function conflict: new: {embedding_function.name()} vs persisted: {persisted_ef_config.get('name')}\"\n            )\n    return None\n\n\ndef update_schema_from_collection_configuration(\n    schema: \"Schema\", configuration: \"UpdateCollectionConfiguration\"\n) -> \"Schema\":\n    \"\"\"\n    Updates a schema with configuration changes.\n    Only updates fields that are present in the configuration update.\n\n    Args:\n        schema: The existing Schema object\n        configuration: The configuration updates to apply\n\n    Returns:\n        Updated Schema object","sourceCodeStart":788,"sourceCodeEnd":824,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/api/collection_configuration.py#L788-L824","documentation":"This ValueError from validate_embedding_function_conflict_on_get fires when you call get_collection (or list/restore paths that re-open collections) with an embedding_function whose name differs from the one persisted in the collection's configuration. Chroma protects against silently querying a collection with an incompatible embedding model, since vectors embedded differently would return garbage results.","triggerScenarios":"Creating a collection with EF A (e.g. OpenAIEmbeddingFunction) and later calling client.get_collection('name', embedding_function=EF_B) where EF_B.name() != 'default' and != persisted name. Common after swapping embedding providers in app config without recreating collections, or in tests that use a different EF than production code that created the data.","commonSituations":"Changing the embedding model in settings/environment between runs; multiple services sharing a persisted Chroma directory with different EFs configured; refactoring from the default EF to a custom one while reusing the same on-disk database; CI tests creating data with one EF and reading with another.","solutions":["Call get_collection with the SAME embedding function class that created the collection (same name()), or pass no embedding_function to use the persisted one","If you intentionally changed embedding models, create a new collection and re-embed the source documents; do not read old vectors with the new EF","If the persisted EF is what you want, rely on the stored configuration instead of passing embedding_function"],"exampleFix":"// before\n# collection was created with SentenceTransformerEmbeddingFunction\ncol = client.get_collection(\n    'docs', embedding_function=OpenAIEmbeddingFunction(api_key=KEY)\n)  # ValueError on get\n\n// after\ncol = client.get_collection('docs')  # uses persisted EF config\n# or explicitly the same function:\ncol = client.get_collection(\n    'docs', embedding_function=SentenceTransformerEmbeddingFunction()\n)","handlingStrategy":"validation","validationCode":"def ef_matches_persisted(persisted_cfg: dict | None, ef) -> bool:\n    if persisted_cfg is None or ef is None:\n        return True\n    name = persisted_cfg.get('name')\n    return name is None or ef.name() == 'default' or ef.name() == name\n\ncol_cfg = client.get_collection('docs').configuration  # or fetch metadata first\n# if ef_matches_persisted(col_cfg.get('embedding_function'), my_ef):\ncol = client.get_collection('docs', embedding_function=my_ef)","typeGuard":"def ef_matches_persisted(persisted_cfg, ef) -> bool:\n    if persisted_cfg is None or ef is None:\n        return True\n    name = persisted_cfg.get('name')\n    return name is None or ef.name() == 'default' or ef.name() == name","tryCatchPattern":"try:\n    col = client.get_collection('docs', embedding_function=my_ef)\nexcept ValueError as e:\n    if 'Embedding function conflict' in str(e):\n        col = client.get_collection('docs')  # rely on persisted EF config\n    else:\n        raise","preventionTips":["Prefer relying on the persisted embedding-function config at get time; pass nothing","Record which EF created each collection in your app's metadata store","When rotating embedding models, plan new collections plus re-embedding instead of reusing names"],"tags":["chroma","embedding-function","get-collection","conflict","configuration"],"backgroundTag":"embedding-function-mismatch","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}