docs: def get_metadata(self, path, include_entities=False, **kwargs):
          """Return metadata found in JSON sidecars for the specified file.
  
          Args:
              path (str): Path to the file to get metadata for.
              include_entities (bool): If True, all available entities extracted
                  from the filename (rather than JSON sidecars) are included in
                  the returned metadata dictionary.
              kwargs (dict): Optional keyword arguments to pass onto
                  get_nearest().
  
          Returns: A dictionary of key/value pairs extracted from all of the
              target file's associated JSON sidecars.
  
          Notes:
              A dictionary containing metadata extracted from all matching .json
              files is returned. In cases where the same key is found in multiple
              files, the values in files closer to the input filename will take
              precedence, per the inheritance rules in the BIDS specification.
  
          """
  
          f = self.get_file(path)
  
          # For querying efficiency, store metadata in the MetadataIndex cache
          self.metadata_index.index_file(f.path)
  
          if include_entities:
              entities = f.entities
              results = entities
          else:
              results = {}
  
          results.update(self.metadata_index.file_index[path])
          return results