Skip to content
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

Support fine-grained provisioning; handle more edge cases on search flow #268

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,25 @@ export type IndexConfig = {
settings: IConfigField;
};

// TODO: may expand to just IndexConfig (including mappings/settings info)
// if we want to persist this for users using some existing index,
// and want to pass that index config around.
export type SearchIndexConfig = {
name: IConfigField;
};

export type IngestConfig = {
enabled: boolean;
enabled: IConfigField;
source: {};
pipelineName: IConfigField;
enrich: ProcessorsConfig;
index: IndexConfig;
};

export type SearchConfig = {
request: IConfigField;
index: SearchIndexConfig;
pipelineName: IConfigField;
enrichRequest: ProcessorsConfig;
enrichResponse: ProcessorsConfig;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@ export function InputTransformModal(props: InputTransformModalProps) {
helpText={`An array specifying how to map fields from the ingested document to the model’s input.`}
helpLink={ML_INFERENCE_DOCS_LINK}
keyPlaceholder="Model input field"
valuePlaceholder="Document field"
valuePlaceholder={
props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST
? 'Query field'
: 'Document field'
}
keyOptions={props.inputFields}
onFormChange={props.onFormChange}
// If the map we are adding is the first one, populate the selected option to index 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,11 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
helpText={`An array specifying how to map fields from the ingested document to the model’s input.`}
helpLink={ML_INFERENCE_DOCS_LINK}
keyPlaceholder="Model input field"
valuePlaceholder="Document field"
valuePlaceholder={
props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST
? 'Query field'
: 'Document field'
}
onFormChange={props.onFormChange}
keyOptions={inputFields}
/>
Expand Down Expand Up @@ -273,7 +277,11 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
label="Output Map"
helpText={`An array specifying how to map the model’s output to new document fields.`}
helpLink={ML_INFERENCE_DOCS_LINK}
keyPlaceholder="New document field"
keyPlaceholder={
props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST
? 'Query field'
: 'Document field'
}
valuePlaceholder="Model output field"
onFormChange={props.onFormChange}
valueOptions={outputFields}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function OutputTransformModal(props: OutputTransformModalProps) {
const valuesWithoutOutputMapConfig = cloneDeep(values);
set(
valuesWithoutOutputMapConfig,
`ingest.enrich.${props.config.id}.outputMap`,
`ingest.enrich.${props.config.id}.output_map`,
[]
);
const curIngestPipeline = formikToPartialPipeline(
Expand Down Expand Up @@ -146,7 +146,7 @@ export function OutputTransformModal(props: OutputTransformModalProps) {
const valuesWithoutOutputMapConfig = cloneDeep(values);
set(
valuesWithoutOutputMapConfig,
`search.enrichResponse.${props.config.id}.outputMap`,
`search.enrichResponse.${props.config.id}.output_map`,
[]
);
const curSearchPipeline = formikToPartialPipeline(
Expand Down Expand Up @@ -226,7 +226,7 @@ export function OutputTransformModal(props: OutputTransformModalProps) {
label="Output Map"
helpText={`An array specifying how to map the model’s output to new fields.`}
helpLink={ML_INFERENCE_DOCS_LINK}
keyPlaceholder="New document field"
keyPlaceholder="Document field"
valuePlaceholder="Model output field"
valueOptions={props.outputFields}
onFormChange={props.onFormChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
EuiText,
EuiTitle,
} from '@elastic/eui';
import { SearchHit, WorkspaceFormValues } from '../../../../../common';
import { SearchHit, WorkflowFormValues } from '../../../../../common';
import { JsonField } from '../input_fields';
import {
AppState,
Expand All @@ -44,18 +44,27 @@ export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
const dispatch = useAppDispatch();

// Form state
const { values } = useFormikContext<WorkspaceFormValues>();
const indexName = values.ingest.index.name;
const { values, setFieldValue, setFieldTouched } = useFormikContext<
WorkflowFormValues
>();
const ingestEnabled = values.ingest.enabled;
const searchIndexNameFormPath = 'search.index.name';

// All indices state
const indices = useSelector((state: AppState) => state.opensearch.indices);

// Selected index state
const [selectedIndex, setSelectedIndex] = useState<string | undefined>(
undefined
values.search.index.name
);

// initial load: set the search index value, if not already set
useEffect(() => {
if (values.ingest.enabled) {
setFieldValue(searchIndexNameFormPath, values.ingest.index.name);
}
}, []);

// Edit modal state
const [isEditModalOpen, setIsEditModalOpen] = useState<boolean>(false);

Expand Down Expand Up @@ -116,7 +125,7 @@ export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
<EuiFlexItem grow={false}>
<EuiFormRow label="Retrieval index">
{ingestEnabled ? (
<EuiFieldText value={indexName} readOnly={true} />
<EuiFieldText value={values.ingest.index.name} readOnly={true} />
) : (
<EuiSuperSelect
options={Object.values(indices).map(
Expand All @@ -130,6 +139,9 @@ export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
valueOfSelected={selectedIndex}
onChange={(option) => {
setSelectedIndex(option);
setFieldValue(searchIndexNameFormPath, option);
setFieldTouched(searchIndexNameFormPath, true);
props.onFormChange();
}}
isInvalid={selectedIndex === undefined}
/>
Expand Down Expand Up @@ -165,7 +177,7 @@ export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
// see https://opensearch.org/docs/latest/search-plugins/search-pipelines/using-search-pipeline/#disabling-the-default-pipeline-for-a-request
dispatch(
searchIndex({
index: indexName,
index: values.search.index.name,
body: values.search.request,
searchPipeline: '_none',
})
Expand Down
Loading
Loading