[docs]classKmknnParameters(Parameters):"""Parameters for the k-means k-nearest neighbors (KMKNN) algorithm."""
[docs]def__init__(self,distance:Literal["Euclidean","Manhattan","Cosine"]="Euclidean",):""" Args: distance: Distance metric for index construction and search. This should be one of ``Euclidean``, ``Manhattan`` or ``Cosine``. """self.distance=distance
@propertydefdistance(self)->str:"""Distance metric, see :meth:`~__init__()`."""returnself._distance@distance.setterdefdistance(self,distance:str):""" Args: distance: Distance metric, see :meth:`~__init__()`. """ifdistancenotin["Euclidean","Manhattan","Cosine"]:raiseValueError("unsupported 'distance'")self._distance=distance
[docs]classKmknnIndex(GenericIndex):"""A prebuilt index for the k-means k-nearest neighbors algorithm, created by :py:func:`~knncolle.define_builder.define_builder` with a :py:class:`~knncolle.kmknn.KmknnParameters` instance. """
[docs]def__init__(self,ptr):""" Args: ptr: Address of a ``knncolle_py::WrappedPrebuilt`` containing a KMKNN search index, allocated in C++. """super().__init__(ptr)