Sorting

You can sort search results using the sort_option and group_by parameters. The platform returns a confidence field for each matching video clip, indicating how well the clip matches your query.

When you omit the group_by parameter, the platform returns a flat list of clips sorted by the confidence field in descending order.

When you set group_by to “video”, the platform groups results by video and sorts the clips within each video by the confidence field in descending order. You can further sort the list of videos using the sort_option parameter:

  • clip_count: Sorts videos by the number of matching clips in descending order.
  • score: Sorts videos by the highest confidence value among their clips in descending order.

To group the response by video and sort the list of videos on the number of matches:

Python
1search_results = client.search.query(
2 index_id="<YOUR_INDEX_ID>,
3 query_text="<YOUR_QUERY>",
4 options=["visual"],
5 group_by="video",
6 sort_option="clip_count"
7)

To group the response by video and sort the list of videos on the maximum value of the confidence field:

Python
1search_results = client.search.query(
2 index_id="<YOUR_INDEX_ID>",
3 query_text="<YOUR_QUERY",
4 options=["visual"],
5 group_by="video",
6 sort_option="score"
7)