KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KDB.AI Get the cosine similarity scores along with the retrieved docs

  • Get the cosine similarity scores along with the retrieved docs

    Posted by Sosycs on May 19, 2024 at 7:42 pm

    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?

    megan_mcp replied 2 months ago 2 Members · 1 Reply
  • 1 Reply
  • megan_mcp

    Administrator
    May 20, 2024 at 4:38 pm

    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

    • This reply was modified 2 months ago by  megan_mcp.

Log in to reply.