Retriever algorithm pseudocode