Dynevia
IT EN
Contact

AI & Data7 min read

Build the yardstick first: evaluating AI search before production

On a large retail catalogue, a semantic search prototype lifted the precision of the first result from 0.60 to 0.76 against the live engine. The decisive work was building the yardstick: the previous one had declared success for a model that made things worse.

Catalogue search is where a language model seems to work before it actually does. You try ten queries, the results look sensible, the demo convinces. In the project behind this article, product search for a retailer with a large catalogue, the fine-tuned model from our own previous version had been described as a success. Under independent evaluation it did worse than the untrained model it started from: 0.782 against 0.817 nDCG@10. The earlier evaluation only measured generic category queries, the one type on which that model improved. What we describe here is a validated prototype, not a production system. That is precisely why the method matters more than the number.

The yardstick comes before the engine

Before touching the engine, we rebuilt the measurement. Three choices changed the conclusions.

  • Queries stratified by type: brand or product name, synonym, typo, description, category, attribute, product not in the catalogue. A system can excel on one type and fail on another, which is exactly what had happened.
  • A judge outside the system, given the declared intent of every query and grading relevance from 0 to 3. The judgement stays the same for every variant, typos and synonyms included.
  • A clean ablation, one component at a time. In our earlier work the baseline received the query already corrected by the dictionary, so the comparison no longer measured anything. For the same reason we removed from training 14,694 examples that overlapped with the test queries.

With 216 queries, the standard error of the differences was about 0.017. We turned that into a rule: between configurations that differ by less than the noise, choose the simpler one, not the one with the higher number.

Where the gains come from

The ablation overturned our starting intuition. Of the roughly 0.12 nDCG gained over hybrid lexical and vector search, 0.095 came from reranking with a cross-encoder. The retrained embedding model added 0.005, within the noise. We also measured the ceiling: perfectly ordering the candidates already retrieved would reach 0.995. The right products were almost always among the candidates; the loss was in the ordering.

The reranker had its own instructive failure. Trained on binary labels, with the product that generated the query as positive and everything else as negative, it made the system worse: 0.868. Punishing equivalent products teaches an arbitrary specificity. With grades from 0 to 3 assigned by a language model, it rose to 0.915. The labels for 2,999 queries cost $0.17. The synthetic queries generated for every product in the catalogue, which enrich the index and supply 75,000 training pairs, cost $0.29. All the data work came to less than one euro: the real cost is engineering.

Zero-result searches as a test bench

The best test material is not written at a desk: it sits in the logs. The log of searches that returned nothing in production held more than 62,000 terms. We took the 664 most frequent and combined them with 515 common queries, which guard against regressions, and with the control sets built earlier: 1,576 queries in all. Both engines were queried live on the same day. Results were shuffled, stripped of their origin, judged blind and then reread by hand.

  • Across all 1,576 queries, precision at the first result rose from 0.60 to 0.76 and nDCG from 0.55 to 0.75. The prototype won 798 queries, tied 570 and lost 208.
  • On the 664 queries that had returned zero results, a relevant first result went from 0.37 to 0.55.
  • On the 515 common queries, where the live engine was already good, from 0.85 to 0.94.
  • On the 86 queries with negations or attributes, such as “without …”, from 0.48 to 0.73.

Next to the numbers, the report carries two caveats. Between collecting the log and running the comparison, the live engine had improved: only 27 of the 664 zero-result queries were still empty. And the prototype's catalogue was two months older: where a difference came from products added or withdrawn, the case was not used as an example, and in the aggregate figures it cuts both ways.

Judge the judge

An automated judge is a measuring instrument and needs calibrating like any other. For a wide gap, such as prototype against live engine, an inexpensive judge plus a manual reread is enough to read the direction. On narrow gaps, inexpensive judges misled us. Later in the project, judges scoring product by product rated two versions of the same engine as equal. People using the demo saw otherwise, and they were right: a side-by-side comparison of full lists with stronger judges put the new version 5.5% behind on the top ten results, with an interval from -9.7% to -1.2%. In the same phase, an apparent nDCG gain of 0.024 turned out to be an artefact of list length: nDCG does not penalise extra results, and those lists carried 25% more irrelevant ones.

Since then, every comparison between versions follows the same protocol.

  • Blind side-by-side lists, with the A and B order swapped between judges.
  • Two strong judges, from model families not used in training.
  • Control pairs with identical lists: 40 out of 40 rated a tie.
  • Point estimate, direction and interval for every comparison, never just “equal”; precision and the count of irrelevant results next to nDCG.
  • A fresh set of 300 queries excluded from every decision, to check the system has not adapted to the test.
  • A manual reread: the judge also accepts matches between words that look alike and mean something else.

A result that does not survive an adversarial check is not a result.

Latency and cost, before production

An engine that wins on quality also has to hold up on the bill. Load tests showed the bottleneck was not the GPU but the CPUs and thread discipline. Inside a container, libraries see every core of the physical host rather than the allotted quota, and spawn too many threads: tuning them cut latency from 131 to 63 milliseconds. A single process topped out below 17 queries per second; four copies of the engine on the same card reached 26.6, at about $8 per million queries. A high-end GPU left on factory settings cost $104 per million. Ported to CPU only, with distilled models and precomputed rankings for known queries, the engine matched the GPU version under external judges on 1,042 queries, on a server costing $0.14 an hour.

One step remains that no offline measure can replace: an A/B test on clicks and add-to-cart. The measurements decide what deserves to get there.

Contact

Is your process still living in a spreadsheet?

Tell us what the system has to do, what data it works with and what constraints apply. We'll come back to you with the questions that matter and a phased proposal.

Get in touch