{"record":{"id":"c748921da3e82f1e","repo":"mem0ai/mem0","slug":"either-chromadb-cloud-configuration-api-key-tena","errorCode":null,"errorMessage":"Either ChromaDB Cloud configuration (api_key, tenant) or local configuration (path or host/port) must be provided.","messagePattern":"Either ChromaDB Cloud configuration \\(api_key, tenant\\) or local configuration \\(path or host/port\\) must be provided\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/configs/vector_stores/chroma.py","lineNumber":39,"sourceCode":"\n    @model_validator(mode=\"before\")\n    def check_connection_config(cls, values):\n        host, port, path = values.get(\"host\"), values.get(\"port\"), values.get(\"path\")\n        api_key, tenant = values.get(\"api_key\"), values.get(\"tenant\")\n        \n        # Check if cloud configuration is provided\n        cloud_config = bool(api_key and tenant)\n        \n        # If cloud configuration is provided, remove any default path that might have been added\n        if cloud_config and path == \"/tmp/chroma\":\n            values.pop(\"path\", None)\n            return values\n        \n        # Check if local/server configuration is provided\n        local_config = bool(path) or bool(host and port)\n        \n        if not cloud_config and not local_config:\n            raise ValueError(\"Either ChromaDB Cloud configuration (api_key, tenant) or local configuration (path or host/port) must be provided.\")\n        \n        if cloud_config and local_config:\n            raise ValueError(\"Cannot specify both cloud configuration and local configuration. Choose one.\")\n            \n        return values\n\n    @model_validator(mode=\"before\")\n    @classmethod\n    def validate_extra_fields(cls, values: Dict[str, Any]) -> Dict[str, Any]:\n        allowed_fields = set(cls.model_fields.keys())\n        input_fields = set(values.keys())\n        extra_fields = input_fields - allowed_fields\n        if extra_fields:\n            raise ValueError(\n                f\"Extra fields not allowed: {', '.join(extra_fields)}. Please input only the following fields: {', '.join(allowed_fields)}\"\n            )\n        return values\n","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/configs/vector_stores/chroma.py#L21-L57","documentation":"Raised by ChromaDbConfig's connection validator when the config describes neither a Chroma Cloud client nor a local/server client. Cloud mode needs both api_key and tenant; local mode needs path, or host together with port. A config with none of these (or host without port) has no way to reach any Chroma instance.","triggerScenarios":"Creating ChromaDbConfig with no path/host/port/api_key/tenant; passing only host without port; passing only api_key without tenant (so cloud_config is False) while no local config exists. Note the validator strips a default path of '/tmp/chroma' when cloud config is present.","commonSituations":"Expecting an env var like CHROMA_API_KEY to be picked up automatically (it is not); passing api_key but forgetting tenant for Chroma Cloud; a default path injected elsewhere being popped because cloud creds exist, leaving neither mode configured.","solutions":["For local embedding mode, set 'path' (e.g. './chroma_db')","For a Chroma server, set both 'host' and 'port'","For Chroma Cloud, set both 'api_key' and 'tenant'","If host is given, double-check port is also given — host alone does not count as local config"],"exampleFix":"# before\nChromaDbConfig(api_key=\"ck_...\")\n\n# after\nChromaDbConfig(api_key=\"ck_...\", tenant=\"my-tenant\")","handlingStrategy":"validation","validationCode":"def validate_chroma_connection(cfg: dict) -> None:\n    cloud = bool(cfg.get(\"api_key\") and cfg.get(\"tenant\"))\n    local = bool(cfg.get(\"path\")) or bool(cfg.get(\"host\") and cfg.get(\"port\"))\n    if not cloud and not local:\n        raise RuntimeError(\"Chroma config needs (api_key+tenant) or path or (host+port)\")","typeGuard":"def chroma_connection_ok(cfg: dict) -> bool:\n    cloud = bool(cfg.get(\"api_key\") and cfg.get(\"tenant\"))\n    local = bool(cfg.get(\"path\")) or bool(cfg.get(\"host\") and cfg.get(\"port\"))\n    return cloud or local","tryCatchPattern":"from pydantic import ValidationError\ntry:\n    ChromaDbConfig(**cfg)\nexcept ValidationError as e:\n    if \"must be provided\" in str(e):\n        # add path / host+port / api_key+tenant, then retry\n        ...","preventionTips":["Remember host requires port; path works alone","Cloud config requires both api_key and tenant — plan both in one commit","Set an explicit path for local dev so no implicit default is relied on"],"tags":["pydantic","configuration","vector-store","chroma","connection"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}