code: def brute_force_topk_sampler(
      similarity_type,
  ) -> cs_config_pb2.BruteForceTopkSamplerConfig:
      """Returns a BruteForceTopkSamplerConfig based on given similarity type.
  
      Args:
        similarity_type: A string or an int indicating the type of similarity
          defined in carls.candidate_sampling.SimilarityType.
  
      Returns:
        An instance of BruteForceTopkSamplerConfig if input is valid.
  
      Raises:
        ValueError: if input is invalid.
      """
      if isinstance(similarity_type, typing.Text):
          similarity_type = cs_config_pb2.SimilarityType.Value(
              similarity_type
          )
      if isinstance(similarity_type, int):
          if similarity_type not in [
              cs_config_pb2.COSINE,
              cs_config_pb2.DOT_PRODUCT,
          ]:
              raise ValueError("Invalid similarity type.")
      else:
          raise ValueError("Invalid input: %r" % similarity_type)
  
      return cs_config_pb2.BruteForceTopkSamplerConfig(
          similarity_type=similarity_type
      )
  
imports: import typing
  from research.carls.candidate_sampling import candidate_sampler_config_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: brute_force_topk_sampler(similarity_type) and returns: cs_config_pb2