Skip to content

Use retriever instead of rank parameter for hybrid search in ES 9 #79

@ezimuel

Description

@ezimuel

In Elasticsearch 9.0.0 we removed the support of rank parameter (see here and here).
This means we need elasticsearch-py ver. 9+ to use the retriever parameter instead of rank.
If you try to use ElasticsearchStore.ApproxRetrievalStrategy(hybrid=True, ...) with Elasticsearch server 9+, you will get an error.
For instance, the following example:

ElasticsearchStore(
    index_name="test",
    es_connection=es,
    query_field="text",
    vector_query_field="text_embedding.predicted_value",
    distance_strategy="COSINE",
    strategy=ElasticsearchStore.ApproxRetrievalStrategy(
        hybrid=True,
        query_model_id="sentence-transformers__all-minilm-l6-v2"
    )
)

It generates the following POST query, that is not valid with ES 9+

POST test/_search
{
  "knn": {
    "field": "text_embedding.predicted_value", 
    "k": 10, 
    "num_candidates": 50, 
    "query_vector_builder": {
      "text_embedding": {
        "model_id": "sentence-transformers__all-minilm-l6-v2", 
        "model_text": "loyer annuel de base"}
      
    }
  }, 
  "query": {
    "bool": {
      "must": [
         {
          "match": {"text": {"query": "loyer annuel de base"}}
         }
        ]
    }
  },
  "rank": {"rrf": {}}
}

/cc @Danouchka

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions