Skip to content

feat(score_traces): offline scoring of production traces with the Opik SDK - #61

Merged
LeoRoccoBreedt merged 3 commits into
mainfrom
LeoRoccoBreedt/score-traces
Jul 31, 2026
Merged

feat(score_traces): offline scoring of production traces with the Opik SDK#61
LeoRoccoBreedt merged 3 commits into
mainfrom
LeoRoccoBreedt/score-traces

Conversation

@LeoRoccoBreedt

Copy link
Copy Markdown
Collaborator

What

A new opik-examples entry — scripts/score_traces/ — that scores existing production
traces
in an Opik project offline and logs the feedback scores (with reasons) back onto
those traces, using the same judge/metric classes and variable mappings an online
evaluation rule would use. Designed so teams whose GenAI gateway isn't yet reachable from
the Opik platform can run evals on a cron now and migrate to online rules later with no
re-authoring
(same score names, same variable mapping).

How it works

Composes three public SDK primitives in a loop:
search_tracesmetric.score()log_traces_feedback_scores (one batched write).

  • model.py — judge-model / gateway wiring (LiteLLM; importable without a gateway)
  • metrics.py — the EVALS list: hallucination (preset), relevance (G-Eval), exact_match (custom BaseMetric)
  • paths.py — resolves a dotted variables mapping into each metric's score() kwargs
  • score_traces.py — the runner (windowed search → score → batched log); per-eval error isolation; DRY_RUN-safe
  • utils/seed_traces.py — seeds ~10 hardcoded Q&A traces (no LLM) for an end-to-end demo
  • tests/test_score_traces.py — 18 unit tests (LLM mocked)

Notes

  • Runs as plain scripts (uv run python score_traces.py / utils/seed_traces.py) — no wheel/entry-point packaging.
  • DRY_RUN-safe: with no OPIK_API_KEY/OPIK_WORKSPACE, both entry points exit 0 without touching the network (the CI contract).
  • G-Eval is fed a labeled INPUT:/OUTPUT: payload so relevance is judged against the question (G-Eval's score() takes a single string).
  • Docs cover judge auth (the LiteLLM openai/ route also needs OPENAI_API_KEY), never committing OPIK_API_KEY (prefer a service account), and pipeline/CI env config.

Testing

uv run pytest18 passed; uv run ruff check . clean; both entry points verified DRY_RUN-safe (exit 0, no network).

🤖 Generated with Claude Code

LeoRoccoBreedt and others added 2 commits July 31, 2026 14:11
…k SDK

Score existing production traces in an Opik project from your own pipeline using
stock SDK judges/metrics (Hallucination, G-Eval, a custom ExactMatch) routed through
a GenAI gateway, and log feedback (with reasons) back onto the traces under the same
names an online rule would use.

Composes three public SDK primitives — search_traces -> metric.score() ->
log_traces_feedback_scores — with per-eval error isolation, one batched write, and a
DRY_RUN-safe entry (exits 0 without credentials). G-Eval receives a labeled
INPUT/OUTPUT payload so relevance is judged against the question. Runs as plain
scripts (uv run python score_traces.py / utils/seed_traces.py); 18 unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…y ruff format

Compliance requires litellm examples to reference OPIK_EXAMPLES_MODEL so CI can route
judges to a cheap model; model.py now reads it (GATEWAY_MODEL stays the local override).
Also ran `ruff format` — the lint job checks `ruff format --check .`, not just `ruff check`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LeoRoccoBreedt
LeoRoccoBreedt marked this pull request as ready for review July 31, 2026 12:43
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@LeoRoccoBreedt
LeoRoccoBreedt merged commit bcb41f1 into main Jul 31, 2026
7 checks passed
@LeoRoccoBreedt
LeoRoccoBreedt deleted the LeoRoccoBreedt/score-traces branch July 31, 2026 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant