Imagine you are Spotify and you have billions of songs. Assume that each of these songs are transcribed into text. How do you design your search and recommendation pipeline such that when somebody searches for a specific song, i.e. searches for a specific text from a song text, you can recommend songs to them according to relevance with the searched query? Basically rank the recommendations according to their relevance with some probability?
A naive solution is of course to use a text comparison algorithm like cosine similarity and compute this for all billions of songs and output the ones with the highest similarity with the computed probabilities which could be ridiculously slow and inaccurate. How is this done in practice?