def save_index()

in retail/recommendation-system/bqml-scann/index_builder/builder/indexer.py [0:0]


def save_index(index, tokens, output_dir):
  print('Saving index as a SavedModel...')
  module = index.serialize_to_module()
  tf.saved_model.save(
    module, output_dir, signatures=None, options=None
  )
  print(f'Index is saved to {output_dir}')
  
  print(f'Saving tokens file...')
  tokens_file_path = os.path.join(output_dir, TOKENS_FILE_NAME)
  with tf.io.gfile.GFile(tokens_file_path, 'wb') as handle:
    pickle.dump(tokens, handle, protocol=pickle.HIGHEST_PROTOCOL)
  print(f'Item file is saved to {tokens_file_path}.')