Skip to content

Compare two document rankers

Which search algorithm puts the right help article first? In this tutorial you will run two Python ranking functions over the same six articles and five labeled questions, then use one question to explain the difference in their scores. Both functions run locally.

Run the bundled starter from the development checkout

After installing the checkout, run this command from its root:

uv run optpilot demo ./my-first-experiment

This creates a project, reviews its compare-rankers study and runs 10 trials. The summary should report succeeded, 10 completed trials, word count's mean reciprocal rank of 0.7667 and BM25's mean of 1.0000. No model API or container service is involved.

Use the experiment detail command printed at the end to inspect the complete retained result. Copy its run ID exactly and keep the --project path. The created directory contains the manifest, article data, two ranking programs and the grader. Edit a ranker and rerun demo on the same directory to record a new comparison without discarding earlier runs.

To create the project without executing it, use uv run optpilot init ./another-experiment with a new or empty directory.

Version note: init and demo are development features, not commands in the published Core 0.2.0 package. The manual workflow below shows the review and execution steps separately.

Manual review-and-run workflow

These commands are also available in published Core 0.2.0, but this guide shows them using the development checkout. uv run selects the checkout environment; it does not select a separately installed Core 0.2.0 environment or change that installation.

Review the comparison

Install Core from the checkout and start in its root directory. Change into the test fixture and validate its manifest.

cd tests/fixtures/catalog/document_search
uv run optpilot validate optpilot.experiment.yaml

You should see Valid experiment project. Open the manifest. The Suite help-questions lists the five cases. Each candidate receives the question and the articles. The grader keeps the expected article ID and records its position in the returned ranking. A first-place answer earns a reciprocal rank of 1, second place earns 1/2, and third place earns 1/3.

uv run optpilot experiment review --suite help-questions \
  --candidate word-count --candidate bm25 \
  --metric reciprocal_rank --direction maximize

Find plannedTrials in the JSON. The two candidates each run once on all five questions, giving 10 trials. The id beginning with study- identifies this review. It pins the selected versions, including the grader and its declared files. Later edits to the working project can be evaluated under a new review.

Run the reviewed versions

Replace REVIEW_ID with the full id from the review. Give this run a name so you can reopen it later.

uv run optpilot experiment run --review REVIEW_ID --run-id first-search

Look for "state": "succeeded" and "completedTrials": 10. You can reopen the record at any time from this project directory.

uv run optpilot experiment detail first-search

The aggregates entries summarize each candidate on this task. To identify an entry, take its candidateVersionId and run uv run optpilot experiment version CANDIDATE_VERSION_ID. Its version.name field names the ranking program that produced those scores.

Ranker Valid trials Expected article ranked first Mean reciprocal rank
Word count 5 / 5 3 / 5 0.767
BM25 5 / 5 5 / 5 1.000

Explain one of the scores

In trials, find the two records whose evidence.query is how can I change files without changing the original? Both name folder as the expected article.

  • Word count places skill and chat before folder. Its position is 3, reciprocal_rank is 1/3 and top_one is 0.
  • BM25 places folder first. Its position is 1 and both metrics are 1.

Both trials succeeded. The zero records a ranking that missed first place. When a worker fails, its attempt carries an error and its missing score contributes no measurement. Read validTrials alongside totalTrials when interpreting an average. These five labeled questions support a comparison on the bundled help articles. A claim about users' searches would need representative questions from that setting.

The project keeps this run under .optpilot/experiments. To keep a separate ledger, pass the same --store DIRECTORY on each review, run and detail command. An interrupted run can resume with its original review and run IDs. Run operations

To write a grader and compare parameter settings, build a factory staffing experiment. To run a comparison on a shared instrument, try display calibration.