Skip to content

AvgEmbeddingLatency metric

Bases: EmbeddingModelOperationalMetric

Average wall-clock latency in seconds per embedding call over this run.

Computed as elapsed_s / calls. Because elapsed_s accumulates each call's own duration, this reports the mean per-call latency regardless of concurrency -- unlike EmbeddingThroughput, which divides by the phase's wall-clock span. The two coincide (latency = 1 / throughput) only when calls run serially.

Example:

program.compile(
    metrics=[
        synalinks.metrics.AvgEmbeddingLatency(),
    ],
)
Source code in synalinks/src/metrics/em_metrics.py
@synalinks_export("synalinks.metrics.AvgEmbeddingLatency")
class AvgEmbeddingLatency(EmbeddingModelOperationalMetric):
    """Average wall-clock latency in seconds per embedding call over this run.

    Computed as ``elapsed_s / calls``. Because ``elapsed_s`` accumulates each
    call's own duration, this reports the mean per-call latency regardless of
    concurrency -- unlike `EmbeddingThroughput`, which divides by the phase's
    wall-clock span. The two coincide (latency = 1 / throughput) only when
    calls run serially.

    Example:

    ```python
    program.compile(
        metrics=[
            synalinks.metrics.AvgEmbeddingLatency(),
        ],
    )
    ```
    """

    def __init__(self, name="avg_embedding_latency"):
        super().__init__(name=name)

    def result(self):
        calls = self._delta("calls")
        if calls <= 0:
            return 0.0
        return self._delta("elapsed_s") / calls