Refactor of cosine similarity query, need to stress test new function