Skip to content

Conversation

mridula-s109
Copy link
Contributor

Changes

  • RRFRetriever.retrievers: RetrieverContainer[]RRFRetrieverContainer[]
  • New RRFRetrieverContainer extends RetrieverContainer with optional weight?: float
  • Defaults to 1.0, must be non-negative

Related: elastic/elasticsearch#130658, elastic/elasticsearch#136477

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for weighted retrievers in the RRF (Reciprocal Rank Fusion) retriever by introducing a new weight parameter. The change allows individual retrievers to have different influence levels when combining their results.

  • Introduced RRFRetrieverContainer class extending RetrieverContainer with optional weight parameter
  • Updated RRFRetriever.retrievers type from RetrieverContainer[] to RRFRetrieverContainer[]
  • Added comprehensive documentation for the weight parameter behavior and constraints

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 2025

Following you can find the validation changes against the target branch for the API.

API Status Request Response
search 🔴 2588/2615 → 2590/2615 2615/2615

You can validate this API yourself by using the make validate target.

@leemthompo
Copy link
Contributor

You'll need to backport this to 9.2 right?

@mridula-s109 mridula-s109 added backport 9.2 and removed skip-backport This pull request should not be backported labels Oct 16, 2025
@mridula-s109 mridula-s109 reopened this Oct 16, 2025
@mridula-s109
Copy link
Contributor Author

You'll need to backport this to 9.2 right?

Thanks for the reminder! I've added the backport-9.2 label but the automation isn't triggering. Does the backport job only run after the PR is merged, or is there a specific way to trigger it manually?

@leemthompo
Copy link
Contributor

The backport job only runs after the PR is merged (if there are conflicts might need to use the manual backport tool to clean those up)

@flobernd
Copy link
Member

flobernd commented Oct 17, 2025

Thanks for the PR @mridula-s109 !

From looking at the JSON example provided in elastic/elasticsearch#130658, @pmpailis seems to be right that the structure is not correct this way.

"retrievers": [ // <- RRFRetriever.retrievers
  {
    "retriever": { // <- RRFRetrieverComponent.retriever
      "standard": { // <- RetrieverContainer variant
        "query": { "match": { "description": "pizza" } } 
      }
    },
    "weight": 0.7 // <- RRFRetrieverComponent.weigth
  },

I think it should rather look like this:

export class RRFRetrieverComponent { // name taken from the server code
  retriever: RetrieverContainer
  weigth?: float
}

and

// In RRFRetriever:
retrievers: RRFRetrieverComponent[]

Btw.: I'm a little bit surprised that we ship this breaking change in a minor release. Is this expected?

Side note: For container variants, it's important to mark all fields that are not actual variants with the @container_property tag (see here).

@pmpailis
Copy link
Contributor

pmpailis commented Oct 17, 2025

Btw.: I'm a little bit surprised that we ship this breaking change in a minor release. Is this expected?

I think that this is an extension, i.e. an alternative format that we support, and not a breaking change. The previous format has not gone away (which also implies some adjustments in this PR)

@flobernd
Copy link
Member

@pmpailis

I think that this is an extension, i.e. an alternative format that we support, and not a breaking change. The previous format has not gone away

Ah right, I just saw the corresponding test cases 👍

which also implies some adjustments in this PR

Unfortunately. This kind of extension will result in an untagged/undiscriminated union in the specification - which is the worst possible construct to have for all statically typed clients 😐

@Anaethelion
Copy link
Contributor

I have removed the 9.2 backport label.
This sadly comes too late for us to include in the release of clients, especially with an untagged union which causes a breaking change in the API.
Please for now merge to main, thank you!

@flobernd flobernd added the skip-backport This pull request should not be backported label Oct 22, 2025
@flobernd
Copy link
Member

@mridula-s109 Are you going to update the PR? Happy to assist, if you need help.

I would suggest something like this:

export class RRFRetrieverComponent { // name taken from the server code
  retriever: RetrieverContainer
  weigth?: float
}

export type RRFRetrieverDescriptor = RetrieverContainer | RRFRetrieverComponent;
// ^ naming is hard. Open for suggestions.
// In RRFRetriever:
retrievers: RRFRetrieverDescriptor[]

@mridula-s109
Copy link
Contributor Author

@mridula-s109 Are you going to update the PR? Happy to assist, if you need help.

I would suggest something like this:

export class RRFRetrieverComponent { // name taken from the server code
  retriever: RetrieverContainer
  weigth?: float
}

export type RRFRetrieverDescriptor = RetrieverContainer | RRFRetrieverComponent;
// ^ naming is hard. Open for suggestions.
// In RRFRetriever:
retrievers: RRFRetrieverDescriptor[]

Thanks for the suggestion @flobernd, Yes i will update the PR accordingly today and rerequest review on the same.

@mridula-s109 mridula-s109 requested a review from Copilot October 22, 2025 11:12
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

* Either a direct RetrieverContainer (backward compatible) or an RRFRetrieverComponent with weight.
* @codegen_names retriever, weighted
*/
export type RRFRetrieverEntry = RetrieverContainer | RRFRetrieverComponent
Copy link
Member

Choose a reason for hiding this comment

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

👍 that name fits better

export class RRFRetrieverComponent {
/** The nested retriever configuration. */
retriever: RetrieverContainer
/** Weight multiplier for this retriever's contribution to the RRF score. Higher values increase influence. Defaults to 1.0 if not specified. Must be non-negative. */
Copy link
Member

Choose a reason for hiding this comment

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

/nit: we should also add the @server_default tag as a machine readable alternative to mentioning the default value in the doc string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation skip-backport This pull request should not be backported specification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants