Skip to content

Commit

Permalink
Support fine-grained provisioning; handle more edge cases on search f…
Browse files Browse the repository at this point in the history
…low (#268) (#269)

Signed-off-by: Tyler Ohlsen <[email protected]>
(cherry picked from commit 1e4127c)

Co-authored-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and ohltyler authored Aug 7, 2024
1 parent 03b5c44 commit 74dd784
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 95 deletions.
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

0 comments on commit 74dd784

Please sign in to comment.