mem0ai/mem0 · error · ValueError

Invalid config type for provider {provider}

Error message

Invalid config type for provider {provider}

What it means

ValueError from the same VectorStoreConfig validator when config is neither a dict nor an instance of the provider's pydantic config class (e.g. QdrantConfig). The validator accepts a plain dict (coerced into the config class) or an already-constructed config object of exactly the right type; anything else — including a config object built for a DIFFERENT provider — is rejected.

Source

Thrown at mem0/vector_stores/configs.py:60

    def validate_and_create_config(self) -> "VectorStoreConfig":
        provider = self.provider
        config = self.config

        if provider not in self._provider_configs:
            raise ValueError(f"Unsupported vector store provider: {provider}")

        module = __import__(
            f"mem0.configs.vector_stores.{provider}",
            fromlist=[self._provider_configs[provider]],
        )
        config_class = getattr(module, self._provider_configs[provider])

        if config is None:
            config = {}

        if not isinstance(config, dict):
            if not isinstance(config, config_class):
                raise ValueError(f"Invalid config type for provider {provider}")
            return self

        # also check if path in allowed kays for pydantic model, and whether config extra fields are allowed
        if "path" not in config and "path" in config_class.__annotations__:
            config["path"] = f"/tmp/{provider}"

        self.config = config_class(**config)
        return self

View on GitHub (pinned to 001c235229)

Solutions

  1. Pass config as a plain dict of the provider's fields: {'provider': 'qdrant', 'config': {'host': ..., 'collection_name': ...}}.
  2. Or pass an instance of the exact matching class, e.g. from mem0.configs.vector_stores.qdrant import QdrantConfig; QdrantConfig(...).
  3. Keep provider and config class in one place (single source of truth) so they cannot drift apart.

Example fix

# before
MemoryConfig(vector_store=VectorStoreConfig(provider="elasticsearch", config=ChromaConfig(...)))

# after
MemoryConfig(vector_store=VectorStoreConfig(provider="elasticsearch", config={"host": "localhost", "port": 9200}))
Defensive patterns

Strategy: type-guard

Validate before calling

def build_vector_store_config(provider: str, config):
    if isinstance(config, dict):
        return VectorStoreConfig(provider=provider, config=dict(config))
    from mem0.vector_stores.configs import VectorStoreConfig
    cls_name = VectorStoreConfig._provider_configs[provider]
    import importlib
    cls = getattr(importlib.import_module(f"mem0.configs.vector_stores.{provider}"), cls_name)
    if not isinstance(config, cls):
        raise TypeError(f"config for {provider} must be a dict or {cls.__name__}")
    return VectorStoreConfig(provider=provider, config=config)

Type guard

def is_valid_provider_config(provider: str, config) -> bool:
    import importlib
    from mem0.vector_stores.configs import VectorStoreConfig
    if isinstance(config, dict):
        return True
    try:
        cls = getattr(importlib.import_module(f"mem0.configs.vector_stores.{provider}"),
                      VectorStoreConfig._provider_configs[provider])
        return isinstance(config, cls)
    except (KeyError, ModuleNotFoundError):
        return False

Prevention

When it happens

Trigger: Passing vector_store={'provider': 'chroma', 'config': QdrantConfig(...)} (mismatched provider/config class), config='some string', config=[...], or a custom dataclass instead of the provider's config class or a dict.

Common situations: Switching the provider string in config but forgetting to change the config object; wrapping config in nested dicts of the wrong shape; passing an OSS MemoryConfig instance where a provider-specific config is expected.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/94823bd2ee5155b3. Report an issue: GitHub.