Get the cosine similarity scores along with the retrieved docs

https://learninghub.kx.com/forums/topic/get-the-cosine-similarity-scores-along-with-the-retrieved-docs

Hello, thank you for the clear documentation. I was worndering if there is a way to disply the calculated cosine similarity for the retrieved docs stored in the database?

Hi @Sosycs

As an example I've used snippets from our Document Search sample (screenshot below):

Simply change the metric to: "metric" : "CS".

To see the distance print the results of the similarity search (the distance will be in a column in the result called "__nn_distance":

print(table.search(query_vector, n=3))

Also take a look at our documentation on cosine similarity for extra help - KDB.AI Similarity Metrics - Documentation (kx.com)

Hope this helps!

Thanks,

Megan