Examples
Example: RAG and search pipeline
A retrieval-augmented answerer: chunk, embed, retrieve, rerank, generate. Step settings are tuned one at a time on frozen inputs, then checked end to end.
What it registers
| Kind | Name | What |
|---|---|---|
| action | retrieve | Vector search: query, k, filters. |
| action | rerank | Cross-encoder rerank of candidates: query, candidates, top_n. |
| scorer | answer_ok | 1 if the answer contains the gold fact (normalised match, judge fallback). |
| scorer | recall_at_k | Share of gold passages in the top k: used for the retrieval step alone. |
| dataset | qa-gold | 400 questions with gold answers and gold passage ids. |
| runner | runner | python rag_eval.py --variant {variant} --tier {tier} |
How it's scored
The harness metric is answer_ok (bar 0.80). The pipeline template's first tier runs only the changed step on frozen inputs: a retrieval change is scored by recall_at_k on cached queries, which is cheap enough to sweep. Survivors run end to end on the dev slice, then on the full test set.
The code
h = Harness.create("Docs answerer", metric="answer_ok", bar=0.80, template="pipeline",
url="https://synaptra.my", token=TOKEN)
@h.tool
def retrieve(query: str, k: int = 20, filters: dict | None = None) -> list:
"""Vector search over the docs index."""
@h.tool
def rerank(query: str, candidates: list, top_n: int = 5) -> list:
"""Cross-encoder rerank; returns the top_n candidates."""
h.register("recall_at_k", "scorer", "Gold passages in the top k (retrieval step alone)")
h.dataset("qa-gold", items=gold) # sends size + fingerprint, not the questions
h.runner("python rag_eval.py --variant {variant} --tier {tier}")
# Step-alone tier: sweep chunk size against cached queries, report recall
for chunk in (256, 384, 512, 768):
variant = f"chunk-{chunk}"
rows = [{"task": q.id, "variant": variant, "tier": "T0",
"metrics": {"recall_at_k": recall(retrieve_with(chunk, q), q.gold, k=10),
"answer_ok": 0.0}, "status": "provisional"}
for q in cached_queries]
h.report(rows, experiment_id=EXP)const h = await Harness.create({ name: "Docs answerer", metric: "answer_ok", bar: 0.8, template: "pipeline",
url: "https://synaptra.my", token: TOKEN });
await h.tool({ name: "retrieve", description: "Vector search over the docs index.",
schema: { type: "object", properties: { query: { type: "string" }, k: { type: "integer", default: 20 },
filters: { type: "object" } }, required: ["query"] } }, retrieve);
await h.tool({ name: "rerank", description: "Cross-encoder rerank; returns the top_n candidates.",
schema: { type: "object", properties: { query: { type: "string" }, candidates: { type: "array" },
top_n: { type: "integer", default: 5 } },
required: ["query", "candidates"] } }, rerank);
await h.register({ name: "recall_at_k", kind: "scorer", description: "Gold passages in the top k (retrieval step alone)" });
await h.dataset("qa-gold", { items: gold }); // sends size + fingerprint, not the questions
await h.runner("node rag_eval.js --variant {variant} --tier {tier}");
// Step-alone tier: sweep chunk size against cached queries, report recall
for (const chunk of [256, 384, 512, 768]) {
const variant = `chunk-${chunk}`;
const rows = cachedQueries.map((q) => ({
task: q.id, variant, tier: "T0", status: "provisional",
metrics: { recall_at_k: recall(retrieveWith(chunk, q), q.gold, 10), answer_ok: 0 },
}));
await h.report(rows, { experimentId: EXP });
}A first experiment
e = h.propose(
"Rerank top 20 down to 5", "rerank-20-5",
{"T0": {"mean_recall_at_k": 0.9}, "T1": {"mean_answer_ok": 0.83, "cost_usd": 0.8}},
hypothesis="The gold passage is retrieved but ranked 6th to 15th",
treatment_axes=["retrieval"],
)const e = await h.propose({
title: "Rerank top 20 down to 5",
variant: "rerank-20-5",
hypothesis: "The gold passage is retrieved but ranked 6th to 15th",
predictions: { T0: { mean_recall_at_k: 0.9 }, T1: { mean_answer_ok: 0.83, cost_usd: 0.8 } },
treatmentAxes: ["retrieval"],
});{"title": "Rerank top 20 down to 5", "variant": "rerank-20-5",
"hypothesis": "The gold passage is retrieved but ranked 6th to 15th",
"treatment_axes": ["retrieval"],
"predictions": {"T0": {"mean_recall_at_k": 0.9}, "T1": {"mean_answer_ok": 0.83, "cost_usd": 0.8}}}What this won't tell you
- Whether better recall becomes better answers: that's why the end-to-end tiers exist.
- Freshness: if the corpus changes, cached inputs go stale; re-freeze them and the dataset fingerprint changes.
Something unclear or missing? Email support@synaptra.my.