Skip to content
mentoor

Topic 2 of 5 · 6 min read

Testing embeddings on your own queries

Goal: Build a 30-question test from real queries and compare two embedding models on recall@k for the team's own documents.

To compare embedding models, collect about 30 real questions, mark the passage that answers each one, and measure how often each model puts that passage in its top results. It takes an afternoon and beats any leaderboard for your data.

Check yourself · 1 of 3

What does recall@5 measure in an embedding test?

Choose one answer

Why it matters

Public benchmarks use public text. Your documents have their own vocabulary, abbreviations and layout. Two models that tie on MTEB can differ a lot on your help-centre articles. A small labelled set turns "feels better" into a number you can defend and rerun when the model changes.

How to build it

  1. Collect real questions. Use search logs, support tickets or questions people ask in chat. Do not invent them from the documents: questions written by looking at a passage copy its wording and make every model look good.
  2. Label the answer. For each question, record the id of the chunk (or chunks) that contains the answer. One person labels, a second checks a sample.
  3. Embed and search. Embed all chunks and all questions with each candidate model, using the model's query and document modes. Retrieve the top k chunks per question.
  4. Score. Recall@k is the share of questions whose correct chunk appears in the top k. MRR (mean reciprocal rank) averages 1 divided by the rank of the first correct chunk, so rank 1 scores 1.0 and rank 4 scores 0.25. Use recall@5 or recall@10 for the retrieval stage and MRR when order matters.
  5. Look at the misses. Read the questions each model fails. A pattern (acronyms, tables, numbers) tells you more than the score.
def recall_at_k(results, gold, k=5):
    hits = sum(1 for q, ids in results.items() if gold[q] in ids[:k])
    return hits / len(results)

Before and after

Before: "Model B looked better on three questions I tried, so we switch."

Three questions are an anecdote.

After: "On 30 labelled tickets, recall@5 is 0.70 for model A and 0.83 for model B; the four questions only A answered all involve part numbers."

What goes wrong

  • With 30 questions, one question moves recall by about 3 points. Do not read a 2-point gap as a win; grow the set when models are close.
  • Writing questions from the passages inflates scores for every model.
  • Tuning the chunking or prompt on the same questions you score on, then reporting the result as if it were untouched.
  • Testing a model in the wrong mode (see query and document asymmetry) and blaming the model.

Examples

Comparing two models

for name in ["model-a", "model-b"]:
    results = search_all(name, questions, k=10)
    print(name, recall_at_k(results, gold, 5), mrr(results, gold))

Keep the labelled set in version control next to the code so every later model change reruns the same test.

A failure pattern

Model A misses 6 of 30 questions, and 5 of the 6 contain a product code such as KX-204. That points to a weakness in exact identifiers, which a hybrid keyword search can cover. The score alone would not have shown it.

Key points

  • Real questions from logs or tickets beat questions written by reading the documents.
  • Label the correct chunk for each question before running any model.
  • Recall@k measures whether the answer is found; MRR also rewards ranking it higher.
  • With about 30 questions, small gaps between models are noise, so enlarge the set for close calls.
  • Reading the failed questions tells you more than the score.

Common mistakes

  • Writing test questions by reading the target passages.
  • Drawing conclusions from a handful of ad-hoc queries.
  • Treating tiny gaps on a 30-question set as proof.
  • Reusing the scoring questions to tune the pipeline and then reporting the same numbers.

Check yourself · 2 of 3

Where should the 30 test questions come from?

Choose one answer

Check yourself · 3 of 3

The correct chunk is ranked 4th for a question and no other question is tested. What is the reciprocal rank?

Choose one answer

Practice items, not counted towards your mastery.

Start here