Skip to content

Upload Layer

The upload layer persists an EvaluationOutput to a running MLflow server — runs table, metrics, assessments, and optionally the captured traces as a JSON artifact.

upload_to_mlflow

ragpill.upload.upload_to_mlflow

upload_to_mlflow(evaluation, mlflow_settings=None, model_params=None, upload_traces=False)

Persist an :class:EvaluationOutput to an MLflow server.

Parameters:

Name Type Description Default
evaluation EvaluationOutput

Output of :func:ragpill.evaluation.evaluate_results.

required
mlflow_settings MLFlowSettings | None

Server connection + experiment info. When omitted, a default :class:MLFlowSettings is loaded from environment vars.

None
model_params dict[str, str] | None

Optional model parameters to log for reproducibility.

None
upload_traces bool

When True, serialize evaluation.dataset_run.to_json() and upload it as an MLflow artifact. Use this for the "disconnected execution + upload later" workflow where traces were captured offline and are not yet on the server.

False
Example
run_output = await execute_dataset(testset, task=my_task)
eval_output = await evaluate_results(run_output, testset)
upload_to_mlflow(eval_output, settings, upload_traces=False)
See Also

execute_dataset: Phase 1. evaluate_results: Phase 2.

Source code in src/ragpill/upload.py
def upload_to_mlflow(
    evaluation: EvaluationOutput,
    mlflow_settings: MLFlowSettings | None = None,
    model_params: dict[str, str] | None = None,
    upload_traces: bool = False,
) -> None:
    """Persist an :class:`EvaluationOutput` to an MLflow server.

    Args:
        evaluation: Output of :func:`ragpill.evaluation.evaluate_results`.
        mlflow_settings: Server connection + experiment info. When omitted, a
            default :class:`MLFlowSettings` is loaded from environment vars.
        model_params: Optional model parameters to log for reproducibility.
        upload_traces: When ``True``, serialize
            ``evaluation.dataset_run.to_json()`` and upload it as an MLflow
            artifact. Use this for the "disconnected execution + upload later"
            workflow where traces were captured offline and are not yet on the
            server.

    Example:
        ```python
        run_output = await execute_dataset(testset, task=my_task)
        eval_output = await evaluate_results(run_output, testset)
        upload_to_mlflow(eval_output, settings, upload_traces=False)
        ```

    See Also:
        [`execute_dataset`][ragpill.execution.execute_dataset]: Phase 1.
        [`evaluate_results`][ragpill.evaluation.evaluate_results]: Phase 2.
    """
    settings = mlflow_settings or MLFlowSettings()  # pyright: ignore[reportCallIssue]
    dataset_run = evaluation.dataset_run
    run_id: str | None = dataset_run.mlflow_run_id if (dataset_run and dataset_run.mlflow_run_id) else None

    previous_uri = _reattach_run(settings, run_id)
    try:
        _log_table_and_metrics(evaluation, model_params)
        _log_assessments_and_tags(evaluation.case_results)
        if upload_traces:
            _log_traces_as_artifact(evaluation)

        # Strip LLM-judge traces created during evaluation (they only clutter the UI).
        experiment_id = _resolve_experiment_id(settings)
        active = mlflow.active_run()
        if active is not None:
            _delete_llm_judge_traces(settings, experiment_id, str(active.info.run_id))  # pyright: ignore[reportUnknownArgumentType]
    finally:
        if mlflow.active_run() is not None:
            mlflow.end_run()
        if previous_uri is not None:
            mlflow.set_tracking_uri(previous_uri)

See Also