relevance-tester

An LLM-judged relevance test for search engines

Version 0.3.5 — November 2026

1Overview

relevance-tester measures how well a search engine ranks its results, on your own collection, without relevance judgments made in advance. An LLM writes test queries for documents of the collection and then judges the engine's top 10 results. The result is one number per engine setup, the average score: 1 is a perfect order, 10 the worst. The test is fully automated, so it can compare different search engines on the same collection, or each new build or setting of one engine with the previous one. The queries and the judgments are kept, so that builds and setups are compared on the same tests. It is open source (Apache License 2.0).

The words used here

CollectionThe set of documents your engine searches, one section of the config file
SetupOne way of searching a collection, such as an index version or a ranking option; setups of a collection are compared on the same queries
Base documentA document of the collection that test queries are written for; every other result is judged against it
TestOne base document with one query; by default each base document has 5 queries, so 5 tests
Version, labelThe version is your name for what you test, such as a build number; a label, <setup>-<version>, names one evaluated result
ScoreThe result of a test, from 1, the best, to 10, the worst; the average score is the result of a label

What you need

Contents

  1. Overview
  2. How the test works
  3. Quick start
  4. Installing from the zip file
  5. Connecting your search engine
  6. Configuration
  7. Running the commands
  8. Interpreting the results
  9. Troubleshooting
  10. Changes in 0.3.5
  11. License

2How the test works

relevance-tester automates and extends the base document method described in How to measure a relevance of the Enterprise Search Engine. In the original method, people wrote the queries and judged the results. Here an LLM does both.

A test is one base document and one query written so that this document is one of the best answers to it. The engine runs the query, and the LLM compares every other result of the top 10 with the base document: much more relevant, somewhat more relevant, the same, less relevant but still relevant, or not relevant. Documents found by the other queries of the same base document are judged too, so a good document the engine missed counts against it. From these judgments the program computes a graded nDCG@10, in which a mistake near the top costs more than one further down, and turns it into a score from 1, when no order of the judged documents could be better, to 10, when the top 10 holds nothing relevant. Lower is better.

How the method works, its formulas, worked examples, and its results on the BEIR collections TREC-COVID and NFCorpus are described in detail in Graded nDCG@10 from Pairwise Judgments against a Base Document.

The steps

Topics (single words)
→
Base documents from the engine
→
LLM writes queries
→
Engine runs the queries
→
LLM judges pairs
→
Report

An example: NFCorpus

A run on the BEIR collection NFCorpus (medical abstracts) with gpt-4o-mini used 10 topics: cholesterol, cancer, diabetes, vitamin, soy, coffee, obesity, inflammation, mercury and fiber. They gave 30 base documents and 150 queries. 17 queries were rejected and written again: 13 were mostly title words, 3 copied a phrase of the document and 1 repeated another query. One base document needed a second request, and none was skipped.

Choosing the base documents. The topic inflammation found 100 results. The LLM was shown 10 of them, at ranks 5, 15, …, 95, in a shuffled order, and chose 3:

ShownRankTitle
195Acne and risk of prostate cancer
215Consumption of Bing sweet cherries lowers circulating concentrations of inflammation markers in healthy men and womenchosen
345Dietary sources of inorganic microparticles and their intake in healthy subjects and patients with Crohn’s disease
475Animal protein intake and risk of inflammatory bowel disease: the E3N prospective studychosen
525Chocolate at heart: the anti-inflammatory impact of cocoa flavanols
635Whole-grain consumption is associated with a reduced risk of noncardiovascular, noncancer death attributed to inflammatory diseases …
755Communicating clinical research to reduce cancer risk through diet: walnuts as a case example
885Effect of a mediterranean-style diet on endothelial dysfunction and markers of vascular inflammation in the metabolic syndrome
965Diet and risk of inflammatory bowel disease
105Evolution of Inflammatory Diseaseschosen

Each choice comes with the LLM’s reason; for rank 5: “explores the evolutionary perspective of inflammation and its association with modern diseases”. The candidates are always in the middle of each tenth of the results: mercury found only 58, so its candidates were at ranks 3, 8, 14, …, 55.

Writing the queries. For its 3 base documents, the LLM wrote:

QueryKindScope
Consumption of Bing sweet cherries lowers circulating concentrations of inflammation markers in healthy men and women (rank 15)
cherry health benefitskeywordsprecise
What foods reduce inflammation?questionbroad
Natural ways to improve immune responsedescriptionbroad
C-reactive protein and fruitskeywordsprecise
Effects of cherries on blood markersquestionprecise
Animal protein intake and risk of inflammatory bowel disease: the E3N prospective study (rank 75)
diet and IBD riskkeywordsprecise
What foods increase the risk of bowel diseases?questionbroad
animal protein IBD associationkeywordsprecise
Impact of nutrition on gut healthdescriptionbroad
How does protein intake affect gut inflammation?questionprecise
Evolution of Inflammatory Diseases (rank 5)
evolutionary biology and diseaseskeywordsprecise
What role does inflammation play in modern health issues?questionbroad
chronic diseases and immune responsekeywordsprecise
How have human diseases evolved over time?questionbroad
adaptive responses to environmental changeskeywordsprecise

The queries of each document use different words and come at its subject from different sides; few of them use the topic word.

3Quick start

The way from the zip file to the first result, in six steps:

StepWhat you doSection
1. InstallDownload and unzip the file, then install the program4
2. ConnectWrite a connector for your engine and check it; with SANDI, skip this step5
3. ConfigureWrite relevance-tester.ini: the LLM, your engine, the topics and the setups to compare6
4. Generaterelevance-tester generate: the test queries, once7
5. Evaluaterelevance-tester evaluate --version 1.0: the score of each setup7
6. Read and compareOpen the report; after a change, evaluate again and compare8

4Installing from the zip file

Download relevance-tester-0.3.5.zip from https://www.softcorporation.com/products/relevance-tester/relevance-tester-0.3.5.zip and unzip it into a folder of your choice:

unzip relevance-tester-0.3.5.zip
cd relevance-tester-0.3.5

Without the unzip command, extract it with your file manager, or with python3 -m zipfile -e relevance-tester-0.3.5.zip .

Then choose one of three ways to run it.

A. With pipx (recommended)

pipx installs the relevance-tester command in its own environment:

pipx install .
relevance-tester --help

With pipx install -e . instead, the command runs the code in this folder, so an updated copy of the files needs no new install.

B. With pip in a virtual environment

python3 -m venv .venv
. .venv/bin/activate              # Windows: .venv\Scripts\activate
pip install .
relevance-tester --help

C. Without installing

Install the only dependency, requests, and run the package from the unzipped folder:

pip install requests
python3 -m relevance_tester --help

In this case write python3 -m relevance_tester wherever this page writes relevance-tester; it runs the same program with the same options. On Windows the interpreter may be called python or py.

Checking the installation

The program's own tests need no search engine and no LLM, only requests in the Python that runs them:

python3 -m unittest discover -s tests

5Connecting your search engine

relevance-tester talks to a search engine through a connector: one Python class with three methods and an optional fourth. The program never knows which engine it talks to. SANDI search has a built-in connector (Section 5.4); for any other engine, write one as shown here.

MethodReturns
from_config(section)The connector, set up from its section of the config file (key → text)
search(query, n)The top n results in the engine's order, as Result(rank, id, title, url)
get_document(doc_id)The whole document for the LLM to read, as Document(id, title, text, url), or None
describe()Optional: the settings saved with every run, to tell setups apart

5.1 How the program uses a connector

CallWhenWhat it means for the connector
search(topic, 100)generate: once per topicIt returns up to max_rank results (100), not only 10
get_document(id)generate: each base document candidateThe LLM writes the queries from the title and the first 10,000 characters of the text (text_chars in [generate])
search(query, 10)evaluate: every query, 4 at a timeIt is called from several threads at once and must be safe to
get_document(id)evaluate: the base document and each of the top 10, once per document per run, 4 at a timeThe LLM judges from the title and the first 10,000 characters of the text (text_chars in [judge]): put the important text first
describe()Saved with every run--resume warns when the settings of the saved run differ from the config

5.2 Writing a connector, step by step

  1. Choose the config keys: how to reach the engine (URL, index, token) and the settings a setup should be able to change.
  2. search: the results in the engine's own order, ranks from 1, ids as strings.
  3. get_document: the same ids as search, the title on its own, and as text everything a user would read to decide whether the document answers the query.
  4. describe: the settings that make two setups different, so that every run records what it measured.
  5. Errors: one requests.Session, a timeout on every request and a short retry loop.
  6. Authentication: a token as a key of the section, read in from_config. The config file is then as private as the API key.
  7. Check it before any LLM call (Section 5.3).

This connector expects GET /<index>/search?q=...&size=n to return {"hits": [{"id": ..., "title": ..., "url": ...}]} and GET /<index>/documents/<id> to return {"id": ..., "title": ..., "body": ...}. Adapt the requests and the field names to your API. Save it as myengine.py in the folder you will run from:

import time

import requests

from relevance_tester.engine import Document, Engine, Result, option, required


class MyEngine(Engine):
    name = "myengine"

    @classmethod
    def from_config(cls, section):
        return cls(url=required(section, "url"),
                   index=option(section, "index", "documents"),
                   token=option(section, "token", ""),
                   timeout=float(option(section, "timeout", "60")))

    def __init__(self, url, index, token, timeout):
        self.url, self.index, self.timeout = url.rstrip("/"), index, timeout
        self.session = requests.Session()
        if token:
            self.session.headers["Authorization"] = "Bearer " + token

    def _get(self, path, **params):
        """The JSON answer of GET url/index/path; None for 404; three tries."""
        for attempt in range(3):
            try:
                response = self.session.get("%s/%s/%s" % (self.url, self.index, path),
                                            params=params, timeout=self.timeout)
                if response.status_code == 404:
                    return None
                response.raise_for_status()
                return response.json()
            except requests.RequestException:
                if attempt == 2:
                    raise
                time.sleep(2 * (attempt + 1))

    def search(self, query, n):
        hits = (self._get("search", q=query, size=n) or {}).get("hits", [])[:n]
        return [Result(rank=i + 1, id=str(hit["id"]), title=hit.get("title", ""),
                       url=hit.get("url", "")) for i, hit in enumerate(hits)]

    def get_document(self, doc_id):
        doc = self._get("documents/%s" % doc_id)
        if doc is None:
            return None
        return Document(id=doc_id, title=doc.get("title", ""), text=doc.get("body", ""),
                        url=doc.get("url", ""))

    def describe(self):
        return {"engine": self.name, "url": self.url, "index": self.index}

describe leaves the token out: it is saved in the data files, which should hold no secret.

The config names the class as module:Class, with the connector's own keys next to it (Section 6 has the whole file):

[my-site]
engine = myengine:MyEngine
url = http://localhost:9000
index = documents
token =                         ; if the engine needs one

python3 -m relevance_tester finds myengine.py in the folder you run from; the installed relevance-tester command finds it on PYTHONPATH, so run it as PYTHONPATH=. relevance-tester ..., or register the connector in a package (Section 5.5).

5.3 Checking the connector

This script loads the connector from the config exactly as the program does and calls it once; no LLM is involved. Save it as check_engine.py next to the config:

import sys

from relevance_tester.config import Config
from relevance_tester.engine import load_engine_class

name, query = sys.argv[1], sys.argv[2]
section = Config("relevance-tester.ini").engine_section(name)
engine = load_engine_class(section["engine"]).from_config(section)
print(engine.describe())
results = engine.search(query, 10)
for result in results:
    print(result.rank, result.id, result.title)
if results:
    doc = engine.get_document(results[0].id)
    print(doc.title if doc else "get_document returned None")
    print(len(doc.text) if doc else 0, "characters:", doc.text[:300] if doc else "")
python3 check_engine.py my-site pricing

Check that the ranks start at 1, that the ids of search work in get_document, and that the text is the document's content, not empty and not only its metadata.

5.4 The SANDI connector

The built-in connector, engine = sandi, talks to the SANDI search API of one client. Its keys:

KeyDefaultMeaning
clientrequiredThe SANDI client whose collection is searched
urlhttp://localhost:8081/sandi/searchThe search endpoint
typevectorThe search type: vector, legacy or hybrid
precisionlowlow or high
rerankyesWhether SANDI reranks the results
title_fieldtitleThe field that holds the title
text_fieldsevery stored field that is not internal or an idComma separated fields that make up the text the LLM reads
timeout120Seconds to wait for one request

5.5 Registering a connector in a package

In an installed package, register the class and use its short name, engine = myengine:

[project.entry-points."relevance_tester.engines"]
myengine = "mypackage.myengine:MyEngine"

Another LLM provider is added the same way: a subclass of relevance_tester.llm.LLM with a complete() method, named by provider = module:Class in [llm].

6Configuration

Every setting is in one file, relevance-tester.ini in the folder you run from (or the file given with --config, or ~/.config/relevance-tester/config.ini). The zip has relevance-tester.example.ini to start from. A whole file for your own engine:

[llm]
base_url = https://api.openai.com/v1
api_key =                       ; your key, or leave empty and set OPENAI_API_KEY
model = gpt-4o-mini             ; writes the queries
judge_models = gpt-4o-mini      ; judges; comma separated, several judges vote

[judge]
cache = relevance-tester-cache.sqlite

[my-site]                       ; a collection: the name used on the command line
engine = myengine:MyEngine
url = http://localhost:9000
index = documents
topics = pricing,install,license,backup,upgrade,security,report,export,user,error

[my-site.current]               ; setup "current"
index = documents

[my-site.new-ranking]           ; setup "new-ranking"
index = documents-v2

The sections

SectionHolds
[llm]The LLM: base_url, api_key, model that writes the queries, judge_models that judge
[generate]How the queries are made: topics, max_rank (100), docs_per_topic (3), queries_per_document (5), exclude_titles (none; title phrases the LLM must not choose, for Wikipedia e.g. list of, category:, draft:, template:, portal:, index of, outline of, glossary of, timeline of, (disambiguation)), language (none), base_ranks (llm, or spread for the ranks of before 0.3.4: 25, 50, 75 of 100, with min_chars (200)), text_chars (10000): the characters of each base document the LLM reads
[run], [judge]workers (4): parallel requests; in [judge]: cache, the file that keeps judgments; floor (0.25), from 0 to 1, the least gain of each position the engine filled in the best possible order: 0 is plain nDCG@10, higher charges not relevant results more; text_chars (10000), the characters of each document the judge reads; both_orders (yes), each pair asked in both orders, or once with no, for half the calls
[report]worst (10): the number of worst tests listed in the report
[<collection>]One collection of your engine: the connector, its keys and the topics
[<collection>.<setup>]One setup of that collection: only the keys that differ

Choosing the topics

The config file holds your API key: keep it private (chmod 600) and out of version control. The document texts are sent to the LLM; for a private collection, use a local model, e.g. base_url = http://localhost:11434/v1 for Ollama, with no key.

7Running the commands

There are three commands. Run them from the folder that holds your config file.

CommandWhat it does
generateSearches the topics and has the LLM write the test queries; once per collection
evaluateRuns the queries on the engine, judges the top 10 and writes a report for each setup
comparePuts two evaluated results side by side; calls no engine and no LLM

generate

relevance-tester generate my-site            # one collection
relevance-tester generate                    # every collection that has no queries yet

It prints each topic with its candidates and the LLM's choice, each chosen document with the LLM's reason, then each base document as its queries are written:

'pricing': 100 results
'pricing': 10 candidates at ranks 5, 15, 25, 35, 45, 55, 65, 75, 85, 95; chosen 15, 45, 85
pricing      rank 15   chosen (explains the discounts and who gets them)  Discounts for nonprofits
pricing      rank 15   5 queries  Discounts for nonprofits  (1 rejected)

The queries are written once and kept in queries.jsonl: every later evaluation uses the same tests. Read some of them; they should look like what your users type. For a new query set, give another file name with --queries q2.jsonl.

The queries are saved as they are written, in queries.jsonl.part. When generate stops part way, for example on an LLM error, run the same command again: it continues with the base documents not yet written. To start over, delete that file.

evaluate

--version is required. It is any name for what you test: a build number, a date or a change, such as 1.0 or new-boosts. Each result is saved under a label, <setup>-<version>, or the version alone for a collection without setups:

relevance-tester evaluate my-site --version 1.0               # every setup: current-1.0, new-ranking-1.0
relevance-tester evaluate my-site.new-ranking --version 1.0   # one setup: new-ranking-1.0
relevance-tester evaluate --version 1.0                       # every setup of every collection

It shows the progress, then one line per setup with the path of its report:

25/150 queries
...
25/150 tests judged
...
new-ranking-1.0: average score 3.24 (95% interval 2.69-3.79), 30 documents, 150 queries
report: data/my-site/report-new-ranking-1.0.html

compare

relevance-tester compare my-site current-1.0 new-ranking-1.0    # two setups, one version
relevance-tester compare my-site current-1.0 current-1.1        # one setup, two versions

The first label is the reference. Both must be in the same collection, run on the same queries and judged the same way: the same version, floor, both_orders, text_chars and judge models.

Cost and time

Files

File in data/<collection>/Content
queries.jsonlThe test queries, one per line, with the base document and topic
run-<label>.jsonlThe top 10 results of every query, as the engine returned them
judged-<label>.jsonlThe judgments of every pair, with the LLM's reasons
report-<label>.html, .csvThe report, and the score of every test
compare-<a>-<b>.html, .csvThe comparison of two labels

8Interpreting the results

The average score

The average score is the average over the base documents, each the average of its queries' scores. Lower is better: 1 means that in every test no order of the judged documents could be better, 10 that the top 10 held nothing relevant, or the base was not found in a shorter list. Mistakes near the top weigh most: a not relevant result at position 1 costs far more than one at position 9, every not relevant result costs something, and documents judged equally good cost nothing in any order.

The score is not the position of the base: a base document not in the top 10 under ten better results scores 1, because that list is as good as it can be. Nor is it the known-item score: the base at position 1 with junk below it does not score 1, because each of those positions could have held at least a weakly relevant document. Returning fewer results is not penalized in itself. More examples are in Graded nDCG@10 from Pairwise Judgments against a Base Document.

Start with a baseline

The score has no absolute scale: it depends on the collection and the topics. Evaluate what you have now first, such as the current build or a plain keyword search, and compare every change with it. A change is better when its average score is lower and the comparison shows more better tests than worse ones.

The 95% interval

The interval shows how sure the average is: a different set of base documents of the same size would likely give an average in this range. When the intervals of two labels overlap widely, the difference may be chance. More topics give narrower intervals.

The report

SectionWhat it shows
SummaryThe average score and its interval, and the share of tests with score 1 and with score 1 to 5: calculated scores. Separately, from the engine's results before judging: the share of tests with the base not in the top 10
nDCG@10The mean nDCG@10 the scores are made from (see below); higher is better
Found and not foundHow many bases were in the top 10, how many at position 1, and the average score of each group
By topicThe average score of each topic: where the engine is weak
JudgesHow often the judge answered "the same" or gave no valid answer, the share of pairs whose two orders disagree, and the share of tests whose base was judged not relevant
Worst testsThe tests with the highest scores, with the top 10 as judged and the documents of the pool judged the same or better, what the engine missed, to read through

The "Judges" section tells how far to trust the judge. As a rule of thumb, a few percent in each column is normal:

A test whose base document could not be read is not judged: it is left out of every number and named below the summary.

The "Found and not found" section tells where to work. When most of the score comes from bases not in the top 10, the engine misses documents (recall); when it comes from bases in the top 10, it orders them badly (ranking).

nDCG@10

The score is a rescaled nDCG@10: score = 1 + 9 × (1 − nDCG@10), so both order the tests and the labels the same way. The report also shows the mean nDCG@10, where higher is better and 1 is perfect.

It is not the nDCG@10 of a test with relevance judgments (qrels): the grades are relative to the base document, and the best possible order is built only from the documents the engine found for the queries of the base. Compare it only between labels of this program judged with the same settings, never with published nDCG@10 figures. Graded nDCG@10 from Pairwise Judgments against a Base Document explains the difference and compares the two on the BEIR collections.

The comparison

compare counts the tests where the second label is better, the same and worse than the reference, with a sign test: a small p-value means the difference is unlikely to be chance. The tests with the biggest differences are listed with their results, so a change can be checked on real queries.

What the score does not tell

Validating on a test collection

On a collection with relevance judgments (qrels), such as the BEIR collections, the method can be compared with the real nDCG@10, the nDCG@10 computed from the qrels. The folder tools of the zip file has two scripts for that; they are not part of the program and are run with python3:

python3 tools/beir_queries.py --dataset datasets/trec-covid --out data/sandi-trec-covid/beir-queries.jsonl \
    --id-prefix BEIR_TREC_COVID/ --config relevance-tester.ini --collection sandi-trec-covid
relevance-tester evaluate sandi-trec-covid --version 0040 --queries beir-queries.jsonl
python3 tools/beir_validate.py --dataset datasets/trec-covid --data data/sandi-trec-covid

The test queries of the collection are not written for their base documents, so the base is often a weaker answer than the engine's top results: most results are then judged more relevant than the base, and the scores bunch near the best. Each base has one query, so there is no pool. Read the numbers as a check of the judge against the qrels and of the order of the labels, not as the method's usual scores. The rank correlations need at least 5 labels.

9Troubleshooting

MessageWhat to do
no config fileRun from the folder with relevance-tester.ini, or give --config
no engine section [x]The name on the command line is not a section of the config; the message lists the sections
no API keySet api_key in [llm], or the OPENAI_API_KEY environment variable
no topicsSet topics in the collection or in [generate]
No module named 'myengine'The connector file is not found: run from its folder with python3 -m relevance_tester, or with PYTHONPATH=.
A connection errorThe engine is not reachable at its url; test it with check_engine.py
queries.jsonl not found: run 'generate' firstRun generate for the collection
queries.jsonl existsThe queries are kept on purpose; for a new set, use --queries with another name
evaluate needs --versionGive --version with a name for what you test
label ... existsUse another version, or --resume to continue a run that stopped
LLM call to ... failedThe LLM did not answer after 4 tries: check base_url, the model name and the key; on a rate limit (HTTP 429), lower workers in [judge]. Then run evaluate again with --resume, or generate again: both continue
HTTP 400 from the LLMThe model does not accept the request: the program sends max_tokens and temperature, which some reasoning models refuse. Use a chat model such as gpt-4o-mini
the model did not answer with JSON (in generate)The model does not keep to the answer format: run generate again, or use another model. In evaluate, such an answer is counted as invalid and the run goes on
different query setscompare needs two labels run on the same queries
judged and scored differently, judged differentlycompare needs two labels judged by the same version, with the same floor, both_orders, text_chars and judge models: evaluate the older one again with --resume under the current config

10Changes in 0.3.5

11License

relevance-tester is released under the Apache License 2.0. See the LICENSE file in the zip.

Python 3.9+ Apache License 2.0 LLM-judged No qrels needed Any search engine OpenAI-compatible LLMs