From c109aa34e9908a4beef782257f964d8f04c37e3c Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Thu, 29 Aug 2024 09:25:12 -0700 Subject: [PATCH 1/2] Add presets for quick config fields Signed-off-by: Tyler Ohlsen --- .../new_workflow/quick_configure_inputs.tsx | 33 +++++++++++++++++++ public/pages/workflows/new_workflow/utils.ts | 26 ++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/public/pages/workflows/new_workflow/quick_configure_inputs.tsx b/public/pages/workflows/new_workflow/quick_configure_inputs.tsx index 02e6a7d7..0bd09472 100644 --- a/public/pages/workflows/new_workflow/quick_configure_inputs.tsx +++ b/public/pages/workflows/new_workflow/quick_configure_inputs.tsx @@ -28,6 +28,10 @@ interface QuickConfigureInputsProps { setFields(fields: QuickConfigureFields): void; } +const DEFAULT_TEXT_FIELD = 'my_text'; +const DEFAULT_VECTOR_FIELD = 'my_embedding'; +const DEFAULT_IMAGE_FIELD = 'my_image'; + // Dynamic component to allow optional input configuration fields for different use cases. // Hooks back to the parent component with such field values export function QuickConfigureInputs(props: QuickConfigureInputsProps) { @@ -50,6 +54,35 @@ export function QuickConfigureInputs(props: QuickConfigureInputsProps) { // Local field values state const [fieldValues, setFieldValues] = useState({}); + // on initial load, and when there are any deployed models found, set + // defaults for the field values for certain workflow types + useEffect(() => { + let defaultFieldValues = {} as QuickConfigureFields; + if ( + props.workflowType === WORKFLOW_TYPE.SEMANTIC_SEARCH || + props.workflowType === WORKFLOW_TYPE.MULTIMODAL_SEARCH || + props.workflowType === WORKFLOW_TYPE.HYBRID_SEARCH + ) { + defaultFieldValues = { + textField: DEFAULT_TEXT_FIELD, + vectorField: DEFAULT_VECTOR_FIELD, + }; + } + if (props.workflowType === WORKFLOW_TYPE.MULTIMODAL_SEARCH) { + defaultFieldValues = { + ...defaultFieldValues, + imageField: DEFAULT_IMAGE_FIELD, + }; + } + if (deployedModels.length > 0) { + defaultFieldValues = { + ...defaultFieldValues, + embeddingModelId: deployedModels[0].id, + }; + } + setFieldValues(defaultFieldValues); + }, [deployedModels]); + // Hook to update the parent field values useEffect(() => { props.setFields(fieldValues); diff --git a/public/pages/workflows/new_workflow/utils.ts b/public/pages/workflows/new_workflow/utils.ts index d41195b4..bd99d011 100644 --- a/public/pages/workflows/new_workflow/utils.ts +++ b/public/pages/workflows/new_workflow/utils.ts @@ -173,7 +173,9 @@ function fetchHybridSearchMetadata(): UIState { }); baseState.config.search.request.value = customStringify(TERM_QUERY); baseState.config.search.enrichResponse.processors = [ - new NormalizationProcessor().toObj(), + injectDefaultWeightsInNormalizationProcessor( + new NormalizationProcessor().toObj() + ), ]; baseState.config.search.enrichRequest.processors = [ injectQueryTemplateInProcessor( @@ -217,3 +219,25 @@ function injectQueryTemplateInProcessor( ); return processorConfig; } + +// set default weights for a normalization processor. assumes there is 2 queries, and equally +// balances the weight. We don't hardcode in the configuration, since we want to set +// invalid defaults for arbitrary use cases (e.g., more than 2 queries). In this case, we +// are already setting 2 queries by default, so we can make this assumption. +function injectDefaultWeightsInNormalizationProcessor( + processorConfig: IProcessorConfig +): IProcessorConfig { + processorConfig.optionalFields = processorConfig.optionalFields?.map( + (optionalField) => { + let updatedField = optionalField; + if (optionalField.id === 'weights') { + updatedField = { + ...updatedField, + value: '0.5, 0.5', + }; + } + return updatedField; + } + ); + return processorConfig; +} From deea78b8fa9e7849cbaedfd696d844541622cacb Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Thu, 29 Aug 2024 09:28:15 -0700 Subject: [PATCH 2/2] tune comment Signed-off-by: Tyler Ohlsen --- public/pages/workflows/new_workflow/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/pages/workflows/new_workflow/utils.ts b/public/pages/workflows/new_workflow/utils.ts index bd99d011..8988c739 100644 --- a/public/pages/workflows/new_workflow/utils.ts +++ b/public/pages/workflows/new_workflow/utils.ts @@ -221,7 +221,7 @@ function injectQueryTemplateInProcessor( } // set default weights for a normalization processor. assumes there is 2 queries, and equally -// balances the weight. We don't hardcode in the configuration, since we want to set +// balances the weight. We don't hardcode in the configuration, since we don't want to set // invalid defaults for arbitrary use cases (e.g., more than 2 queries). In this case, we // are already setting 2 queries by default, so we can make this assumption. function injectDefaultWeightsInNormalizationProcessor(