rewrote to perform magnitudes and cosine similarity online, as required by the algorithm