Skip to content

Conversation

@saikatsarkar056
Copy link
Contributor

@saikatsarkar056 saikatsarkar056 commented Nov 20, 2024

These are related to this Issue.

This PR involves the integation of IBM watsonx re-ranking. The changes leverage the reranker model and the text reranker API provided by watsonx.ai to order a collection of passages based on their relevance to a given query, ranking them from most to least likely to provide an answer.

Screen.Recording.2025-01-27.at.5.42.57.PM.mov
PUT _inference/rerank/ibm_watsonx_rerank
{
    "service": "watsonxai",
    "service_settings": {
        "api_key": <API_KEY>,
        "url": "us-south.ml.cloud.ibm.com",
        "model_id": "cross-encoder/ms-marco-minilm-l-12-v2",
        "project_id": <PROJECT_ID>,
        "api_version": "2024-05-02"
    }
}

POST _inference/rerank/ibm_watsonx_rerank
{
  "query": "database",
  "input": [
  "Greenland is the world's largest island and is known for its vast tundra and immense glaciers. It is an autonomous territory of Denmark.",
  "Google is a multinational technology company specializing in internet-related services such as search engines, online advertising, and cloud computing.",
  "Harry Potter is a fictional wizard created by J.K. Rowling, featured in a series of novels and films. The story revolves around his journey to defeat the dark wizard Voldemort.",
  "Canada is the second-largest country in the world by land area, known for its natural beauty, multicultural population, and strong economy.",
  "MySQL is a popular open-source relational database management system. It is widely used in web applications and supports structured query language (SQL) for database operations.",
  "Solar panels are a sustainable energy solution that convert sunlight into electricity. They are increasingly used for residential and commercial purposes to reduce carbon footprints."
],
  "task_settings": {
        "truncate_input_tokens": 50,
        "return_documents": true,
        "top_n": 2
    }
}

Response

{
  "rerank": [
    {
      "index": 4,
      "relevance_score": -1.889183,
      "text": "MySQL is a popular open-source relational database management system. It is widely used in web applications and supports structured query language (SQL) for database operations."
    },
    {
      "index": 2,
      "relevance_score": -3.2549715,
      "text": "Harry Potter is a fictional wizard created by J.K. Rowling, featured in a series of novels and films. The story revolves around his journey to defeat the dark wizard Voldemort."
    }
  ]
}

@saikatsarkar056 saikatsarkar056 marked this pull request as draft November 20, 2024 17:16
@saikatsarkar056 saikatsarkar056 self-assigned this Nov 20, 2024
@saikatsarkar056 saikatsarkar056 force-pushed the watsonx_reranking branch 2 times, most recently from 2f71fb5 to e6b0bfd Compare January 22, 2025 20:15
@saikatsarkar056 saikatsarkar056 changed the title [Space-time] Integrate watsonx for re-ranking task Integrate watsonx for re-ranking task Jan 22, 2025
@saikatsarkar056 saikatsarkar056 force-pushed the watsonx_reranking branch 9 times, most recently from a0df982 to 92b3491 Compare January 27, 2025 20:57
@saikatsarkar056 saikatsarkar056 added v8.18.0 >enhancement :SearchOrg/Experiences Label for the Search Experiences team labels Jan 28, 2025
@saikatsarkar056 saikatsarkar056 force-pushed the watsonx_reranking branch 2 times, most recently from 5695650 to ab0d138 Compare January 28, 2025 23:10
@saikatsarkar056 saikatsarkar056 marked this pull request as ready for review January 28, 2025 23:22
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-experiences-team (Team:Search - Experiences)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-eng (Team:SearchOrg)

Copy link
Contributor

@jonathan-buttner jonathan-buttner left a comment

Choose a reason for hiding this comment

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

Looking good, left a few comments.

@saikatsarkar056 saikatsarkar056 merged commit 09b1c6d into elastic:main Jan 31, 2025
17 checks passed
bpintea pushed a commit to bpintea/elasticsearch that referenced this pull request Jan 31, 2025
* Integrate watsonx reranking to inference api

* Add api_version to the watsonx api call

* Fix the return_doc option

* Add top_n parameter to task_settings

* Add truncate_input_tokens parameter to task_settings

* Add test for IbmWatonxRankedResponseEntity

* Add test for IbmWatonxRankedRequestEntity

* Add test for IbmWatonxRankedRequest

* [CI] Auto commit changes from spotless

* Add changelog

* Fix transport version

* Add test for IbmWatsonxService

* Remove canHandleStreamingResponses

* Add requireNonNull for modelId and projectId

* Remove maxInputToken method

* Convert all optionals to required

* [CI] Auto commit changes from spotless

* Set minimal_supported version to be ML_INFERENCE_IBM_WATSONX_RERANK_ADDED

* Remove extraction of unused fields from IbmWatsonxRerankServiceSettings

* Add space

* Add space

---------

Co-authored-by: elasticsearchmachine <[email protected]>
thecoop pushed a commit to thecoop/elasticsearch that referenced this pull request Jan 31, 2025
* Integrate watsonx reranking to inference api

* Add api_version to the watsonx api call

* Fix the return_doc option

* Add top_n parameter to task_settings

* Add truncate_input_tokens parameter to task_settings

* Add test for IbmWatonxRankedResponseEntity

* Add test for IbmWatonxRankedRequestEntity

* Add test for IbmWatonxRankedRequest

* [CI] Auto commit changes from spotless

* Add changelog

* Fix transport version

* Add test for IbmWatsonxService

* Remove canHandleStreamingResponses

* Add requireNonNull for modelId and projectId

* Remove maxInputToken method

* Convert all optionals to required

* [CI] Auto commit changes from spotless

* Set minimal_supported version to be ML_INFERENCE_IBM_WATSONX_RERANK_ADDED

* Remove extraction of unused fields from IbmWatsonxRerankServiceSettings

* Add space

* Add space

---------

Co-authored-by: elasticsearchmachine <[email protected]>
@thecoop thecoop added the v9.0.1 label Jan 31, 2025
@thecoop
Copy link
Member

thecoop commented Jan 31, 2025

This PR was created before 9.0 and 8.18 were branched. Where does this need to be backported to?

saikatsarkar056 added a commit that referenced this pull request Jan 31, 2025
* Integrate watsonx reranking to inference api

* Add api_version to the watsonx api call

* Fix the return_doc option

* Add top_n parameter to task_settings

* Add truncate_input_tokens parameter to task_settings

* Add test for IbmWatonxRankedResponseEntity

* Add test for IbmWatonxRankedRequestEntity

* Add test for IbmWatonxRankedRequest

* [CI] Auto commit changes from spotless

* Add changelog

* Fix transport version

* Add test for IbmWatsonxService

* Remove canHandleStreamingResponses

* Add requireNonNull for modelId and projectId

* Remove maxInputToken method

* Convert all optionals to required

* [CI] Auto commit changes from spotless

* Set minimal_supported version to be ML_INFERENCE_IBM_WATSONX_RERANK_ADDED

* Remove extraction of unused fields from IbmWatsonxRerankServiceSettings

* Add space

* Add space

---------

Co-authored-by: Saikat Sarkar <[email protected]>
Co-authored-by: elasticsearchmachine <[email protected]>
@saikatsarkar056
Copy link
Contributor Author

@thecoop
This should be backported to 8.18 and 9.0

@saikatsarkar056
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Questions ?

Please refer to the Backport tool documentation

saikatsarkar056 added a commit that referenced this pull request Jan 31, 2025
* Integrate watsonx reranking to inference api

* Add api_version to the watsonx api call

* Fix the return_doc option

* Add top_n parameter to task_settings

* Add truncate_input_tokens parameter to task_settings

* Add test for IbmWatonxRankedResponseEntity

* Add test for IbmWatonxRankedRequestEntity

* Add test for IbmWatonxRankedRequest

* [CI] Auto commit changes from spotless

* Add changelog

* Fix transport version

* Add test for IbmWatsonxService

* Remove canHandleStreamingResponses

* Add requireNonNull for modelId and projectId

* Remove maxInputToken method

* Convert all optionals to required

* [CI] Auto commit changes from spotless

* Set minimal_supported version to be ML_INFERENCE_IBM_WATSONX_RERANK_ADDED

* Remove extraction of unused fields from IbmWatsonxRerankServiceSettings

* Add space

* Add space

---------

Co-authored-by: elasticsearchmachine <[email protected]>
(cherry picked from commit 09b1c6d)
@serenachou
Copy link
Contributor

@saikatsarkar056 does this mean it made it into 8.18/9.0 after all?

@saikatsarkar056
Copy link
Contributor Author

@serenachou This means these changes made it to 8.19 and 9.0. I tested reranking in those deployments.

@saikatsarkar056
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.18

Questions ?

Please refer to the Backport tool documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants