Reference

Evaluation and compilation

How it works

Declare the tunable parameters and hard constraints. Add metrics used for selection. The callback evaluates each distinct configuration once. Use the same frozen development cases for every callback invocation. Constraint failures remove a candidate from selection. Feasible candidates receive a weighted utility score. Run the selected candidate once on held-out cases. Compilation returns the winner and all candidate metrics. Held-out evaluation, caching, and deployment stay in application code.

Metric weights operate on raw values. Normalize scales or choose weights explicitly so latency units have the intended influence. Missing objective metrics, nonfinite values, and a search with zero feasible candidates raise ValueError. Preserve the active configuration when selection fails.

Research basisDSPy compiles parameterized LM pipelines against a declared metric. Mari generalizes the search space to retrieval, indexing, parsing, graph, consolidation, and packing configuration. Hard provenance, update-fidelity, and ACL constraints are Mari requirements and must be evaluated independently.

Grounded recallmaximize

Provenance accuracyrequire 1.0

Update fidelityrequire 1.0

ACL leakagerequire 0.0

Context tokensminimize

Latency p95minimize

Constraint-first configuration search
from mari_kit.platform import (
    MetricObjective,
    ObjectiveDirection,
    compile_configurations,
)

def evaluate(config):
    return benchmark(index=config["index"], k=config["k"])

compiled = compile_configurations(
    [
        {"index": "bm25", "k": 20},
        {"index": "hnsw", "k": 40},
    ],
    evaluate=evaluate,
    objectives=[
        MetricObjective(
            name="grounded_recall",
            direction=ObjectiveDirection.MAXIMIZE,
            minimum=0.85,
        ),
        MetricObjective(
            name="acl_leakage",
            direction=ObjectiveDirection.MINIMIZE,
            maximum=0.0,
        ),
        MetricObjective(
            name="latency_p95",
            direction=ObjectiveDirection.MINIMIZE,
            weight=0.01,
        ),
    ],
)
print(compiled.configuration, compiled.winner.metrics)