class_docstr: Class to build and search annoy indices.
  
  TODO(b/162421415): Split the managing of indices and the index logic.
  
  Upon instantiation of this class, it will first create empty indices for
  every model/embedding/dataset triple. It will then search for existing indices
  in the data directory and fill those. If the flag `initialize_new_indices` is
  set, it will fill the remaining indices by iterating over the data.
  During the saving process, both the index and a mapping from index-row to
  example are saved. These are used during the nearest neighbor lookup to return
  the closest example.
  
  Attributes:
     models: specification akin to the LIT server.
     datasets: specification akin to the LIT server.
     data_dir: path for (de-)serialization of indices.
     initialize_new_indices: whether to build new indices or simply load
       existing ones.
docstr: Create the empty indices for a model and dataset.
docstr_tok: ["Create","the","empty","indices","for","a","model","and","dataset","."]
code: def _create_empty_indices(self, model_name, dataset_name):
      """Create the empty indices for a model and dataset."""
      model = self._models[model_name]
      examples = self.datasets[dataset_name].indexed_examples
      model_embeddings_names = utils.find_spec_keys(
          model.output_spec(), lit_types.Embeddings
      )
      if not model_embeddings_names:
          return
  
      # To first create an index, we need to know the shapes - peek at first ex.
      peeked_example = list(model.predict([examples[0]["data"]]))[0]
      for emb_name in model_embeddings_names:
          index_key = self._get_index_key(
              model_name, dataset_name, emb_name
          )
          emb_dimension = len(peeked_example[emb_name])
          assert (
              self._indices.get(index_key) is None
          ), "Index already exists."
          self._indices[index_key] = annoy.AnnoyIndex(
              emb_dimension, "euclidean"
          )
  
imports: import collections
  from collections.abc import Mapping
  import os
  import pickle
  from typing import Optional
  from absl import logging
  import annoy
  from lit_nlp.api import dataset
  from lit_nlp.api import model
  from lit_nlp.api import types
  from lit_nlp.lib import utils
label_desc: Use image node_id 6 for calling the Indexer obj's underlying member method code with example usage: obj._create_empty_indices(model_name, dataset_name) without return types