findIdsWithScores method

List<IdWithScore> findIdsWithScores()

Finds IDs of objects matching the query associated to their query score (e. g. distance in NN search).

Returns a list of IdWithScore that wraps IDs of matching objects and their score, sorted by score in ascending order.

This only works on objects with a property with an HnswIndex.

Implementation

List<IdWithScore> findIdsWithScores() {
  final resultPtr = checkObxPtr(C.query_find_ids_with_scores(_ptr));
  try {
    final items = resultPtr.ref.ids_scores;
    final count = resultPtr.ref.count;
    return List.generate(count, (i) {
      // items[i] only available with Dart 3.3
      final item = items.elementAt(i).ref;
      final id = item.id;
      final score = item.score;
      return IdWithScore(id, score);
    }, growable: false);
  } finally {
    C.id_score_array_free(resultPtr);
  }
}