Is there a way to get Cosine Similarity score returned?
Hi!
I was wondering if there is a way to get the actual cosine similarity score/value returned by the api?
So I have a code snippet where I fetch all embeddings and do a sort & filter on the
cosineSimilarity. But I noticed I can do greaterThan at the filter, which is already nice.
But when for example returning 3 items, we know they are all above 0.7, But I would like to determine things based on what similarity score they got. So for that I would need the score they got returned.
I thought it was in the select and than embeddingCosineSimilarityTo: true, while this is an option in the SDK, it throws.
Kind regards,
Dane3 Replies
Hello,
There's currently no way for you to be returned the value of the similarity. I'm not sure what kind of priority we would put to this but it definitely could be useful. Could you please make a #feature-requests ticket for this?
we actually do expose this on the graphql api (however it does not work on the js api client (going to file a bug to fix))
if I have a model called
myModel with a vector field called vec
you will get the cosine similarity
if you don't want to drop down to the graphql api you could also implement this yourself using i.e. https://www.npmjs.com/package/compute-cosine-similarity (or just rolling your own, it's a pretty easy calculation)For the meantime I’ve rolled my own, thanks for the clarification guys!