Skip to main content
Score threshold search returns only results that meet a minimum similarity score. This ensures that all returned documents have a meaningful semantic relationship to your query. Use score thresholds when result quality matters more than result count. Without a threshold, search always returns up to limit results regardless of how relevant they are. A threshold discards low-confidence matches early, reducing noise in downstream processing. Before running this example, make sure you have a VectorAI DB instance running at localhost:6574 and the relevant SDK installed. For setup instructions, see Docker installation.
The score threshold parameter (score_threshold in Python, scoreThreshold in JavaScript) filters out any result with a cosine similarity score below 0.5. The number of returned results may be less than limit if fewer documents meet the threshold. Each result includes these fields:
  • id: The unique identifier of the matching document
  • score: Similarity score guaranteed to be at or above the threshold
  • payload: Metadata object containing the document text and attributes

Choosing a threshold

The optimal threshold depends on your embedding model and data:
  • Higher thresholds (for example, 0.7 or above) return fewer, more precise results. Use this when false positives are costly.
  • Lower thresholds (for example, 0.3 to 0.5) return more results with broader recall. Use this when coverage matters more than precision.
  • No threshold returns exactly limit results regardless of quality. Use this when you always need a fixed number of results.
Experiment with different thresholds on your data to find the right balance. Threshold behavior varies across embedding models because different models produce different score distributions.