code: def test_object_similarity(self):
      dataset = fo.Dataset()
      dataset.add_samples(
          [
              fo.Sample(
                  filepath="image1.png",
                  ground_truth=fo.Detections(
                      detections=[
                          fo.Detection(label="cat"),
                          fo.Detection(label="dog"),
                          fo.Detection(label="rabbit"),
                          fo.Detection(label="squirrel"),
                      ]
                  ),
              ),
              fo.Sample(
                  filepath="image2.png",
                  ground_truth=fo.Detections(
                      detections=[
                          fo.Detection(label="cat"),
                          fo.Detection(label="dog"),
                      ]
                  ),
              ),
          ]
      )
  
      embeddings = {}
      for sample in dataset:
          embeddings[sample.id] = np.random.randn(
              len(sample.ground_truth.detections), 4
          )
  
      fob.compute_similarity(
          dataset,
          patches_field="ground_truth",
          embeddings=embeddings,
          brain_key="obj_sim",
      )
  
      query_id = dataset.first().ground_truth.detections[0].id
  
      view = dataset.sort_by_similarity(
          query_id, k=3, brain_key="obj_sim"
      )
  
      self.assertEqual(view.count("ground_truth.detections"), 3)
  
      patches = dataset.to_patches("ground_truth")
  
      view1 = patches.sort_by_similarity(query_id)
      values1 = view1.values("id")
  
      view2 = patches.sort_by_similarity(query_id, reverse=True)
      values2 = view2.values("id")
  
      self.assertListEqual(values2, values1[::-1])
  
      view3 = patches.sort_by_similarity(query_id, k=4)
      values3 = view3.values("id")
  
      self.assertListEqual(values3, values1[:4])
  
      view4 = patches.sort_by_similarity(query_id, brain_key="obj_sim")
      values4 = view4.values("id")
  
      self.assertEqual(values4, values1)
  
      view5 = view4.limit(2)
      values5 = view5.values("id")
  
      self.assertListEqual(values5, values1[:2])
  
      view5.reload()
      values5 = view5.values("id")
  
      self.assertListEqual(values5, values1[:2])
  
file_path: fiftyone/tests/unittests/similarity_tests.py
imports: import unittest
  import numpy
  import fiftyone
  import fiftyone.brain
  from fiftyone.core.brain import BrainMethod
  from fiftyone.core.evaluation import EvaluationMethod
  from decorators import drop_datasets
label_desc: Use image node_id 4 for calling the SimilarityTests obj's underlying member method code with example usage: obj.test_object_similarity() without return types