code: def build_indexer(models):
      """Build nearest-neighbor indices."""
      assert (
          FLAGS.data_dir
      ), "--data_dir must be set to use the indexer."
      # Datasets for indexer - this one loads the training corpus instead of val.
      index_datasets = {}
      if _CNNDM_TRAIN_HOSTED in _HOSTED_DATASETS.value:
          index_datasets["CNNDM"] = summarization.CNNDMData(
              filepath=_CNNDM_TRAIN_HOSTED_URL
          )
      else:
          index_datasets["CNNDM"] = summarization.CNNDMData(
              split="train", max_examples=_MAX_INDEX_EXAMPLES.value
          )
  
      index_datasets = lit_dataset.IndexedDataset.index_all(
          index_datasets, caching.input_hash
      )
      # TODO(lit-dev): add training data and indexing for MT task. This will be
      # easier after we remap the model specs, so it doesn't try to cross-index
      # between the summarization model and the MT data.
      index_models = {
          k: m
          for k, m in models.items()
          if isinstance(m, t5.SummarizationWrapper)
      }
      # Set up the Indexer, building index if necessary (this may be slow).
      return index.Indexer(
          datasets=index_datasets,
          models=index_models,
          data_dir=FLAGS.data_dir,
          initialize_new_indices=_INITIALIZE_INDEX.value,
      )
  
imports: from collections.abc import Sequence
  import sys
  from typing import Optional
  from absl import app
  from absl import flags
  from absl import logging
  from lit_nlp import app
  from lit_nlp import dev_server
  from lit_nlp import server_flags
  from lit_nlp.api import dataset
  from lit_nlp.components import index
  from lit_nlp.components import similarity_searcher
  from lit_nlp.components import word_replacer
  from lit_nlp.examples.datasets import mt
  from lit_nlp.examples.datasets import summarization
  from lit_nlp.examples.models import t5
  from lit_nlp.lib import caching
label_desc: Use image node_id 2 for calling a global function with example usage: build_indexer(models) and returns: index