mem0ai/mem0 · error · ValueError

Both 'user' and 'password' must be provided when not using c

Error message

Both 'user' and 'password' must be provided when not using connection_string.

What it means

Error "Both 'user' and 'password' must be provided when not using connection_string." thrown in mem0ai/mem0.

Source

Thrown at mem0/configs/vector_stores/pgvector.py:37

    sslmode: Optional[str] = Field(None, description="SSL mode for PostgreSQL connection (e.g., 'require', 'prefer', 'disable')")
    connection_string: Optional[str] = Field(None, description="PostgreSQL connection string (overrides individual connection parameters)")
    connection_pool: Optional[Any] = Field(None, description="psycopg connection pool object (overrides connection string and individual parameters)")

    @model_validator(mode="before")
    def check_auth_and_connection(cls, values):
        # If connection_pool is provided, skip validation of individual connection parameters
        if values.get("connection_pool") is not None:
            return values

        # If connection_string is provided, skip validation of individual connection parameters
        if values.get("connection_string") is not None:
            return values
        
        # Otherwise, validate individual connection parameters
        user, password = values.get("user"), values.get("password")
        host, port = values.get("host"), values.get("port")
        if not user and not password:
            raise ValueError("Both 'user' and 'password' must be provided when not using connection_string.")
        if not host and not port:
            raise ValueError("Both 'host' and 'port' must be provided when not using connection_string.")
        return values

    @model_validator(mode="before")
    @classmethod
    def validate_extra_fields(cls, values: Dict[str, Any]) -> Dict[str, Any]:
        allowed_fields = set(cls.model_fields.keys())
        input_fields = set(values.keys())
        extra_fields = input_fields - allowed_fields
        if extra_fields:
            raise ValueError(
                f"Extra fields not allowed: {', '.join(extra_fields)}. Please input only the following fields: {', '.join(allowed_fields)}"
            )
        return values

    model_config = ConfigDict(arbitrary_types_allowed=True)

View on GitHub (pinned to 001c235229)

Solutions

  1. Provide both user and password, or use a full connection_string instead.

When it happens

Trigger: Thrown at mem0/configs/vector_stores/pgvector.py:37 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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