class_docstr: Index Dense Embeddings.
class_docstr_tok: ["Index","Dense","Embeddings","."]
docstr: First train data, then add it.
  
  If we're only training... then don't add!!
docstr_tok: ["First","train","data",",","then","add","it",".","If","we","'re","only","training","...","then","do","n't","add","!","!"]
code: def train_then_add(self, input_files: List[str]):
      """
      First train data, then add it.
  
      If we're only training... then don't add!!
      """
      assert isinstance(self.index, CompressedIndexer)
      # Train
      random.seed(42)
  
      tensors = []
      for s in input_files:
          logging.info(f"Loading in file {s}")
          tensor = torch.load(s)
          if self.opt["partition_index"]:
              self.index.train([tensor])
              self.index.add([tensor])
          else:
              tensors.append(tensor)
  
      if not self.opt["partition_index"]:
          self.index.train([torch.cat(tensors)])
          self.index.add([torch.cat(tensors)])
  
file_path: ParlAI/parlai/agents/rag/scripts/index_dense_embeddings.py
imports: import os
  import random
  import torch
  from typing import List
  from parlai.core.params import ParlaiParser
  from parlai.core.script import ParlaiScript
  import parlai.utils.logging
  from parlai.agents.rag.rag import RagAgent
  from parlai.agents.rag.indexers import indexer_factory, CompressedIndexer
label_desc: Use image node_id 4 for calling the Indexer obj's underlying member method code with example usage: obj.train_then_add(input_files) without return types