Big Data storage, for relative data storage
This is not a database question, this is a mathematical question.  Mathematicians love problems like that -- find the best match between these 30M things and those 500K things.  It's sort of like matching your picture against all images in Facebook.

The mathematicians will (you can hope) come up with a way of chopping the problem up into pieces and coming up with an approximate best fit in a few million operations instead of 15 trillion operations.  Once you find that algorithm, then database gurus can discuss how to best store and fetch the data involved.

You will need to give the math guys the details of the function for metric of "closeness".  Part of the answer will probably take advantage of those details.