Rebuild the internal key to index mapping.

def _rebuild_key_ids(self):
        """Rebuild the internal key to index mapping."""
        self._key_ids = collections.defaultdict(list)
        for i, x in enumerate(self._pairs):
            self._key_ids[x[0]].append(i)