New Tool Radar

AI Concepts

How to Set a Similarity-Score Threshold for Embedding Search Results

Set a similarity-score threshold for embedding search by testing where good matches end and poor ones begin.

Schematic illustration of set a similarity-score threshold for embedding search results: step one collect scored results, step two find the gap, step three set the threshold.

Cosine similarity gives every result a score, but a score on its own means little: 0.75 is good for one collection and poor for another. The way to set a threshold is to collect scored results for your own questions, find where the good matches end and the poor ones begin, and cut there. Results below the threshold are not shown, so the user never sees the weakest matches.

Prerequisites

  • An embedded index and a search that returns similarity scores.
  • At least 10 test questions with known relevant documents.
  • A note of which results your users found useful.

Steps

Step 1: Collect scored results

Run your test questions and record the score of each returned document, marking each one relevant or not. You need both the score and the judgement; a score without a judgement cannot set a threshold.

Step 2: Find the gap

Sort the results by score and look for the gap: the point where relevant results stop and irrelevant ones start. If relevant and irrelevant results are mixed at every score, no threshold will fix the ranking.

Step 3: Set the threshold

Set the threshold just below the lowest relevant score in your test. Apply it in the search, so results below it are dropped, and re-test: the threshold should remove mostly irrelevant results.

Worked example: Bluebell Bakery ingredient search

The fictional Bluebell Bakery tests a threshold on 4 results for the question about strong white flour.

Result Similarity score Relevant Above 0.75
Strong white flour, 25 kg 0.91 Yes Keep
Wholemeal flour, 25 kg 0.78 Yes Keep
Rye flour, 25 kg 0.71 No Drop
Cleaning spray 0.44 No Drop

A threshold of 0.75 keeps the 2 relevant results at 0.91 and 0.78 and drops the 2 irrelevant ones at 0.71 and 0.44.

Expected result. The threshold keeps the relevant results and drops the irrelevant ones on your test questions. UNTESTED: this guide was not run against a live model or API. The worked example below is fictional practice material, and its result is the expected result, not a measured one.

Limits

  • A threshold tuned on 10 questions may not hold on the next 100; re-check it when the collection grows.
  • Similarity scores are not comparable across embedding models or dimension counts.
  • This guide does not cover re-ranking results after the threshold.

Sources

See all