code: def reconstruct_artifact_id_multimap(
      events: Sequence[metadata_store_pb2.Event],
  ) -> Dict[str, Tuple[int, ...]]:
      """Reconstructs events to the {key: [artifact_ids]} multimap."""
      key_to_index_and_id = collections.defaultdict(list)
      for event in events:
          for key, index in _parse_path(event):
              key_to_index_and_id[key].append(
                  (index, event.artifact_id)
              )
      result = {}
      for key in key_to_index_and_id:
          indices, artifact_ids = zip(*sorted(key_to_index_and_id[key]))
          if tuple(indices) != tuple(range(len(indices))):
              raise ValueError(
                  f'Index values for key "{key}" are not consecutive. '
                  "Maybe some events are missing?"
              )
          result[key] = artifact_ids
      return result
  
file_path: tfx/tfx/orchestration/portable/mlmd/event_lib.py
imports: import collections
  import contextlib
  from typing import Dict, List, Optional, Sequence, Tuple, TypeVar
  from tfx import types
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 2 for calling a global function with example usage: reconstruct_artifact_id_multimap(events) and returns: result