Skip to content
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

[ML] Add rerank task type to internal service #108452

Merged
merged 5 commits into from
May 13, 2024

Conversation

davidkyle
Copy link
Member

Implements the rerank task using cross encoder models uploaded to Elasticsearch using Eland and the _ml/trained_models APIs. The cross encoder model should be configured for text_similarity.

This example installs the BAAI/bge-reranker-base model:

docker run -it --rm elastic/eland \
    eland_import_hub_model \
      --cloud-id $CLOUD_ID \
      -u elastic -p $CLOUD_PWD \
      --hub-model-id BAAI/bge-reranker-base \
      --task-type text_similarity 

The rerank endpoint is created in the inference API with:

PUT _inference/rerank/bge-rerank
{
  "service": "elasticsearch",
  "service_settings": {
    "model_id": "baai__bge-reranker-base",
    "num_allocations": 1,
    "num_threads": 1
  },
  "task_settings": {
    "return_documents": true
  }  
}

There is one task setting return_documents which defaults to true. Return documents controls whether or not the response contains the input text.

Then to rerank:

POST _inference/rerank/bge-rerank
{
  "query": "How many people live in Berlin?",
  "input": [
    "Berlin has a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.",
    "New York City is famous for the Metropolitan Museum of Art.",
    "Paris is the capital and most populous city of France. With an official estimated population of 2,102,650 residents"
  ]
}

The response is ordered by relevance, index links back to the original document position

{
  "rerank": [
    {
      "index": 0,
      "relevance_score": 9.379423,
      "text": "Berlin has a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers."
    },
    {
      "index": 2,
      "relevance_score": 0.83300024,
      "text": "Paris is the capital and most populous city of France. With an official estimated population of 2,102,650 residents"
    },
    {
      "index": 1,
      "relevance_score": -6.987791,
      "text": "New York City is famous for the Metropolitan Museum of Art."
    }
  ]
}

With return_documents: false the response does not contain the input text

POST _inference/rerank/bge-rerank
{
  "query": "How many people live in Berlin?",
  "input": [
    "Berlin has a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.",
    "New York City is famous for the Metropolitan Museum of Art.",
    "Paris is the capital and most populous city of France. With an official estimated population of 2,102,650 residents"
  ],
  "task_settings" : {
    "return_documents": false
  }
}


{
  "rerank": [
    {
      "index": 0,
      "relevance_score": 9.379423
    },
    {
      "index": 2,
      "relevance_score": 0.83300024
    },
    {
      "index": 1,
      "relevance_score": -6.987791
    }
  ]
}

@elasticsearchmachine
Copy link
Collaborator

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

@elasticsearchmachine elasticsearchmachine added the Team:ML Meta label for the ML team label May 9, 2024
@elasticsearchmachine
Copy link
Collaborator

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

docs/changelog/108452.yaml Outdated Show resolved Hide resolved
# Conflicts:
#	server/src/main/java/org/elasticsearch/TransportVersions.java
@davidkyle davidkyle merged commit 8831aaf into elastic:main May 13, 2024
15 checks passed
@davidkyle davidkyle deleted the refactor-es-services branch May 13, 2024 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement :ml Machine learning Team:ML Meta label for the ML team v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants