class_docstr: Class to construct and perform search using a BKTree.
docstr: Function to search the bktree given a hash of the query image.
  
  Args:
      query: hash string for which BKTree needs to be searched.
      tol: distance upto which duplicate is valid.
  
  Returns:
      List of tuples of the form [(valid_retrieval_filename1: distance), (valid_retrieval_filename2: distance)]
docstr_tok: ["Function","to","search","the","bktree","given","a","hash","of","the","query","image",".","Args",":","query",":","hash","string","for","which","BKTree","needs","to","be","searched",".","tol",":","distance","upto","which","duplicate","is","valid",".","Returns",":","List","of","tuples","of","the","form","[","(","valid_retrieval_filename1",":","distance",")",",","(","valid_retrieval_filename2",":","distance",")","]"]
code: def search(self, query: str, tol: int = 5) -> Dict:
      """
      Function to search the bktree given a hash of the query image.
  
      Args:
          query: hash string for which BKTree needs to be searched.
          tol: distance upto which duplicate is valid.
  
      Returns:
          List of tuples of the form [(valid_retrieval_filename1: distance), (valid_retrieval_filename2: distance)]
      """
  
      valid_retrievals = []
      candidates_local = copy.deepcopy(self.candidates)
      while len(candidates_local) != 0:
          candidate_name = candidates_local.pop()
          cand_list, valid_flag, dist = self._get_next_candidates(
              query, self.dict_all[candidate_name], tolerance=tol
          )
          if valid_flag:
              valid_retrievals.append(
                  (candidate_name, int(dist))
              )  # typecast dist to int to save later as np.int64
              # can't be saved by json
          candidates_local.extend(cand_list)
      return valid_retrievals
  
file_path: imagededup/imagededup/handlers/search/bktree.py
imports: import copy
  from typing import Callable, Dict, Tuple
label_desc: Use image node_id 5 for calling the BKTree obj's underlying member method code with example usage: obj.search(query, tol) and returns: valid_retrievals