pathwaycom/pathway · error · ValueError

Not supported `type` {type} in knn_lsh_classifier_train. The

Error message

Not supported `type` {type} in knn_lsh_classifier_train. The allowed values are 'euclidean' and 'cosine'.

What it means

knn_lsh_classifier_train implements locality-sensitive-hashing KNN classification with two built-in distance regimes: 'euclidean' (random-projection LSH with Euclidean distance) and 'cosine' (cosine-oriented LSH buckets with cosine distance). Any other value of the `type` keyword reaches the else branch and raises this ValueError naming the offending value and the two allowed choices.

Source

Thrown at python/pathway/stdlib/ml/classifiers/_knn_lsh.py:94

        lsh_projection = generate_euclidean_lsh_bucketer(
            kwargs["d"], kwargs["M"], L, kwargs["A"]
        )
        return knn_lsh_generic_classifier_train(
            data,
            lsh_projection,
            _euclidean_distance,
            L,
        )
    elif type == "cosine":
        lsh_projection = generate_cosine_lsh_bucketer(kwargs["d"], kwargs["M"], L)
        return knn_lsh_generic_classifier_train(
            data,
            lsh_projection,
            compute_cosine_dist,
            L,
        )
    else:
        raise ValueError(
            f"Not supported `type` {type} in knn_lsh_classifier_train. "
            "The allowed values are 'euclidean' and 'cosine'."
        )


# support for glob metadata search
def _globmatch_impl(pat_i, pat_n, pattern, p_i, p_n, path, memo):
    """Match pattern to path, recursively expanding **, using memoization."""
    state = (pat_i, p_i)
    if state in memo:
        return memo[state]

    if pat_i == pat_n:
        memo[state] = p_i == p_n
        return memo[state]
    if p_i == p_n:
        memo[state] = False
        return memo[state]

View on GitHub (pinned to fa2f74a464)

Solutions

  1. Set type to one of 'euclidean' or 'cosine' exactly (lowercase).
  2. Validate the value at config load time against {'euclidean', 'cosine'} and fail fast with a clear config error.
  3. If you need another metric, implement a custom LSH classifier instead of relying on this helper.

Example fix

# before
model = knn_lsh_classifier_train(data, type="manhattan")

# after
model = knn_lsh_classifier_train(data, type="euclidean")
Defensive patterns

Strategy: validation

Validate before calling

ALLOWED = {'euclidean', 'cosine'}
def validate_lsh_type(t: str) -> str:
    if t not in ALLOWED:
        raise ValueError(f"type must be one of {sorted(ALLOWED)}, got {t!r}")
    return t

Type guard

def is_valid_lsh_type(t: str) -> bool:
    return t in {'euclidean', 'cosine'}

Prevention

When it happens

Trigger: Calling knn_lsh_classifier_train(..., type="manhattan"), type="cosine_sim", or any string other than 'euclidean'/'cosine' (including typos and wrong case).

Common situations: Config-driven model selection where the config permits free-form metric names; porting code from scikit-learn or another library whose metric vocabulary differs; typos such as 'Euclidean' or 'cosine '.

Related errors


AI-assisted analysis of pathwaycom/pathway@fa2f74a464 (2026-08-15). Data as JSON: /api/errors/5bcfd12c0a948f84. Report an issue: GitHub.