Mapping issue with for KNN and Cosine Similarity

Hi,
I am trying to create a mapping which will take image embeddings as input and should store in a field which will allow me to apply cosine or knn upon my request. I am trying to map a field with knn and coosine property in both.

Thanks for any help.

You want a dense_vector field type but you have to choose the similarity e.g. cosine when the mapping is created.

@Kathleen_DeRusso is correct

To store image embeddings and perform cosine similarity or k-nearest neighbor (KNN) searches in Elasticsearch, use a dense_vector field in your mapping. This field type allows storing embeddings and supports cosine similarity out of the box. For KNN, you might need additional plugins, depending on your Elasticsearch version. Here's a quick guide:

  1. Create an index with a dense_vector field for your embeddings, specifying the dimension size.
  2. Index your image embeddings as dense vectors.
  3. For cosine similarity, use a script_score query with a cosine similarity calculation to find similar images.
  4. For KNN searches, your approach might vary based on Elasticsearch version and available plugins.

Remember, script-based similarity calculations can impact performance, so monitor and optimize your setup as needed.

@latif Welcome to the community.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.