Inconsistent results using KNN script score with Cosine Similarity

Thank you very much for the quick reply, this is super helpful.

  1. When you increase size greater than 1 (say 100), do you see the document?

When I do this the variance in the results does decrease, as in I get fewer incorrect results but the odd random result does still pop up. So in theory, as I add more documents this becomes less of a problem but it just becomes significantly harder to debug at that stage.

  1. Are there any duplicates in the index?

No duplicates.

  1. Is the enabled field on the doc you are querying set to true?

Yes, it is. This is always the first thing I look for when testing to ensure I haven’t made that mistake.

“must” may impact the score in the query. If you replace that with filter

I did not know this. WIll make this change and take another look thanks.

so to get the cosine similarity score maybe first do a query without the nested parameter and then use the formula in the link above to reverse engineer the cosine similarity from the score returned.

This is also very helpful will try now thanks

1 Like