Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Evidentlyai Evidently Embeddings Drift Metric

From Leeroopedia
Knowledge Sources
Domains Metrics, Data Drift, Embeddings
Last Updated 2026-02-14 12:00 GMT

Overview

Implements the EmbeddingsDrift metric for detecting distribution drift in embedding columns using configurable drift detection methods.

Description

The Embeddings Drift Metric module provides a modern metric interface for detecting drift in embedding representations between current and reference datasets. It wraps the legacy EmbeddingsDriftMetric through the LegacyMetricCalculation bridge pattern.

Key classes:

  • EmbeddingsDrift -- A SingleValueMetric that specifies which embeddings to analyze (embeddings_name) and an optional drift_method for the detection algorithm. The drift score is returned as a single numeric value.
  • EmbeddingsDriftCalculation -- The calculation class that combines SingleValueCalculation and LegacyMetricCalculation. It overrides _gen_input_data to ensure embedding column definitions are properly propagated to the legacy input data. The legacy_metric method creates the corresponding EmbeddingsDriftMetric instance. The calculate_value method extracts the drift score from the legacy result and attaches the legacy rendering widgets.

The module re-exports the following drift method classes for convenience:

  • ModelDriftMethod -- Uses a trained classifier to detect drift
  • DistanceDriftMethod -- Uses distance metrics between distributions
  • RatioDriftMethod -- Uses share of drifted embedding components
  • MMDDriftMethod -- Uses Maximum Mean Discrepancy

Usage

Use EmbeddingsDrift in an Evidently report to detect whether the distribution of named embedding columns has shifted between reference and current datasets. Specify the embeddings_name that corresponds to an entry in the data definition's embeddings mapping. Optionally provide a drift_method to control the detection algorithm.

Code Reference

Source Location

Signature

class EmbeddingsDrift(SingleValueMetric):
    embeddings_name: str
    drift_method: Optional[DriftMethod] = None

class EmbeddingsDriftCalculation(
    SingleValueCalculation[EmbeddingsDrift],
    LegacyMetricCalculation[SingleValue, EmbeddingsDrift, EmbeddingsDriftMetricResults, EmbeddingsDriftMetric],
):
    def _gen_input_data(self, context: "Context", task_name: Optional[str]) -> InputData:
        ...
    def legacy_metric(self) -> EmbeddingsDriftMetric:
        ...
    def calculate_value(self, context, legacy_result, render) -> SingleValue:
        ...
    def display_name(self) -> str:
        ...

Import

from evidently.metrics.embeddings import (
    EmbeddingsDrift,
    EmbeddingsDriftCalculation,
    ModelDriftMethod,
    DistanceDriftMethod,
    RatioDriftMethod,
    MMDDriftMethod,
)

I/O Contract

Inputs

Name Type Required Description
embeddings_name str Yes Name of the embedding group as defined in the data definition's embeddings mapping
drift_method Optional[DriftMethod] No Drift detection method to use (ModelDriftMethod, DistanceDriftMethod, RatioDriftMethod, or MMDDriftMethod); defaults to None (auto-selected)

Outputs

Name Type Description
result SingleValue A single numeric drift score value with attached visualization widgets
display_name str Formatted as "Drift in embeddings: {embeddings_name}"

Usage Examples

from evidently.metrics.embeddings import EmbeddingsDrift, MMDDriftMethod
from evidently.core.report import Report

# Basic embeddings drift detection
report = Report(metrics=[
    EmbeddingsDrift(embeddings_name="text_embeddings"),
])

# With a specific drift method
report = Report(metrics=[
    EmbeddingsDrift(
        embeddings_name="image_embeddings",
        drift_method=MMDDriftMethod(),
    ),
])

report.run(reference_data=ref_df, current_data=curr_df)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment