Shortcuts module

class GroupMetric(distance_metric_name: Distance = Distance.COSINE)[source]

Bases: BaseMetric

Base class for group metrics


distance_metric_name – name of a distance metric to calculate distance or similarity matrices. Available names could be found in Distance.

Provides default implementations for distance and interaction matrices calculation. Accumulates embeddings and groups in an accumulator.

compute(embeddings: Tensor, groups: Tensor) Tensor[source]

Compute metric value

  • embeddings – embeddings to calculate metrics on

  • groups – groups to calculate labels


torch.Tensor - computed metric

evaluate() Tensor[source]

Perform metric computation with accumulated state

static prepare_labels(groups: Tensor)[source]

Compute metric labels based on samples groups


groups – groups to distinguish similar and dissimilar objects


target – torch.Tensor - labels to be used during metric computation

raw_compute(distance_matrix: Tensor, labels: Tensor) Tensor[source]

Perform metric computation on ready distance_matrix and labels

This method does not make any data and labels preparation. It is assumed that distance_matrix has already been calculated, required changes such masking distance from an element to itself have already been applied and corresponding labels have been prepared.

  • distance_matrix – distance matrix ready to metric computation

  • labels – labels ready to metric computation with the same shape as distance_matrix. Possible values are in {0, 1}.


torch.Tensor - calculated metric value


Reset accumulated embeddings, groups

update(embeddings: Tensor, groups: LongTensor, device=None) None[source]

Process and accumulate batch

  • embeddings – embeddings to accumulate

  • groups – groups to distinguish similar and dissimilar objects.

  • device – device to store calculated embeddings and groups on.


Learn more about Qdrant vector search project and ecosystem

Discover Qdrant

Similarity Learning

Explore practical problem solving with Similarity Learning

Learn Similarity Learning


Find people dealing with similar problems and get answers to your questions

Join Community