Profile:true does not work with hybrid query

Versions opensearch v2.19.2

Enabling profile: true in a hybrid search query (BM25 + vector search) causes the request to fail with an error, while the same query executes successfully and returns results when profiling is not enabled.

query:

POST products/_search
{
  "size": 5,
  "profile": true,
  "search_pipeline": {
    "phase_results_processors": [
      {
        "normalization-processor": {
          "combination": {
            "parameters": {
              "weights": [
                0.99,
                0.01
              ]
            },
            "technique": "arithmetic_mean"
          },
          "normalization": {
            "technique": "min_max"
          }
        }
      }
    ]
  },
  "query": {
    "hybrid": {
      "queries": [
        {
          "function_score": {
            "query": {
              "match": {
                "product_name": "iphone"
              }
            },
            "boost": 1,
            "functions": [
              {
                "weight": 1.2
              }
            ],
            "score_mode": "sum",
            "boost_mode": "multiply"
          }
        },
        {
          "function_score": {
            "query": {
              "knn": {
                "text_vector": {
                  "vector": [
                    0.11,
                    0.4,
                    -0.32,
                    0.77,
                    -0.55,
                    0.92,
                    -0.22,
                    0.45,
                    0.2,
                    -0.65,
                    0.89,
                    -0.13,
                    0.34,
                    0.57,
                    -0.46,
                    0.79,
                    0.15,
                    -0.21,
                    0.31,
                    -0.12,
                    0.28,
                    0.65,
                    -0.36,
                    0.44,
                    0.53,
                    -0.62,
                    0.7,
                    -0.18,
                    0.37,
                    0.47,
                    -0.73,
                    0.81,
                    0.14,
                    -0.38,
                    0.29,
                    0.6,
                    -0.48,
                    0.63,
                    -0.21,
                    0.55,
                    0.27,
                    -0.53,
                    0.67,
                    -0.3,
                    0.31,
                    0.64,
                    -0.4,
                    0.72,
                    0.18,
                    -0.27,
                    0.5,
                    0.62,
                    -0.54,
                    0.65,
                    -0.35,
                    0.51,
                    0.23,
                    -0.43,
                    0.73,
                    -0.26,
                    0.41,
                    0.56,
                    -0.37,
                    0.74,
                    0.16,
                    -0.32,
                    0.43,
                    0.66,
                    -0.51,
                    0.68,
                    -0.29,
                    0.49,
                    0.25,
                    -0.42,
                    0.76,
                    -0.28,
                    0.36,
                    0.61,
                    -0.39,
                    0.78,
                    0.19,
                    -0.3,
                    0.48,
                    0.63,
                    -0.52,
                    0.72,
                    -0.33,
                    0.54,
                    0.21,
                    -0.47,
                    0.79,
                    -0.25,
                    0.39,
                    0.59,
                    -0.41,
                    0.81
                  ],
                  "k": 5
                }
              }
            },
            "boost": 1,
            "functions": [
              {
                "weight": 1
              }
            ],
            "score_mode": "sum",
            "boost_mode": "multiply"
          }
        }
      ]
    }
  }
}

result:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "scorers are null for all sub-queries in hybrid query"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "products",
        "node": "MwuYt0TAQ8GrBvldHHuG6A",
        "reason": {
          "type": "illegal_argument_exception",
          "reason": "scorers are null for all sub-queries in hybrid query"
        }
      }
    ],
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "scorers are null for all sub-queries in hybrid query",
      "caused_by": {
        "type": "illegal_argument_exception",
        "reason": "scorers are null for all sub-queries in hybrid query"
      }
    }
  },
  "status": 400
}

Steps to reproduce the issue:

# create index
PUT products
{
  "settings": {
    "index": {
      "knn": true,
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "product_name": {
        "type": "text"
      },
      "product_description": {
        "type": "text"
      },
      "text_vector": {
        "type": "knn_vector",
        "dimension": 96
      }
    }
  }
}

# insert a sample record
POST products/_doc/1
{
  "product_name": "Apple iPhone 15",
  "product_description": "The latest iPhone with A16 Bionic chip and advanced camera system.",
  "text_vector": [
    0.12,
    0.45,
    -0.33,
    0.78,
    -0.56,
    0.91,
    -0.23,
    0.44,
    0.19,
    -0.67,
    0.88,
    -0.12,
    0.35,
    0.56,
    -0.44,
    0.77,
    0.11,
    -0.22,
    0.33,
    -0.11,
    0.25,
    0.66,
    -0.39,
    0.41,
    0.52,
    -0.63,
    0.71,
    -0.15,
    0.38,
    0.49,
    -0.72,
    0.83,
    0.14,
    -0.36,
    0.27,
    0.59,
    -0.46,
    0.62,
    -0.19,
    0.57,
    0.22,
    -0.54,
    0.68,
    -0.28,
    0.33,
    0.61,
    -0.42,
    0.74,
    0.17,
    -0.29,
    0.48,
    0.63,
    -0.51,
    0.69,
    -0.32,
    0.53,
    0.21,
    -0.47,
    0.72,
    -0.26,
    0.39,
    0.58,
    -0.41,
    0.75,
    0.15,
    -0.34,
    0.46,
    0.62,
    -0.48,
    0.67,
    -0.31,
    0.55,
    0.23,
    -0.49,
    0.71,
    -0.27,
    0.36,
    0.59,
    -0.43,
    0.76,
    0.18,
    -0.35,
    0.47,
    0.64,
    -0.52,
    0.7,
    -0.33,
    0.54,
    0.2,
    -0.46,
    0.73,
    -0.25,
    0.37,
    0.6,
    -0.4,
    0.78
  ]
}

Configuration:

Relevant Logs or Screenshots:

GET /_cluster/health

{
  "cluster_name": "docker-cluster",
  "status": "green",
  "timed_out": false,
  "number_of_nodes": 1,
  "number_of_data_nodes": 1,
  "discovered_master": true,
  "discovered_cluster_manager": true,
  "active_primary_shards": 6,
  "active_shards": 6,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 0,
  "delayed_unassigned_shards": 0,
  "number_of_pending_tasks": 0,
  "number_of_in_flight_fetch": 0,
  "task_max_waiting_in_queue_millis": 0,
  "active_shards_percent_as_number": 100
}

Hi @aithinep, There is already an issue raised for this here

You might be able to use a workaround using scripted_score and explain see below, however this query is very expensive, you would need to add strong filter inside script_score.query (e.g., date range, category, language) to shrink the candidate pool:

PUT _cluster/settings
{
  "transient": {
    "search.allow_expensive_queries": true
  }
}

PUT _search/pipeline/hybrid-debug
{
  "description": "Min-max + weighted arithmetic mean; includes hybrid score explanation",
  "phase_results_processors": [
    {
      "normalization-processor": {
        "normalization": { "technique": "min_max" },
        "combination": {
          "technique": "arithmetic_mean",
          "parameters": { "weights": [0.99, 0.01] }   // 2 weights = 2 subqueries
        }
      }
    }
  ],
  "response_processors": [
    { "hybrid_score_explanation": {} }
  ]
}

PUT products
{
  "settings": {
    "index": {
      "knn": true,
      "number_of_replicas": 0
    }
  },
  "mappings": {
    "properties": {
      "product_name": { "type": "text" },
      "text_vector":  { "type": "knn_vector", "dimension": 96 }
    }
  }
}

POST products/_doc/1
{
  "product_name": "Apple iPhone 15",
  "text_vector": [
    0.12,0.45,-0.33,0.78,-0.56,0.91,-0.23,0.44,0.19,-0.67,0.88,-0.12,0.35,0.56,-0.44,0.77,0.11,-0.22,0.33,-0.11,0.25,0.66,-0.39,0.41,0.52,-0.63,0.71,-0.15,0.38,0.49,-0.72,0.83,0.14,-0.36,0.27,0.59,-0.46,0.62,-0.19,0.57,0.22,-0.54,0.68,-0.28,0.33,0.61,-0.42,0.74,0.17,-0.29,0.48,0.63,-0.51,0.69,-0.32,0.53,0.21,-0.47,0.72,-0.26,0.39,0.58,-0.41,0.75,0.15,-0.34,0.46,0.62,-0.48,0.67,-0.31,0.55,0.23,-0.49,0.71,-0.27,0.36,0.59,-0.43,0.76,0.18,-0.35,0.47,0.64,-0.52,0.7,-0.33,0.54,0.2,-0.46,0.73,-0.25,0.37,0.6,-0.4,0.78]
}

POST products/_refresh

POST products/_search?search_pipeline=hybrid-debug&explain=true
{
  "size": 5,
  "query": {
    "hybrid": {
      "queries": [
        { "match": { "product_name": "iphone" } },
        {
          "script_score": {
            "query": { "match_all": {} }, 
            "script": {
              "lang": "knn",
              "source": "knn_score",
              "params": {
                "field": "text_vector",
                "query_value": [
                  0.11,0.40,-0.32,0.77,-0.55,0.92,-0.22,0.45,0.20,-0.65,0.89,-0.13,0.34,0.57,-0.46,0.79,0.15,-0.21,0.31,-0.12,0.28,0.65,-0.36,0.44,0.53,-0.62,0.70,-0.18,0.37,0.47,-0.73,0.81,0.14,-0.38,0.29,0.60,-0.48,0.63,-0.21,0.55,0.27,-0.53,0.67,-0.30,0.31,0.64,-0.40,0.72,0.18,-0.27,0.50,0.62,-0.54,0.65,-0.35,0.51,0.23,-0.43,0.73,-0.26,0.41,0.56,-0.37,0.74,0.16,-0.32,0.43,0.66,-0.51,0.68,-0.29,0.49,0.25,-0.42,0.76,-0.28,0.36,0.61,-0.39,0.78,0.19,-0.30,0.48,0.63,-0.52,0.72,-0.33,0.54,0.21,-0.47,0.79,-0.25,0.39,0.59,-0.41,0.81
                ],
                "space_type": "cosinesimil"
              }
            }
          }
        }
      ]
    }
  }
}

Expected result:

{
  "took": 119,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_shard": "[products][0]",
        "_node": "-ps8uS34RV-C21n1mWCzbg",
        "_index": "products",
        "_id": "1",
        "_score": 1,
        "_source": {
          "product_name": "Apple iPhone 15",
          "text_vector": [
            0.12,
            0.45,
            -0.33,
            0.78,
            -0.56,
            0.91,
            -0.23,
            0.44,
            0.19,
            -0.67,
            0.88,
            -0.12,
            0.35,
            0.56,
            -0.44,
            0.77,
            0.11,
            -0.22,
            0.33,
            -0.11,
            0.25,
            0.66,
            -0.39,
            0.41,
            0.52,
            -0.63,
            0.71,
            -0.15,
            0.38,
            0.49,
            -0.72,
            0.83,
            0.14,
            -0.36,
            0.27,
            0.59,
            -0.46,
            0.62,
            -0.19,
            0.57,
            0.22,
            -0.54,
            0.68,
            -0.28,
            0.33,
            0.61,
            -0.42,
            0.74,
            0.17,
            -0.29,
            0.48,
            0.63,
            -0.51,
            0.69,
            -0.32,
            0.53,
            0.21,
            -0.47,
            0.72,
            -0.26,
            0.39,
            0.58,
            -0.41,
            0.75,
            0.15,
            -0.34,
            0.46,
            0.62,
            -0.48,
            0.67,
            -0.31,
            0.55,
            0.23,
            -0.49,
            0.71,
            -0.27,
            0.36,
            0.59,
            -0.43,
            0.76,
            0.18,
            -0.35,
            0.47,
            0.64,
            -0.52,
            0.7,
            -0.33,
            0.54,
            0.2,
            -0.46,
            0.73,
            -0.25,
            0.37,
            0.6,
            -0.4,
            0.78
          ]
        },
        "_explanation": {
          "value": 1,
          "description": "arithmetic_mean, weights [0.99, 0.01] combination of:",
          "details": [
            {
              "value": 1,
              "description": "min_max normalization of:",
              "details": [
                {
                  "value": 0.2876821,
                  "description": "weight(product_name:iphone in 0) [PerFieldSimilarity], result of:",
                  "details": [
                    {
                      "value": 0.2876821,
                      "description": "score(freq=1.0), computed as boost * idf * tf from:",
                      "details": [
                        {
                          "value": 2.2,
                          "description": "boost",
                          "details": []
                        },
                        {
                          "value": 0.2876821,
                          "description": "idf, computed as log(1 + (N - n + 0.5) / (n + 0.5)) from:",
                          "details": [
                            {
                              "value": 1,
                              "description": "n, number of documents containing term",
                              "details": []
                            },
                            {
                              "value": 1,
                              "description": "N, total number of documents with field",
                              "details": []
                            }
                          ]
                        },
                        {
                          "value": 0.45454544,
                          "description": "tf, computed as freq / (freq + k1 * (1 - b + b * dl / avgdl)) from:",
                          "details": [
                            {
                              "value": 1,
                              "description": "freq, occurrences of term within document",
                              "details": []
                            },
                            {
                              "value": 1.2,
                              "description": "k1, term saturation parameter",
                              "details": []
                            },
                            {
                              "value": 0.75,
                              "description": "b, length normalization parameter",
                              "details": []
                            },
                            {
                              "value": 3,
                              "description": "dl, length of field",
                              "details": []
                            },
                            {
                              "value": 3,
                              "description": "avgdl, average length of field",
                              "details": []
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "value": 1,
              "description": "min_max normalization of:",
              "details": [
                {
                  "value": 0.9994249,
                  "description": "script score function, computed with script:\"Script{type=inline, lang='knn', idOrCode='knn_score', options={}, params={field=text_vector, query_value=[0.11, 0.4, -0.32, 0.77, -0.55, 0.92, -0.22, 0.45, 0.2, -0.65, 0.89, -0.13, 0.34, 0.57, -0.46, 0.79, 0.15, -0.21, 0.31, -0.12, 0.28, 0.65, -0.36, 0.44, 0.53, -0.62, 0.7, -0.18, 0.37, 0.47, -0.73, 0.81, 0.14, -0.38, 0.29, 0.6, -0.48, 0.63, -0.21, 0.55, 0.27, -0.53, 0.67, -0.3, 0.31, 0.64, -0.4, 0.72, 0.18, -0.27, 0.5, 0.62, -0.54, 0.65, -0.35, 0.51, 0.23, -0.43, 0.73, -0.26, 0.41, 0.56, -0.37, 0.74, 0.16, -0.32, 0.43, 0.66, -0.51, 0.68, -0.29, 0.49, 0.25, -0.42, 0.76, -0.28, 0.36, 0.61, -0.39, 0.78, 0.19, -0.3, 0.48, 0.63, -0.52, 0.72, -0.33, 0.54, 0.21, -0.47, 0.79, -0.25, 0.39, 0.59, -0.41, 0.81], space_type=cosinesimil}}\"",
                  "details": []
                }
              ]
            }
          ]
        }
      }
    ]
  }
}
2 Likes