-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Search][Playground] Support Multiple Context Fields (#210703)
## Summary This PR updates the search playground to allow selecting > 1 context fields to be included in context documents for the LLM. ### Screenshots <img width="1399" alt="image" src="https://github.com/user-attachments/assets/76c6bd84-1dc6-4862-b822-a7fc3595cd69" /> Context Fields Updated to ComboBox: <img width="384" alt="image" src="https://github.com/user-attachments/assets/e246628b-4952-4832-9ac3-f2203700a667" /> ### Checklist - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed --------- Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
f67036b
commit ef2ec69
Showing
26 changed files
with
836 additions
and
214 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
...search/plugins/search_playground/public/components/edit_context/context_fields_select.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useMemo, useCallback } from 'react'; | ||
|
||
import { EuiCallOut, EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { QuerySourceFields } from '../../types'; | ||
|
||
export interface ContextFieldsSelectProps { | ||
indexName: string; | ||
indexFields: QuerySourceFields; | ||
selectedContextFields?: string[]; | ||
updateSelectedContextFields: (index: string, value: string[]) => void; | ||
} | ||
|
||
export const ContextFieldsSelect = ({ | ||
indexName, | ||
indexFields, | ||
selectedContextFields, | ||
updateSelectedContextFields, | ||
}: ContextFieldsSelectProps) => { | ||
const { options: selectOptions, selectedOptions } = useMemo(() => { | ||
if (!indexFields.source_fields?.length) return { options: [], selectedOptions: [] }; | ||
|
||
const options: Array<EuiComboBoxOptionOption<unknown>> = indexFields.source_fields.map( | ||
(field) => ({ | ||
label: field, | ||
'data-test-subj': `contextField-${field}`, | ||
}) | ||
); | ||
const selected: Array<EuiComboBoxOptionOption<unknown>> = | ||
selectedContextFields | ||
?.map((field) => options.find((opt) => opt.label === field)) | ||
?.filter( | ||
( | ||
val: EuiComboBoxOptionOption<unknown> | undefined | ||
): val is EuiComboBoxOptionOption<unknown> => val !== undefined | ||
) ?? []; | ||
return { | ||
options, | ||
selectedOptions: selected, | ||
}; | ||
}, [indexFields.source_fields, selectedContextFields]); | ||
const onSelectFields = useCallback( | ||
(updatedSelectedOptions: Array<EuiComboBoxOptionOption<unknown>>) => { | ||
// always require at least 1 selected field | ||
if (updatedSelectedOptions.length === 0) return; | ||
updateSelectedContextFields( | ||
indexName, | ||
updatedSelectedOptions.map((opt) => opt.label) | ||
); | ||
}, | ||
[indexName, updateSelectedContextFields] | ||
); | ||
|
||
if (selectOptions.length === 0) { | ||
return ( | ||
<EuiCallOut | ||
title={i18n.translate('xpack.searchPlayground.editContext.noSourceFieldWarning', { | ||
defaultMessage: 'No source fields found', | ||
})} | ||
color="warning" | ||
iconType="warning" | ||
size="s" | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<EuiComboBox | ||
data-test-subj={`contextFieldsSelectable-${indexName}`} | ||
options={selectOptions} | ||
selectedOptions={selectedOptions} | ||
onChange={onSelectFields} | ||
isClearable={false} | ||
fullWidth | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 100 additions & 5 deletions
105
...layground/public/components/view_code/examples/__snapshots__/py_lang_client.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.