Skip to content

Conversation

@kderusso
Copy link
Member

@kderusso kderusso commented Aug 26, 2025

This is a followup to #129369, but instead of using the highlighter to create snippets we chunk and score field content directly.

Allows users to configure the chunk sizes we use to generate snippets in the following ways:

  • Specifying chunking_settings in the request
  • Specifying a chunk_size in the request, which we use to construct a default chunking settings with that size
  • Not specifying, in which we construct a default chunking settings

Example API calls:

// Specifying chunking settings 
POST my-index/_search
{
  "track_total_hits": true,
  "fields": [
    "text"
  ],
  "retriever": {
    "text_similarity_reranker": {
      "retriever": {
        "standard": {
          "query": {
            "match": {
              "text": "What is the capital of the USA?"
            }
          }
        }
      },
      "field": "text",
      "chunk_rescorer": {
        "size": 3,
        "chunking_settings": {
          "strategy": "sentence",
          "max_chunk_size": 25,
          "sentence_overlap": 0
        }
      },
      "rank_window_size": 10,
      "inference_text": "What is the capital of the USA?"
    }
  }
}

// Only specifying chunk size, inferring sentence with 0 boundary 
POST my-index/_search
{
  "track_total_hits": true,
  "fields": [
    "text"
  ],
  "retriever": {
    "text_similarity_reranker": {
      "retriever": {
        "standard": {
          "query": {
            "match": {
              "text": "What is the capital of the USA?"
            }
          }
        }
      },
      "field": "text",
      "chunk_rescorer": {
        "size": 3,
        "chunking_settings": {
          "max_chunk_size": 25
        }
      },
      "rank_window_size": 10,
      "inference_text": "What is the capital of the USA?"
    }
  }
}

// Defaults
POST my-index/_search
{
  "track_total_hits": true,
  "fields": [
    "text"
  ],
  "retriever": {
    "text_similarity_reranker": {
      "retriever": {
        "standard": {
          "query": {
            "match": {
              "text": "What is the capital of the USA?"
            }
          }
        }
      },
      "field": "text",
      "chunk_rescorer": {},
      "rank_window_size": 10,
      "inference_text": "What is the capital of the USA?"
    }
  }
}

NOTE:

  • Specifying an inference ID to pull chunking settings is planned in a followup PR.

@kderusso kderusso added >enhancement :SearchOrg/Relevance Label for the Search (solution/org) Relevance team labels Aug 27, 2025
@kderusso kderusso marked this pull request as ready for review August 27, 2025 18:59
@kderusso kderusso requested a review from jimczi August 27, 2025 18:59
@elasticsearchmachine elasticsearchmachine added the Team:Search - Relevance The Search organization Search Relevance team label Aug 27, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-relevance (Team:Search - Relevance)

@elasticsearchmachine
Copy link
Collaborator

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

@kderusso kderusso requested a review from a team August 27, 2025 19:00
Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a very elegant solution @kderusso , I like where this is going.
I made some comment about the API, since we adopt chunking explicitly I think we need to remove the confusion with snippets.
The API could look like this:

{
    "text_similarity_reranker": {
        "inference_id": "my_rerank_inference_id",
        "field": "semantic_text_field",
        "chunk_scorer": {
            "top": 2,
            "chunking_settings": {
                "strategy": "sentence",
                "max_chunk_size": 128, 
                "sentence_overlap": 0
            }
        }
    }
}

We can also say that:

{
    "text_similarity_reranker": {
        "inference_id": "",
        "field": "semantic_text_field",
        "chunk_scorer": {
            "top": 2,
            "chunking_settings": {
                "max_chunk_size": 128
            }
         }
     }
}

is valid with good default for all fields as long as chunk_scorer is provided.
So something like:

{
    "text_similarity_reranker": {
        "inference_id": "",
        "field": "semantic_text_field",
        "chunk_scorer": {
            "top": 2
         }
     }
}

is valid too.

@kderusso kderusso requested a review from jimczi August 28, 2025 13:08
Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @kderusso , I left some nits about the API.
We should also remove the feature flag!

Copy link
Contributor

@jimczi jimczi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kderusso
Copy link
Member Author

kderusso commented Sep 9, 2025

@elasticmachine update branch

@kderusso
Copy link
Member Author

@elasticmachine update branch

@kderusso
Copy link
Member Author

@elasticmachine run elasticsearch-ci/pr-upgrade-part-2

@kderusso kderusso merged commit 436ec11 into elastic:main Sep 11, 2025
34 checks passed
kderusso added a commit to elastic/kibana that referenced this pull request Oct 3, 2025
elastic/elasticsearch#133576 introduced the
concept of a `chunk_rescorer` in the `text_similarity_reranker`
retriever. This PR adds the chunk rescorer to Dev Tools AutoComplete.


https://github.com/user-attachments/assets/9688a4ce-2cd5-40ad-ba8e-e8e69abed26e

---------

Co-authored-by: kibanamachine <[email protected]>
rylnd pushed a commit to rylnd/kibana that referenced this pull request Oct 17, 2025
elastic/elasticsearch#133576 introduced the
concept of a `chunk_rescorer` in the `text_similarity_reranker`
retriever. This PR adds the chunk rescorer to Dev Tools AutoComplete.


https://github.com/user-attachments/assets/9688a4ce-2cd5-40ad-ba8e-e8e69abed26e

---------

Co-authored-by: kibanamachine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :SearchOrg/Relevance Label for the Search (solution/org) Relevance team Team:Search - Relevance The Search organization Search Relevance team v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants