{"record":{"id":"5e280630c0002205","repo":"chroma-core/chroma","slug":"the-model-name-cannot-be-changed-after-the-embeddi-5e2806","errorCode":null,"errorMessage":"The model name cannot be changed after the embedding function has been initialized.","messagePattern":"The model name cannot be changed after the embedding function has been initialized\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/ollama_embedding_function.py","lineNumber":102,"sourceCode":"    @staticmethod\n    def build_from_config(config: Dict[str, Any]) -> \"EmbeddingFunction[Documents]\":\n        url = config.get(\"url\")\n        model_name = config.get(\"model_name\")\n        timeout = config.get(\"timeout\")\n\n        if url is None or model_name is None or timeout is None:\n            assert False, \"This code should not be reached\"\n\n        return OllamaEmbeddingFunction(url=url, model_name=model_name, timeout=timeout)\n\n    def get_config(self) -> Dict[str, Any]:\n        return {\"url\": self.url, \"model_name\": self.model_name, \"timeout\": self.timeout}\n\n    def validate_config_update(\n        self, old_config: Dict[str, Any], new_config: Dict[str, Any]\n    ) -> None:\n        if \"model_name\" in new_config:\n            raise ValueError(\n                \"The model name cannot be changed after the embedding function has been initialized.\"\n            )\n\n    @staticmethod\n    def validate_config(config: Dict[str, Any]) -> None:\n        \"\"\"\n        Validate the configuration using the JSON schema.\n\n        Args:\n            config: Configuration to validate\n\n        Raises:\n            ValidationError: If the configuration does not match the schema\n        \"\"\"\n        validate_config_schema(config, \"ollama\")\n","sourceCodeStart":84,"sourceCodeEnd":118,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/ollama_embedding_function.py#L84-L118","documentation":"OllamaEmbeddingFunction.get_config() persists {url, model_name, timeout} and validate_config_update() rejects any update whose new_config contains the \"model_name\" key. Embedding models map text into a fixed vector space, so swapping the model after a collection has been embedded would make new vectors incomparable with stored ones; Chroma therefore makes model_name immutable while url/timeout remain updatable.","triggerScenarios":"Reconfiguring an existing collection's EF with {\"model_name\": \"llama2\"} via the config-update flow that calls validate_config_update(old, new); editing persisted EF config JSON and adding model_name; migrating from the default chroma/all-minilm-l6-v2-f32 to nomic-embed-text by update instead of rebuild.","commonSituations":"Trying out a new Ollama model (e.g. mxbai-embed-large) on an existing collection; config-management tooling that diffs get_config() output and pushes changed keys back; hand-edited config files in a GitOps pipeline.","solutions":["Create a new collection with the new model_name and re-ingest your documents (embeddings must be regenerated)","If you only need to repoint the server, update \"url\" or \"timeout\" instead — only \"model_name\" is rejected","Keep model choice out of mutable config; treat it as part of the collection's identity"],"exampleFix":"// before\nnew_cfg = fn.get_config(); new_cfg[\"model_name\"] = \"mxbai-embed-large\"\nfn.validate_config_update(fn.get_config(), new_cfg)  # ValueError\n\n// after\ncol_new = client.create_collection(\"docs_mxbai\", embedding_function=OllamaEmbeddingFunction(url=\"http://localhost:11434\", model_name=\"mxbai-embed-large\"))\n# copy documents from the old collection into col_new","handlingStrategy":"validation","validationCode":"def assert_ollama_update_allowed(new_config: dict) -> None:\n    if \"model_name\" in new_config:\n        raise ValueError(\"model_name is immutable; create a new collection to change models\")\nassert_ollama_update_allowed(my_new_config)","typeGuard":null,"tryCatchPattern":"try:\n    fn.validate_config_update(old_cfg, new_cfg)\nexcept ValueError as e:\n    if \"model name cannot be changed\" in str(e):\n        new_cfg.pop(\"model_name\", None)  # or start a migration\n    else:\n        raise","preventionTips":["Only send url/timeout in EF config updates for Ollama","Record model_name in collection metadata at creation for auditability","Automate model changes as re-ingestion pipelines"],"tags":["ollama","embedding-function","immutable-config","config-update","chroma"],"backgroundTag":"immutable-config-update","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}