{"record":{"id":"5bcfd12c0a948f84","repo":"pathwaycom/pathway","slug":"not-supported-type-type-in-knn-lsh-classifier","errorCode":null,"errorMessage":"Not supported `type` {type} in knn_lsh_classifier_train. The allowed values are 'euclidean' and 'cosine'.","messagePattern":"Not supported `type` (.+?) in knn_lsh_classifier_train\\. The allowed values are 'euclidean' and 'cosine'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/stdlib/ml/classifiers/_knn_lsh.py","lineNumber":94,"sourceCode":"        lsh_projection = generate_euclidean_lsh_bucketer(\n            kwargs[\"d\"], kwargs[\"M\"], L, kwargs[\"A\"]\n        )\n        return knn_lsh_generic_classifier_train(\n            data,\n            lsh_projection,\n            _euclidean_distance,\n            L,\n        )\n    elif type == \"cosine\":\n        lsh_projection = generate_cosine_lsh_bucketer(kwargs[\"d\"], kwargs[\"M\"], L)\n        return knn_lsh_generic_classifier_train(\n            data,\n            lsh_projection,\n            compute_cosine_dist,\n            L,\n        )\n    else:\n        raise ValueError(\n            f\"Not supported `type` {type} in knn_lsh_classifier_train. \"\n            \"The allowed values are 'euclidean' and 'cosine'.\"\n        )\n\n\n# support for glob metadata search\ndef _globmatch_impl(pat_i, pat_n, pattern, p_i, p_n, path, memo):\n    \"\"\"Match pattern to path, recursively expanding **, using memoization.\"\"\"\n    state = (pat_i, p_i)\n    if state in memo:\n        return memo[state]\n\n    if pat_i == pat_n:\n        memo[state] = p_i == p_n\n        return memo[state]\n    if p_i == p_n:\n        memo[state] = False\n        return memo[state]","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/stdlib/ml/classifiers/_knn_lsh.py#L76-L112","documentation":"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.","triggerScenarios":"Calling knn_lsh_classifier_train(..., type=\"manhattan\"), type=\"cosine_sim\", or any string other than 'euclidean'/'cosine' (including typos and wrong case).","commonSituations":"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 '.","solutions":["Set type to one of 'euclidean' or 'cosine' exactly (lowercase).","Validate the value at config load time against {'euclidean', 'cosine'} and fail fast with a clear config error.","If you need another metric, implement a custom LSH classifier instead of relying on this helper."],"exampleFix":"# before\nmodel = knn_lsh_classifier_train(data, type=\"manhattan\")\n\n# after\nmodel = knn_lsh_classifier_train(data, type=\"euclidean\")","handlingStrategy":"validation","validationCode":"ALLOWED = {'euclidean', 'cosine'}\ndef validate_lsh_type(t: str) -> str:\n    if t not in ALLOWED:\n        raise ValueError(f\"type must be one of {sorted(ALLOWED)}, got {t!r}\")\n    return t","typeGuard":"def is_valid_lsh_type(t: str) -> bool:\n    return t in {'euclidean', 'cosine'}","tryCatchPattern":null,"preventionTips":["Use an Enum/Literal in config models (pydantic Literal['euclidean','cosine']) so invalid metrics are rejected at parse time.","Normalize metric strings to lowercase before use."],"tags":["pathway","ml","classifier","lsh","invalid-argument"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}