-
Notifications
You must be signed in to change notification settings - Fork 8.4k
[ES|QL] Add support for RRF
#221349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[ES|QL] Add support for RRF
#221349
Conversation
Pinging @elastic/kibana-esql (Team:ESQL) |
@elasticmachine merge upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, added some comments.
Also RRF is on snapshot releases (which means we are not ready to suggest them). With your changes it is going to appear and we don't want it.
I am not sure if utilizing the hidden flag is a correct decision here. Ideally I want to have hidden true if it is still on snaphsots and find another way to hide it when it makes sense only after specific commands.
cc @drewdaemon
import { parse } from '../parser'; | ||
|
||
describe('RRF', () => { | ||
describe('correctly formatted', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 describe methods are unecessary when you only have one test. But I think you should add some tests for errors too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ commit 80655cef7dd31f8c20a5da366432993d5c7801df
@@ -13,6 +13,14 @@ import { ESQLFieldWithMetadata } from '../validation/types'; | |||
import { fieldTypes } from '../definitions/types'; | |||
import { ESQLCallbacks } from '../shared/types'; | |||
|
|||
export const metadataFields: ESQLFieldWithMetadata[] = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have already declared the metadataFields here src/platform/packages/shared/kbn-esql-validation-autocomplete/src/tests/helpers.ts so no need to re-declare them here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stratoula couldn't find the tests folder, and the file in tests one is this same file 🤔
import { getCommandAutocompleteDefinitions } from '../../complete_items'; | ||
import { SuggestionRawDefinition } from '../../types'; | ||
|
||
export function commandsSuggestionsAfter(suggestions: SuggestionRawDefinition[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing the existing suggestions and add RRF you can change this method to return the extra commands and just populate them here [src/autocomplete/autocomplete.ts](https://github.com/elastic/kibana/pull/221349/files#diff-40ae50a3a9b3ffeaf11039070a8f527dc27264a985ba6378ac7c4b86e626ec55)
I think it will be a bit cleaner.
So this should be
return [
...getCommandAutocompleteDefinitions([
{
...(getCommandDefinition('rrf') as CommandDefinition<string>),
hidden: false,
},
]),
]
const lastCommand = root.commands[root.commands.length - 1]; | ||
const lastCommandDefinition = getCommandDefinition(lastCommand.name); | ||
|
||
if (lastCommandDefinition.commandsSuggestionsAfter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check my other comment. Let's change the commandsSuggestionsAfter
to only return the extra suggestions. So you won't need to reassign here, just push to the existing suggestions. I think it is cleaner
import type { SuggestionRawDefinition } from '../../types'; | ||
import { pipeCompleteItem } from '../../complete_items'; | ||
|
||
export function suggest(_params: CommandSuggestParams<'rrf'>): SuggestionRawDefinition[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function suggest(_params: CommandSuggestParams<'rrf'>): SuggestionRawDefinition[] { | |
export function suggest(): SuggestionRawDefinition[] { |
I don't think that this is needed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ 2130458
@@ -69,6 +70,8 @@ import { | |||
suggest as suggestForRename, | |||
fieldsSuggestionsAfter as fieldsSuggestionsAfterRename, | |||
} from '../autocomplete/commands/rename'; | |||
import { suggest as suggestForRrf } from '../autocomplete/commands/rrf'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically as we return only the pipe we don't need the extra folder, we can just add the code immediately here. @drewdaemon wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's planned to be added some customizations to the command, so at some point it'll become more complex. elastic/elasticsearch#123389
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be an internal thing and not something that will change the RRF syntax if I understand correctly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes just confirmed with ES
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stratoula I do lean toward keeping it this way because it might be confusing to see every command but one when I open the autocomplete/commands
directory. limit
is another very small and simple suggest function, but I think it is nice to have consistency.
That said, I really have no strong feelings here. I can see an argument for going the other way, too. WDYT
return { | ||
location: command.location, | ||
text: i18n.translate('kbn-esql-validation-autocomplete.esql.validation.rrfMissingMetadata', { | ||
defaultMessage: `[RRF] {metadataField} metadata must be selected in the FROM command.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the text 🤔
I would like something more obvious that it is in FROM .... METADATA option.
@andreadelrio it appears here, any suggestions?

values: { metadataField }, | ||
}), | ||
type: 'error', | ||
code: `rrfMissing${fieldName}Metadata`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You dont need a different code per field.
code: `rrfMissing${fieldName}Metadata`, | |
code: `rrfMissingMetadataField`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ 37b15c7
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Module Count
Public APIs missing comments
Page load bundle
History
|
This makes me wonder again if we should be treating RRF-after-FORK as a special case instead of trying to build a generic system for this. I don't think it's a bad system @sddonne has set up here, but the autocomplete refactor was supposed to fix the anti-pattern of adding "generic" properties to the command definitions to support quirks only found in a single command. If we just handled RRF as a one-off in the top-level suggest method it might
|
Summary
Part of #215092
Considerations
commandsSuggestionsAfter
The
RRF
command must be shown only immediately after a FORK command. To achieve this, the proposed solution is to keep thehidden
flag set totrue
for the lifetime of the command, and a new propertycommandsSuggestionsAfter
has been added to theCommandDefinition
interface, following the same concept asfieldsSuggestionsAfter
, this new method lets each command to alter the commands suggested after them, in this case, it's used byFORK
to add theRRF
command to the list. (If the approach is approved by the team, will add documentation about it.)Warning
This means that
RRF
will be activated when theFORK
command does. Thoughts?RRF
may change in the future@ioanatia has stated that the command may change in the future as it's not fully implemented yet.
Licence check
Will be addressed at #216791
Screen.Recording.2025-05-23.at.12.42.15.mov
New command support checklist
AST support
ESQLCommand<Name>
interface. If the syntax of your command cannot be decomposed only in parameters, you can hold extra information by extending theESQLCommand
interface. I.E., check the Rerank command.onExit
listeners atkbn-esql-ast/src/parser/esql_ast_builder_listener.ts
. Implement theonExit<COMMAND_NAME>
method based on the interface autogenerated by ANTLR and push the new node into the AST.Walker
API can visit the new node.Synth
API can construct the new node.Validating that the command works well when prettifying the query
Creating the command definition
kbn-esql-validation-autocomplete/src/definitions/commands.ts
.Adding the corresponding client-side validations
Adding the autocomplete suggestions
kbn-esql-validation-autocomplete/src/autocomplete/commands
for your command.suggest
function that should return an array of suggestions and set it up into the command definition.fieldsSuggestionsAfter
method to the command definition. Read this documentation to understand how it works.Checklist
Check the PR satisfies following conditions.
Reviewers should verify this PR satisfies this list as well.
release_note:breaking
label should be applied in these situations.release_note:*
label is applied per the guidelinesIdentify risks
Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss.
Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging.