mem0ai/mem0 · error · ValueError

threshold must be a valid number

Error message

threshold must be a valid number

What it means

Error "threshold must be a valid number" thrown in mem0ai/mem0.

Source

Thrown at mem0/memory/main.py:225

            f"Invalid {name}: cannot contain whitespace. Provide a valid identifier without spaces."
        )
    return trimmed


def _validate_search_params(threshold: Optional[float] = None, top_k: Optional[int] = None) -> None:
    """
    Validates search parameters.

    Args:
        threshold: Similarity threshold (must be between 0 and 1)
        top_k: Number of results to return (must be non-negative integer)

    Raises:
        ValueError: If threshold or top_k are invalid
    """
    if threshold is not None:
        if not isinstance(threshold, (int, float)):
            raise ValueError("threshold must be a valid number")
        if threshold < 0 or threshold > 1:
            raise ValueError(
                f"Invalid threshold: {threshold}. Must be between 0 and 1 (inclusive)."
            )
    if top_k is not None:
        if not isinstance(top_k, int) or isinstance(top_k, bool):
            raise ValueError("top_k must be a valid integer")
        if top_k < 0:
            raise ValueError(
                f"Invalid top_k: {top_k}. Must be a non-negative integer."
            )


def _validate_and_trim_search_query(query: str) -> str:
    """
    Validates and normalizes a search query before embedding/vector search.

    Raises:

View on GitHub (pinned to 001c235229)

Solutions

  1. Pass threshold as a number (int or float), not a string or other type.

When it happens

Trigger: Thrown at mem0/memory/main.py:225 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/9b76fcfb75507afb. Report an issue: GitHub.