Similarity Score Thresholds
What you'll learn: How to filter out irrelevant search results by setting minimum similarity score cutoffs.
When performing semantic search, you retrieve the most similar documents by comparing cosine similarity scores (or dot products). But "most similar" doesn't always mean "relevant enough." A document might be the closest match in your collection yet still be completely off-topic if your collection is large and diverse.
Why Thresholds Matter
Think of similarity scores like grades on a test. Just because someone scored highest in a class doesn't mean they passed—if the top score was 40%, it's still a failure. Similarly, a cosine similarity of 0.3 might be your "best match," but it's not actually similar enough to be useful.
Setting Your Threshold
A similarity score threshold is a minimum value you require before returning a result to the user. Common practices:
- Cosine similarity: Typically ranges from -1 to 1 (or 0 to 1 for normalized embeddings)
- Common thresholds: 0.6-0.8 for meaningful matches, though this varies by domain
- Too high: You'll miss relevant results (false negatives)
- Too low: You'll include irrelevant junk (false positives)
Implementation Pattern
After computing top-K results, filter by threshold:
threshold = 0.7
relevant_results = [
doc for doc, score in top_k_results
if score >= threshold
]
Tuning Your Threshold
Start with a reasonable guess (0.7), then examine borderline cases manually. Look at documents scoring 0.65-0.75—are the lower-scoring ones actually relevant? Adjust accordingly. Different query types may need different thresholds.
Key Takeaway: Similarity score thresholds act as a quality gate, ensuring you only return results that meet a minimum relevance standard rather than just "the best of what's available."