def compute_average_cosine_similarity(square_norm_of_sum, num_vectors):
  """Calculate the average cosine similarity between unit length vectors.

  Args:
    square_norm_of_sum: The squared norm of the sum of the normalized vectors.
    num_vectors: The number of vectors the sum was taken over.

  Returns:
    A float representing the average pairwise cosine similarity among all
      vectors.
  """
  return (square_norm_of_sum - num_vectors) / (
      num_vectors * (num_vectors - 1.0))