Hierarchical Retrieval: The Geometry and a Pretrain-Finetune Recipe