Skip to content

Conversation

@afoucret
Copy link
Contributor

@afoucret afoucret commented Jun 16, 2025

  • RERANK will only compute scores for the provided rows. We let the user append a SORT command explicitly if he want the rows to be sorted
  • Here is the minimum syntax for RERANK
| RERANK <query_text> ON <field> 
  • <query_text> : The query
  • <field>: Text field use as input for the rerank model
  • Using ON is consistent with other command syntax (LOOKUP JOIN and ENRICH are using it to specify a field to join/enrich on)
  • Default:
    • The rerank score is put into the _score column (overriding it if it already exists)
    • The inference endpoint is the one that is preconfigured for the Elastic Rerank model (.rerank-v1-elastic)
    • User will be able to override the output column for the score and the inference id using the optional parameters inferenceId and scoreColumn :
| RERANK <query_text> ON <field> WITH inferenceId=<inferenceId>, scoreColumn=<scoreColumn>

Additional notes:
RERANK does not sort the documents anymore. This give us the ability to add all the optimizers rules that were added on the COMPLETION command to RERANK too (such in PushDownAndCombineLimits )

Rerank command main issue: #124337

@cla-checker-service
Copy link

cla-checker-service bot commented Jun 16, 2025

💚 CLA has been signed

@afoucret afoucret force-pushed the rerank-refactoring branch 3 times, most recently from 4aec0dc to cc96232 Compare June 16, 2025 14:58
@afoucret afoucret force-pushed the rerank-refactoring branch from cc96232 to 1fdb090 Compare June 16, 2025 14:59
afoucret added 4 commits June 16, 2025 18:32
- Not sorting the data anymore
- Output the score in the specified column
- Applied additional logical plan optimizations since the plan is now a generating plan (because we removed the SORT clause)
- Updated tests
@afoucret afoucret force-pushed the rerank-refactoring branch from f503e74 to d388ff8 Compare June 17, 2025 10:12
@afoucret afoucret added >non-issue auto-backport Automatically create backport pull requests when merged :Analytics/ES|QL AKA ESQL v8.19.0 labels Jun 17, 2025
@afoucret afoucret marked this pull request as ready for review June 17, 2025 14:37
@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Jun 17, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@afoucret afoucret force-pushed the rerank-refactoring branch from 72ff951 to d86d16b Compare June 18, 2025 14:36
}

return refs.build();
return Rerank.computeReferences(rerankFields);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to add the scoreAttribute here as well the way we had it before.
I am just looking at what we do in the Analyzer when we resolve the score attribute.
If the child plan has the score attribute, we reuse it.

Copy link
Contributor Author

@afoucret afoucret Jun 19, 2025

Choose a reason for hiding this comment

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

It is not really needed to consider the target field as a reference, no matter if it exists before or not.
Indeed it is not really a reference because its value is never used / read by the plan.

Eval, Grok and other Generating plans are doing exactly the same and are not putting output fields in references.

Hope it makes sense.

@afoucret afoucret requested a review from ioanatia June 19, 2025 12:06
@afoucret afoucret merged commit 34ccaba into elastic:main Jun 19, 2025
27 checks passed
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.19 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 129488

@afoucret
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.19

Questions ?

Please refer to the Backport tool documentation

afoucret added a commit to afoucret/elasticsearch that referenced this pull request Jun 19, 2025
…9488)

(cherry picked from commit 34ccaba)

# Conflicts:
#	x-pack/plugin/esql/qa/testFixtures/src/main/resources/rerank.csv-spec
#	x-pack/plugin/esql/src/main/antlr/EsqlBaseParser.g4
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/logical/PushDownAndCombineFilters.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser.interp
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParser.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParserBaseListener.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParserBaseVisitor.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParserListener.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlBaseParserVisitor.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/LogicalPlanBuilder.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/inference/Rerank.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/planner/LocalExecutionPlanner.java
#	x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java
afoucret added a commit that referenced this pull request Jun 20, 2025
…9488) (#129718)

* [ES|QL] RERANK command - Updating the syntax and behavior (#129488)
kderusso pushed a commit to kderusso/elasticsearch that referenced this pull request Jun 23, 2025
mridula-s109 pushed a commit to mridula-s109/elasticsearch that referenced this pull request Jun 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL auto-backport Automatically create backport pull requests when merged backport pending >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.19.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants