Skip to content

Adding support for binary embedding type to Cohere service embedding type #120751

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 12 commits into from
Feb 3, 2025

Conversation

ymao1
Copy link
Contributor

@ymao1 ymao1 commented Jan 23, 2025

Towards #111747

Summary

Adds support for binary embedding type in the Cohere text_embedding task.

Usage

# Create a Cohere binary inference endpoint
PUT /_inference/text_embedding/cohere_embeddings_bit
{
    "service": "cohere",
    "service_settings": {
        "api_key": <apiKey>,
        "model_id": "embed-english-v3.0",
        "embedding_type": "bit"
    }
}

# Perform an inference task
POST /_inference/text_embedding/cohere_embeddings_bit
{
    "input": "hello",
    "task_settings": {
        "input_type": "ingest"
    }
}

# Response
{
    "text_embedding_bits": [
        {
            "embedding": [
                -55,
                74,
                101,
                67,
                83,
                1,
                53,
                -101,
                -71,
                -98,
                -116,
                -99,
                80,
                -49,
                65,
                .
                .
                .
            ]
        }
    ]
}

Notes

Requesting a binary embedding from Cohere returns an array of binary embeddings encoded as bytes with int8 precision. Since this aligns with what is expected as input when you specify a dense_vector mapping with element_type: bit, we do not perform any bit unpacking on the Cohere response and handle the bytes as-is.

@ymao1 ymao1 changed the title Adding support for binary embedding type to Cohere service embedding … Adding support for binary embedding type to Cohere service embedding type Jan 23, 2025
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.

Nice!

This looks good to merge, please make it a non draft PR when you are ready.

If it is simple to add in this PR then Jina AI also have binary embeddings. They have a good blog at https://jina.ai/news/binary-embeddings-all-the-ai-3125-of-the-fat/

ymao1 and others added 2 commits January 30, 2025 07:42
…inference/results/InferenceByteEmbedding.java

Co-authored-by: David Kyle <[email protected]>
@elasticsearchmachine
Copy link
Collaborator

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

@ymao1
Copy link
Contributor Author

ymao1 commented Jan 30, 2025

If it is simple to add in this PR then Jina AI also have binary embeddings.

I will do this in a follow-up PR!

Copy link
Contributor

It looks like this PR modifies one or more .asciidoc files. These files are being migrated to Markdown, and any changes merged now will be lost. See the migration guide for details.

@ymao1
Copy link
Contributor Author

ymao1 commented Jan 30, 2025

Reverted the docs change due to the docs freeze, looks like I'll have to create a PR to 8.x for the asciidocs change and then an issue in https://github.com/elastic/docs-content/issues to get the docs update to 9.0

@ymao1 ymao1 marked this pull request as ready for review January 30, 2025 15:08
@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine added Team:ML Meta label for the ML team v9.1.0 and removed v9.0.0 labels Jan 30, 2025
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

@ymao1 ymao1 added v8.19.0 auto-backport Automatically create backport pull requests when merged labels Jan 31, 2025
@ymao1 ymao1 merged commit 89d71e1 into elastic:main Feb 3, 2025
17 checks passed
@ymao1 ymao1 deleted the es-111747 branch February 3, 2025 18:55
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.x Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 120751

@ymao1
Copy link
Contributor Author

ymao1 commented Feb 3, 2025

💚 All backports created successfully

Status Branch Result
8.x

Questions ?

Please refer to the Backport tool documentation

@ymao1
Copy link
Contributor Author

ymao1 commented Feb 4, 2025

Documentation request made in elastic/docs-content#310

ymao1 added a commit that referenced this pull request Feb 4, 2025
…dding type (#120751) (#121584)

* Adding support for binary embedding type to Cohere service embedding type (#120751)

* Adding support for binary embedding type to Cohere service embedding type

* Returning response in separate text_embedding_bits field

* Update x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/results/InferenceByteEmbedding.java

Co-authored-by: David Kyle <[email protected]>

* Update docs/changelog/120751.yaml

* Reverting docs change

---------

Co-authored-by: David Kyle <[email protected]>
(cherry picked from commit 89d71e1)

# Conflicts:
#	server/src/main/java/org/elasticsearch/TransportVersions.java
#	x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/inference/results/InferenceTextEmbeddingByteResults.java

* Adding docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged >enhancement :ml Machine learning Team:ML Meta label for the ML team v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants