A Mechanism for Sample-Efficient In-Context Learning for Sparse Retrieval Tasks