feat(score_traces): offline scoring of production traces with the Opik SDK - #61
Merged
Conversation
…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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A new opik-examples entry —
scripts/score_traces/— that scores existing productiontraces 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_traces→metric.score()→log_traces_feedback_scores(one batched write).model.py— judge-model / gateway wiring (LiteLLM; importable without a gateway)metrics.py— theEVALSlist:hallucination(preset),relevance(G-Eval),exact_match(customBaseMetric)paths.py— resolves a dottedvariablesmapping into each metric'sscore()kwargsscore_traces.py— the runner (windowed search → score → batched log); per-eval error isolation; DRY_RUN-safeutils/seed_traces.py— seeds ~10 hardcoded Q&A traces (no LLM) for an end-to-end demotests/test_score_traces.py— 18 unit tests (LLM mocked)Notes
uv run python score_traces.py/utils/seed_traces.py) — no wheel/entry-point packaging.OPIK_API_KEY/OPIK_WORKSPACE, both entry points exit 0 without touching the network (the CI contract).INPUT:/OUTPUT:payload sorelevanceis judged against the question (G-Eval'sscore()takes a single string).openai/route also needsOPENAI_API_KEY), never committingOPIK_API_KEY(prefer a service account), and pipeline/CI env config.Testing
uv run pytest→ 18 passed;uv run ruff check .clean; both entry points verified DRY_RUN-safe (exit 0, no network).🤖 Generated with Claude Code