code: def _get_index(dataset, custom_distance=None, custom_dim=None):
      url = "http://ann-benchmarks.com/%s.hdf5" % dataset
      vectors_fn = os.path.join("test", dataset + ".hdf5")
      index_fn = os.path.join("test", dataset + ".annoy")
  
      if not os.path.exists(vectors_fn):
          print("downloading", url, "->", vectors_fn)
          urlretrieve(url, vectors_fn)
  
      dataset_f = h5py.File(vectors_fn, "r")
      distance = dataset_f.attrs["distance"]
      if custom_distance is not None:
          distance = custom_distance
      f = dataset_f["train"].shape[1]
      if custom_dim:
          f = custom_dim
      if custom_distance:
          dataset = dataset.rsplit("-", 2)[0] + "-%d-%s" % (
              f,
              custom_distance,
          )
          index_fn = os.path.join("test", dataset + ".annoy")
  
      annoy = AnnoyIndex(f, distance)
  
      if not os.path.exists(index_fn):
          print("adding items", distance, f)
          for i, v in enumerate(dataset_f["train"]):
              if len(v) > f:
                  v = v[:f]
              annoy.add_item(i, v)
  
          print("building index")
          annoy.build(10)
          annoy.save(index_fn)
      else:
          annoy.load(index_fn)
      return annoy, dataset_f, dataset
  
file_path: annoy/test/accuracy_test.py
imports: from __future__ import print_function
  import os
  import h5py
  from annoy import AnnoyIndex
label_desc: Use image node_id 1 for calling a global function with example usage: _get_index(dataset, custom_distance, custom_dim) and returns: annoy,  dataset_f,  dataset