# Using inner\_hits in knn search with rrf

**URL:** <https://discuss.elastic.co/t/using-inner-hits-in-knn-search-with-rrf/374086>\
**Category:** Elasticsearch\
**Tags:** vector-search\
**Created:** [February 4, 2025, 9:00pm UTC](https://discuss.elastic.co/t/using-inner-hits-in-knn-search-with-rrf/374086 "2025-02-04T21:00:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregp](https://avatars.discourse-cdn.com/v4/letter/g/c37758/32.png) [@gregp](https://discuss.elastic.co/u/gregp)\
**Post date:** [February 4, 2025, 9:00pm UTC](https://discuss.elastic.co/t/using-inner-hits-in-knn-search-with-rrf/374086/1 "2025-02-04T21:00:04Z")

</div>

I'm relatively new to elasticsearch and have a `knn` query that uses `inner_hits` to retrieve nested passages within a document. I want to combine this `knn` query with a matching query as part of a hybrid search, but I'm getting errrors.

I see on the `rrf` documentation ([here](https://www.elastic.co/guide/en/elasticsearch/reference/current/rrf.html#_inner_hits_in_rrf)) it should be possible, but looking at the documentation for the knn retriever for rrf ([here](https://www.elastic.co/guide/en/elasticsearch/reference/current/retriever.html#knn-retriever)) it doesn't mention `inner_hits` as one of the params.

Am I misunderstanding the capabilities of `rrf`?

Whenever I try running a query I get an error saying:

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "x_content_parse_exception",
        "reason": "[27:13] [knn] unknown field [inner_hits]"
      }
    ],
    "type": "x_content_parse_exception",
    "reason": "[27:27] [rrf] failed to parse field [retrievers]",
    "caused_by": {
      "type": "x_content_parse_exception",
      "reason": "[27:13] [knn] unknown field [inner_hits]"
    }
  },
  "status": 400
}

```

Here is the query I am running:

```auto
{
  "retriever": {
    "rrf": {
      "retrievers": [
        {
          "standard": {
            "query": {
              "match": {
                "extracted_text": {
                  "query": "${query}"
                }
              }
            }
          }
        },
        {
          "knn": {
            "k": 4,
            "field": "passages.passage_embedding.predicted_value",
            "num_candidates": 100,
            "query_vector_builder": {
              "text_embedding": {
                "model_id": "intfloat__multilingual-e5-large",
                "model_text": "${query}"
              }
            },
            "inner_hits": {
              "size": 4,
              "_source": {
                "includes": [
                  "passages.text",
                  "passages.title",
                  "passages.url"
                ]
              }
            }
          }
        }
      ],
      "rank_constant": 1,
      "rank_window_size": 10
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [February 5, 2025, 3:03am UTC](https://discuss.elastic.co/t/using-inner-hits-in-knn-search-with-rrf/374086/2 "2025-02-05T03:03:54Z")

</div>

Hi @gregp

I have my doubts if rff works with inner\_hits only with the [nested query](https://www.elastic.co/guide/en/elasticsearch/reference/current/rrf.html#_inner_hits_in_rrf). Maybe someone from the Elastic team can confirm this.

---

<div class="post-metadata">

**Author:** ![mayya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mayya/32/83147_2.png) [@mayya](https://discuss.elastic.co/u/mayya)\
**Post date:** [February 5, 2025, 1:55pm UTC](https://discuss.elastic.co/t/using-inner-hits-in-knn-search-with-rrf/374086/3 "2025-02-05T13:55:22Z")

</div>

Sorry, indeed knn retriever doesn't support inner\_hits. I've created an issue to add this [functionality](https://github.com/elastic/elasticsearch/issues/121763) .

Meanwhile, as a workaround instead of a knn retriever, you can use `standard` retriever with a nested knn query, like this:

```js
{
  "retriever": {
    "standard": {
      "query": {
        "nested": {
          "path": "paragraph",
          "inner_hits": {
            "size": 4,
            "_source": {
              "includes": [
                "paragraph.text"
              ]
            }
          },
          "query": {
            "knn": {
              "query_vector": [0.45, 45],
              "field": "paragraph.vector",
              "k": 2
            }
          }
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![gregp](https://avatars.discourse-cdn.com/v4/letter/g/c37758/32.png) [@gregp](https://discuss.elastic.co/u/gregp)\
**Post date:** [February 10, 2025, 7:34pm UTC](https://discuss.elastic.co/t/using-inner-hits-in-knn-search-with-rrf/374086/4 "2025-02-10T19:34:26Z")

</div>

Thank you! I will look into using this!
