qdrant_client.local.distances module¶
- class ContextQuery(context_pairs: list[ContextPair])[source]¶
Bases:
object
- class DiscoveryQuery(target: list[float], context: list[ContextPair])[source]¶
Bases:
object
- class DistanceOrder(value)[source]¶
Bases:
str
,Enum
An enumeration.
- BIGGER_IS_BETTER = 'bigger_is_better'¶
- SMALLER_IS_BETTER = 'smaller_is_better'¶
- class RecoQuery(positive: Optional[list[list[float]]] = None, negative: Optional[list[list[float]]] = None)[source]¶
Bases:
object
- calculate_context_scores(query: ContextQuery, vectors: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], distance_type: Distance) ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]] [source]¶
- calculate_discovery_ranks(context: list[ContextPair], vectors: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], distance_type: Distance) ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]] [source]¶
- calculate_discovery_scores(query: DiscoveryQuery, vectors: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], distance_type: Distance) ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]] [source]¶
- calculate_distance(query: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], vectors: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], distance_type: Distance) ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]] [source]¶
- calculate_distance_core(query: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], vectors: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], distance_type: Distance) ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]] [source]¶
Calculate same internal distances as in core, rather than the final displayed distance
- calculate_recommend_best_scores(query: RecoQuery, vectors: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], distance_type: Distance) ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]] [source]¶
- cosine_similarity(query: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], vectors: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]]) ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]] [source]¶
Calculate cosine distance between query and vectors :param query: query vector :param vectors: vectors to calculate distance with
- Returns:
distances
- distance_to_order(distance: Distance) DistanceOrder [source]¶
Convert distance to order :param distance: distance to convert
- Returns:
order
- dot_product(query: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], vectors: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]]) ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]] [source]¶
Calculate dot product between query and vectors :param query: query vector. :param vectors: vectors to calculate distance with
- Returns:
distances
- euclidean_distance(query: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], vectors: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]]) ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]] [source]¶
Calculate euclidean distance between query and vectors :param query: query vector. :param vectors: vectors to calculate distance with
- Returns:
distances
- manhattan_distance(query: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]], vectors: ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]]) ndarray[tuple[int, ...], dtype[Union[bool, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, longdouble]]] [source]¶
Calculate manhattan distance between query and vectors :param query: query vector. :param vectors: vectors to calculate distance with
- Returns:
distances