Skip to content

Commit

Permalink
Add presets for quick config fields (#328)
Browse files Browse the repository at this point in the history
* Add presets for quick config fields

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

* tune comment

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>

---------

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
(cherry picked from commit 13ef723)
  • Loading branch information
ohltyler authored and github-actions[bot] committed Aug 29, 2024
1 parent e63d23c commit 72ca0d9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
33 changes: 33 additions & 0 deletions public/pages/workflows/new_workflow/quick_configure_inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -50,6 +54,35 @@ export function QuickConfigureInputs(props: QuickConfigureInputsProps) {
// Local field values state
const [fieldValues, setFieldValues] = useState<QuickConfigureFields>({});

// 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);
Expand Down
26 changes: 25 additions & 1 deletion public/pages/workflows/new_workflow/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 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(
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;
}

0 comments on commit 72ca0d9

Please sign in to comment.