code: def range_search_pr_curve(
      dist_ann: np.ndarray, metric_score: np.ndarray, gt_rsm: float
  ):
      assert dist_ann.shape == metric_score.shape
      assert dist_ann.ndim == 1
      l = len(dist_ann)
      if l == 0:
          return {
              "dist_ann": [],
              "metric_score_sample": [],
              "cum_score": [],
              "precision": [],
              "recall": [],
              "unique_key": [],
          }
      sort_by_dist_ann = dist_ann.argsort()
      dist_ann = dist_ann[sort_by_dist_ann]
      metric_score = metric_score[sort_by_dist_ann]
      cum_score = np.cumsum(metric_score)
      precision = cum_score / np.arange(1, len(cum_score) + 1)
      recall = cum_score / gt_rsm
      unique_key = np.round(precision * 100) * 100 + np.round(
          recall * 100
      )
      tbl = np.vstack(
          [
              dist_ann,
              metric_score,
              cum_score,
              precision,
              recall,
              unique_key,
          ]
      )
      group_by_dist_max_cum_score = np.empty(l, bool)
      group_by_dist_max_cum_score[-1] = True
      group_by_dist_max_cum_score[:-1] = dist_ann[1:] != dist_ann[:-1]
      tbl = tbl[:, group_by_dist_max_cum_score]
      _, unique_key_idx = np.unique(tbl[5], return_index=True)
      (
          dist_ann,
          metric_score,
          cum_score,
          precision,
          recall,
          unique_key,
      ) = tbl[:, np.sort(unique_key_idx)].tolist()
      return {
          "dist_ann": dist_ann,
          "metric_score_sample": metric_score,
          "cum_score": cum_score,
          "precision": precision,
          "recall": recall,
          "unique_key": unique_key,
      }
  
imports: import logging
  from copy import copy
  from dataclasses import dataclass
  from operator import itemgetter
  from statistics import median, mean
  from typing import Any, Dict, List, Optional
  from .utils import dict_merge
  from .index import Index, IndexFromCodec, IndexFromFactory
  from .descriptors import DatasetDescriptor, IndexDescriptor
  import faiss
  import numpy
  from scipy.optimize import curve_fit
label_desc: Use image node_id 1 for calling a global function with example usage: range_search_pr_curve(dist_ann, metric_score, gt_rsm) and returns: dict, dict