Skip to content

Reproduce the tagged benchmark ​

INFO

This page records measurements. It is not required reading: you can use the package without it.

This procedure reproduces the measurements of tagged retrieval reported in the performance workbook and in the post Right passage, wrong document? Consider Tagged Retrieval. Three public corpora can be checked by anyone: Anthropic's code set and LegalBench-RAG at no model cost, because their section tags are published as packs, and FinanceBench with section tags that you write yourself on Amazon Bedrock. The engineering pages are private, so their figures cannot be checked by anyone else. The commands below belong to release v261127 and its scripts/kb_*.py. Later releases ship the same steps as duckdb-vectors annotate, generate-questions and evaluate-retrieval, described in the evaluation procedure.

What do you need? ​

  • Python 3.12 or later and uv.
  • About 1 GB of disk for the embedding models, which are downloaded on first use.
  • For FinanceBench only: AWS credentials with access to Claude Haiku 4.5 on Amazon Bedrock, an S3 bucket and a role that Bedrock can assume for batch jobs.

No account and no key are needed for steps 2 and 3.

Step 1: set up the repository ​

Everything below runs from a clone of the repository, at release v261127, the first one that writes section tags to sidematter files. We measured at release v261119, with section tags in the front matter, and the indexer builds the same chunks from either file. Results are written as JSON files, keyed by the git commit, and one script prints the tables and the decision.

shell
$ git clone --branch v261127 https://github.com/bernard357/duckdb-vectors.git
$ cd duckdb-vectors
$ make setup-python

Step 2: run the Anthropic code set at no cost ​

The first command converts Anthropic's code set into pages, with its questions as a validation set. The data is downloaded from the Anthropic cookbook, pinned to one commit. The second command writes our section tags into the pages, from a pack in fixtures/benchmarks/, with no model call. It refuses a pack that names a page or a section that the folder does not have.

shell
$ .venv/bin/python -m scripts.benchmark_kb_datasets anthropic \
    --folder tmp/kb/anthropic/pages --work tmp/kb/anthropic
$ make kb-context KB=tmp/kb/anthropic/pages WORK=tmp/kb/anthropic \
    KB_ARGS="--from-pack fixtures/benchmarks/anthropic-contexts.json.gz"

The pack is applied to a sidematter file next to each page, as kb-context does by default. Add --write-to frontmatter to KB_ARGS to write into the pages instead. The scores are the same, since the indexer merges both.

Then score the baseline and the section tags with each embedding model, and print the table:

shell
$ for model in minishlab/potion-multilingual-128M \
      sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 \
      BAAI/bge-small-en-v1.5; do
    make kb-evaluate KB=tmp/kb/anthropic/pages WORK=tmp/kb/anthropic \
      TAGS='context=context: $.retrieval.context' \
      KB_ARGS="--split all --backend fastembed:$model \
        --output tmp/kb/anthropic/results/bar-${model##*/}.json"
  done
$ .venv/bin/python -m scripts.benchmark_kb_analyze tmp/kb/anthropic/results/bar-*.json

The last command prints one row per model, with the baseline failure rate in hybrid search, then the gain in Pass@20 with its 95% interval, then the share of failures avoided. You should get the following:

text
| anthropic-codebases / MiniLM-384    | 248 | 0.235 | +0.136 [+0.095, +0.179] * | 58% |
| anthropic-codebases / bge-small-384 | 248 | 0.124 | +0.070 [+0.040, +0.102] * | 56% |
| anthropic-codebases / potion-256    | 248 | 0.199 | +0.065 [+0.029, +0.102] * | 33% |

On a laptop, the pages and the tags take a few seconds, and the evaluation 87 seconds with potion, 111 seconds with MiniLM and 261 seconds with bge-small. The six figures of the comparison with Anthropic are 33%, 46% and 62% in vector search, and 33%, 58% and 56% in hybrid search.

Step 3: run LegalBench-RAG at no cost ​

The LegalBench-RAG data is not downloaded automatically. Fetch the archive from the authors' download link, 86 MB, and unpack it into tmp/benchmarks/cache/legalbenchrag/data. Then the steps are the same as for the code set, with the test split:

shell
$ .venv/bin/python -m scripts.benchmark_kb_datasets legalbench \
    --folder tmp/kb/legalbench/pages --work tmp/kb/legalbench
$ make kb-context KB=tmp/kb/legalbench/pages WORK=tmp/kb/legalbench \
    KB_ARGS="--from-pack fixtures/benchmarks/legalbench-contexts.json.gz"
$ make kb-evaluate KB=tmp/kb/legalbench/pages WORK=tmp/kb/legalbench \
    TAGS='context=context: $.retrieval.context' \
    KB_ARGS="--backend fastembed:BAAI/bge-small-en-v1.5"

The split of the questions is frozen by page, and each result file records its digest under split_digest. You should find 3a12ea0599e4425b, with 208 questions for development and 374 for test. If the digest differs, then your pages differ from ours, and the scores cannot be compared. Repeat the evaluation with the other two models, then run benchmark_kb_analyze on tmp/kb/legalbench/results/*-test.json. You should get the following:

text
| legalbench-rag-mini / MiniLM-384    | 374 | 0.384 | +0.147 [+0.101, +0.192] * | 38% |
| legalbench-rag-mini / bge-small-384 | 374 | 0.286 | +0.121 [+0.081, +0.162] * | 42% |
| legalbench-rag-mini / potion-256    | 374 | 0.417 | +0.037 [+0.000, +0.074] * |  9% |

The evaluation takes about 3 minutes with potion, 8 minutes with MiniLM and 33 minutes with bge-small, for 7,199 chunks embedded twice.

Note that the script prints "helps" for potion here, while the published decision says that it does not pass. This is expected: run on one corpus, the script corrects for three tests, while the published decision corrects for all nine tests of the three corpora. Give it the result files of every corpus, and it applies the same correction.

Step 4: run FinanceBench with section tags written in batch ​

FinanceBench is published under CC BY-NC 4.0, so we publish its results and not its section tags. The data is downloaded on first use, pinned to commit cc39aeb. We used the eu. inference profile from eu-central-1, and the options --model and --region select others.

shell
$ .venv/bin/python -m scripts.benchmark_kb_datasets financebench \
    --folder tmp/kb/financebench/pages --work tmp/kb/financebench
$ make kb-context KB=tmp/kb/financebench/pages WORK=tmp/kb/financebench \
    KB_ARGS="--batch --max-document-chars 12000"
$ make kb-batch KB=tmp/kb/financebench/pages WORK=tmp/kb/financebench STEP=submit \
    BATCH_BUCKET=your-bucket BATCH_ROLE_ARN=arn:aws:iam::123456789012:role/your-role

When STEP=status shows the jobs as completed, run STEP=fetch, then the kb-context command again: it finds every answer in its cache and writes the pages. Then evaluate as in step 3. The split digest to expect is a67fb18cc0c6ca02, with 39 questions for development and 110 for test.

Expect about $26 for the section tags, an estimate from the size of the pages. Our own batch jobs for this corpus finished within about 30 minutes. We did not run this corpus again from a fresh clone, so this is the one result that we did not check that way.

What to expect ​

You should get our numbers within a small margin, and not exactly. There are two reasons for this:

  • DuckDB does not guarantee the order of results with equal scores. When we ran the same evaluation twice, nDCG moved by up to 0.0006 and Pass@5 by up to 0.001.
  • Section tags that you write yourself differ from ours, even at temperature 0. With our packs, this second source of variation is gone.

To apply the same measurement to your own pages, follow the evaluation procedure, and the generation procedure to write contexts. The troubleshooting procedure tells you which layer to start with.

Where do the numbers come from? ​

  • Code: measured at release v261119, reproduced from release v261127, with the curation scripts in scripts/kb_*.py. The method, the pre-registration and the results are recorded in issue #65.
  • Data: Anthropic's cookbook at commit ce8b2629, MIT. LegalBench-RAG subsets privacy_qa, contractnli and cuad, 194 questions each; code MIT, data CC BY 4.0 and MIT. FinanceBench open sample at commit cc39aeb4, CC BY-NC 4.0. The benchmark README has the sources and licences.
  • Splits, frozen by page: engineering pages b0389e706464bead, LegalBench-RAG 3a12ea0599e4425b, FinanceBench a67fb18cc0c6ca02, code set da768fde2106de04.
  • Embedding models through fastembed: minishlab/potion-multilingual-128M, sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 and BAAI/bge-small-en-v1.5.
  • Section tags, questions, page tags and judgements: eu.anthropic.claude-haiku-4-5-20251001-v1:0 on Amazon Bedrock, temperature 0.
  • Prompts, versioned in fixtures/prompts/: contextual-header.v1, Anthropic's prompt; query-local.v1; query-contextual.v1; relevance-judge.v1; schema-discovery.v2; tagging.v2.

Next steps ​