original_docstring: 
          Train the index by fetching training data from PSQLStorage
          :param parameters:
          :param kwargs:
          :return:
          
docstring: Train the index by fetching training data from PSQLStorage
docstring_tokens: Train the index by fetching training data from PSQLStorage
code: def train(self, parameters: Optional[Dict] = {}, **kwargs):
          """
          Train the index by fetching training data from PSQLStorage
          :param parameters:
          :param kwargs:
          :return:
          """
  
          force_retrain = parameters.get('force', False)
  
          if self.runtime_args.pea_id != 0:
              return
  
          if self._vec_indexer.is_trained and not force_retrain:
              self.logger.warning(
                  'The index has already been trained. '
                  'Please use the `force=True` in parameters to retrain the index'
              )
              return
  
          max_num_training_points = int(
              parameters.get('max_num_training_points', self.max_num_training_points)
          )
  
          self.logger.info('Taking indexed data as training points...')
          train_docs = DocumentArray()
          for doc in self._kv_indexer.get_document_iterator(
              limit=max_num_training_points, check_embedding=True, return_embedding=True
          ):
              train_docs.append(doc)
  
          if len(train_docs) == 0:
              self.logger.warning('The training failed as there is no data for training!')
              return
  
          self._vec_indexer.train(train_docs, parameters={'index_data': False})
  
          import tempfile
  
          temp = tempfile.NamedTemporaryFile(suffix='.bin', prefix='trained_faiss_')
          try:
              success = self._vec_indexer.save_trained_model(temp.name)
              if success:
                  self.logger.info('Dumping the trained indexer into PSQL database...')
                  temp.seek(0)
  
                  model_data = temp.read()
                  model_checksum = self._vec_indexer.index_key
  
                  self._kv_indexer.save_trained_model(model_data, model_checksum)
          finally:
              temp.close()
code_tokens: def train ( self , parameters : Optional [ Dict ] = { } , ** kwargs ) : force_retrain = parameters . get ( 'force' , False ) if self . runtime_args . pea_id != 0 : return if self . _vec_indexer . is_trained and not force_retrain : self . logger . warning ( 'The index has already been trained. ' 'Please use the `force=True` in parameters to retrain the index' ) return max_num_training_points = int ( parameters . get ( 'max_num_training_points' , self . max_num_training_points ) ) self . logger . info ( 'Taking indexed data as training points...' ) train_docs = DocumentArray ( ) for doc in self . _kv_indexer . get_document_iterator ( limit = max_num_training_points , check_embedding = True , return_embedding = True ) : train_docs . append ( doc ) if len ( train_docs ) == 0 : self . logger . warning ( 'The training failed as there is no data for training!' ) return self . _vec_indexer . train ( train_docs , parameters = { 'index_data' : False } ) import tempfile temp = tempfile . NamedTemporaryFile ( suffix = '.bin' , prefix = 'trained_faiss_' ) try : success = self . _vec_indexer . save_trained_model ( temp . name ) if success : self . logger . info ( 'Dumping the trained indexer into PSQL database...' ) temp . seek ( 0 ) model_data = temp . read ( ) model_checksum = self . _vec_indexer . index_key self . _kv_indexer . save_trained_model ( model_data , model_checksum ) finally : temp . close ( )
short_docstring: Train the index by fetching training data from PSQLStorage
short_docstring_tokens: Train the index by fetching training data from PSQLStorage
comment: """
          Train the index by fetching training data from PSQLStorage
          :param parameters:
          :param kwargs:
          :return:
          """