Evaluate retrieval on your own queries
You changed something, such as a tag, a context or an embedding model, and the answers look better. This procedure tells you whether they are, on questions that you did not tune the change on. A knowledge manager builds a set of questions with the passages that answer them, then compares each variant of the index with a baseline, with a confidence interval. It is the second layer of the troubleshooting procedure, and it applies to every other layer. A few questions show a problem, and they do not measure a gain. Hence the need for a larger set, built before the change.
What do you need?
pip install "duckdb-vectors[anthropic]", or the extra of the provider that generates and judges the questions:bedrock,anthropicoropenai.- A manifest next to the pages, written by
duckdb-vectors init, with anannotation.modelfor the steps that call a model. If your pages are private, keep the calls with a provider and in a region where you are allowed to send them. - A working copy of the pages. Other procedures write sidematter files next to them. To try the whole path first, with no provider and at no cost, set
annotation.model: fakeandembeddings: local:hashing. A deterministic stand-in answers each prompt in the expected shape. Its answers only exercise the commands, so do not read anything into the numbers. On the eight pages offixtures/tagged/, every step completes in seconds. The questions, the split, the audit and the results live in theworkfolder of the manifest. Every model answer is cached on disk by content, so a re-run costs nothing, and an edited page costs only that page.duckdb-vectors statusshows the questions and their split, and names the next command to run.
Which questions to use?
Real questions come first. Take them from the log of your search or of your support desk, and import them as they are. They are the only questions that say what your users want. When you have no log, or too few queries, generate two strata of questions with the model:
- Local questions are written from one passage, and a passage alone can answer them. They are a control: page context should not matter for them.
- Contextual questions are written for one of two near-identical passages from different pages, so that only the page context tells them apart. Why two strata? A set of questions written from one passage cannot show the effect of a tag. The passage already holds the words of the question, so the baseline is at 0.87 to 0.96 and there is no room to gain. Our first benchmark made this mistake, and its figures should not be cited. The contextual stratum is the one where a tag can help, and it is where you read your result. Build the questions before you write any tag or context, so that the design of the tags cannot shape the test.
Step 1: build the questions
$ duckdb-vectors generate-questions --local 200 --contextual 150
$ duckdb-vectors import-questions real-queries.txtimport-questions adds real questions, one per line. Questions are only written from passages of at least 60 words. For a knowledge base of short sections, lower the limit with --min-words 30.
Step 2: freeze the split
$ duckdb-vectors split-questionssplit-questions assigns whole pages to a dev split (about 30%) and a test split, and freezes the assignment with a digest. Choose prompts, fields and thresholds on dev only, and score test once. A later run refuses to change a frozen split unless you pass --force, which voids earlier test results.
Step 3: pool and judge the golden passages
The golden passages of each question come from pooling and judging. pool-passages collects the top 20 results of several search systems. judge-passages has the model grade each pooled passage 0, 1 or 2 against the question and its reference answer, without seeing any tag or context. A passage graded 1 or more is golden.
$ duckdb-vectors pool-passages
$ duckdb-vectors judge-passagesThe judge makes one call per pooled passage, tens of thousands for a few hundred questions. With a bedrock: model and a batch section in the manifest, the command runs as batch jobs, and exits with status 3 until they finish. Run it again, as the generation procedure explains.
Step 4: audit the judge
Check the judge against a person, before you trust any number:
$ duckdb-vectors audit-judge --size 60audit-judge writes audit.yaml in the work folder: 60 questions, balanced across strata, each with its source passage, one passage that the judge kept and one that it rejected. Fill question_valid (yes or no) once per question, and human_grade (0, 1 or 2) before each passage. The grades of the judge are in audit-judge.yaml. Do not open it before you are done. Then:
$ duckdb-vectors score-auditscore-audit reports Cohen's κ between you and the judge, on the 0 to 2 grades and on golden or not. Golden or not is what Pass@k uses. If its κ is below 0.6, then revise the judge prompt, relevance-judge, and judge again. On our engineering pages, κ on golden or not was 0.736.
Step 5: measure the variants
evaluate-retrieval indexes the same chunks once per condition and compares each with the baseline, per stratum, with a 95% paired bootstrap interval. The baseline has no tags. Each tag set is measured in the embedding, in the keyword index, and in both. The embeddings come from the manifest, and tags.fields is one of the tag sets. A tag set is NAME=label: $.path;label: $.path. To measure the projected metadata of the first layer:
$ duckdb-vectors evaluate-retrieval --split dev \
--tags 'title=title: $.document.title' \
--tags 'headings=where: $.section.headings'To measure a context written by a model, which the generation procedure produces:
$ duckdb-vectors evaluate-retrieval --split dev --tags 'context=context: $.retrieval.context'Results go to results/ in the work folder. Iterate on dev. When the choice is made, run --split test once and report that. Then set tags in the manifest and index, as in the projection procedure. To look at the tags that you kept, use the inspection procedure. A gain counts when its interval excludes zero. If you test several sets at once, then correct for the number of tests, as the evaluation of the tags that cost nothing does with a Holm correction. When the knowledge base is in a git work tree, the results record its git state.
How many questions are needed?
There is no magic number, and the width of the interval is what to read. In our runs the test splits had 110 to 374 questions in the contextual stratum. With 110 and 162 questions, the intervals were too wide for most gains to count after the correction, even when every estimate was positive. With 180 and 374 questions, gains of 0.03 to 0.15 counted. As a rule of thumb, which is our judgement and not a measured threshold, start with 150 contextual questions, and add more if the interval of the gain that you care about still spans zero. A small gain needs more questions than a large one. If you cannot afford them, then say so in your report and treat the result as a hint. The measures and costs that we observed are in the performance workbook.
Next steps
- Generate contextual tags: the third layer, which
evaluate-retrievalmeasures. - Project tags in embeddings: the first layer.
- Reproduce the tagged benchmark: the same measure on public corpora.
- Performance workbook: the measured gains and costs.
- Issue #65: the method and its pre-registration.