Assuming you have enough RAM to load the dataset at once you can either load it with what library you would do it usually or you can load it once and save it as huge torch tensor (which might be faster for loading) and then load it via torch.load. Once you have the dataset loaded to your RAM you can simply index it.