Skip to content

Set default similarity for Cohere model to cosine #125370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 21, 2025

Conversation

jimczi
Copy link
Contributor

@jimczi jimczi commented Mar 21, 2025

Cohere embeddings are expected to be normalized to unit vectors, but due to floating point precision issues, our check (DenseVectorFieldMapper#isNotUnitVector) often fails. This change fixes this bug by setting the default similarity for newly created Cohere inference endpoint to cosine.

Closes #122878

Cohere embeddings are expected to be normalized to unit vectors, but due to floating point precision issues,
our check ({@link DenseVectorFieldMapper#isNotUnitVector(float)}) often fails.
This change fixes this bug by setting the default similarity for newly created Cohere inference endpoint to cosine.

Closes elastic#122878
@elasticsearchmachine elasticsearchmachine added the Team:ML Meta label for the ML team label Mar 21, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/ml-core (Team:ML)

@elasticsearchmachine
Copy link
Collaborator

Hi @jimczi, I've created a changelog YAML for you.

Copy link
Member

@davidkyle davidkyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

There is a concern the a user might delete an Cohere inference endpoint with default similarity dot_product then recreate it but this time the similarity has defaulted to cosine. If that inference endpoint is used in semantic_text then this could cause suboptimal relevance.

This problem is described in #124272, that work should now be prioritised

@jimczi
Copy link
Contributor Author

jimczi commented Mar 21, 2025

. If that inference endpoint is used in semantic_text then this could cause suboptimal relevance.

We check the model configuration on every index request so this will result in an error. For users that deleted their endpoint and re-create it, they will need to override the similarity explicitly to match the old one. Since the user forced the deletion, I am not particularly concerned by this regression. WDYT?

@davidkyle
Copy link
Member

I see no reason not to merge this PR. It would be a better user experience to have the check performed up front and I will follow up on that

@jimczi jimczi merged commit a26bbe2 into elastic:main Mar 21, 2025
17 checks passed
@jimczi jimczi deleted the cohere_default_similarity branch March 21, 2025 12:23
@jimczi jimczi added auto-backport Automatically create backport pull requests when merged backport pending v9.0.1 and removed auto-backport Automatically create backport pull requests when merged labels Mar 21, 2025
jimczi added a commit to jimczi/elasticsearch that referenced this pull request Mar 21, 2025
Cohere embeddings are expected to be normalized to unit vectors, but due to floating point precision issues,
our check ({@link DenseVectorFieldMapper#isNotUnitVector(float)}) often fails.
This change fixes this bug by setting the default similarity for newly created Cohere inference endpoint to cosine.

Closes elastic#122878
jimczi added a commit to jimczi/elasticsearch that referenced this pull request Mar 21, 2025
Cohere embeddings are expected to be normalized to unit vectors, but due to floating point precision issues,
our check ({@link DenseVectorFieldMapper#isNotUnitVector(float)}) often fails.
This change fixes this bug by setting the default similarity for newly created Cohere inference endpoint to cosine.

Closes elastic#122878
smalyshev pushed a commit to smalyshev/elasticsearch that referenced this pull request Mar 21, 2025
Cohere embeddings are expected to be normalized to unit vectors, but due to floating point precision issues,
our check ({@link DenseVectorFieldMapper#isNotUnitVector(float)}) often fails.
This change fixes this bug by setting the default similarity for newly created Cohere inference endpoint to cosine.

Closes elastic#122878
elasticsearchmachine pushed a commit that referenced this pull request Mar 21, 2025
Cohere embeddings are expected to be normalized to unit vectors, but due to floating point precision issues,
our check ({@link DenseVectorFieldMapper#isNotUnitVector(float)}) often fails.
This change fixes this bug by setting the default similarity for newly created Cohere inference endpoint to cosine.

Closes #122878
elasticsearchmachine pushed a commit that referenced this pull request Mar 21, 2025
Cohere embeddings are expected to be normalized to unit vectors, but due to floating point precision issues,
our check ({@link DenseVectorFieldMapper#isNotUnitVector(float)}) often fails.
This change fixes this bug by setting the default similarity for newly created Cohere inference endpoint to cosine.

Closes #122878
elasticsearchmachine pushed a commit that referenced this pull request Mar 21, 2025
Cohere embeddings are expected to be normalized to unit vectors, but due to floating point precision issues,
our check ({@link DenseVectorFieldMapper#isNotUnitVector(float)}) often fails.
This change fixes this bug by setting the default similarity for newly created Cohere inference endpoint to cosine.

Closes #122878
omricohenn pushed a commit to omricohenn/elasticsearch that referenced this pull request Mar 28, 2025
Cohere embeddings are expected to be normalized to unit vectors, but due to floating point precision issues,
our check ({@link DenseVectorFieldMapper#isNotUnitVector(float)}) often fails.
This change fixes this bug by setting the default similarity for newly created Cohere inference endpoint to cosine.

Closes elastic#122878
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :ml Machine learning Team:ML Meta label for the ML team v8.18.1 v8.19.0 v9.0.1 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handling Unit-Length Embeddings in Inference API
3 participants