# Weird results (and explanation) when combining KNN and ELSER in RRF

**URL:** <https://discuss.elastic.co/t/weird-results-and-explanation-when-combining-knn-and-elser-in-rrf/372897>\
**Category:** Elastic Search\
**Created:** [January 7, 2025, 2:16pm UTC](https://discuss.elastic.co/t/weird-results-and-explanation-when-combining-knn-and-elser-in-rrf/372897 "2025-01-07T14:16:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafael\_Melhem](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafael_melhem/32/137503_2.png) [@Rafael\_Melhem](https://discuss.elastic.co/u/Rafael_Melhem)\
**Post date:** [January 7, 2025, 2:16pm UTC](https://discuss.elastic.co/t/weird-results-and-explanation-when-combining-knn-and-elser-in-rrf/372897/1 "2025-01-07T14:16:55Z")

</div>

Hello, community,

I’m experiencing unexpected behavior in the `explain` output when using Elasticsearch with both ELSER and KNN in RRF. Specifically, the explanation details for KNN differ when executed alongside ELSER compared to running KNN alone. It is like when running together, the results are "combined", the part for method KNN EMBEDDING even has the "elser field" in the details:

```auto
"description": "Linear function on the complete_description_elser_embedding field for the ben feature, computed as w * S from:",

```

which sounds pretty weird to me, something I wouldn't expect since they are two different searches in my query and have different fields!

Would appreciate if someone could tell what's happening under the hood. Elasticsearch deployed version is 8.15.3. Codes were tested using both console and python client.

**Code 1:**

```auto
GET /my-index/_search?explain=true
{
  "_source": {
    "excludes": [
      "complete_description_elser_embedding",
      "complete_description_vector"
    ]
  },
  "retriever": {
    "rrf": {
      "retrievers": [
        {
          "standard": {
            "query": {
              "sparse_vector": {
                "field": "complete_description_elser_embedding",
                "inference_id": ".elser_model_2",
                "query": "term",
                "_name": " ***METHOD_ELSER***"
              }
            }
          }
        },
        {
          "standard": {
            "query": {
              "match": {
                "query": "term"
                
              }
            }
          }
        },
        {
          "knn": {
            "field": "complete_description_vector",
            "query_vector": "${embedding}",
            "k": 10,
            "num_candidates": 10,
            "_name": " ***METHOD_KNN_EMBEDDINGS***"
          }
        }
      ],
      "rank_constant": 1,
      "rank_window_size": 50
    }
  }
}

```

**Explanation results from Code 1:**  
(unexpected, at least for me)

```auto
      "matched_queries": [
          " ***METHOD_KNN_EMBEDDINGS***",
          " ***METHOD_ELSER***"
        ],
        "_explanation": {
          "value": 0.8333334,
          "description": "rrf score: [0.8333334] computed for initial ranks [2, 0, 1] with rankConstant: [1] as sum of [1 / (rank + rankConstant)] for each query",
          "details": [
            {
              "value": 2,
              "description": "rrf score: [0.33333334], for rank [2] in query [***METHOD_ELSER***] computed as [1 / (2 + 1]), for matching query with score: ",
              "details": [
                {
                  "value": 5.4686527,
                  "description": "Linear function on the complete_description_elser_embedding field for the 25 feature, computed as w * S from:",
                  "details": [
                    {
                      "value": 2.4221022,
                      "description": "w, weight of this function",
                      "details": []
                    },
                    {
                      "value": 2.2578125,
                      "description": "S, feature value",
                      "details": []
                    }
                  ]
                }
              ]
            },
            {
              "value": 0,
              "description": "rrf score: [0], result not found in query at index [1]",
              "details": []
            },
            {
              "value": 1,
              "description": "rrf score: [0.5], for rank [1] in query [***METHOD_KNN_EMBEDDINGS***] computed as [1 / (1 + 1]), for matching query with score: ",
              "details": [
                {
                  "value": 5.0325375,
                  "description": "Linear function on the complete_description_elser_embedding field for the ben feature, computed as w * S from:",
                  "details": [
                    {
                      "value": 2.368253,
                      "description": "w, weight of this function",
                      "details": []
                    },
                    {
                      "value": 2.125,
                      "description": "S, feature value",
                      "details": []
                    }
                  ]
                }
              ]
            }
          ]
        }

```

**Code 2:**

```auto
GET /my-index/_search?explain=true
{
  "_source": {
    "excludes": [
      "complete_description_elser_embedding",
      "complete_description_vector"
    ]
  },
  "retriever": {
    "rrf": {
      "retrievers": [
        {
          "standard": {
            "query": {
              "match": {
                "query": "term"
              }
            }
          }
        },
        {
          "knn": {
            "field": "complete_description_vector",
            "query_vector": "${embedding}",
            "k": 10,
            "num_candidates": 10,
            "_name": " ***METHOD_KNN_EMBEDDINGS***"
          }
        }
      ],
      "rank_constant": 1,
      "rank_window_size": 50
    }
  }
}

```

**Explanation results from Code 2:**  
(seems like the correct and expected behavior)

```auto
      "matched_queries": [
          " ***METHOD_KNN_EMBEDDINGS***"
        ],
        "_explanation": {
          "value": 0.5,
          "description": "rrf score: [0.5] computed for initial ranks [0, 1] with rankConstant: [1] as sum of [1 / (rank + rankConstant)] for each query",
          "details": [
            {
              "value": 0,
              "description": "rrf score: [0], result not found in query at index [0]",
              "details": []
            },
            {
              "value": 1,
              "description": "rrf score: [0.5], for rank [1] in query [***METHOD_KNN_EMBEDDINGS***] computed as [1 / (1 + 1]), for matching query with score: ",
              "details": [
                {
                  "value": 0.9523511,
                  "description": "within top k documents",
                  "details": []
                }
              ]
            }
          ]
        }
      },
      {

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 4, 2025, 2:17pm UTC](https://discuss.elastic.co/t/weird-results-and-explanation-when-combining-knn-and-elser-in-rrf/372897/2 "2025-02-04T14:17:33Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
