code: def cosine_similarity(u: _Embedding, v: _Embedding) -> float:
      """Utility function to compute cosine similarity between two embedding.
  
      May return an InvalidArgumentError if e.g. the feature vectors are of
      different types (quantized vs. float), have different sizes, or have an
      L2-norm of 0.
  
      Args:
        u: An embedding.
        v: An embedding.
  
      Returns:
        Cosine similarity value.
      """
      if len(u.embedding) != len(v.embedding):
          raise ValueError(
              f"Cannot compute cosine similarity between embeddings "
              f"of different sizes "
              f"({len(u.embedding)} vs. {len(v.embedding)})."
          )
  
      if u.embedding.dtype == float and v.embedding.dtype == float:
          return _compute_cosine_similarity(u.embedding, v.embedding)
  
      if (
          u.embedding.dtype == np.uint8
          and v.embedding.dtype == np.uint8
      ):
          return _compute_cosine_similarity(
              u.embedding.view("int8").astype("float"),
              v.embedding.view("int8").astype("float"),
          )
  
      raise ValueError(
          "Cannot compute cosine similarity between quantized and "
          "float embeddings."
      )
  
imports: import numpy
  from mediapipe.tasks.python.components.containers import embedding_result
label_desc: Use image node_id 2 for calling a global function with example usage: cosine_similarity(u, v) and returns: _compute_cosine_similarity, _compute_cosine_similarity